https://github.com/polychromatist/tree-sitter-motoko
tree-sitter for motoko
https://github.com/polychromatist/tree-sitter-motoko
dfinity helix-editor ic motoko motoko-language tree-sitter
Last synced: 10 months ago
JSON representation
tree-sitter for motoko
- Host: GitHub
- URL: https://github.com/polychromatist/tree-sitter-motoko
- Owner: polychromatist
- License: apache-2.0
- Created: 2022-11-02T05:08:22.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2023-04-13T12:12:02.000Z (about 3 years ago)
- Last Synced: 2024-10-28T12:46:45.417Z (over 1 year ago)
- Topics: dfinity, helix-editor, ic, motoko, motoko-language, tree-sitter
- Language: C
- Homepage:
- Size: 376 KB
- Stars: 4
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
## tree-sitter-motoko
Here you can find my attempt to reflect the [Motoko](https://github.com/dfinity/motoko) grammar into tree-sitter. Motoko is the language of the [Internet Computer](https://internetcomputer.org/), a web3 platform that serves HTTP requests through distributed, containerized applications called canisters.
The grammar used in this reflection is found [here](https://github.com/dfinity/motoko/blob/39d1b5e8a3fa8cecbd93fafad46bc22da58be584/doc/md/examples/grammar.txt).
In addition, the following non-standard syntax is supported:
- Motoko-san syntax, e.g. `assert:invariant` and the `implies` operator
- The `prim` keyword as used in determining a nullary type, e.g. `type Bool = prim "Bool"`
### Note about Whitespace
Motoko parses operators `" > "`, `" < "`, `" >>"` rather than `">"`, `"<"`, `">>"`. It is my understanding that the internal tree-sitter lexer takes this as a cue to, in contexts where these operators may be found, consume rather than skip the space character `0x20`. This may result in queries capturing whitespace as part of the text of a syntax node, which has results like syntax highlight queries decorating (e.g. underlining) whitespace that is ahead of the token. As far as I know, this discrepancy does not interact with the structural result of the syntax tree.