From fb8e298a51a8cc94d069fae9d6c26c3a5389b865 Mon Sep 17 00:00:00 2001 From: Guilherme Gois Date: Tue, 3 Sep 2019 09:07:58 -0300 Subject: [PATCH 1/2] WIP: create AssemblySwitch --- solidity.pegjs | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/solidity.pegjs b/solidity.pegjs index a8d8b0c..ab04ed1 100755 --- a/solidity.pegjs +++ b/solidity.pegjs @@ -219,6 +219,7 @@ Keyword / ContractToken / InterfaceToken / DeleteToken + / DefaultToken / DoToken / ElseToken / ForToken @@ -230,6 +231,7 @@ Keyword / PragmaToken / ReturnToken / ReturnsToken + / SwitchToken / ThisToken / ThrowToken / VarToken @@ -492,7 +494,9 @@ ConstantToken = "constant" !IdentifierPart ContinueToken = "continue" !IdentifierPart ContractToken = "contract" !IdentifierPart ConstructorToken = "constructor" !IdentifierPart +CaseToken = "case" !IdentifierPart DaysToken = "days" !IdentifierPart +DefaultToken = "default" !IdentifierPart DeleteToken = "delete" !IdentifierPart DoToken = "do" !IdentifierPart ElseToken = "else" !IdentifierPart @@ -531,6 +535,7 @@ SolidityToken = "solidity" !IdentifierPart StorageToken = "storage" !IdentifierPart StructToken = "struct" !IdentifierPart SuperToken = "super" !IdentifierPart +SwitchToken = "switch" !IdentifierPart SzaboToken = "szabo" !IdentifierPart ThisToken = "this" !IdentifierPart ThrowToken = "throw" !IdentifierPart @@ -1774,7 +1779,9 @@ AssemblyItem / AssemblyAssignment / AssemblyLabel / AssemblyIf + / AssemblySwitch / AssemblyFor + / AssemblyBreakContinue / NumericLiteral / StringLiteral / HexStringLiteral @@ -1875,6 +1882,42 @@ AssemblyIf } } +AssemblySwitch + = SwitchToken __ test:AssemblyExpression __ body:AssemblySwitchStatement { + return { + type: "AssemblySwitch", + test: test, + body: body, + start: location().start.offset, + end: location().end.offset + } + } + +AssemblySwitchStatement + = AssemblyCase+ AssemblyDefault? + / AssemblyDefault + +AssemblyCase + = CaseToken __ value:Literal __ body:InlineAssemblyBlock { + return { + type: "AssemblyCase", + value: value, + body: body, + start: location().start.offset, + end: location().end.offset + } + } + +AssemblyDefault + = DefaultToken __ body:InlineAssemblyBlock { + return { + type: "AssemblyDefault", + body: body, + start: location().start.offset, + end: location().end.offset + } + } + AssemblyFor = ForToken __ init:(InlineAssemblyBlock / FunctionalAssemblyInstruction) __ @@ -1892,3 +1935,7 @@ AssemblyFor end: location().end.offset }; } + +AssemblyBreakContinue + = BreakToken + / ContinueToken From dc897ad608335eb484116ff6c8024b0e7a356ec1 Mon Sep 17 00:00:00 2001 From: Guilherme Gois Date: Sat, 7 Sep 2019 20:55:50 -0300 Subject: [PATCH 2/2] Fix AssemblySwitch rule for case with default --- solidity.pegjs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/solidity.pegjs b/solidity.pegjs index ab04ed1..dc845ca 100755 --- a/solidity.pegjs +++ b/solidity.pegjs @@ -1894,7 +1894,7 @@ AssemblySwitch } AssemblySwitchStatement - = AssemblyCase+ AssemblyDefault? + = AssemblyCase+ __ AssemblyDefault? / AssemblyDefault AssemblyCase