summaryrefslogtreecommitdiff
path: root/src/parser/grammar.pegjs
diff options
context:
space:
mode:
Diffstat (limited to 'src/parser/grammar.pegjs')
-rw-r--r--src/parser/grammar.pegjs27
1 files changed, 27 insertions, 0 deletions
diff --git a/src/parser/grammar.pegjs b/src/parser/grammar.pegjs
new file mode 100644
index 0000000..48a7564
--- /dev/null
+++ b/src/parser/grammar.pegjs
@@ -0,0 +1,27 @@
+LambdaTerm
+ = Abstraction
+ / Application
+ / Variable
+
+Application
+ = LPAREN _? left:LambdaTerm _? right:LambdaTerm _? RPAREN {
+ return { left, right };
+ }
+
+Abstraction
+ = LPAREN _? LAMBDA _? param:Variable _? DOT _? body:LambdaTerm _? RPAREN {
+ return { param, body };
+ }
+
+Variable
+ = name:([a-zA-Z][A-Z0-9a-z]*) { return { name: name[0] + name[1].join('') }; }
+
+LAMBDA = "λ"
+
+DOT = "."
+
+LPAREN = "("
+
+RPAREN = ")"
+
+_ = (" " / "\n" / "\t" / "\t\n")+ \ No newline at end of file