From 6450da87ba36a48b85c34e0cec6eee520b86fe2c Mon Sep 17 00:00:00 2001 From: James Sanderson Date: Thu, 19 May 2016 00:54:54 +0100 Subject: Failing test for empty table on last line --- src/parser.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/parser.rs b/src/parser.rs index 8fa2d77..68e12d5 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -1205,6 +1205,14 @@ trimmed in raw strings. table.lookup("foo.1.bar").unwrap().as_table().unwrap(); } + #[test] + fn empty_table() { + let mut p = Parser::new(r#" +[foo]"#); + let table = Table(p.parse().unwrap()); + table.lookup("foo").unwrap().as_table().unwrap(); + } + #[test] fn fruit() { let mut p = Parser::new(r#" -- cgit v1.2.3 From 112adaaa3fcf612fb107db311a47cdbb5bef93dc Mon Sep 17 00:00:00 2001 From: James Sanderson Date: Thu, 19 May 2016 01:09:33 +0100 Subject: Accept empty table on last line --- src/parser.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/parser.rs b/src/parser.rs index 68e12d5..31205c8 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -285,7 +285,7 @@ impl<'a> Parser<'a> { }; if self.require_newline_after_table { self.ws(); - if !self.comment() && !self.newline() { + if !self.comment() && !self.newline() && self.peek(0).is_some() { self.errors.push(ParserError { lo: start, hi: start, -- cgit v1.2.3 From dd7e31ea5351780e284a80598a66094f32b51b1d Mon Sep 17 00:00:00 2001 From: James Sanderson Date: Thu, 19 May 2016 01:12:58 +0100 Subject: Refactor checking for EOF into method --- src/parser.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/parser.rs b/src/parser.rs index 31205c8..08f032d 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -243,6 +243,11 @@ impl<'a> Parser<'a> { } } + // Match EOF + fn eof(&self) -> bool { + self.peek(0).is_none() + } + /// Executes the parser, parsing the string contained within. /// /// This function will return the `TomlTable` instance if parsing is @@ -285,7 +290,7 @@ impl<'a> Parser<'a> { }; if self.require_newline_after_table { self.ws(); - if !self.comment() && !self.newline() && self.peek(0).is_some() { + if !self.comment() && !self.newline() && !self.eof() { self.errors.push(ParserError { lo: start, hi: start, -- cgit v1.2.3