Program Parser v6
Program Parser v6
Parse tokens into an AST for the v6 language (modules + type annotations).
Function signature
func Parse(tokens []Token) (*Program, error)
New syntax
let x: number = 1;
fn add(a: number, b: number) -> number { return a + b; }
let xs: array<number> = [1,2];
let m: map<string, number> = {"k": 1};
Type grammar
type -> simple | fnType
simple -> number | bool | string | nil
| array<type>
| map<type, type>
fnType -> fn("typeList?") -> type
AST additions
TypetreeStmt.TypeAnn *Typefor variablesStmt.ParamTypes []*TypeandStmt.ReturnType *Typefor functions
Rules
- Function parameters must include type annotations.
- Function return type is required after
->. - Type names are identifiers (
number,bool,string,array,map).
Other grammar rules match v5.
Run tests to see results
No issues detected