Skip to content

Commit 7fbf4d2

Browse files
authored
[v2] Fix multiline natspec comment lexing (#1470)
Fixes #1469 Goes from matching multiline NatSpec comments with `r#"/\*\*[^\*]*\*+([^/\*][^\*]*\*+)*/"#` to `r#"/\*\*([^/\*][^\*]*)?\*+([^/\*][^\*]*\*+)*/"#`. The main difference is that immediately after the `/**` a character different than `/` is expected. A [sourcify run over all the chains](https://github.com/NomicFoundation/slang/actions/runs/19328166314) shows a few errors, but I think these are different. Still, a lot less failing contracts than before.
1 parent a005493 commit 7fbf4d2

File tree

3 files changed

+7
-10
lines changed

3 files changed

+7
-10
lines changed

crates/solidity-v2/inputs/language/src/definition.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,7 @@ language_v2_macros::compile!(Language(
440440
// https://stackoverflow.com/a/36328890
441441
scanner = Sequence([
442442
Atom("/**"),
443-
ZeroOrMore(Not(['*'])),
443+
Optional(Sequence([Not(['/', '*']), ZeroOrMore(Not(['*']))])),
444444
OneOrMore(Atom("*")),
445445
ZeroOrMore(Sequence([
446446
Not(['/', '*']),

crates/solidity-v2/outputs/cargo/parser/src/lexer/contexts.generated.rs

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/solidity-v2/outputs/cargo/parser/src/lexer/tests/trivia.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,9 @@ fn multi_line_comment() {
3232
test(
3333
"/**/ /**/",
3434
&[
35-
// TODO(v2): lexer is greedy, and tries to match the longest possible token by default.
36-
// Grammar should be fixed to consider this input as two separate comments with whitespace in between:
37-
// (L::MultiLineComment, 0..4),
38-
// (L::Whitespace, 4..5),
39-
// (L::MultiLineComment, 5..9),
40-
(L::MultiLineNatSpecComment, 0..9),
35+
(L::MultiLineComment, 0..4),
36+
(L::Whitespace, 4..5),
37+
(L::MultiLineComment, 5..9),
4138
],
4239
);
4340

0 commit comments

Comments
 (0)