Skip to content

Commit e24eecf

Browse files
authored
Merge pull request #2348 from ehuss/fix-more-comments
Fix nested block comment grammar
2 parents 7ae6109 + c49c560 commit e24eecf

4 files changed

Lines changed: 39 additions & 10 deletions

File tree

‎.github/workflows/daily-grammar-check.yml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ jobs:
4141
cargo run --release -p grammar-check -- lex-compare --path rust
4242
cargo run --release -p grammar-check -- lex-compare --permute Token --tool rustc_parse
4343
cargo run --release -p grammar-check -- lex-compare --permute three
44+
cargo run --release -p grammar-check -- lex-compare --tool rustc_parse
4445
4546
- name: Check for existing open issues
4647
if: steps.grammar-check.outcome == 'failure'

‎src/comments.md‎

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ LINE_COMMENT ->
1717
| `//` _immediately followed by LF_
1818
1919
BLOCK_COMMENT ->
20-
`/*` !(`!` | `*` ![`*` `/`]) ^
21-
( BLOCK_COMMENT_OR_DOC | (!`*/` CHAR) )*
20+
`/*` ^
21+
( BLOCK_COMMENT | BLOCK_CHAR )*
2222
`*/`
2323
2424
INNER_LINE_DOC ->
@@ -27,24 +27,24 @@ INNER_LINE_DOC ->
2727
LINE_DOC_COMMENT_CONTENT -> (!CR ~LF)*
2828
2929
INNER_BLOCK_DOC ->
30-
`/*!` ^ ( BLOCK_COMMENT_OR_DOC | BLOCK_CHAR )* `*/`
30+
`/*!` ^ ( NESTED_BLOCK_DOC_COMMENT | DOC_BLOCK_CHAR )* `*/`
3131
3232
OUTER_LINE_DOC ->
3333
`///` ^ LINE_DOC_COMMENT_CONTENT (LF | EOF)
3434
3535
OUTER_BLOCK_DOC ->
3636
`/**` ![`*` `/`]
3737
^
38-
( ~[`*` CR] | BLOCK_COMMENT_OR_DOC )
39-
( BLOCK_COMMENT_OR_DOC | BLOCK_CHAR )*
38+
~[`*` CR]
39+
( NESTED_BLOCK_DOC_COMMENT | DOC_BLOCK_CHAR )*
4040
`*/`
4141
42-
BLOCK_CHAR -> (!(`*/` | CR) CHAR)
42+
BLOCK_CHAR -> !`*/` CHAR
4343
44-
BLOCK_COMMENT_OR_DOC ->
45-
INNER_BLOCK_DOC
46-
| OUTER_BLOCK_DOC
47-
| BLOCK_COMMENT
44+
DOC_BLOCK_CHAR -> (!(`*/` | CR) CHAR)
45+
46+
NESTED_BLOCK_DOC_COMMENT ->
47+
`/*` ( NESTED_BLOCK_DOC_COMMENT | DOC_BLOCK_CHAR )* `*/`
4848
```
4949

5050
r[comments.normal]

‎tools/grammar-check/src/main.rs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,7 @@ fn translate_position(input: &str, index: usize) -> (&str, usize, usize) {
419419

420420
fn display_line(src: &str, range: &Range<usize>) -> String {
421421
let (line, line_no, col_no) = translate_position(src, range.start);
422+
let line = line.replace('\r', "␍");
422423
let prefix = format!("{line_no}: ");
423424
let indent = col_no.saturating_sub(1);
424425
let len = (range.end - range.start).min(line.len().saturating_sub(indent));

‎tools/grammar-check/src/test_cases.rs‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,27 @@ cases! {
4141
"/// ☃"
4242
comment::outer_block_doc =>
4343
"/** outer block doc */"
44+
comment::cr_starting_block_doc =>
45+
"/**\r CR starting block doc comment */"
46+
comment::cr_starting_inner_block_doc =>
47+
"/*!\r CR starting inner block doc comment */"
48+
49+
comment::block::nested_cr1 =>
50+
"/* /**\r*/ */"
51+
comment::block::nested_cr2 =>
52+
"/* /*!\r*/ */"
53+
comment::block::nested_cr3 =>
54+
"/* /** x\r y */ */"
55+
comment::block::nested_cr4 =>
56+
"/** /*\r*/ */"
57+
comment::block::nested_cr5 =>
58+
"/*! /*\r*/ */"
59+
comment::block::nested_cr6 =>
60+
"/** /* x\r y */ */"
61+
comment::block::nested_cr7 =>
62+
"/** /* /*\r*/ */ */"
63+
comment::block::nested_cr8 =>
64+
"/* /* /**\r*/ */ */"
4465

4566
reserved::pounds =>
4667
"##"
@@ -54,6 +75,9 @@ cases! {
5475
"'x'"
5576
string =>
5677
"\"string\""
78+
string::continuation::bare_carriage =>
79+
"\"string\\\n\n\r\tcontinuation\""
80+
5781
raw_string =>
5882
"r\"raw string\""
5983
"r#\"raw string\"#"
@@ -81,4 +105,7 @@ cases! {
81105
identifier =>
82106
"ident"
83107
"fn"
108+
109+
shebang::doc_comment =>
110+
"#! /** doc */ [attr]\n"
84111
}

0 commit comments

Comments
 (0)