aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAlex Crichton <alex@alexcrichton.com>2016-05-18 20:52:28 -0700
committerAlex Crichton <alex@alexcrichton.com>2016-05-18 20:52:28 -0700
commit97592e120f24938c06d036271aa658f9dfb6dd5e (patch)
treecafadb721d29374bdf56eef908e0229ab0a91398 /src
parent00a3452fa9def944d47de99415027c0455f63b3c (diff)
parentdd7e31ea5351780e284a80598a66094f32b51b1d (diff)
downloadmilf-rs-97592e120f24938c06d036271aa658f9dfb6dd5e.tar.gz
milf-rs-97592e120f24938c06d036271aa658f9dfb6dd5e.zip
Merge pull request #98 from zofrex/accept-empty-table
Accept empty table
Diffstat (limited to 'src')
-rw-r--r--src/parser.rs15
1 files changed, 14 insertions, 1 deletions
diff --git a/src/parser.rs b/src/parser.rs
index 8fa2d77..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() {
+ if !self.comment() && !self.newline() && !self.eof() {
self.errors.push(ParserError {
lo: start,
hi: start,
@@ -1206,6 +1211,14 @@ trimmed in raw strings.
}
#[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#"
[[fruit]]