diff --git a/parser/src/scanner.rs b/parser/src/scanner.rs index 528fd8e..4a49666 100644 --- a/parser/src/scanner.rs +++ b/parser/src/scanner.rs @@ -311,6 +311,8 @@ pub struct Scanner { stream_start_produced: bool, /// Whether we have already emitted the `StreamEnd` token. stream_end_produced: bool, + /// In some flow contexts, the value of a mapping is allowed to be adjacent to the `:`. When it + /// is, the index at which the `:` may be must be stored in `adjacent_value_allowed_at`. adjacent_value_allowed_at: usize, /// Whether a simple key could potentially start at the current position. /// @@ -1395,6 +1397,15 @@ impl> Scanner { self.skip(); self.skip_ws_to_eol(SkipTabs::Yes)?; + // A flow collection within a flow mapping can be a key. In that case, the value may be + // adjacent to the `:`. + // ```yaml + // - [ {a: b}:value ] + // ``` + if self.flow_level > 0 { + self.adjacent_value_allowed_at = self.mark.index; + } + self.tokens.push_back(Token(start_mark, tok)); Ok(()) } diff --git a/parser/tests/yaml-test-suite.rs b/parser/tests/yaml-test-suite.rs index 0933a59..dbd00db 100644 --- a/parser/tests/yaml-test-suite.rs +++ b/parser/tests/yaml-test-suite.rs @@ -315,7 +315,6 @@ fn expected_events(expected_tree: &str) -> Vec { #[rustfmt::skip] static EXPECTED_FAILURES: &[&str] = &[ // Misc - "9MMW", // Mapping key in implicit mapping in flow sequence(!) "G9HC", // Anchor indent problem(?) "H7J7", // Anchor indent / linebreak problem? "3UYS", // Escaped /