An open-source Modelica (Modelica Language Specification v3.5) grammar and highlighting-query for tree-sitter.
- Node.js
- Docker
npm install
npm run buildTo generate the C code to parse Modelica run:
npx tree-sitter generateNote
If you have ./node_modules/.bin in your PATH environment variable you can skip npx
tree-sitter generateThere is a number of tests included. To run all tests defined in test/ just run:
npx tree-sitter testTo test the parser on a Modelica file run:
npx tree-sitter parse examples/SimpleMath.moThere 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.moUse 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)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