v6 Parsing: typed declarations and signatures
What changes in v6
- Type annotations are parsed as AST nodes, not strings.
- Every function parameter requires
IDENT : type. - Function declarations require
->return type. - Types are recursive (
fn(...) -> ...,map<k, v>,array<elem>).
Type parser contract
- primitives:
number,bool,string,nil array<type>: exactly one element typemap<key, value>: exactly two type arguments- function type:
fn(typeList?) -> type
AST outputs
Stmt.TypeAnnfor variable declarationsStmt.ParamTypesfor each function parameterStmt.ReturnTypefor function returnTypenodes withElem,Key,Value,Params,Return
Parser mechanics
parseFnDeclsequence is strict:fnname(params)->returnType block
- parameter parser returns both names and types in parallel arrays
parseTypeis called from both var declarations and function params
Practice focus
1) parse missing return type errors 2) nested type nesting (fn inside map/array) 3) map type arity and delimiter validation 4) unknown named type rejection 5) keep v5 declaration behavior for assignments and for-inits
1 / 1