Implement parser steps 00-20: crate scaffold, AST + dump, type grammar #6
Loading…
Reference in a new issue
No description provided.
Delete branch "parser/implementation"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Parser implementation — steps 00, 10, 20
Implements the first three steps of the
docs/parser/decomposition on theparser/implementationbranch. The parse phase's crate boundary, AST shape, golden-dump test contract, and the type-reference grammar are in place; statements/expressions/functions/user-types/top-level (steps 30–70) come next.Commits
parser: scaffold the parser crate under the workspace (step 00)— newparser/workspace member linking againstlexer;parse(tokens) -> Result<Program, ParseError>entrypoint; empty-program test passes from day one.parser: declare AST backbone + golden dump inspector (step 10)— full AST node families (decl/type/stmt/expr) as tagged structs, every node carrying its sourceSpan, and the recursivedump()S-expression inspector that makes every later step's unit test a one-line golden assertion (the parser's equivalent of the lexer'scheck_kind).parser: type-reference grammar over tokens (step 20)—parse_type_ref()and the binding chain behind every annotation: type unions (A | B | C, loosest), the?/*/[]prefixes (*binds tighter than|), static[N]Tvs dynamic[]T/[..]Tarrays, named/qualified types with optional<T, U>generics, tuple types(T1, U), and function types(T1,U) -> R.parser: dump array types as ([] T) / ([N] T)— finalizes the array dump spelling.Design decision (settled in review)
Spanis a standard-library type name, not a reserved keyword. The old lexer reserved lowercasespan— but the language's actual spelling (every fixture, the grammar's type production, the spec's Slices and Ranges) isSpan, which arrived as an ordinary identifier anyway. So:KeywordKind::Spanand the lexer's"span"keyword mapping.Span<T>/ bareSpannow parse as a plainNamedtype, exactly likestring(also an un-reserved aliased type).spanis a distinct name.docs/prd/language-grammar.mdanddocs/parser/20-type-refs.mdupdated to record the decision.Test contract
cargo testat the workspace root is green (9 lexer + 8 parser tests). Every type alternative in step 20 is pinned by a golden dump (int,*int,?*int,[]int,[..]int,[25]int,Span<u8>, unions, tuples, function types), following the RED → GREEN → VERIFY discipline fromAGENTS.md.Notes
tests/fixtures/parse/) stay red until step 70 wires top-level assembly; steps 30–70 land in follow-up PRs.Spande-reservation.