A TOPAS-Academic grammar for Tree-sitter.
This grammar can be setup within Neovim to provide highlighting for .inp files.
It requires:
- Neovim 0.10 or newer.
- Nvim-treesitter
- Git
- A C compiler
-
Add the following Lua snippet to your
init.vimorinit.lua:vim.filetype.add { extension = { inp = 'topas', } } local parser_config = require "nvim-treesitter.parsers".get_parser_configs() parser_config.topas = { install_info = { url = "https://github.com/JamesDoingStuff/tree-sitter-topas", -- can be replaced with path to cloned repo files = {"src/parser.c"}, branch = "main", requires_generate_from_grammar = false, }, filetype = "inp", } require'nvim-treesitter.configs'.setup{ highlight={ enable = true, additional_vim_regex_highlighting = false, }, }
-
To apply highlights to a file, queries are used to match up nodes of the syntax tree, such as
(identifier), to a pre-configured higlight group, such asvariable.The highlights file cannot yet be installed automatically; download highlights.scm from this repository and add it to a location within your Neovim runtime path inside a directory named
queries/topas/e.g.,.config/nvim/queries/topas/highlights.scm -
Open Neovim and run
:TSInstall topas. Once the installation has completed, highlighting should be active for TOPAS. Check by running:checkhealth nvim-treesitterand looking for a tick in the first column of the row labelledtopas.
Through a third-party extension, this grammar can be used to provide semantic highlighting for TOPAS .inp files in Visual Studio Code.
Requirements:
- VS Code
- The tree-sitter-vscode extension
-
You will also need local copies of
tree-sitter-topas.wasmandhighlights.scm, included in each release. Experimental versions of the .wasm file can also be sourced as artifacts of the CI workflow. -
In the
package.jsonfor the tree-sitter-vscode extension, add the following key to the "contributes" section:"languages": [ { "id": "topas", "extensions": [ ".inp" ] } ]
If you are having trouble locating the
package.json, bring up the command palette (Ctrl+shift+P), use the command> Extensions: Open extensions folder, then look in the folderalecghost.tree-sitter-vscode-0.0.1 -
In that same file, change the
activationEventsarray to the following:"activationEvents": [ "onLanguage:topas" ]
-
In your
settings.json(> Open user settings (JSON)), add the following, updating the file paths to point to the respective files:"tree-sitter-vscode.languageConfigs": [ { "lang": "topas", "parser": "/path/to/tree-sitter-topas.wasm", "highlights": "/path/to/highlights.scm" } ]
-
Now, a
.inpfile should register as having a language mode of 'topas' in the lower right corner of VS Code. To turn on highlighting, open settings (Ctrl+,), search for 'semantic highlighting' and make sureEditor > Semantic Higlightingis enabled.
- Comments
- Numbers
- Strings
- Macro declarations
- Macro invocations
- Preprocessor directives
- Unary operators
- Binary operators
- Equations
- Refinement signallers
- Variable declaration keywords (
prm,local) -
existing_prmkeyword -
sitedeclaration keywords - Unstructured keyword identification
- Built-in maths functions
- Structured keywords
- File path strings
- Data blocks { ... }
- Function declarations (
fnkeyword) - If statements (
ifkeyword)