Disambiguate "" empty strings from multiline strings properly.

Previously `""` would go into multiline mode and thus *require* a
following ".
This commit is contained in:
Huon Wilson 2014-07-18 20:19:21 +10:00
parent 05f8c0bc41
commit e756f56b62
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('"') {
multiline = true; if self.eat('"') {
if !self.expect('"') { return None } multiline = true;
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 = ""