From 35bf004cc923c1bd61a75fa0ff9b336644f0c8b0 Mon Sep 17 00:00:00 2001 From: David Li Date: Sat, 4 Nov 2017 08:34:52 -0400 Subject: Add location information to AST --- src/taiga.lalrpop | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'src/taiga.lalrpop') 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 = { - Num => Box::new(ast::Expression::Number(<>)), +Expression: Box> = { + Num => Box::new(<>.map(|v| ast::Expression::Number(v))), }; -Num: u64 = r"[0-9]+" => u64::from_str(<>).unwrap(); +Num: WithLocation = > => e.map(|v| u64::from_str(v).unwrap()); + +Spanned: WithLocation = { + => WithLocation::new(v, l, r) +}; -- cgit v1.2.3