Skip to content

JamesDoingStuff/tree-sitter-topas

Repository files navigation

Tree-sitter TOPAS

A TOPAS-Academic grammar for Tree-sitter.

Usage

Neovim

This grammar can be setup within Neovim to provide highlighting for .inp files. It requires:

  1. Add the following Lua snippet to your init.vim or init.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,
      },
    }
  2. 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 as variable.

    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

  3. Open Neovim and run :TSInstall topas. Once the installation has completed, highlighting should be active for TOPAS. Check by running :checkhealth nvim-treesitter and looking for a tick in the first column of the row labelled topas.

VS Code

Through a third-party extension, this grammar can be used to provide semantic highlighting for TOPAS .inp files in Visual Studio Code.

Requirements:

  1. You will also need local copies of tree-sitter-topas.wasm and highlights.scm, included in each release. Experimental versions of the .wasm file can also be sourced as artifacts of the CI workflow.

  2. In the package.json for 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 folder alecghost.tree-sitter-vscode-0.0.1

  3. In that same file, change the activationEvents array to the following:

    "activationEvents": [
       "onLanguage:topas"
     ]
  4. 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"
       }
     ]
  5. Now, a .inp file 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 sure Editor > Semantic Higlighting is enabled.

Features

  • Comments
  • Numbers
  • Strings
  • Macro declarations
  • Macro invocations
  • Preprocessor directives
  • Unary operators
  • Binary operators
  • Equations
  • Refinement signallers
  • Variable declaration keywords (prm, local)
  • existing_prm keyword
  • site declaration keywords
  • Unstructured keyword identification
  • Built-in maths functions
  • Structured keywords
  • File path strings
  • Data blocks { ... }
  • Function declarations (fn keyword)
  • If statements (if keyword)

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 2

  •  
  •  

Languages