summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Li <li.davidm96@gmail.com>2017-11-04 19:53:47 -0400
committerDavid Li <li.davidm96@gmail.com>2017-11-04 19:53:47 -0400
commit9cbe12458d9b3e3dc55e30fff1e396e1b7cf0d9a (patch)
treee0509b2033bd414eccd687ac53a8158d21ae875f
parent13e7a55d3924f77fccf8b97a2373dfb29eba6e5a (diff)
Parse strings without escapes
-rw-r--r--src/ast.rs1
-rw-r--r--src/taiga.lalrpop4
2 files changed, 5 insertions, 0 deletions
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<WithLocation<Expression>>),
BinOp(BinOp, Box<WithLocation<Expression>>, Box<WithLocation<Expression>>),
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<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))),
Spanned<r"nil"> => Box::new(<>.map(|v| ast::Expression::Nil)),
"(" <Expression> ")" => <>,
};
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)
+};
Spanned<T>: WithLocation<T> = {
<l: @L> <v: T> <r: @R> => WithLocation::new(v, l, r)