summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDavid Li <li.davidm96@gmail.com>2017-11-04 19:58:32 -0400
committerDavid Li <li.davidm96@gmail.com>2017-11-04 19:58:32 -0400
commit1e8d8896b36c581121c7ba5c501c45bedce084e2 (patch)
tree368dc8aeb9882525a1c969e5cc45edae34a5dd98 /src
parent9cbe12458d9b3e3dc55e30fff1e396e1b7cf0d9a (diff)
Parse identifiers
Diffstat (limited to 'src')
-rw-r--r--src/ast.rs1
-rw-r--r--src/taiga.lalrpop12
2 files changed, 13 insertions, 0 deletions
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<WithLocation<Expression>>, Box<WithLocation<Expression>>),
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<ast::WithLocation<ast::Expression>> = {
ExpressionBase: Box<ast::WithLocation<ast::Expression>> = {
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<r"nil"> => Box::new(<>.map(|v| ast::Expression::Nil)),
"(" <Expression> ")" => <>,
};
+Name: WithLocation<String> = <e: Spanned<r"[[:alpha:]_][[:alpha:]_0-9]*">> => e.map(|v| v.to_owned());
Num: WithLocation<u64> = <e: Spanned<r"[0-9]+">> => e.map(|v| u64::from_str(v).unwrap());
String: WithLocation<String> = <l: @L> <v:r##""(?:[^"\\]|\\\\)*""##> <r: @R> => {
WithLocation::new(v[1..v.len() - 1].to_owned(), l, r)
@@ -97,3 +99,13 @@ String: WithLocation<String> = <l: @L> <v:r##""(?:[^"\\]|\\\\)*""##> <r: @R> =>
Spanned<T>: WithLocation<T> = {
<l: @L> <v: T> <r: @R> => WithLocation::new(v, l, r)
};
+
+match {
+ "nil",
+}
+else {
+ r"[[:alpha:]_][[:alpha:]_0-9]*",
+}
+else {
+ _,
+}