diff options
author | Alex Crichton <alex@alexcrichton.com> | 2017-02-08 21:36:38 -0800 |
---|---|---|
committer | Alex Crichton <alex@alexcrichton.com> | 2017-02-08 21:36:38 -0800 |
commit | 204d1b14e6bd7b67d782def4c4c7837b9045cd8d (patch) | |
tree | 7805b214df8707f69dcd9c1daaeb87875a73c825 /src | |
parent | 6821911bc7cebac458d2cfb2c14b8d107aa60521 (diff) | |
download | milf-rs-204d1b14e6bd7b67d782def4c4c7837b9045cd8d.tar.gz milf-rs-204d1b14e6bd7b67d782def4c4c7837b9045cd8d.zip |
Implement Deserializer::set_require_newline_after_table
Diffstat (limited to 'src')
-rw-r--r-- | src/de.rs | 32 |
1 files changed, 26 insertions, 6 deletions
@@ -581,7 +581,7 @@ impl<'a> Deserializer<'a> { Deserializer { tokens: Tokenizer::new(input), input: input, - require_newline_after_table: false, + require_newline_after_table: true, } } @@ -626,8 +626,22 @@ impl<'a> Deserializer<'a> { let start = self.tokens.current(); self.expect(Token::LeftBracket)?; let array = self.eat(Token::LeftBracket)?; - let ret = Header::new(self.tokens.clone(), array); - self.tokens.skip_to_newline(); + let ret = Header::new(self.tokens.clone(), + array, + self.require_newline_after_table); + if self.require_newline_after_table { + self.tokens.skip_to_newline(); + } else { + loop { + match self.next()? { + Some(Token::RightBracket) | + Some(Token::Newline) | + None => break, + _ => {} + } + } + self.eat_whitespace()?; + } Ok(Line::Table { at: start, header: ret, array: array }) } @@ -1134,15 +1148,19 @@ enum Line<'a> { struct Header<'a> { first: bool, array: bool, + require_newline_after_table: bool, tokens: Tokenizer<'a>, } impl<'a> Header<'a> { - fn new(tokens: Tokenizer<'a>, array: bool) -> Header<'a> { + fn new(tokens: Tokenizer<'a>, + array: bool, + require_newline_after_table: bool) -> Header<'a> { Header { first: true, array: array, tokens: tokens, + require_newline_after_table: require_newline_after_table, } } @@ -1160,8 +1178,10 @@ impl<'a> Header<'a> { } self.tokens.eat_whitespace()?; - if !self.tokens.eat_comment()? { - self.tokens.eat_newline_or_eof()?; + if self.require_newline_after_table { + if !self.tokens.eat_comment()? { + self.tokens.eat_newline_or_eof()?; + } } Ok(None) } |