Tree-sitter grammar for the Almide programming language.
grammar.js mirrors the compiler's parser (crates/almide-syntax), including
its real operator-precedence table:
or < and < comparison (non-assoc) < |> (asymmetric) < ranges
< + - < * / % < ^ (right) < >> < unary < postfix (() [] . ! ? ?. ??)
|> is asymmetric — its right-hand side is a single call/compose chain, so
xs |> list.map(f) + ys parses as (xs |> list.map(f)) + ys, exactly like the
compiler (see test/corpus/precedence.txt). The executable truth upstream is
crates/almide-syntax/src/parser/test_expr_precedence.rs.
- Modules, imports (incl. selective
import mod.{ A, b }), functions (incl. convention methodsfn Type.method,mut/ default parameters), types (records with field defaults, variants, conventions clausetype Name: Eq, Repr), protocols, tests,strict - Attributes:
@extern(...),@intrinsic("..."),@name(args), named arguments@deprecated(since=3, use="??") - Effect system (
effect fn),guard/guard let,fan { a, b }and thefan.settle/fan.any/fan.race(n)/fan.bounded(b)/fan.timeout(d)heads - Pattern matching with guards, list patterns, negative literals, record rest,
module-qualified cases (
core.ErrConfig(m) =>);if let x = v { } else { } - Pipe (
|>, incl.x |> match { ... }), compose (>>), postfix!??.?? - Generic types with
[]syntax; function typesfn(A) -> B/(A) -> B,effect (A) -> B;T?for Option (ADR-0010); fallible returns-> T!and-> T!E; module-qualified typescore.Usage;(T?)? - Module-qualified records, cases and constants in expressions:
live.Request { ... },core.FinishStop,ask.MODEL_WORK - Assignments as
ifbranches,(expr: Type)ascription,((k, v)) =>lambda parameters, trailing commas in calls - String interpolation, single-quote strings, heredocs, raw strings
- Comments:
//and/* ... */
Queries in queries/:
highlights.scm— syntax highlightingtags.scm— the symbol index repo-map tools build from (@definition.function/.type/.interface/.method/.constant/.test, and@reference.call/.module). Every@definition.*spans the whole declaration;@nameinside it is the identifier the index is keyed by.
Keyword and precedence data mirrors almide-grammar, the descriptive single source of truth for Almide syntax.
Note: an earlier iteration generated
grammar.jsfrom an Almide-written generator (generator/). That generator bit-rotted against the modern language (it used removed syntax like++andfn(x) =>lambdas) and fell far behind the hand-maintained grammar, so it was removed;grammar.jsis the maintained source for now. Restoring an at-parity Almide generator is tracked in the issues.
Checked against real code as well as the corpus: every .almd file in the
compiler's stdlib/ and examples/, and in almai, comide, golemide, gramide
and hew, parses with no ERROR node.
Almide source files use the .almd extension.
[dependencies]
tree-sitter-almide = { git = "https://github.com/almide/tree-sitter-almide" }
tree-sitter-language = "0.1"use tree_sitter_almide::LANGUAGE;
let mut parser = tree_sitter::Parser::new();
parser.set_language(&LANGUAGE.into()).unwrap();
let tree = parser.parse(source, None).unwrap();const Parser = require("tree-sitter");
const Almide = require("tree-sitter-almide");
const parser = new Parser();
parser.setLanguage(Almide);
const tree = parser.parse(source);tree-sitter generate # grammar.js → src/parser.c
tree-sitter test # run test/corpus/MIT