blob: 520d6c86d1538418d3662c8b3c4b57406406da7e (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
|
LambdaTerm = Application / Abstraction / Variable
Application = LPAREN _? left:LambdaTerm _ argList:(LambdaTerm _)* lastArg:LambdaTerm _? RPAREN {
const args = lastArg || argList.length ? [...argList.map(x => x[0]), lastArg] : [];
return { application: { left, args } };
}
Abstraction = LPAREN _? LAMBDA _? LPAREN _? param:Variable _? RPAREN _? DOT _? body:LambdaTerm _? RPAREN { return { abstraction: { param, body } }; }
Variable = param:[a-zA-Z0-9]+ { return param.join(""); }
LPAREN = "("
RPAREN = ")"
DOT = "."
LAMBDA = "λ" / "\\"
_ = ("\n" / " " / "\t" / "\r\n")+
|