summaryrefslogtreecommitdiff
path: root/src/taiga.lalrpop
diff options
context:
space:
mode:
authorDavid Li <li.davidm96@gmail.com>2017-11-04 08:34:52 -0400
committerDavid Li <li.davidm96@gmail.com>2017-11-04 08:34:52 -0400
commit35bf004cc923c1bd61a75fa0ff9b336644f0c8b0 (patch)
tree4a06430b9289a03f047a4650c51149078887ec5b /src/taiga.lalrpop
parent8b3f3271be72b89f557d84238f9e3df5c1ea418c (diff)
Add location information to AST
Diffstat (limited to 'src/taiga.lalrpop')
-rw-r--r--src/taiga.lalrpop12
1 files changed, 8 insertions, 4 deletions
diff --git a/src/taiga.lalrpop b/src/taiga.lalrpop
index b60d68f..08c3cd3 100644
--- a/src/taiga.lalrpop
+++ b/src/taiga.lalrpop
@@ -1,5 +1,5 @@
use std::str::FromStr;
-use ast;
+use ast::{self, WithLocation};
grammar;
@@ -7,8 +7,12 @@ pub Program: ast::Program = {
Expression => ast::Program(<>),
};
-Expression: Box<ast::Expression> = {
- Num => Box::new(ast::Expression::Number(<>)),
+Expression: Box<ast::WithLocation<ast::Expression>> = {
+ Num => Box::new(<>.map(|v| ast::Expression::Number(v))),
};
-Num: u64 = r"[0-9]+" => u64::from_str(<>).unwrap();
+Num: WithLocation<u64> = <e: Spanned<r"[0-9]+">> => e.map(|v| u64::from_str(v).unwrap());
+
+Spanned<T>: WithLocation<T> = {
+ <l: @L> <v: T> <r: @R> => WithLocation::new(v, l, r)
+};