Skip to content

Commit

Permalink
Don't explicitly specify not_followed_by to disambiguate scanners (#688)
Browse files Browse the repository at this point in the history
Part of #638

This leverages the existing trie construction for the literal scanners.
By not explicitly disambiguating ourselves, we won't have to be careful
about missing something when updating the grammar.

cc @OmarTawfik since we talked about this recently
  • Loading branch information
Xanewok authored Dec 4, 2023
1 parent b5fca94 commit 3619746
Show file tree
Hide file tree
Showing 6 changed files with 348 additions and 446 deletions.
112 changes: 16 additions & 96 deletions crates/solidity/inputs/language/src/definition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1825,25 +1825,15 @@ codegen_language_macros::compile!(Language(
),
Token(
name = Colon,
definitions = [TokenDefinition(
scanner = TrailingContext(
scanner = Atom(":"),
not_followed_by = Atom("=")
)
)]
definitions = [TokenDefinition(scanner = Atom(":"))]
),
Token(
name = ColonEqual,
definitions = [TokenDefinition(scanner = Atom(":="))]
),
Token(
name = Equal,
definitions = [TokenDefinition(
scanner = TrailingContext(
scanner = Atom("="),
not_followed_by = Choice([Atom("="), Atom(">")])
)
)]
definitions = [TokenDefinition(scanner = Atom("="))]
),
Token(
name = EqualEqual,
Expand All @@ -1855,12 +1845,7 @@ codegen_language_macros::compile!(Language(
),
Token(
name = Asterisk,
definitions = [TokenDefinition(
scanner = TrailingContext(
scanner = Atom("*"),
not_followed_by = Choice([Atom("="), Atom("*")])
)
)]
definitions = [TokenDefinition(scanner = Atom("*"))]
),
Token(
name = AsteriskEqual,
Expand All @@ -1872,12 +1857,7 @@ codegen_language_macros::compile!(Language(
),
Token(
name = Bar,
definitions = [TokenDefinition(
scanner = TrailingContext(
scanner = Atom("|"),
not_followed_by = Choice([Atom("="), Atom("|")])
)
)]
definitions = [TokenDefinition(scanner = Atom("|"))]
),
Token(
name = BarEqual,
Expand All @@ -1889,12 +1869,7 @@ codegen_language_macros::compile!(Language(
),
Token(
name = Ampersand,
definitions = [TokenDefinition(
scanner = TrailingContext(
scanner = Atom("&"),
not_followed_by = Choice([Atom("="), Atom("&")])
)
)]
definitions = [TokenDefinition(scanner = Atom("&"))]
),
Token(
name = AmpersandEqual,
Expand All @@ -1906,77 +1881,47 @@ codegen_language_macros::compile!(Language(
),
Token(
name = LessThan,
definitions = [TokenDefinition(
scanner = TrailingContext(
scanner = Atom("<"),
not_followed_by = Choice([Atom("="), Atom("<")])
)
)]
definitions = [TokenDefinition(scanner = Atom("<"))]
),
Token(
name = LessThanEqual,
definitions = [TokenDefinition(scanner = Atom("<="))]
),
Token(
name = LessThanLessThan,
definitions = [TokenDefinition(
scanner = TrailingContext(
scanner = Atom("<<"),
not_followed_by = Atom("=")
)
)]
definitions = [TokenDefinition(scanner = Atom("<<"))]
),
Token(
name = LessThanLessThanEqual,
definitions = [TokenDefinition(scanner = Atom("<<="))]
),
Token(
name = GreaterThan,
definitions = [TokenDefinition(
scanner = TrailingContext(
scanner = Atom(">"),
not_followed_by = Choice([Atom("="), Atom(">")])
)
)]
definitions = [TokenDefinition(scanner = Atom(">"))]
),
Token(
name = GreaterThanEqual,
definitions = [TokenDefinition(scanner = Atom(">="))]
),
Token(
name = GreaterThanGreaterThan,
definitions = [TokenDefinition(
scanner = TrailingContext(
scanner = Atom(">>"),
not_followed_by = Choice([Atom("="), Atom(">")])
)
)]
definitions = [TokenDefinition(scanner = Atom(">>"))]
),
Token(
name = GreaterThanGreaterThanEqual,
definitions = [TokenDefinition(scanner = Atom(">>="))]
),
Token(
name = GreaterThanGreaterThanGreaterThan,
definitions = [TokenDefinition(
scanner = TrailingContext(
scanner = Atom(">>>"),
not_followed_by = Atom("=")
)
)]
definitions = [TokenDefinition(scanner = Atom(">>>"))]
),
Token(
name = GreaterThanGreaterThanGreaterThanEqual,
definitions = [TokenDefinition(scanner = Atom(">>>="))]
),
Token(
name = Plus,
definitions = [TokenDefinition(
scanner = TrailingContext(
scanner = Atom("+"),
not_followed_by = Choice([Atom("="), Atom("+")])
)
)]
definitions = [TokenDefinition(scanner = Atom("+"))]
),
Token(
name = PlusEqual,
Expand All @@ -1988,12 +1933,7 @@ codegen_language_macros::compile!(Language(
),
Token(
name = Minus,
definitions = [TokenDefinition(
scanner = TrailingContext(
scanner = Atom("-"),
not_followed_by = Choice([Atom("="), Atom("-"), Atom(">")])
)
)]
definitions = [TokenDefinition(scanner = Atom("-"))]
),
Token(
name = MinusEqual,
Expand All @@ -2009,51 +1949,31 @@ codegen_language_macros::compile!(Language(
),
Token(
name = Slash,
definitions = [TokenDefinition(
scanner = TrailingContext(
scanner = Atom("/"),
not_followed_by = Atom("=")
)
)]
definitions = [TokenDefinition(scanner = Atom("/"))]
),
Token(
name = SlashEqual,
definitions = [TokenDefinition(scanner = Atom("/="))]
),
Token(
name = Percent,
definitions = [TokenDefinition(
scanner = TrailingContext(
scanner = Atom("%"),
not_followed_by = Atom("=")
)
)]
definitions = [TokenDefinition(scanner = Atom("%"))]
),
Token(
name = PercentEqual,
definitions = [TokenDefinition(scanner = Atom("%="))]
),
Token(
name = Bang,
definitions = [TokenDefinition(
scanner = TrailingContext(
scanner = Atom("!"),
not_followed_by = Atom("=")
)
)]
definitions = [TokenDefinition(scanner = Atom("!"))]
),
Token(
name = BangEqual,
definitions = [TokenDefinition(scanner = Atom("!="))]
),
Token(
name = Caret,
definitions = [TokenDefinition(
scanner = TrailingContext(
scanner = Atom("^"),
not_followed_by = Atom("=")
)
)]
definitions = [TokenDefinition(scanner = Atom("^"))]
),
Token(
name = CaretEqual,
Expand Down
Loading

0 comments on commit 3619746

Please sign in to comment.