From 9b653e607b311d9673ecd3825e33972c23ba4cf1 Mon Sep 17 00:00:00 2001 From: Ethiraric Date: Fri, 19 Jan 2024 19:33:26 +0100 Subject: [PATCH] Fix block scalars and document end interaction. --- parser/src/scanner.rs | 16 ++++++++++++++++ parser/tests/yaml-test-suite.rs | 4 +--- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/parser/src/scanner.rs b/parser/src/scanner.rs index c0a7cef..18a681f 100644 --- a/parser/src/scanner.rs +++ b/parser/src/scanner.rs @@ -612,6 +612,16 @@ impl> Scanner { } } + /// Check whether the next characters correspond to an end of document. + /// + /// [`Self::lookahead`] must have been called before calling this function. + fn next_is_document_end(&self) -> bool { + self.buffer[0] == '.' + && self.buffer[1] == '.' + && self.buffer[2] == '.' + && is_blankz(self.buffer[3]) + } + /// Insert a token at the given position. fn insert_token(&mut self, pos: usize, tok: Token) { let old_len = self.tokens.len(); @@ -1592,6 +1602,12 @@ impl> Scanner { let start_mark = self.mark; while self.mark.col == indent && !is_z(self.ch()) { + if indent == 0 { + self.lookahead(4); + if self.next_is_document_end() { + break; + } + } // We are at the beginning of a non-empty line. trailing_blank = is_blank(self.ch()); if !literal && !leading_break.is_empty() && !leading_blank && !trailing_blank { diff --git a/parser/tests/yaml-test-suite.rs b/parser/tests/yaml-test-suite.rs index 1e88b65..45cd15d 100644 --- a/parser/tests/yaml-test-suite.rs +++ b/parser/tests/yaml-test-suite.rs @@ -220,7 +220,7 @@ fn events_differ(actual: Vec, expected: &str) -> Option { continue; } else { Some(format!( - "line {} differs: expected `{}`, found `{}`", + "line {} differs: \n=> expected `{}`\n=> found `{}`", idx, exp, act )) } @@ -297,8 +297,6 @@ fn expected_events(expected_tree: &str) -> Vec { #[rustfmt::skip] static EXPECTED_FAILURES: &[&str] = &[ - // Directives (various) - "W4TN", // scalar confused as directive // Losing trailing newline "JEF9-02", "L24T-01",