Skip to content

Commit

Permalink
fix: Define DecimalLiteral in DSL v2 using the DSL v1 rules
Browse files Browse the repository at this point in the history
Otherwise, the following rule:

```rust
// An integer (without a dot or a fraction) is enabled in all versions:
TokenDefinition(
    scanner = TrailingContext(
        scanner = Sequence([
            Fragment(DecimalDigits),
            Optional(Fragment(DecimalExponent))
        ]),
        not_followed_by = Fragment(IdentifierStart)
    )
),
```

was a catch-all rule that could successfully lex "1.2" as "1" in all versions.

Instead, this mimicks the following version from the DSL v1:
```rust
scanner DecimalLiteral = (
        (
            (
                { removed in "0.5.0"    (DecimalDigits (("." (DecimalDigits ?) ) ?)) } |
                { introduced in "0.5.0" (DecimalDigits (("." DecimalDigits     ) ?)) } |
                ('.' DecimalDigits)
            )
            (DecimalExponent ?)
        ) not followed by IdentifierStart
    ) ;
```
  • Loading branch information
Xanewok committed Nov 7, 2023
1 parent a59a464 commit 560c04d
Showing 1 changed file with 18 additions and 18 deletions.
36 changes: 18 additions & 18 deletions crates/solidity/inputs/language/src/definition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3671,44 +3671,44 @@ codegen_language_macros::compile!(Language(
Token(
name = DecimalLiteral,
definitions = [
// An integer (without a dot or a fraction) is enabled in all versions:
TokenDefinition(
scanner = TrailingContext(
scanner = Sequence([
Fragment(DecimalDigits),
Optional(Fragment(DecimalExponent))
]),
not_followed_by = Fragment(IdentifierStart)
)
),
// An integer and a dot (without a fraction) is disabled in "0.5.0"
// An integer, optionally with a dot that may not be followed by a fraction, is disabled in "0.5.0":
TokenDefinition(
enabled = Till("0.5.0"),
scanner = TrailingContext(
scanner = Sequence([
Fragment(DecimalDigits),
Atom("."),
Sequence([
Fragment(DecimalDigits),
Optional(Sequence([
Atom("."),
Optional(Fragment(DecimalDigits))
]))
]),
Optional(Fragment(DecimalExponent))
]),
not_followed_by = Fragment(IdentifierStart)
)
),
// A dot and a fraction (without an integer) is enabled in all versions:
// An integer, optionally with dot that is always followed by a fraction, is enabled in "0.5.0":
TokenDefinition(
enabled = From("0.5.0"),
scanner = TrailingContext(
scanner = Sequence([
Atom("."),
Fragment(DecimalDigits),
Sequence([
Fragment(DecimalDigits),
Optional(Sequence([
Atom("."),
Fragment(DecimalDigits)
]))
]),
Optional(Fragment(DecimalExponent))
]),
not_followed_by = Fragment(IdentifierStart)
)
),
// An integer, a dot, and 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([
Fragment(DecimalDigits),
Atom("."),
Fragment(DecimalDigits),
Optional(Fragment(DecimalExponent))
Expand Down

0 comments on commit 560c04d

Please sign in to comment.