Skip to content

OpenModelica/tree-sitter-modelica

Repository files navigation

build-parser

tree-sitter-modelica

An open-source Modelica (Modelica Language Specification v3.5) grammar and highlighting-query for tree-sitter.

Dependencies

  • Node.js
  • Docker

Installation

npm install
npm run build

To generate the C code to parse Modelica run:

npx tree-sitter generate

Note

If you have ./node_modules/.bin in your PATH environment variable you can skip npx

tree-sitter generate

Unit Tests

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

npx tree-sitter test

Examples

To test the parser on a Modelica file run:

npx tree-sitter parse examples/SimpleMath.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-modelica. So if this directory is in /home/USER/workspace/tree-sitter-modelica 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/SimpleMath.mo

Usage

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

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

await Parser.init()
const parser = new Parser

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

Current Status

Tree-sitter-modelica has been tested on a "Save Total" version of the Modelica.Fluid.Examples.DrumBoiler.DrumBoiler which was successfully parsed and highlighted.

npx tree-sitter parse examples/DrumBoiler.mo
npx tree-sitter highlight examples/DrumBoiler.mo