agtest/let.ag

26 lines
619 B
Plaintext
Raw Normal View History

2021-06-09 07:44:52 +00:00
iface HasEnv {
2021-06-14 20:52:53 +00:00
env: Map<str, str>,
2021-06-09 07:44:52 +00:00
}
iface HasVal {
2021-06-14 20:52:53 +00:00
val: str,
2021-06-09 07:44:52 +00:00
}
alias Ident = /([a-zA-Z][a-zA-Z0-9_]*)|(_[a-zA-Z0-9_]+)/
node Expr : HasEnv + HasVal {
2021-06-14 20:52:53 +00:00
"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;
}
2021-06-09 07:44:52 +00:00
}