mirror of
https://github.com/pezkuwichain/serde.git
synced 2026-06-14 04:41:01 +00:00
Clean up checking for trailing characters
This commit is contained in:
@@ -1008,10 +1008,6 @@ enum ParserState {
|
|||||||
ParseObjectKey,
|
ParseObjectKey,
|
||||||
// Parse a value in an object.
|
// Parse a value in an object.
|
||||||
ParseObjectValue,
|
ParseObjectValue,
|
||||||
// Expecting the stream to end.
|
|
||||||
ParseBeforeFinish,
|
|
||||||
// Parsing can't continue.
|
|
||||||
ParseFinished,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A Stack represents the current position of the parser in the logical
|
/// A Stack represents the current position of the parser in the logical
|
||||||
@@ -1171,21 +1167,21 @@ impl<T: Iterator<char>> Iterator<Result<de::Token, ParserError>> for Parser<T> {
|
|||||||
fn next(&mut self) -> Option<Result<de::Token, ParserError>> {
|
fn next(&mut self) -> Option<Result<de::Token, ParserError>> {
|
||||||
let state = match self.state.pop() {
|
let state = match self.state.pop() {
|
||||||
Some(state) => state,
|
Some(state) => state,
|
||||||
None => { return None; }
|
None => {
|
||||||
|
// If we have no state left, then we're expecting the structure
|
||||||
|
// to be done, so make sure there are no trailing characters.
|
||||||
|
|
||||||
|
self.parse_whitespace();
|
||||||
|
|
||||||
|
if self.eof() {
|
||||||
|
return None;
|
||||||
|
} else {
|
||||||
|
return Some(self.error(TrailingCharacters));
|
||||||
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
match state {
|
match state {
|
||||||
ParseFinished => None,
|
|
||||||
ParseBeforeFinish => {
|
|
||||||
self.parse_whitespace();
|
|
||||||
// Make sure there is no trailing characters.
|
|
||||||
if self.eof() {
|
|
||||||
self.state.push(ParseFinished);
|
|
||||||
None
|
|
||||||
} else {
|
|
||||||
Some(self.error(TrailingCharacters))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
ParseValue => Some(self.parse_value()),
|
ParseValue => Some(self.parse_value()),
|
||||||
ParseListStart => Some(self.parse_list_start()),
|
ParseListStart => Some(self.parse_list_start()),
|
||||||
ParseListCommaOrEnd => Some(self.parse_list_comma_or_end()),
|
ParseListCommaOrEnd => Some(self.parse_list_comma_or_end()),
|
||||||
@@ -1205,7 +1201,7 @@ impl<T: Iterator<char>> Parser<T> {
|
|||||||
ch: Some('\x00'),
|
ch: Some('\x00'),
|
||||||
line: 1,
|
line: 1,
|
||||||
col: 0,
|
col: 0,
|
||||||
state: vec!(ParseBeforeFinish, ParseValue),
|
state: vec!(ParseValue),
|
||||||
};
|
};
|
||||||
p.bump();
|
p.bump();
|
||||||
return p;
|
return p;
|
||||||
|
|||||||
Reference in New Issue
Block a user