Fix use of dashes in flow contexts.

This commit is contained in:
Ethiraric 2024-01-19 21:57:39 +01:00
parent 628549085c
commit 5dbd6f9a55
2 changed files with 10 additions and 5 deletions

View file

@ -2030,6 +2030,7 @@ impl<T: Iterator<Item = char>> Scanner<T> {
Ok(()) Ok(())
} }
#[allow(clippy::too_many_lines)]
fn scan_plain_scalar(&mut self) -> Result<Token, ScanError> { fn scan_plain_scalar(&mut self) -> Result<Token, ScanError> {
self.unroll_non_block_indents(); self.unroll_non_block_indents();
let indent = self.indent + 1; let indent = self.indent + 1;
@ -2044,7 +2045,6 @@ impl<T: Iterator<Item = char>> Scanner<T> {
loop { loop {
/* Check for a document indicator. */ /* Check for a document indicator. */
self.lookahead(4); self.lookahead(4);
if self.mark.col == 0 if self.mark.col == 0
&& (((self.buffer[0] == '-') && (self.buffer[1] == '-') && (self.buffer[2] == '-')) && (((self.buffer[0] == '-') && (self.buffer[1] == '-') && (self.buffer[2] == '-'))
|| ((self.buffer[0] == '.') || ((self.buffer[0] == '.')
@ -2058,6 +2058,14 @@ impl<T: Iterator<Item = char>> Scanner<T> {
if self.ch() == '#' { if self.ch() == '#' {
break; break;
} }
if self.flow_level > 0 && self.ch() == '-' && is_flow(self.buffer[1]) {
return Err(ScanError::new(
self.mark,
"plain scalar cannot start with '-' followed by ,[]{}",
));
}
while !is_blankz(self.ch()) { while !is_blankz(self.ch()) {
// indicators can end a plain scalar, see 7.3.3. Plain Style // indicators can end a plain scalar, see 7.3.3. Plain Style
match self.ch() { match self.ch() {
@ -2066,7 +2074,7 @@ impl<T: Iterator<Item = char>> Scanner<T> {
{ {
break; break;
} }
',' | '[' | ']' | '{' | '}' if self.flow_level > 0 => break, c if is_flow(c) && self.flow_level > 0 => break,
_ => {} _ => {}
} }

View file

@ -297,9 +297,6 @@ fn expected_events(expected_tree: &str) -> Vec<String> {
#[rustfmt::skip] #[rustfmt::skip]
static EXPECTED_FAILURES: &[&str] = &[ static EXPECTED_FAILURES: &[&str] = &[
// Dashes in flow sequence (should be forbidden)
"G5U8",
"YJV2",
// Misc // Misc
"9MMW", // Mapping key in implicit mapping in flow sequence(!) "9MMW", // Mapping key in implicit mapping in flow sequence(!)
"G9HC", // Anchor indent problem(?) "G9HC", // Anchor indent problem(?)