Created
May 21, 2024 13:47
-
-
Save sambacha/6a3c5c1c163da8f1631c65450f60dd99 to your computer and use it in GitHub Desktop.
solidity.grammar for Lezer Parser - https://lezer.codemirror.net/docs/guide/#writing-a-grammar
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@top Program { Statement* } | |
@tokens { | |
pragma { "pragma" } | |
import { "import" } | |
contract { "contract" } | |
interface { "interface" } | |
library { "library" } | |
function { "function" } | |
modifier { "modifier" } | |
event { "event" } | |
struct { "struct" } | |
enum { "enum" } | |
mapping { "mapping" } | |
address { "address" } | |
bool { "bool" } | |
string { "string" } | |
int { "int" } | |
uint { "uint" } | |
public { "public" } | |
private { "private" } | |
internal { "internal" } | |
external { "external" } | |
view { "view" } | |
pure { "pure" } | |
payable { "payable" } | |
returns { "returns" } | |
memory { "memory" } | |
storage { "storage" } | |
calldata { "calldata" } | |
if { "if" } | |
else { "else" } | |
while { "while" } | |
for { "for" } | |
return { "return" } | |
break { "break" } | |
continue { "continue" } | |
new { "new" } | |
delete { "delete" } | |
require { "require" } | |
assert { "assert" } | |
Operator { | |
"+" | "-" | "*" | "/" | "%" | "=" | "==" | "!=" | "<=" | ">=" | "<" | ">" | | |
"&&" | "||" | "!" | "++" | "--" | "+=" | "-=" | "*=" | "/=" | "%=" | "&" | | |
"|" | "^" | "<<" | ">>" | "~" | |
} | |
Number { std.digit+ } | |
Boolean { "true" | "false" } | |
String { "\"" [^"]* "\"" } | |
"{ }" { "{" | "}" } | |
"( )" { "(" | ")" } | |
"[ ]" { "[" | "]" } | |
";" { ";" } | |
"," { "," } | |
"." { "." } | |
Identifier { std.asciiLetter std.asciiLetterOrDigit* } | |
} | |
Statement { | |
VariableDeclaration | FunctionDeclaration | IfStatement | WhileStatement | | |
ForStatement | ReturnStatement | ExpressionStatement | |
} | |
Expression { | |
Literal | Identifier | BinaryExpression | FunctionCall | Assignment | | |
NewExpression | |
} | |
Literal { | |
Number | Boolean | String | |
} | |
BinaryExpression { | |
Expression Operator Expression | |
} | |
FunctionCall { | |
Identifier "(" ArgumentList? ")" | |
} | |
Assignment { | |
Identifier "=" Expression | |
} | |
NewExpression { | |
"new" Type "(" ArgumentList? ")" | |
} | |
FunctionDeclaration { | |
"function" Identifier "(" ParameterList? ")" VisibilitySpecifier* | |
ReturnParameters? Block | |
} | |
ParameterList { | |
(Type Identifier ("," Type Identifier)*)? | |
} | |
VisibilitySpecifier { | |
"public" | "private" | "internal" | "external" | |
} | |
ReturnParameters { | |
"returns" "(" Type ("," Type)* ")" | |
} | |
Block { | |
"{" Statement* "}" | |
} | |
VariableDeclaration { | |
Type Identifier "=" Expression ";" | |
} | |
IfStatement { | |
"if" "(" Expression ")" Block ("else" Block)? | |
} | |
WhileStatement { | |
"while" "(" Expression ")" Block | |
} | |
ForStatement { | |
"for" "(" (VariableDeclaration | Expression? ";") Expression? ";" | |
Expression? ")" Block | |
} | |
ReturnStatement { | |
"return" Expression? ";" | |
} | |
ExpressionStatement { | |
Expression ";" | |
} | |
Type { | |
ElementaryType | UserDefinedType | |
} | |
ElementaryType { | |
"uint" | "int" | "bool" | "address" | "string" | |
} | |
UserDefinedType { | |
Identifier | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment