Fix block scalars and document end interaction.

This commit is contained in:
Ethiraric 2024-01-19 19:33:26 +01:00
parent 308b07bad2
commit 9b653e607b
2 changed files with 17 additions and 3 deletions

View file

@ -612,6 +612,16 @@ impl<T: Iterator<Item = char>> Scanner<T> {
}
}
/// 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<T: Iterator<Item = char>> Scanner<T> {
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 {

View file

@ -220,7 +220,7 @@ fn events_differ(actual: Vec<String>, expected: &str) -> Option<String> {
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<String> {
#[rustfmt::skip]
static EXPECTED_FAILURES: &[&str] = &[
// Directives (various)
"W4TN", // scalar confused as directive
// Losing trailing newline
"JEF9-02",
"L24T-01",