Skip to content
1 change: 1 addition & 0 deletions .github/workflows/daily-grammar-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
20 changes: 10 additions & 10 deletions src/comments.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ LINE_COMMENT ->
| `//` _immediately followed by LF_

BLOCK_COMMENT ->
`/*` !(`!` | `*` ![`*` `/`]) ^
( BLOCK_COMMENT_OR_DOC | (!`*/` CHAR) )*
`/*` ^
( BLOCK_COMMENT | BLOCK_CHAR )*
`*/`

INNER_LINE_DOC ->
Expand All @@ -27,24 +27,24 @@ 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)

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]
Expand Down
1 change: 1 addition & 0 deletions tools/grammar-check/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,7 @@ fn translate_position(input: &str, index: usize) -> (&str, usize, usize) {

fn display_line(src: &str, range: &Range<usize>) -> 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));
Expand Down
27 changes: 27 additions & 0 deletions tools/grammar-check/src/test_cases.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 =>
"##"
Expand All @@ -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\"#"
Expand Down Expand Up @@ -81,4 +105,7 @@ cases! {
identifier =>
"ident"
"fn"

shebang::doc_comment =>
"#! /** doc */ [attr]\n"
}
Loading