aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Crichton <alex@alexcrichton.com>2016-05-12 11:28:32 -0700
committerAlex Crichton <alex@alexcrichton.com>2016-05-12 11:28:32 -0700
commit1ed6801137ede253844a6d798d5f9f8327dc0090 (patch)
treeebe804488ca32b8597d0c29a01663cf32956f5ed
parent50dfc8ac79bf8a18a03a8b9f53a520335c1fd2d0 (diff)
downloadmilf-rs-1ed6801137ede253844a6d798d5f9f8327dc0090.tar.gz
milf-rs-1ed6801137ede253844a6d798d5f9f8327dc0090.zip
Add option to enable old behavior
Cargo will use this in the interim.
-rw-r--r--src/parser.rs32
1 files changed, 23 insertions, 9 deletions
diff --git a/src/parser.rs b/src/parser.rs
index 8c689f8..60767eb 100644
--- a/src/parser.rs
+++ b/src/parser.rs
@@ -89,6 +89,7 @@ impl Value {
pub struct Parser<'a> {
input: &'a str,
cur: str::CharIndices<'a>,
+ require_newline_after_table: bool,
/// A list of all errors which have occurred during parsing.
///
@@ -138,6 +139,7 @@ impl<'a> Parser<'a> {
input: s,
cur: s.char_indices(),
errors: Vec::new(),
+ require_newline_after_table: true,
}
}
@@ -155,6 +157,16 @@ impl<'a> Parser<'a> {
(self.input.lines().count(), 0)
}
+ /// Historical versions of toml-rs accidentally allowed a newline after a
+ /// table definition, but the TOML spec requires a newline after a table
+ /// definition header.
+ ///
+ /// This option can be set to `false` (the default is `true`) to emulate
+ /// this behavior for backwards compatibility with older toml-rs versions.
+ pub fn set_require_newline_after_table(&mut self, require: bool) {
+ self.require_newline_after_table = require;
+ }
+
fn next_pos(&self) -> usize {
self.cur.clone().next().map(|p| p.0).unwrap_or(self.input.len())
}
@@ -271,15 +283,17 @@ impl<'a> Parser<'a> {
values: BTreeMap::new(),
defined: true,
};
- self.ws();
- self.comment();
- if !self.newline() {
- self.errors.push(ParserError {
- lo: start,
- hi: start,
- desc: format!("expected a newline after table definition"),
- });
- return None
+ if self.require_newline_after_table {
+ self.ws();
+ self.comment();
+ if !self.newline() {
+ self.errors.push(ParserError {
+ lo: start,
+ hi: start,
+ desc: format!("expected a newline after table definition"),
+ });
+ return None
+ }
}
if !self.values(&mut table) { return None }
if array {