ref: ac297020506255ca01cde01c14145f3203d1a155
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 = [][:],
.stmts = [][:],
.extinit = [][:],
.init = `std.None,
.globls = mkstab(),
.builtin = mkstab(),
])
f.globls.super = `std.Some f.builtin
while true
match tokpeek(ts)
| (loc, `Teof):
break
| (loc, `Tendln):
continue
| (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
}
const traitdef = {ts, f
}
const tydef = {ts, f
}
const decl = {ts, f
}
const expectendblk = {ts, f
match toknext(ts)
| (loc, `Tendblk): /* ok */
| (loc, t): err(loc, "expected ;; after block, got {}\n", t)
;;
}