Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Support arbitrary escapes until 0.4.25 #923

Merged
merged 4 commits into from
Apr 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/poor-lemons-hammer.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@nomicfoundation/slang": patch
---

Support arbitrary ASCII escape sequences in string literals until 0.4.25
46 changes: 42 additions & 4 deletions crates/solidity/inputs/language/src/definition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3820,9 +3820,21 @@ codegen_language_macros::compile!(Language(
Token(
name = SingleQuotedStringLiteral,
definitions = [
// Allows unicode characters:
// Allows unicode characters and arbitrary escape sequences:
TokenDefinition(
enabled = Till("0.7.0"),
enabled = Till("0.4.25"),
scanner = Sequence([
Atom("'"),
ZeroOrMore(Choice([
Fragment(EscapeSequenceArbitrary),
Not(['\'', '\\', '\r', '\n'])
])),
Atom("'")
])
),
// Allows unicode characters but allows only known ASCII escape sequences:
TokenDefinition(
enabled = Range(from = "0.4.25", till = "0.7.0"),
scanner = Sequence([
Atom("'"),
ZeroOrMore(Choice([
Expand Down Expand Up @@ -3850,9 +3862,21 @@ codegen_language_macros::compile!(Language(
Token(
name = DoubleQuotedStringLiteral,
definitions = [
// Allows unicode characters:
// Allows unicode characters and arbitrary escape sequences:
TokenDefinition(
enabled = Till("0.7.0"),
enabled = Till("0.4.25"),
scanner = Sequence([
Atom("\""),
ZeroOrMore(Choice([
Fragment(EscapeSequenceArbitrary),
Not(['"', '\\', '\r', '\n'])
])),
Atom("\"")
])
),
// Allows unicode characters but allows only known ASCII escape sequences:
TokenDefinition(
enabled = Range(from = "0.4.25", till = "0.7.0"),
scanner = Sequence([
Atom("\""),
ZeroOrMore(Choice([
Expand Down Expand Up @@ -3981,6 +4005,20 @@ codegen_language_macros::compile!(Language(
])
])
),
Fragment(
name = EscapeSequenceArbitrary,
enabled = Till("0.4.25"),
scanner = Sequence([
Atom("\\"),
Choice([
// Prior to 0.4.25, it was legal to "escape" any character (incl. unicode),
// however only the ones from `AsciiEscape` were escaped in practice.
Not(['x', 'u']),
Fragment(HexByteEscape),
Fragment(UnicodeEscape)
])
])
),
Fragment(
name = AsciiEscape,
scanner = Choice([
Expand Down

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.

13 changes: 11 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.

Loading