From d5b2603bcba9505b13afa487ee4c8e028d6267e1 Mon Sep 17 00:00:00 2001 From: Niko Matsakis Date: Sun, 19 Jul 2015 14:14:40 -0400 Subject: [PATCH] fix minor thing with string literal spans (and add a test) --- lalrpop/src/tok/mod.rs | 4 ++-- lalrpop/src/tok/test.rs | 9 +++++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/lalrpop/src/tok/mod.rs b/lalrpop/src/tok/mod.rs index fa9474e..d8b7e87 100644 --- a/lalrpop/src/tok/mod.rs +++ b/lalrpop/src/tok/mod.rs @@ -224,8 +224,8 @@ impl<'input> Tokenizer<'input> { match self.take_until(terminate) { Some(idx1) => { self.bump(); // consume the '"' - let text = &self.text[idx0+1..idx1]; // do not include the `` in the str - Ok((idx0, StringLiteral(text), idx1)) + let text = &self.text[idx0+1..idx1]; // do not include the "" in the str + Ok((idx0, StringLiteral(text), idx1+1)) } None => { Err(UnterminatedStringLiteral(idx0)) diff --git a/lalrpop/src/tok/test.rs b/lalrpop/src/tok/test.rs index f90d59e..4864ce4 100644 --- a/lalrpop/src/tok/test.rs +++ b/lalrpop/src/tok/test.rs @@ -78,3 +78,12 @@ fn various_kinds_of_ids() { (" ~", GreaterThan), ]); } + +#[test] +fn string_literals() { + test(r#"foo "bar\"\n" baz"#, vec![ + (r#"~~~ "#, Id("foo")), + (r#" ~~~~~~~~~ "#, StringLiteral(r#"bar\"\n"#)), + (r#" ~~~"#, Id("baz")), + ]); +}