A tree-sitter grammar for the
Ante programming language (.an files).
Covers the surface syntax of Ante, including:
- Significant indentation via a hand-written external scanner
(
src/scanner.c) —INDENT/DEDENT/NEWLINEwith Ante's context-sensitive "semicolon inference" (an indented line only opens a block after a token that expects one, otherwise it continues the current expression). - Definitions: functions, methods (
Type.method), operators ((+) x y = …,(.*) = …), value bindings and irrefutable destructuring. - Types: structs, tagged unions, aliases, type application, function types with
closure environments (
[env]) and effect rows ({Fail}), references,forall. - Expressions: full operator-precedence table, application by juxtaposition,
member access / indexing / deref, lambdas and trailing lambdas,
_placeholders, named constructors (T with …), string interpolation. - Control flow:
if/then/else,match,while,for,loop/recur, effecthandler … for … in …,doblocks and thunks. - Abilities & effects:
ability,impl … with,implicit. - Comments: line (
//), doc (///), and block (/* … */).
tree-sitter generate # build src/parser.c from grammar.js (+ scanner.c)
tree-sitter test # run the corpus in test/corpus/
tree-sitter parse FILE.an # print a parse treeThe grammar parses 214 of 215 valid files across the Ante compiler's
stdlib/src and examples trees with zero ERROR/MISSING nodes (the
examples/parser directory is excluded because it intentionally contains
syntactically invalid programs that exercise the compiler's error recovery).
- A trailing
dothunk whose body is written at the same indentation as its call (e.g.panic_on_fail dofollowed by same-indent statements) is not yet handled;doblocks that are indented or inline parse fine. - Block comments (
/* … */) do not yet nest, though Ante allows nesting. - The strict indentation-consistency checks (all-spaces-or-all-tabs, 2-space minimum) are not enforced — well-formed input parses regardless.
- The generated
src/parser.cis large (~21k parse states) because Ante's juxtaposition-based application, significant indentation, and shared expression/pattern syntax are highly ambiguous. A future pass could shrink it by layering the expression grammar to remove some GLR conflicts.
