Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/openmodelica/tree-sitter-modelica
A tree-sitter parser for Modelica
https://github.com/openmodelica/tree-sitter-modelica
Last synced: about 1 month ago
JSON representation
A tree-sitter parser for Modelica
- Host: GitHub
- URL: https://github.com/openmodelica/tree-sitter-modelica
- Owner: OpenModelica
- License: other
- Created: 2022-01-27T18:46:03.000Z (almost 3 years ago)
- Default Branch: master
- Last Pushed: 2024-04-18T10:11:09.000Z (9 months ago)
- Last Synced: 2024-06-11T17:53:36.953Z (7 months ago)
- Language: JavaScript
- Size: 338 KB
- Stars: 3
- Watchers: 21
- Forks: 5
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
[![build-parser](https://github.com/OpenModelica/tree-sitter-modelica/actions/workflows/build-parser.yml/badge.svg)](https://github.com/OpenModelica/tree-sitter-modelica/actions/workflows/build-parser.yml)
# tree-sitter-modelica
An [open-source](OSMC-License.txt) Modelica
([Modelica Language Specification v3.5](https://specification.modelica.org/maint/3.5/MLS.html))
grammar and highlighting-query for
[tree-sitter](https://github.com/tree-sitter/tree-sitter).## Dependencies
- Node.js
- Docker## Installation
```bash
npm install
npm run build
```To generate the C code to parse Modelica run:
```bash
npx tree-sitter generate
```> [!NOTE]
> If you have ./node_modules/.bin in your `PATH` environment variable you can skip `npx`
> ```bash
> tree-sitter generate
> ```## Unit Tests
There is a number of tests included. To run all tests defined in [test/](./test/) just run:
```bash
npx tree-sitter test
```### Examples
To test the parser on a Modelica file run:
```bash
npx tree-sitter parse examples/SimpleMath.mo
```## Highlighting
There is also a highlighting query included.
Make sure that the
[tree-sitter per-user configuration](https://tree-sitter.github.io/tree-sitter/syntax-highlighting#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**
```json
{
"parser-directories": [
"/home/USER/workspace"
],
}
```To test the highlighting configure run:
```bash
npx tree-sitter highlight examples/SimpleMath.mo
```## Usage
Use [Web Tree-sitter](https://github.com/tree-sitter/tree-sitter/blob/master/lib/binding_web/README.md)
`tree-sitter-modelica.wasm` in your application:```typescript
import * as Parser from 'web-tree-sitter'await Parser.init()
const parser = new Parserconst 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](./examples/DrumBoiler.mo) which was
successfully parsed and highlighted.```bash
npx tree-sitter parse examples/DrumBoiler.mo
npx tree-sitter highlight examples/DrumBoiler.mo
```