diff --git a/parser/src/scanner.rs b/parser/src/scanner.rs index de22531..23c56ba 100644 --- a/parser/src/scanner.rs +++ b/parser/src/scanner.rs @@ -595,6 +595,11 @@ impl> Scanner { Ok(()) } + /// Skip over all whitespace and comments until the next token. + /// + /// # Errors + /// This function returns an error if a tabulation is encountered where there should not be + /// one. fn skip_to_next_token(&mut self) -> ScanResult { loop { // TODO(chenyh) BOM @@ -604,7 +609,10 @@ impl> Scanner { // "Indentation" only exists as long as a block is started, but does not exist // inside of flow-style constructs. Tabs are allowed as part of leaading // whitespaces outside of indentation. - '\t' if self.is_within_block() && self.leading_whitespace => { + '\t' if self.is_within_block() + && self.leading_whitespace + && (self.mark.col as isize) < self.indent => + { return Err(ScanError::new( self.mark, "tabs disallowed within this context (block indentation)", @@ -1239,18 +1247,13 @@ impl> Scanner { } } - // Eat whitespaces and comments to the end of the line. - self.lookahead(1); - - while is_blank(self.ch()) { + while is_blank(self.look_ch()) { self.skip(); - self.lookahead(1); } if self.ch() == '#' { - while !is_breakz(self.ch()) { + while !is_breakz(self.look_ch()) { self.skip(); - self.lookahead(1); } } @@ -1267,6 +1270,13 @@ impl> Scanner { self.skip_line(); } + if self.look_ch() == '\t' { + return Err(ScanError::new( + start_mark, + "a block scalar content cannot start with a tab", + )); + } + if increment > 0 { indent = if self.indent >= 0 { (self.indent + increment as isize) as usize diff --git a/parser/tests/yaml-test-suite.rs b/parser/tests/yaml-test-suite.rs index 42b1668..780e08d 100644 --- a/parser/tests/yaml-test-suite.rs +++ b/parser/tests/yaml-test-suite.rs @@ -299,7 +299,6 @@ fn expected_events(expected_tree: &str) -> Vec { static EXPECTED_FAILURES: &[&str] = &[ // These seem to be plain bugs // TAB as start of plain scalar instead of whitespace - "DK95-00", "Y79Y-06", "Y79Y-03", // unexpected pass "Y79Y-04", // unexpected pass