Skip to content

Commit

Permalink
refactor: Use disjoint token definitions for DecimalLiteral
Browse files Browse the repository at this point in the history
  • Loading branch information
Xanewok committed Mar 19, 2024
1 parent 2ae750d commit 3c9f225
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 45 deletions.
42 changes: 22 additions & 20 deletions crates/solidity/inputs/language/src/definition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3664,7 +3664,18 @@ codegen_language_macros::compile!(Language(
Token(
name = DecimalLiteral,
definitions = [
// An integer (without a dot or a fraction) is enabled in all versions:
// A dot and a fraction (without an integer) is enabled in all versions:
TokenDefinition(
scanner = TrailingContext(
scanner = Sequence([
Atom("."),
Fragment(DecimalDigits),
Optional(Fragment(DecimalExponent))
]),
not_followed_by = Fragment(IdentifierStart)
)
),
// A bare integer (without a dot or a fraction) is enabled in all versions:
TokenDefinition(
scanner = TrailingContext(
scanner = Sequence([
Expand All @@ -3677,7 +3688,7 @@ codegen_language_macros::compile!(Language(
not_followed_by = Fragment(IdentifierStart)
)
),
// An integer and a dot (without a fraction) is disabled in "0.5.0"
// Till 0.5.0, the following lone dot was considered a part of the literal:
TokenDefinition(
enabled = Till("0.5.0"),
scanner = TrailingContext(
Expand All @@ -3692,39 +3703,30 @@ codegen_language_macros::compile!(Language(
not_followed_by = Fragment(IdentifierStart)
)
),
// Since 0.5.0, only consume a dot if it's followed by a digit:
// As well as the full form of digits followed by a dot followed by digits...
TokenDefinition(
enabled = From("0.5.0"),
enabled = Till("0.5.0"),
scanner = TrailingContext(
scanner = Sequence([
Fragment(DecimalDigits),
Optional(Sequence([
Atom("."),
Fragment(DecimalDigits)
])),
Optional(Fragment(DecimalExponent))
]),
not_followed_by = Fragment(IdentifierStart)
)
),
// A dot and a fraction (without an integer) is enabled in all versions:
TokenDefinition(
scanner = TrailingContext(
scanner = Sequence([
Atom("."),
Fragment(DecimalDigits),
Optional(Fragment(DecimalExponent))
]),
not_followed_by = Fragment(IdentifierStart)
)
),
// An integer, a dot, and a fraction is enabled in all versions:
// ...both of which was subsumed by a more general form that only included
// the dot if it was followed by a decimal literal:
TokenDefinition(
enabled = From("0.5.0"),
scanner = TrailingContext(
scanner = Sequence([
Fragment(DecimalDigits),
Atom("."),
Fragment(DecimalDigits),
Optional(Sequence([
Atom("."),
Fragment(DecimalDigits)
])),
Optional(Fragment(DecimalExponent))
]),
not_followed_by = Fragment(IdentifierStart)
Expand Down

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

9 changes: 5 additions & 4 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.

0 comments on commit 3c9f225

Please sign in to comment.