summaryrefslogtreecommitdiff
path: root/src/taiga.lalrpop
diff options
context:
space:
mode:
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)
+};