26 lines
553 B
Text
26 lines
553 B
Text
|
iface HasEnv {
|
||
|
env: Map<str, str>,
|
||
|
}
|
||
|
|
||
|
iface HasVal {
|
||
|
val: str,
|
||
|
}
|
||
|
|
||
|
alias Ident = /([a-zA-Z][a-zA-Z0-9_]*)|(_[a-zA-Z0-9_]+)/
|
||
|
|
||
|
node Expr : HasEnv + HasVal {
|
||
|
"let" <name:Ident> "=" <val:Expr> "in" <body:Expr> => {
|
||
|
body.env = self.env.with(name, val);
|
||
|
self.val = body.val;
|
||
|
}
|
||
|
<name:Ident> => {
|
||
|
// TODO: does env need to be referenced here?
|
||
|
// TODO: how to check for unbound names ahead of time
|
||
|
// (for self-implementation)
|
||
|
self.val = self.env.lookup(name);
|
||
|
}
|
||
|
<string:StringLit> => {
|
||
|
self.val = string;
|
||
|
}
|
||
|
}
|