2022-06-20 20:32:29 -07:00
|
|
|
// Grammar for our EVM assembly code.
|
|
|
|
|
// Loosely based on https://gist.github.com/axic/17ddbbce4738ccf4040d30cbb5de484e
|
|
|
|
|
|
|
|
|
|
WHITESPACE = _{ " " | "\t" | NEWLINE }
|
|
|
|
|
COMMENT = _{ "/*" ~ (!"*/" ~ ANY)* ~ "*/" | "//" ~ (!NEWLINE ~ ANY)* ~ NEWLINE }
|
|
|
|
|
|
|
|
|
|
identifier_first_char = _{ ASCII_ALPHA | "_" }
|
|
|
|
|
identifier_char = _{ ASCII_ALPHANUMERIC | "_" }
|
|
|
|
|
identifier = @{ identifier_first_char ~ identifier_char* }
|
|
|
|
|
|
|
|
|
|
literal_decimal = @{ ASCII_DIGIT+ }
|
|
|
|
|
literal_hex = @{ ^"0x" ~ ASCII_HEX_DIGIT+ }
|
|
|
|
|
literal = { literal_hex | literal_decimal }
|
|
|
|
|
|
2022-07-07 08:59:53 -07:00
|
|
|
variable = ${ "$" ~ identifier }
|
2022-07-08 08:56:46 -07:00
|
|
|
constant = ${ "@" ~ identifier }
|
2022-07-07 08:59:53 -07:00
|
|
|
|
2022-06-25 23:10:08 -07:00
|
|
|
item = { macro_def | macro_call | global_label | local_label | bytes_item | push_instruction | nullary_instruction }
|
2022-07-07 08:59:53 -07:00
|
|
|
macro_def = { ^"%macro" ~ identifier ~ macro_paramlist? ~ item* ~ ^"%endmacro" }
|
|
|
|
|
macro_call = ${ "%" ~ !(^"macro" | ^"endmacro") ~ identifier ~ macro_arglist? }
|
|
|
|
|
macro_paramlist = { "(" ~ identifier ~ ("," ~ identifier)* ~ ")" }
|
|
|
|
|
macro_arglist = !{ "(" ~ push_target ~ ("," ~ push_target)* ~ ")" }
|
2022-06-20 20:32:29 -07:00
|
|
|
global_label = { ^"GLOBAL " ~ identifier ~ ":" }
|
|
|
|
|
local_label = { identifier ~ ":" }
|
|
|
|
|
bytes_item = { ^"BYTES " ~ literal ~ ("," ~ literal)* }
|
2022-07-07 08:59:53 -07:00
|
|
|
push_instruction = { ^"PUSH " ~ push_target }
|
2022-07-08 08:56:46 -07:00
|
|
|
push_target = { literal | identifier | variable | constant }
|
2022-06-20 20:32:29 -07:00
|
|
|
nullary_instruction = { identifier }
|
|
|
|
|
|
|
|
|
|
file = { SOI ~ item* ~ silent_eoi }
|
|
|
|
|
silent_eoi = _{ !ANY }
|