Skip to content

Commit

Permalink
use v1 grammar for string literals
Browse files Browse the repository at this point in the history
  • Loading branch information
OmarTawfik committed Nov 9, 2023
1 parent f0cb998 commit 2ac86a0
Showing 1 changed file with 74 additions and 99 deletions.
173 changes: 74 additions & 99 deletions crates/solidity/inputs/language/src/definition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ codegen_language_macros::compile!(Language(
Struct(
name = PathImportSymbol,
fields = (
path = Required(NonTerminal(AsciiStringLiteral)),
path = Required(Terminal([AsciiStringLiteral])),
alias = Optional(kind = NonTerminal(ImportAlias))
)
),
Expand All @@ -233,7 +233,7 @@ codegen_language_macros::compile!(Language(
asterisk = Required(Terminal([Asterisk])),
alias = Required(NonTerminal(ImportAlias)),
from_keyword = Required(Terminal([FromKeyword])),
path = Required(NonTerminal(AsciiStringLiteral))
path = Required(Terminal([AsciiStringLiteral]))
)
),
Struct(
Expand All @@ -247,7 +247,7 @@ codegen_language_macros::compile!(Language(
fields = Required(NonTerminal(ImportDeconstructionFields)),
close_brace = Required(Terminal([CloseBrace])),
from_keyword = Required(Terminal([FromKeyword])),
path = Required(NonTerminal(AsciiStringLiteral))
path = Required(Terminal([AsciiStringLiteral]))
)
),
Separated(
Expand Down Expand Up @@ -3797,38 +3797,28 @@ codegen_language_macros::compile!(Language(
]
),
Repeated(name = HexStringLiterals, repeated = HexStringLiteral),
Enum(
Token(
name = HexStringLiteral,
variants = [
EnumVariant(
name = SingleQuoted,
reference = SingleQuotedHexStringLiteral
),
EnumVariant(
name = DoubleQuoted,
reference = DoubleQuotedHexStringLiteral
)
definitions = [
TokenDefinition(scanner = Fragment(SingleQuotedHexStringLiteral)),
TokenDefinition(scanner = Fragment(DoubleQuotedHexStringLiteral))
]
),
Token(
Fragment(
name = SingleQuotedHexStringLiteral,
definitions = [TokenDefinition(
scanner = Sequence([
Atom("hex'"),
Optional(Fragment(HexStringContents)),
Atom("'")
])
)]
scanner = Sequence([
Atom("hex'"),
Optional(Fragment(HexStringContents)),
Atom("'")
])
),
Token(
Fragment(
name = DoubleQuotedHexStringLiteral,
definitions = [TokenDefinition(
scanner = Sequence([
Atom("hex\""),
Optional(Fragment(HexStringContents)),
Atom("\"")
])
)]
scanner = Sequence([
Atom("hex\""),
Optional(Fragment(HexStringContents)),
Atom("\"")
])
),
Fragment(
name = HexStringContents,
Expand All @@ -3851,95 +3841,80 @@ codegen_language_macros::compile!(Language(
])
),
Repeated(name = AsciiStringLiterals, repeated = AsciiStringLiteral),
Enum(
Token(
name = AsciiStringLiteral,
variants = [
EnumVariant(
name = SingleQuoted,
reference = SingleQuotedAsciiStringLiteral
),
EnumVariant(
name = DoubleQuoted,
reference = DoubleQuotedAsciiStringLiteral
)
definitions = [
TokenDefinition(scanner = Fragment(SingleQuotedAsciiStringLiteral)),
TokenDefinition(scanner = Fragment(DoubleQuotedAsciiStringLiteral))
]
),
Token(
Fragment(
name = SingleQuotedAsciiStringLiteral,
definitions = [TokenDefinition(
scanner = Sequence([
Atom("'"),
ZeroOrMore(Choice([
Fragment(EscapeSequence),
Range(inclusive_start = ' ', inclusive_end = '&'),
Range(inclusive_start = '(', inclusive_end = '['),
Range(inclusive_start = ']', inclusive_end = '~')
])),
Atom("'")
])
)]
scanner = Sequence([
Atom("'"),
ZeroOrMore(Choice([
Fragment(EscapeSequence),
Range(inclusive_start = ' ', inclusive_end = '&'),
Range(inclusive_start = '(', inclusive_end = '['),
Range(inclusive_start = ']', inclusive_end = '~')
])),
Atom("'")
])
),
Token(
Fragment(
name = DoubleQuotedAsciiStringLiteral,
definitions = [TokenDefinition(
scanner = Sequence([
Atom("\""),
ZeroOrMore(Choice([
Fragment(EscapeSequence),
Range(inclusive_start = ' ', inclusive_end = '!'),
Range(inclusive_start = '#', inclusive_end = '['),
Range(inclusive_start = ']', inclusive_end = '~')
])),
Atom("\"")
])
)]
scanner = Sequence([
Atom("\""),
ZeroOrMore(Choice([
Fragment(EscapeSequence),
Range(inclusive_start = ' ', inclusive_end = '!'),
Range(inclusive_start = '#', inclusive_end = '['),
Range(inclusive_start = ']', inclusive_end = '~')
])),
Atom("\"")
])
),
Repeated(
name = UnicodeStringLiterals,
repeated = UnicodeStringLiteral,
enabled = From("0.7.0")
),
Enum(
Token(
name = UnicodeStringLiteral,
enabled = From("0.7.0"),
variants = [
EnumVariant(
name = SingleQuoted,
reference = SingleQuotedUnicodeStringLiteral
definitions = [
TokenDefinition(
enabled = From("0.7.0"),
scanner = Fragment(SingleQuotedUnicodeStringLiteral)
),
EnumVariant(
name = DoubleQuoted,
reference = DoubleQuotedUnicodeStringLiteral
TokenDefinition(
enabled = From("0.7.0"),
scanner = Fragment(DoubleQuotedUnicodeStringLiteral)
)
]
),
Token(
Fragment(
name = SingleQuotedUnicodeStringLiteral,
definitions = [TokenDefinition(
enabled = From("0.7.0"),
scanner = Sequence([
Atom("unicode'"),
ZeroOrMore(Choice([
Fragment(EscapeSequence),
Not(['\'', '\\', '\r', '\n'])
])),
Atom("'")
])
)]
enabled = From("0.7.0"),
scanner = Sequence([
Atom("unicode'"),
ZeroOrMore(Choice([
Fragment(EscapeSequence),
Not(['\'', '\\', '\r', '\n'])
])),
Atom("'")
])
),
Token(
Fragment(
name = DoubleQuotedUnicodeStringLiteral,
definitions = [TokenDefinition(
enabled = From("0.7.0"),
scanner = Sequence([
Atom("unicode\""),
ZeroOrMore(Choice([
Fragment(EscapeSequence),
Not(['"', '\\', '\r', '\n'])
])),
Atom("\"")
])
)]
enabled = From("0.7.0"),
scanner = Sequence([
Atom("unicode\""),
ZeroOrMore(Choice([
Fragment(EscapeSequence),
Not(['"', '\\', '\r', '\n'])
])),
Atom("\"")
])
),
Fragment(
name = EscapeSequence,
Expand Down Expand Up @@ -4035,7 +4010,7 @@ codegen_language_macros::compile!(Language(
name = AssemblyStatement,
fields = (
assembly_keyword = Required(Terminal([AssemblyKeyword])),
label = Optional(kind = NonTerminal(AsciiStringLiteral)),
label = Optional(kind = Terminal([AsciiStringLiteral])),
flags = Optional(kind = NonTerminal(AssemblyFlagsDeclaration)),
body = Required(NonTerminal(YulBlock))
)
Expand Down

0 comments on commit 2ac86a0

Please sign in to comment.