v5 Parsing: modules, imports, and member access
- Build Program.Modules and choose parse mode once.
- Preserve member/call/index postfix structure and export flags.
- Reject invalid export forms without performing module resolution.
1 / 6
Parse module main { import util as u; let x=u.make()[0]; }:
| Representation | Recorded fields |
|---|---|
| Program | one Module named main |
| Import | Name=util, Alias=u |
| variable x | initializer Index(Call(Member(Ident(u),make)),0) |
The parser accepts this shape without proving util exists; the analyzer checks
that later. Dot wraps the accumulated postfix expression just like calls and
indexes. For m.get(1).x[2], the wrappers are Member, Call, Member, Index in
source order. Some resulting member bases may later be rejected by module
semantics even though their syntax is valid.
A parser produces Call(Ident("u.make")) for u.make() and accepts export while(true){}. What structure and grammar boundary were lost?
Draw ASTs for u.f()[1] and u.f[1]() and explain which value each calls. Construct an implicit-main program and then append an explicit module declaration; predict the fixed-mode parsing failure.
Carry ordered Modules, Imports, Exported flags, and Member nodes into v5 analysis. Keep unresolved-module syntax tests distinct from module-graph validity tests.