ref: a3e640134dc9e002a2b56ee14f7250c36871d1e8
dir: /mparse/parse.myr/
use std use "ast.use" use "stab.use" use "types.use" use "tokdefs.use" use "tok.use" use "util.use" pkg parse = const tsfile : (ts : tokstream# -> file#) ;; const tsfile = {ts var f f = std.mk([ .uses = [][:], .libs = [][:], .extlibs = [][:], .dcls = [][:], .extinit = [][:], .init = `std.None, .globls = mkstab(), .builtin = mkstab(), .ns = std.mkht(std.strhash, std.streq), ]) f.globls.super = `std.Some f.builtin while true match tokpeek(ts) | (loc, `Teof): break | (loc, `Tendln): toknext(ts) | (loc, `Tuse): usestmt(ts, f) | (loc, `Tpkg): pkgdef(ts, f) | (loc, `Ttrait): traitdef(ts, f) | (loc, `Ttype): tydef(ts, f) | _: decl(ts, ts) ;; ;; -> f } const usestmt = {ts, f } const pkgdef = {ts, f match toknext(ts) | (loc, `Tpkg): /* ok */ | (loc, t): err(loc, "unexpected token in pkg {}\n", t) ;; match toknext(ts) | (loc, `Tident id): setpkg(f, f.globls, id) | (loc, `Tgap): /* pkg _ */ | (loc, t): err(loc, "invalid package name {}\n", t) ;; match toknext(ts) | (loc, `Tasn): /* ok */ | (loc, t): err(loc, "expected '=' after pkg name, got {}\n", t) ;; pkgbody(ts, f) expectendblk(ts, f) } const pkgbody = {ts, f endlns(ts) } const traitdef = {ts, f } const tydef = {ts, f } const decl = {ts, f } const endlns = {ts while true match tokpeek(ts) | (loc, `Tendln): toknext(ts) | _: break ;; ;; } const expectendblk = {ts, f match toknext(ts) | (loc, `Tendblk): /* ok */ | (loc, t): err(loc, "expected ;; after block, got {}\n", t) ;; }