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 type
  • map<key, value>: exactly two type arguments
  • function type: fn(typeList?) -> type

AST outputs

  • Stmt.TypeAnn for variable declarations
  • Stmt.ParamTypes for each function parameter
  • Stmt.ReturnType for function return
  • Type nodes with Elem, Key, Value, Params, Return

Parser mechanics

  • parseFnDecl sequence is strict:
    • fn name ( params ) -> returnType block
  • parameter parser returns both names and types in parallel arrays
  • parseType is 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
Use arrow keys or click edges to navigate. Press H to toggle help, F for fullscreen.