v5 Parsing: modules + member access

Compile unit behavior

  • If first token is module, parse full module mode.
  • Otherwise, wrap statement stream into implicit module main.
  • In module mode, parse moduleItem* until closing }.

Module-level declarations

  • Module header: module IDENT { ... }
  • Imports are module items only.
  • Import alias defaults to the module name.
  • import name as alias; is valid; trailing ; is required.

Export contract

  • export only wraps declaration nodes.
  • valid: export fn ..., export let/var/const ...
  • invalid export target should error as declaration mismatch.

Postfix chain strategy

postfix -> primary (call | index | member)*

  • chain is left-to-right
  • member adds ExprMember with Value = identifier
  • member is parsed via a . IDENT, where IDENT is mandatory

Assignment target rule

  • valid assignment target kinds: identifier and index
  • ExprMember is intentionally not a valid left side in v5 parser

AST additions

  • Program.Modules []*Module
  • Module{Name, Imports, Stmts}
  • Import{Name, Alias}
  • Stmt.Exported bool
  • ExprMember node
1 / 1
Use arrow keys or click edges to navigate. Press H to toggle help, F for fullscreen.