From 1e8d8896b36c581121c7ba5c501c45bedce084e2 Mon Sep 17 00:00:00 2001
From: David Li
Date: Sat, 4 Nov 2017 19:58:32 -0400
Subject: Parse identifiers
---
src/ast.rs | 1 +
src/taiga.lalrpop | 12 ++++++++++++
2 files changed, 13 insertions(+)
(limited to 'src')
diff --git a/src/ast.rs b/src/ast.rs
index 7074e56..22d968e 100644
--- a/src/ast.rs
+++ b/src/ast.rs
@@ -64,5 +64,6 @@ pub enum Expression {
BinOp(BinOp, Box>, Box>),
Number(u64),
String(String),
+ Name(String),
Nil,
}
diff --git a/src/taiga.lalrpop b/src/taiga.lalrpop
index ffee4ee..be47147 100644
--- a/src/taiga.lalrpop
+++ b/src/taiga.lalrpop
@@ -85,10 +85,12 @@ ExpressionSign: Box> = {
ExpressionBase: Box> = {
Num => Box::new(<>.map(|v| ast::Expression::Number(v))),
String => Box::new(<>.map(|v| ast::Expression::String(v))),
+ Name => Box::new(<>.map(|v| ast::Expression::Name(v))),
Spanned => Box::new(<>.map(|v| ast::Expression::Nil)),
"(" ")" => <>,
};
+Name: WithLocation = > => e.map(|v| v.to_owned());
Num: WithLocation = > => e.map(|v| u64::from_str(v).unwrap());
String: WithLocation = => {
WithLocation::new(v[1..v.len() - 1].to_owned(), l, r)
@@ -97,3 +99,13 @@ String: WithLocation = =>
Spanned: WithLocation = {
=> WithLocation::new(v, l, r)
};
+
+match {
+ "nil",
+}
+else {
+ r"[[:alpha:]_][[:alpha:]_0-9]*",
+}
+else {
+ _,
+}
--
cgit v1.2.3