From 495b16ebea5f34c69f6ed51b9808cfd306fa29e5 Mon Sep 17 00:00:00 2001 From: Oleksandr Zarudnyi Date: Thu, 9 May 2024 14:01:58 +0200 Subject: [PATCH] fix: handle the code keyword in Ethereum tests --- .../parser/lexical/token/lexeme/keyword.rs | 4 ++++ .../function_call/parser/syntax/parser/gas.rs | 23 ++++++++++++++++++- 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/solidity_adapter/src/test/function_call/parser/lexical/token/lexeme/keyword.rs b/solidity_adapter/src/test/function_call/parser/lexical/token/lexeme/keyword.rs index afe1da02..83808cf9 100644 --- a/solidity_adapter/src/test/function_call/parser/lexical/token/lexeme/keyword.rs +++ b/solidity_adapter/src/test/function_call/parser/lexical/token/lexeme/keyword.rs @@ -41,6 +41,8 @@ pub enum Keyword { Legacy, /// The `legacyOptimized` keyword. LegacyOptimized, + /// The `code` keyword. + Code, /// The `bool` type keyword. Bool, @@ -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), @@ -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"), diff --git a/solidity_adapter/src/test/function_call/parser/syntax/parser/gas.rs b/solidity_adapter/src/test/function_call/parser/syntax/parser/gas.rs index 98441b9f..105f4cb6 100644 --- a/solidity_adapter/src/test/function_call/parser/syntax/parser/gas.rs +++ b/solidity_adapter/src/test/function_call/parser/syntax/parser/gas.rs @@ -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, @@ -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( @@ -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),