Experimental documentation — Work in progress
This page has not completed the documentation audit. Current documentation version: experimental.
Parser
The strict parser consumes the token stream and constructs typed,
ownership-safe Sagan syntax trees with source-spanned diagnostics. The separate
compiler-owned src/syntax layer wraps it for editor workloads, retaining
trivia and exact source while recovering independent top-level declarations
after malformed or incomplete input.
Implemented slices
- Programs and newline-separated declarations and executable root statements
- Single-name
letdeclarations with optional type annotations and initializers; parallelletdeclarations with one initializer per name constdeclarations with mandatory initializers and ASCIISCREAMING_SNAKE_CASEnames- Identifier, numeric, Boolean, and grouped primary expressions
- Prefix and postfix operators
- Calls with zero or more arguments
- Indexing, member access, safe member access, and chained postfix expressions
- Ruby-style mutating method names such as
normalize!() - Ordinary, raw, and multiline string expressions
- Interpolated strings with complete embedded expressions
- Arrays and dictionaries, including empty forms and expression keys
- Cartesian vectors and points with a minimum of two elements
- Exactly three-component spherical vectors and points using adjacent
s<...>ands(...) - Trailing commas in calls and every collection form
- Spread expressions and dictionary spread entries
- Right-associative exponentiation
- Multiplicative and additive arithmetic
- Non-chainable comparisons and equality expressions
- Logical
andandor - Conditional expressions
- Right-associative value-producing
:=assignment - Statement blocks, including empty and nested blocks, plus same-line single-statement control-flow bodies
- Ordinary and compound (
+=,-=,*=,/=,%=,^=) assignment statements, parallel reassignment, plus expression statements inside blocks if/elsestatements andelse ifchainsfor/in,while, anduntilloops- Unlabeled
breakandcontinue, restricted to loop bodies - Bare and value-bearing
returnstatements - Bare and value-bearing
yieldstatements - Braced or same-line single-statement
match/case, with an optional finalcase else hope/unless/finallyexception regions and value-bearingscreamfacesignatures and default methods, plusis/hascomposition listsclassfields, methods, leading-dot private methods, andself- Newline- or comma-separated enum members, including typed payloads and explicit numeric tags
- Documentation comments on individual enum members
- Named block- or expression-bodied functions with optional annotations
- Anonymous expression-bodied lambdas with optional annotations
- One optional leading
moduledeclaration per source file - Top-level
importdeclarations with optionalfromandasclauses - Standalone top-level
exportdeclarations with optional aliases - Enum cases with zero or more typed payload declarations
- Declaration-attached
///and/** ... */documentation comments with retained source spans and focused placement diagnostics - Script-style root statements; imported modules are checked separately to remain declaration-only
- Human-readable AST output and success/error demonstrations
- DOT and standalone SVG AST rendering
- A self-contained HTML view that places source input beside the visual tree
Inspecting a tree
The quickest visual demonstration is:
It parses examples/ast.sagan, writes
build/ast-demo.html, and opens
the page in the default Windows browser. The page embeds its SVG tree and has no
Graphviz or network dependency. Its controls provide zoom in, zoom out, fit,
and 100% views; the mouse wheel zooms around the pointer and dragging pans the
tree. Pass --no-open when only the generated file is wanted.
Text, DOT, SVG, and HTML are also available from bin/sagan through --ast,
--ast-dot, --ast-svg, and --ast-html respectively. The renderer currently
supports every AST node the parser can produce; new node kinds must be added to
the renderer as their parser slices land.
Focused diagnostics cover malformed assignments, postfix and member access,
control flow, declarations and types, string interpolation, collections,
matching, exceptions, lambdas, modules, documentation-comment placement, and
other established grammar rules. bash tests/integration/parser_test.sh runs
the broad successful fixture and focused failure fixtures together. Run
make editor-tooling-demo to see deliberately incomplete source produce
multiple structured diagnostics and a recovered compiler result.
The parser now covers the complete current concrete grammar. Strict compilation still rejects the first malformed construct; editor analysis instead provides bounded recovery without loosening the language grammar.