Skip to content

Commit

Permalink
prevent parsing multiple literals under StringExpression before `0.…
Browse files Browse the repository at this point in the history
…5.14` (#799)

Introduced in ethereum/solidity#7524
  • Loading branch information
OmarTawfik authored Feb 13, 2024
1 parent ac9d107 commit 303dda9
Show file tree
Hide file tree
Showing 37 changed files with 497 additions and 67 deletions.
5 changes: 5 additions & 0 deletions .changeset/four-cats-bake.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@nomicfoundation/slang": patch
---

prevent parsing multiple literals under `StringExpression` before `0.5.14`
27 changes: 23 additions & 4 deletions crates/solidity/inputs/language/src/definition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3690,15 +3690,30 @@ codegen_language_macros::compile!(Language(
Enum(
name = StringExpression,
variants = [
EnumVariant(reference = HexStringLiterals),
EnumVariant(reference = AsciiStringLiterals),
EnumVariant(reference = HexStringLiteral, enabled = Till("0.5.14")),
EnumVariant(
reference = HexStringLiterals,
enabled = From("0.5.14")
),
EnumVariant(
reference = AsciiStringLiteral,
enabled = Till("0.5.14")
),
EnumVariant(
reference = AsciiStringLiterals,
enabled = From("0.5.14")
),
EnumVariant(
reference = UnicodeStringLiterals,
enabled = From("0.7.0")
)
]
),
Repeated(name = HexStringLiterals, reference = HexStringLiteral),
Repeated(
name = HexStringLiterals,
reference = HexStringLiteral,
enabled = From("0.5.14")
),
Token(
name = HexStringLiteral,
definitions = [
Expand Down Expand Up @@ -3742,7 +3757,11 @@ codegen_language_macros::compile!(Language(
Range(inclusive_start = 'A', inclusive_end = 'F')
])
),
Repeated(name = AsciiStringLiterals, reference = AsciiStringLiteral),
Repeated(
name = AsciiStringLiterals,
reference = AsciiStringLiteral,
enabled = From("0.5.14")
),
Token(
name = AsciiStringLiteral,
definitions = [
Expand Down
64 changes: 46 additions & 18 deletions crates/solidity/outputs/cargo/crate/src/generated/language.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 20 additions & 14 deletions crates/solidity/outputs/npm/package/src/ast/generated/ast_types.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 6 additions & 2 deletions crates/solidity/outputs/spec/generated/grammar.ebnf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# This file is generated automatically by infrastructure scripts. Please don't edit by hand.

Source: >
1 │ "foo" 'bar' │ 0..11
Errors: # 1 total
- >
Error: Expected end of file.
╭─[crates/solidity/testing/snapshots/cst_output/AsciiStringLiterals/multiple/input.sol:1:1]
1 │ "foo" 'bar'
│ ─────┬─────
│ ╰─────── Error occurred here.
───╯
Tree:
- (SKIPPED): '"foo" ''bar''' # (0..11)
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# This file is generated automatically by infrastructure scripts. Please don't edit by hand.

Source: >
1 │ "foo" │ 0..5
Errors: # 1 total
- >
Error: Expected end of file.
╭─[crates/solidity/testing/snapshots/cst_output/AsciiStringLiterals/single/input.sol:1:1]
1 │ "foo"
│ ──┬──
│ ╰──── Error occurred here.
───╯
Tree:
- (SKIPPED): '"foo"' # (0..5)
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,13 @@ Source: >
Errors: # 1 total
- >
Error: Expected AsciiStringLiteral.
╭─[crates/solidity/testing/snapshots/cst_output/AsciiStringLiterals/single_trailing_ident/input.sol:1:6]
Error: Expected end of file.
╭─[crates/solidity/testing/snapshots/cst_output/AsciiStringLiterals/single_trailing_ident/input.sol:1:1]
1 │ "foo"bar
──┬
─── Error occurred here.
────┬───
╰────── Error occurred here.
───╯
Tree:
- (AsciiStringLiterals): # '"foo"bar\n' (0..9)
- (item꞉ AsciiStringLiteral): '"foo"' # (0..5)
- (SKIPPED): "bar\n" # (5..9)
- (SKIPPED): '"foo"bar\n' # (0..9)
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# This file is generated automatically by infrastructure scripts. Please don't edit by hand.

Source: >
1 │ "foo"bar │ 0..8
Errors: # 1 total
- >
Error: Expected AsciiStringLiteral.
╭─[crates/solidity/testing/snapshots/cst_output/AsciiStringLiterals/single_trailing_ident/input.sol:1:6]
1 │ "foo"bar
│ ──┬─
│ ╰─── Error occurred here.
───╯
Tree:
- (AsciiStringLiterals): # '"foo"bar\n' (0..9)
- (item꞉ AsciiStringLiteral): '"foo"' # (0..5)
- (SKIPPED): "bar\n" # (5..9)
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,9 @@ Tree:
- (LeadingTrivia) ► (Whitespace): " " # (158..159)
- (variant꞉ Identifier): "amount" # (159..165)
- (separator꞉ Comma): "," # (165..166)
- (item꞉ Expression) ► (variant꞉ StringExpression) ► (variant꞉ AsciiStringLiterals): # ' "Address: insufficient balance"' (166..198)
- (item꞉ Expression) ► (variant꞉ StringExpression): # ' "Address: insufficient balance"' (166..198)
- (LeadingTrivia) ► (Whitespace): " " # (166..167)
- (item꞉ AsciiStringLiteral): '"Address: insufficient balance"' # (167..198)
- (variant꞉ AsciiStringLiteral): '"Address: insufficient balance"' # (167..198)
- (close_paren꞉ CloseParen): ")" # (198..199)
- (semicolon꞉ Semicolon): ";" # (199..200)
- (TrailingTrivia) ► (EndOfLine): "\n" # (200..201)
Expand Down Expand Up @@ -132,9 +132,9 @@ Tree:
- (arguments꞉ PositionalArguments): # 'success, "Address: unable to send value, recipient...' (274..343)
- (item꞉ Expression) ► (variant꞉ Identifier): "success" # (274..281)
- (separator꞉ Comma): "," # (281..282)
- (item꞉ Expression) ► (variant꞉ StringExpression) ► (variant꞉ AsciiStringLiterals): # ' "Address: unable to send value, recipient may hav...' (282..343)
- (item꞉ Expression) ► (variant꞉ StringExpression): # ' "Address: unable to send value, recipient may hav...' (282..343)
- (LeadingTrivia) ► (Whitespace): " " # (282..283)
- (item꞉ AsciiStringLiteral): '"Address: unable to send value, recipient may have...' # (283..343)
- (variant꞉ AsciiStringLiteral): '"Address: unable to send value, recipient may have...' # (283..343)
- (close_paren꞉ CloseParen): ")" # (343..344)
- (semicolon꞉ Semicolon): ";" # (344..345)
- (TrailingTrivia) ► (EndOfLine): "\n" # (345..346)
Expand Down
Loading

0 comments on commit 303dda9

Please sign in to comment.