diff --git a/.github/workflows/daily-grammar-check.yml b/.github/workflows/daily-grammar-check.yml index 7cf4417528..8b90c2e53b 100644 --- a/.github/workflows/daily-grammar-check.yml +++ b/.github/workflows/daily-grammar-check.yml @@ -41,6 +41,7 @@ jobs: cargo run --release -p grammar-check -- lex-compare --path rust cargo run --release -p grammar-check -- lex-compare --permute Token --tool rustc_parse cargo run --release -p grammar-check -- lex-compare --permute three + cargo run --release -p grammar-check -- lex-compare --tool rustc_parse - name: Check for existing open issues if: steps.grammar-check.outcome == 'failure' diff --git a/src/comments.md b/src/comments.md index 7102bf5825..44ef06fc33 100644 --- a/src/comments.md +++ b/src/comments.md @@ -17,8 +17,8 @@ LINE_COMMENT -> | `//` _immediately followed by LF_ BLOCK_COMMENT -> - `/*` !(`!` | `*` ![`*` `/`]) ^ - ( BLOCK_COMMENT_OR_DOC | (!`*/` CHAR) )* + `/*` ^ + ( BLOCK_COMMENT | BLOCK_CHAR )* `*/` INNER_LINE_DOC -> @@ -27,7 +27,7 @@ INNER_LINE_DOC -> LINE_DOC_COMMENT_CONTENT -> (!CR ~LF)* INNER_BLOCK_DOC -> - `/*!` ^ ( BLOCK_COMMENT_OR_DOC | BLOCK_CHAR )* `*/` + `/*!` ^ ( NESTED_BLOCK_DOC_COMMENT | DOC_BLOCK_CHAR )* `*/` OUTER_LINE_DOC -> `///` ^ LINE_DOC_COMMENT_CONTENT (LF | EOF) @@ -35,16 +35,16 @@ OUTER_LINE_DOC -> OUTER_BLOCK_DOC -> `/**` ![`*` `/`] ^ - ( ~[`*` CR] | BLOCK_COMMENT_OR_DOC ) - ( BLOCK_COMMENT_OR_DOC | BLOCK_CHAR )* + ~[`*` CR] + ( NESTED_BLOCK_DOC_COMMENT | DOC_BLOCK_CHAR )* `*/` -BLOCK_CHAR -> (!(`*/` | CR) CHAR) +BLOCK_CHAR -> !`*/` CHAR -BLOCK_COMMENT_OR_DOC -> - INNER_BLOCK_DOC - | OUTER_BLOCK_DOC - | BLOCK_COMMENT +DOC_BLOCK_CHAR -> (!(`*/` | CR) CHAR) + +NESTED_BLOCK_DOC_COMMENT -> + `/*` ( NESTED_BLOCK_DOC_COMMENT | DOC_BLOCK_CHAR )* `*/` ``` r[comments.normal] diff --git a/tools/grammar-check/src/main.rs b/tools/grammar-check/src/main.rs index 12512d26dd..ea571d59e3 100644 --- a/tools/grammar-check/src/main.rs +++ b/tools/grammar-check/src/main.rs @@ -419,6 +419,7 @@ fn translate_position(input: &str, index: usize) -> (&str, usize, usize) { fn display_line(src: &str, range: &Range) -> String { let (line, line_no, col_no) = translate_position(src, range.start); + let line = line.replace('\r', "␍"); let prefix = format!("{line_no}: "); let indent = col_no.saturating_sub(1); let len = (range.end - range.start).min(line.len().saturating_sub(indent)); diff --git a/tools/grammar-check/src/test_cases.rs b/tools/grammar-check/src/test_cases.rs index da3a13e19c..7b7b7f6606 100644 --- a/tools/grammar-check/src/test_cases.rs +++ b/tools/grammar-check/src/test_cases.rs @@ -41,6 +41,27 @@ cases! { "/// ☃" comment::outer_block_doc => "/** outer block doc */" + comment::cr_starting_block_doc => + "/**\r CR starting block doc comment */" + comment::cr_starting_inner_block_doc => + "/*!\r CR starting inner block doc comment */" + + comment::block::nested_cr1 => + "/* /**\r*/ */" + comment::block::nested_cr2 => + "/* /*!\r*/ */" + comment::block::nested_cr3 => + "/* /** x\r y */ */" + comment::block::nested_cr4 => + "/** /*\r*/ */" + comment::block::nested_cr5 => + "/*! /*\r*/ */" + comment::block::nested_cr6 => + "/** /* x\r y */ */" + comment::block::nested_cr7 => + "/** /* /*\r*/ */ */" + comment::block::nested_cr8 => + "/* /* /**\r*/ */ */" reserved::pounds => "##" @@ -54,6 +75,9 @@ cases! { "'x'" string => "\"string\"" + string::continuation::bare_carriage => + "\"string\\\n\n\r\tcontinuation\"" + raw_string => "r\"raw string\"" "r#\"raw string\"#" @@ -81,4 +105,7 @@ cases! { identifier => "ident" "fn" + + shebang::doc_comment => + "#! /** doc */ [attr]\n" }