Merge pull request #8 from huonw/fixit

Disambiguate "" empty strings from multiline strings properly.
This commit is contained in:
Alex Crichton 2014-07-18 09:55:32 -04:00
commit 76cf3d1d3e
4 changed files with 19 additions and 4 deletions

View file

@ -265,11 +265,16 @@ impl<'a> Parser<'a> {
let mut multiline = false; let mut multiline = false;
let mut ret = String::new(); let mut ret = String::new();
// detect multiline literals // detect multiline literals, but be careful about empty ""
// strings
if self.eat('"') {
if self.eat('"') { if self.eat('"') {
multiline = true; multiline = true;
if !self.expect('"') { return None }
self.eat('\n'); self.eat('\n');
} else {
// empty
return Some(String(ret))
}
} }
loop { loop {

View file

@ -122,6 +122,9 @@ test!(long_float,
test!(long_integer, test!(long_integer,
include_str!("valid/long-integer.toml"), include_str!("valid/long-integer.toml"),
include_str!("valid/long-integer.json")) include_str!("valid/long-integer.json"))
test!(string_empty,
include_str!("valid/string-empty.toml"),
include_str!("valid/string-empty.json"))
test!(string_escapes, test!(string_escapes,
include_str!("valid/string-escapes.toml"), include_str!("valid/string-escapes.toml"),
include_str!("valid/string-escapes.json")) include_str!("valid/string-escapes.json"))

View file

@ -0,0 +1,6 @@
{
"answer": {
"type": "string",
"value": ""
}
}

View file

@ -0,0 +1 @@
answer = ""