Skip to content

Commit

Permalink
fix: handle the code keyword in Ethereum tests
Browse files Browse the repository at this point in the history
  • Loading branch information
hedgar2017 committed May 9, 2024
1 parent e81f05a commit 495b16e
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ pub enum Keyword {
Legacy,
/// The `legacyOptimized` keyword.
LegacyOptimized,
/// The `code` keyword.
Code,

/// The `bool` type keyword.
Bool,
Expand Down Expand Up @@ -153,6 +155,7 @@ impl TryFrom<&str> for Keyword {
"irOptimized" => return Ok(Self::IrOptimized),
"legacy" => return Ok(Self::Legacy),
"legacyOptimized" => return Ok(Self::LegacyOptimized),
"code" => return Ok(Self::Code),

"bool" => return Ok(Self::Bool),
"string" => return Ok(Self::String),
Expand Down Expand Up @@ -249,6 +252,7 @@ impl fmt::Display for Keyword {
Self::IrOptimized => write!(f, "irOptimized"),
Self::Legacy => write!(f, "legacy"),
Self::LegacyOptimized => write!(f, "legacyOptimized"),
Self::Code => write!(f, "code"),

Self::Bool => write!(f, "bool"),
Self::String => write!(f, "string"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ pub enum State {
/// The `gas` has been parsed so far.
Variant,
/// The `gas {variant}` has been parsed so far.
CodeOrColon,
/// The `gas {variant}` has been parsed so far.
Colon,
/// The `gas {variant}:` has been parsed so far.
Value,
Expand Down Expand Up @@ -93,7 +95,7 @@ impl Parser {
..
} => {
self.builder.set_keyword(keyword);
self.state = State::Colon;
self.state = State::CodeOrColon;
}
Token { lexeme, location } => {
return Err(SyntaxError::new(
Expand All @@ -104,6 +106,25 @@ impl Parser {
.into());
}
},
State::CodeOrColon => match parser::take_or_next(self.next.take(), stream.clone())?
{
Token {
lexeme: Lexeme::Keyword(Keyword::Code),
location,
} => {
self.builder.set_location(location);
self.state = State::Colon;
}
Token {
lexeme: Lexeme::Symbol(Symbol::Colon),
..
} => {
self.state = State::Value;
}
Token { lexeme, location } => {
return Err(SyntaxError::new(location, vec!["code", ":"], lexeme).into());
}
},
State::Colon => match parser::take_or_next(self.next.take(), stream.clone())? {
Token {
lexeme: Lexeme::Symbol(Symbol::Colon),
Expand Down

0 comments on commit 495b16e

Please sign in to comment.