aboutsummaryrefslogtreecommitdiff
path: root/src/parser.rs
diff options
context:
space:
mode:
authorAlex Crichton <alex@alexcrichton.com>2016-05-22 23:30:43 -0700
committerAlex Crichton <alex@alexcrichton.com>2016-05-22 23:30:43 -0700
commit44fc9d9f37cd1b2e3d9170d04fd0a8a04d7884ff (patch)
treedca1a42b18e8236a3ce23f55747544b444866f0f /src/parser.rs
parent97592e120f24938c06d036271aa658f9dfb6dd5e (diff)
downloadmilf-rs-44fc9d9f37cd1b2e3d9170d04fd0a8a04d7884ff.tar.gz
milf-rs-44fc9d9f37cd1b2e3d9170d04fd0a8a04d7884ff.zip
Require newlines to be present after keys
Closes #100
Diffstat (limited to 'src/parser.rs')
-rw-r--r--src/parser.rs37
1 files changed, 35 insertions, 2 deletions
diff --git a/src/parser.rs b/src/parser.rs
index 08f032d..40d12a6 100644
--- a/src/parser.rs
+++ b/src/parser.rs
@@ -398,10 +398,20 @@ impl<'a> Parser<'a> {
Some(value) => value,
None => return false,
};
+ let end = self.next_pos();
self.insert(into, key, value, key_lo);
self.ws();
- self.comment();
- self.newline();
+ if !self.comment() && !self.newline() {
+ if self.peek(0).is_none() {
+ return true
+ }
+ self.errors.push(ParserError {
+ lo: key_lo,
+ hi: end,
+ desc: format!("expected a newline after a key"),
+ });
+ return false
+ }
}
true
}
@@ -1591,4 +1601,27 @@ trimmed in raw strings.
bad!("foo = 2016-09-09T09:09:09-2:00", "malformed date literal");
bad!("foo = 2016-09-09T09:09:09Z-2:00", "expected");
}
+
+ #[test]
+ fn require_newline_after_value() {
+ bad!("0=0r=false", "expected a newline");
+ bad!(r#"
+0=""o=""m=""r=""00="0"q="""0"""e="""0"""
+"#, "expected a newline");
+ bad!(r#"
+[[0000l0]]
+0="0"[[0000l0]]
+0="0"[[0000l0]]
+0="0"l="0"
+"#, "expected a newline");
+ bad!(r#"
+0=[0]00=[0,0,0]t=["0","0","0"]s=[1000-00-00T00:00:00Z,2000-00-00T00:00:00Z]
+"#, "expected a newline");
+ bad!(r#"
+0=0r0=0r=false
+"#, "expected a newline");
+ bad!(r#"
+0=0r0=0r=falsefal=false
+"#, "expected a newline");
+ }
}