Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
  • Loading branch information
OmarTawfik committed Oct 10, 2023
1 parent 4e75da6 commit 0102823
Showing 1 changed file with 306 additions and 16 deletions.
322 changes: 306 additions & 16 deletions crates/solidity/inputs/language/src/definition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,6 @@ codegen_language_macros::compile!(
name = Experimental,
fields = (
experimental_keyword = Single(Token([ExperimentalKeyword])),
// Grammar says any token but semicolon
feature = Single(Token([AsciiStringLiteral, Identifier]))
)
),
Expand Down Expand Up @@ -1090,7 +1089,7 @@ codegen_language_macros::compile!(
name = ReturnsDeclaration,
fields = (
returns_keyword = Single(Token([ReturnsKeyword])),
parameters = Single(Rule(ParametersDeclaration))
variables = Single(Rule(ParametersDeclaration))
)
),
Enum(
Expand Down Expand Up @@ -1820,11 +1819,10 @@ codegen_language_macros::compile!(
enabled_in = "0.8.4",
fields = (statement = Single(Rule(RevertStatement)))
),
// TODO: re-enable
// Variant(
// name = Assembly,
// fields = (statement = Single(Rule(AssemblyStatement)))
// ),
Variant(
name = Assembly,
fields = (statement = Single(Rule(AssemblyStatement)))
),
Variant(name = Block, fields = (block = Single(Rule(Block)))),
Variant(
name = UncheckedBlock,
Expand Down Expand Up @@ -2816,14 +2814,306 @@ codegen_language_macros::compile!(
]
)
]
) // TODO: fill in this whole section (3 topics):
// Section(
// title = "Yul",
// topics = [
// Topic(title = "Assembly Block", items = []),
// Topic(title = "Yul Statements", items = []),
// Topic(title = "Yul Expressions", items = [])
// ]
// )
),
Section(
title = "Yul",
topics = [
Topic(
title = "Yul Statements",
items = [
Struct(
name = AssemblyStatement,
fields = (
assembly_keyword = Single(Token([AssemblyKeyword])),
label = Optional(reference = Token([AsciiStringLiteral])),
flags = Optional(reference = Rule(AssemblyFlagsDeclaration)),
body = Single(Rule(YulBlock))
)
),
Struct(
name = AssemblyFlagsDeclaration,
fields = (
open_paren = Single(Token([OpenParen])),
flags = Single(Rule(AssemblyFlags)),
close_paren = Single(Token([CloseParen]))
)
),
Separated(
name = AssemblyFlags,
separated = AsciiStringLiteral,
separator = Comma,
allow_empty = true
),
Struct(
name = YulBlock,
fields = (
open_paren = Single(Token([OpenParen])),
statements = Single(Rule(YulStatements)),
close_paren = Single(Token([CloseParen]))
)
),
Repeated(
name = YulStatements,
repeated = YulStatement,
allow_empty = true
),
Enum(
name = YulStatement,
variants = [
Variant(name = Block, fields = (block = Single(Rule(YulBlock)))),
Variant(
name = Function,
fields = (definition = Single(Rule(YulFunctionDefinition)))
),
Variant(
name = VariableDeclaration,
fields =
(statement = Single(Rule(YulVariableDeclarationStatement)))
),
Variant(
name = Assignment,
fields = (statement = Single(Rule(YulAssignmentStatement)))
),
Variant(
name = If,
fields = (statement = Single(Rule(YulIfStatement)))
),
Variant(
name = For,
fields = (statement = Single(Rule(YulForStatement)))
),
Variant(
name = Switch,
fields = (statement = Single(Rule(YulSwitchStatement)))
),
Variant(
name = Leave,
enabled_in = "0.6.0",
fields = (statement = Single(Rule(YulLeaveStatement)))
),
Variant(
name = Break,
fields = (statement = Single(Rule(YulBreakStatement)))
),
Variant(
name = Continue,
fields = (statement = Single(Rule(YulContinueStatement)))
),
Variant(
name = Expression,
fields = (expression = Single(Rule(YulExpression)))
)
]
),
Struct(
name = YulFunctionDefinition,
fields = (
function_keyword = Single(Token([FunctionKeyword])),
name = Single(Token([YulIdentifier])),
parameters = Single(Rule(YulParametersDeclaration)),
returns = Optional(reference = Rule(YulReturnsDeclaration)),
body = Single(Rule(YulBlock))
)
),
Struct(
name = YulParametersDeclaration,
fields = (
open_paren = Single(Token([OpenParen])),
parameters = Single(Rule(YulParameters)),
close_paren = Single(Token([CloseParen]))
)
),
Separated(
name = YulParameters,
separated = YulIdentifier,
separator = Comma,
allow_empty = true
),
Struct(
name = YulReturnsDeclaration,
fields = (
minus_greater_than = Single(Token([MinusGreaterThan])),
variables = Single(Rule(YulReturnVariables))
)
),
Separated(
name = YulReturnVariables,
separated = YulIdentifier,
separator = Comma
),
Struct(
name = YulVariableDeclarationStatement,
fields = (
let_keyword = Single(Token([LetKeyword])),
names = Single(Rule(YulIdentifierPaths)),
value = Optional(reference = Rule(YulVariableDeclarationValue))
)
),
Struct(
name = YulVariableDeclarationValue,
fields = (
colon_equal = Single(Token([ColonEqual])),
expression = Single(Rule(YulExpression))
)
),
Struct(
name = YulAssignmentStatement,
fields = (
names = Single(Rule(YulIdentifierPaths)),
colon_equal = Single(Token([ColonEqual])),
expression = Single(Rule(YulExpression))
)
),
Struct(
name = YulIfStatement,
fields = (
if_keyword = Single(Token([IfKeyword])),
condition = Single(Rule(YulExpression)),
body = Single(Rule(YulBlock))
)
),
Struct(
name = YulLeaveStatement,
enabled_in = "0.6.0",
fields = (leave_keyword = Single(Token([LeaveKeyword])))
),
Struct(
name = YulBreakStatement,
fields = (break_keyword = Single(Token([BreakKeyword])))
),
Struct(
name = YulContinueStatement,
fields = (continue_keyword = Single(Token([ContinueKeyword])))
),
Struct(
name = YulForStatement,
fields = (
for_keyword = Single(Token([ForKeyword])),
initialization = Single(Rule(YulBlock)),
condition = Single(Rule(YulExpression)),
iterator = Single(Rule(YulBlock)),
body = Single(Rule(YulBlock))
)
),
Struct(
name = YulSwitchStatement,
fields = (
switch_keyword = Single(Token([SwitchKeyword])),
expression = Single(Rule(YulExpression)),
cases = Single(Rule(YulSwitchCases))
)
),
Repeated(name = YulSwitchCases, repeated = YulSwitchCase),
Enum(
name = YulSwitchCase,
variants = [
Variant(
name = Default,
fields = (
default_keyword = Single(Token([DefaultKeyword])),
body = Single(Rule(YulBlock))
)
),
Variant(
name = Case,
fields = (
case_keyword = Single(Token([CaseKeyword])),
value = Single(Rule(YulLiteral)),
body = Single(Rule(YulBlock))
)
)
]
)
]
),
Topic(
title = "Yul Expressions",
items = [
Precedence(
name = YulExpression,
operators = [Operator(
expression_name = YulFunctionCallExpression,
model = Postfix,
fields = (
open_paren = Single(Token([OpenParen])),
arguments = Single(Rule(YulArguments)),
close_paren = Single(Token([CloseParen]))
)
)],
primary_expressions = [
Variant(
name = YulLiteral,
fields = (expression = Single(Rule(YulLiteral)))
),
Variant(
name = YulIdentifierPath,
fields = (expression = Single(Rule(YulIdentifierPath)))
)
]
),
Separated(
name = YulArguments,
separated = YulExpression,
separator = Comma,
allow_empty = true
),
Separated(
name = YulIdentifierPaths,
separated = YulIdentifierPath,
separator = Comma
),
Separated(
name = YulIdentifierPath,
separated = YulIdentifier,
separator = Period
),
Token(name = YulIdentifier, scanner = Fragment(RawIdentifier)),
Enum(
name = YulLiteral,
variants = [
Variant(
name = Boolean,
fields = (literal = Single(Token([TrueKeyword, FalseKeyword])))
),
Variant(
name = Decimal,
fields = (literal = Single(Token([YulDecimalLiteral])))
),
Variant(
name = Hex,
fields = (literal = Single(Token([YulHexLiteral])))
),
Variant(
name = HexString,
fields = (literal = Single(Token([HexStringLiteral])))
),
Variant(
name = AsciiString,
fields = (literal = Single(Token([AsciiStringLiteral])))
)
]
),
Token(
name = YulDecimalLiteral,
scanner = TrailingContext(
scanner = Choice([
Terminal("0"),
Sequence([Range('1'..'9'), ZeroOrMore(Range('0'..'9'))])
]),
not_followed_by = Fragment(IdentifierPart)
)
),
Token(
name = YulHexLiteral,
scanner = TrailingContext(
scanner =
Sequence([Terminal("0x"), OneOrMore(Fragment(HexCharacter))]),
not_followed_by = Fragment(IdentifierPart)
)
)
]
)
]
)
]
);

0 comments on commit 0102823

Please sign in to comment.