Skip to content

polychromatist/tree-sitter-motoko

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

tree-sitter-motoko

Here you can find my attempt to reflect the Motoko grammar into tree-sitter. Motoko is the language of the Internet Computer, a web3 platform that serves HTTP requests through distributed, containerized applications called canisters.

The grammar used in this reflection is found here.

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.