From 5679068cb93ac96439d3ed8410a2776cfeb3e09b Mon Sep 17 00:00:00 2001 From: Irene Knapp Date: Fri, 17 Dec 2021 23:05:07 -0800 Subject: 18 --- 18/src/expression.lalrpop | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 18/src/expression.lalrpop (limited to '18/src/expression.lalrpop') 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 COMMA RIGHT_BRACKET => { + Pair { + left: left, + right: right, + } + }, +}; + +Value: Value = { + NUMBER => { + Value::Literal(<>.parse::().unwrap()) + }, + Pair => { + Value::Pair(Box::new(<>)) + }, +}; + +match { + r"\p{Zs}+" => { }, + + r"[0-9]+" => NUMBER, + + "," => COMMA, + + "[" => LEFT_BRACKET, + + "]" => RIGHT_BRACKET, +} + -- cgit 1.4.1