From 9cbe12458d9b3e3dc55e30fff1e396e1b7cf0d9a Mon Sep 17 00:00:00 2001
From: David Li
Date: Sat, 4 Nov 2017 19:53:47 -0400
Subject: Parse strings without escapes
---
src/ast.rs | 1 +
src/taiga.lalrpop | 4 ++++
2 files changed, 5 insertions(+)
(limited to 'src')
diff --git a/src/ast.rs b/src/ast.rs
index 4eea431..7074e56 100644
--- a/src/ast.rs
+++ b/src/ast.rs
@@ -63,5 +63,6 @@ pub enum Expression {
UnaryOp(UnaryOp, Box>),
BinOp(BinOp, Box>, Box>),
Number(u64),
+ String(String),
Nil,
}
diff --git a/src/taiga.lalrpop b/src/taiga.lalrpop
index 68238eb..ffee4ee 100644
--- a/src/taiga.lalrpop
+++ b/src/taiga.lalrpop
@@ -84,11 +84,15 @@ ExpressionSign: Box> = {
ExpressionBase: Box> = {
Num => Box::new(<>.map(|v| ast::Expression::Number(v))),
+ String => Box::new(<>.map(|v| ast::Expression::String(v))),
Spanned => Box::new(<>.map(|v| ast::Expression::Nil)),
"(" ")" => <>,
};
Num: WithLocation = > => e.map(|v| u64::from_str(v).unwrap());
+String: WithLocation = => {
+ WithLocation::new(v[1..v.len() - 1].to_owned(), l, r)
+};
Spanned: WithLocation = {
=> WithLocation::new(v, l, r)
--
cgit v1.2.3