From 0102823cac61f98da939fcd7562b34ad1a13285b Mon Sep 17 00:00:00 2001 From: OmarTawfik <15987992+OmarTawfik@users.noreply.github.com> Date: Tue, 10 Oct 2023 14:29:47 -0700 Subject: [PATCH] --- --- .../inputs/language/src/definition.rs | 322 +++++++++++++++++- 1 file changed, 306 insertions(+), 16 deletions(-) diff --git a/crates/solidity/inputs/language/src/definition.rs b/crates/solidity/inputs/language/src/definition.rs index 378ab0052d..81b1d23a01 100644 --- a/crates/solidity/inputs/language/src/definition.rs +++ b/crates/solidity/inputs/language/src/definition.rs @@ -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])) ) ), @@ -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( @@ -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, @@ -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) + ) + ) + ] + ) + ] + ) ] );