/tree-sitter-metamodelica

A tree-sitter parser for MetaModelica

Primary LanguageJavaScriptOtherNOASSERTION

build-parser

tree-sitter-metamodelica

An open-source MetaModelica (MetaModelica 2.0) grammar and highlighting-query for tree-sitter.

Dependencies

  • Node.js
  • Docker

Installation

npm install
npm run build

Unit Tests

There is a number of tests included. To run all tests defined in test/ just run:

npm run test

Examples

To test the parser on a MetaModelica file run:

npx tree-sitter parse examples/Main.mo

Highlighting

There is also a highlighting query included. Make sure that the tree-sitter per-user configuration are pointing to the parent directory of tree-sitter-metamodelica. So if this directory is in /home/USER/workspace/tree-sitter-metamodelica add /home/USER/workspace to the parser directories:

config.json

{
  "parser-directories": [
    "/home/USER/workspace"
  ],
}

To test the highlighting configure run:

npx tree-sitter highlight examples/Main.mo

Tags

tree-sitter-metamodelica supports tagging for code navigation systems to provide a list of all definitions.

npx tree-sitter tags examples/Main.mo

Usage

Use Web Tree-sitter tree-sitter-metamodelica.wasm in your application:

import * as Parser from 'web-tree-sitter'

await Parser.init()
const parser = new Parser

const MetaModelica = await Parser.Language.load(`tree-sitter-metamodelica.wasm`)
parser.setLanguage(MetaModelica)

Current Status

tree-sitter-metamodelica has been tested on all of the MetaModelica files of the OpenModelica Compiler and can parse all but the following features:

  • Susan / Template interface packages
  • code_equations
npx tree-sitter parse examples/Main.mo
npx tree-sitter highlight examples/Main.mo
npx tree-sitter tags examples/Main.mo