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
exportonly 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
memberaddsExprMemberwithValue= identifier- member is parsed via
a . IDENT, whereIDENTis mandatory
Assignment target rule
- valid assignment target kinds: identifier and index
ExprMemberis intentionally not a valid left side in v5 parser
AST additions
Program.Modules []*ModuleModule{Name, Imports, Stmts}Import{Name, Alias}Stmt.Exported boolExprMembernode
1 / 1