summary refs log tree commit diff
path: root/18/src/expression.lalrpop
diff options
context:
space:
mode:
authorIrene Knapp <ireneista@gmail.com>2021-12-17 23:05:07 -0800
committerIrene Knapp <ireneista@gmail.com>2021-12-17 23:05:07 -0800
commit5679068cb93ac96439d3ed8410a2776cfeb3e09b (patch)
tree3279b012e7644e21c502d352caef4d8dc72e8b40 /18/src/expression.lalrpop
parentccd4d3b436259b86f2fa3b433cd19a7bd60752da (diff)
18
Diffstat (limited to '18/src/expression.lalrpop')
-rw-r--r--18/src/expression.lalrpop34
1 files changed, 34 insertions, 0 deletions
diff --git a/18/src/expression.lalrpop b/18/src/expression.lalrpop
new file mode 100644
index 0000000..49356f6
--- /dev/null
+++ b/18/src/expression.lalrpop
@@ -0,0 +1,34 @@
+use crate::types::{Pair, Value};
+
+grammar;
+
+pub Pair: Pair = {
+  LEFT_BRACKET <left:Value> COMMA <right:Value> RIGHT_BRACKET => {
+    Pair {
+      left: left,
+      right: right,
+    }
+  },
+};
+
+Value: Value = {
+  NUMBER => {
+    Value::Literal(<>.parse::<i64>().unwrap())
+  },
+  Pair => {
+    Value::Pair(Box::new(<>))
+  },
+};
+
+match {
+  r"\p{Zs}+" => { },
+
+  r"[0-9]+" => NUMBER,
+
+  "," => COMMA,
+
+  "[" => LEFT_BRACKET,
+
+  "]" => RIGHT_BRACKET,
+}
+