Parsing

Tree-sitter is used to generate a concrete syntax tree from a MiniZinc model. The grammar is located in the parsers/tree-sitter-minizinc/grammar.js file. There is also a corpus of tests which can be run to test the parser's output.

Since this concrete syntax tree is too low level to perform most useful compilation steps, an abstract syntax tree will be constructed (with the AST nodes linked to the related CST nodes) during AST generation.

Example

The model

test foo() = true;
function bool: bar() = true;
var 1..3: x;

Gives the CST

kind="source_file", named=true, has_error=false, error=false, missing=false, extra=false, field=None
  kind="predicate", named=true, has_error=false, error=false, missing=false, extra=false, field=Some("item")
    kind="test", named=false, has_error=false, error=false, missing=false, extra=false, field=Some("type")
    kind="identifier", named=true, has_error=false, error=false, missing=false, extra=false, field=Some("name")
    kind="(", named=false, has_error=false, error=false, missing=false, extra=false, field=None
    kind=")", named=false, has_error=false, error=false, missing=false, extra=false, field=None
    kind="=", named=false, has_error=false, error=false, missing=false, extra=false, field=None
    kind="boolean_literal", named=true, has_error=false, error=false, missing=false, extra=false, field=Some("body")
      kind="true", named=false, has_error=false, error=false, missing=false, extra=false, field=None
  kind=";", named=false, has_error=false, error=false, missing=false, extra=false, field=None
  kind="function_item", named=true, has_error=false, error=false, missing=false, extra=false, field=Some("item")
    kind="function", named=false, has_error=false, error=false, missing=false, extra=false, field=None
    kind="type_base", named=true, has_error=false, error=false, missing=false, extra=false, field=Some("type")
      kind="primitive_type", named=true, has_error=false, error=false, missing=false, extra=false, field=Some("domain")
        kind="bool", named=false, has_error=false, error=false, missing=false, extra=false, field=None
    kind=":", named=false, has_error=false, error=false, missing=false, extra=false, field=None
    kind="identifier", named=true, has_error=false, error=false, missing=false, extra=false, field=Some("name")
    kind="(", named=false, has_error=false, error=false, missing=false, extra=false, field=None
    kind=")", named=false, has_error=false, error=false, missing=false, extra=false, field=None
    kind="=", named=false, has_error=false, error=false, missing=false, extra=false, field=None
    kind="boolean_literal", named=true, has_error=false, error=false, missing=false, extra=false, field=Some("body")
      kind="true", named=false, has_error=false, error=false, missing=false, extra=false, field=None
  kind=";", named=false, has_error=false, error=false, missing=false, extra=false, field=None
  kind="declaration", named=true, has_error=false, error=false, missing=false, extra=false, field=Some("item")
    kind="type_base", named=true, has_error=false, error=false, missing=false, extra=false, field=Some("type")
      kind="var", named=false, has_error=false, error=false, missing=false, extra=false, field=Some("var_par")
      kind="infix_operator", named=true, has_error=false, error=false, missing=false, extra=false, field=Some("domain")
        kind="integer_literal", named=true, has_error=false, error=false, missing=false, extra=false, field=Some("left")
        kind="..", named=false, has_error=false, error=false, missing=false, extra=false, field=Some("operator")
        kind="integer_literal", named=true, has_error=false, error=false, missing=false, extra=false, field=Some("right")
    kind=":", named=false, has_error=false, error=false, missing=false, extra=false, field=None
    kind="identifier", named=true, has_error=false, error=false, missing=false, extra=false, field=Some("name")
  kind=";", named=false, has_error=false, error=false, missing=false, extra=false, field=None