From 5cf6b7fedb432ec895c3a4d19851f3cb15e1e7c5 Mon Sep 17 00:00:00 2001 From: Igor Matuszewski Date: Mon, 8 Apr 2024 12:51:11 +0200 Subject: [PATCH 1/9] Skip contracts from Sanctuary that rely on exotic parser bugs (#896) Ref #892 --- crates/solidity/testing/sanctuary/src/main.rs | 2 +- .../solidity/testing/sanctuary/src/tests.rs | 46 ++++++++++++++++--- 2 files changed, 40 insertions(+), 8 deletions(-) diff --git a/crates/solidity/testing/sanctuary/src/main.rs b/crates/solidity/testing/sanctuary/src/main.rs index 2834694e6f..26b79da0b4 100644 --- a/crates/solidity/testing/sanctuary/src/main.rs +++ b/crates/solidity/testing/sanctuary/src/main.rs @@ -92,7 +92,7 @@ fn main() -> Result<()> { if failure_count > 0 { println!(); println!( - "Found '{failure_count}' failures. Please check the logs above for more information." + "Found {failure_count} failure(s). Please check the logs above for more information.", ); println!(); diff --git a/crates/solidity/testing/sanctuary/src/tests.rs b/crates/solidity/testing/sanctuary/src/tests.rs index a516ac5c9a..4c94e46982 100644 --- a/crates/solidity/testing/sanctuary/src/tests.rs +++ b/crates/solidity/testing/sanctuary/src/tests.rs @@ -1,4 +1,5 @@ use std::cmp::min; +use std::path::Path; use anyhow::Result; use infra_utils::paths::PathExtensions; @@ -59,26 +60,42 @@ pub(crate) fn select_tests<'d>( } pub fn run_test(file: &SourceFile, events: &Events) -> Result<()> { + if !file.path.exists() { + // Index can be out of date: + events.test(TestOutcome::NotFound); + return Ok(()); + } + + // Ignore contracts that rely on obvious, exotic parser bugs fixed in later versions: + if uses_exotic_parser_bug(&file.path) { + events.test(TestOutcome::Incompatible); + return Ok(()); + } + let Some(version) = extract_compiler_version(&file.compiler) else { events.test(TestOutcome::Incompatible); return Ok(()); }; - if !file.path.exists() { - // Index can be out of date: - events.test(TestOutcome::NotFound); + let source = file.path.read_to_string()?; + // Heuristic: ignore wrongly scraped sanctuary files that + // contain HTML with a Cloudflare email obfuscation attribute: + // https://github.com/tintinweb/smart-contract-sanctuary/issues/32 + if source.contains("data-cfemail=") { + events.test(TestOutcome::Incompatible); return Ok(()); } - let source = file - .path - .read_to_string()? + let source = source // Some files are null terminated. Remove the null character: // https://github.com/tintinweb/smart-contract-sanctuary/issues/30 .trim_end_matches('\0') // Remove unicode character inserted by sanctuary (illegal in Solidity): // https://github.com/tintinweb/smart-contract-sanctuary/issues/31 - .replace("[email protected]", "[email-protected]"); + .replace("[email protected]", "[email-protected]") + // Select contracts from Sanctuary were probably incorrectly web-scraped: + // https://github.com/tintinweb/smart-contract-sanctuary/issues/32 + .replace("'", "\""); let language = Language::new(version.clone())?; let output = language.parse(RuleKind::SourceUnit, &source); @@ -123,3 +140,18 @@ fn extract_compiler_version(compiler: &str) -> Option { Some(version) } + +fn uses_exotic_parser_bug(file: &Path) -> bool { + static CONTRACTS_WITH_EXOTIC_PARSER_BUGS: &[&str] = &[ + // 0.4.24: // Accepts malformed `* /` in multi-line comments: + // Fixed in 0.4.25: https://github.com/ethereum/solidity/pull/4937 + "ethereum/contracts/mainnet/79/79bb6f4492d5cb13fad8ca0ecfbccd9e2c26ac42_Gateway.sol", + // 0.4.18: // Accepts unfinished multi-line comments at the end of the file: + // Fixed in 0.4.25: https://github.com/ethereum/solidity/pull/4937 + "ethereum/contracts/mainnet/7d/7d81c361d6ac60634117dd81ab1b01b8dc795a9d_LILITHCOIN.sol", + ]; + + CONTRACTS_WITH_EXOTIC_PARSER_BUGS + .iter() + .any(|path| file.ends_with(path)) +} From e336462a5acd23f5e42234b7ad9345bbd1258c54 Mon Sep 17 00:00:00 2001 From: Igor Matuszewski Date: Mon, 8 Apr 2024 14:02:32 +0200 Subject: [PATCH 2/9] Fix nested bindings in queries (#927) Cherry-picked from https://github.com/NomicFoundation/slang/pull/884/commits/bb9238437941400b84a8b40f0d9ef953f26611f1. We need this for 0.14 to allow for more interesting queries for https://github.com/NomicFoundation/hardhat-vscode/issues/547. Co-authored-by: Antony Blakey --- crates/codegen/parser/runtime/src/query/engine.rs | 1 + .../slang_solidity/src/generated/query/engine.rs | 1 + .../slang_testlang/src/generated/query/engine.rs | 1 + .../outputs/cargo/tests/src/query/engine_tests.rs | 11 +++++++++++ 4 files changed, 14 insertions(+) diff --git a/crates/codegen/parser/runtime/src/query/engine.rs b/crates/codegen/parser/runtime/src/query/engine.rs index cb41f382d4..7be82f4133 100644 --- a/crates/codegen/parser/runtime/src/query/engine.rs +++ b/crates/codegen/parser/runtime/src/query/engine.rs @@ -181,6 +181,7 @@ impl Combinator for BindingCombinator { .entry(self.matcher.name.clone()) .or_default() .push(self.cursor.clone()); + self.child.accumulate_bindings(bindings); } } diff --git a/crates/solidity/outputs/cargo/slang_solidity/src/generated/query/engine.rs b/crates/solidity/outputs/cargo/slang_solidity/src/generated/query/engine.rs index 6cdb482c51..63ea8aa85a 100644 --- a/crates/solidity/outputs/cargo/slang_solidity/src/generated/query/engine.rs +++ b/crates/solidity/outputs/cargo/slang_solidity/src/generated/query/engine.rs @@ -183,6 +183,7 @@ impl Combinator for BindingCombinator { .entry(self.matcher.name.clone()) .or_default() .push(self.cursor.clone()); + self.child.accumulate_bindings(bindings); } } diff --git a/crates/testlang/outputs/cargo/slang_testlang/src/generated/query/engine.rs b/crates/testlang/outputs/cargo/slang_testlang/src/generated/query/engine.rs index 6cdb482c51..63ea8aa85a 100644 --- a/crates/testlang/outputs/cargo/slang_testlang/src/generated/query/engine.rs +++ b/crates/testlang/outputs/cargo/slang_testlang/src/generated/query/engine.rs @@ -183,6 +183,7 @@ impl Combinator for BindingCombinator { .entry(self.matcher.name.clone()) .or_default() .push(self.cursor.clone()); + self.child.accumulate_bindings(bindings); } } diff --git a/crates/testlang/outputs/cargo/tests/src/query/engine_tests.rs b/crates/testlang/outputs/cargo/tests/src/query/engine_tests.rs index 2d406bf0da..e102eedef7 100644 --- a/crates/testlang/outputs/cargo/tests/src/query/engine_tests.rs +++ b/crates/testlang/outputs/cargo/tests/src/query/engine_tests.rs @@ -250,3 +250,14 @@ fn test_optional() { }, ); } + +#[test] +fn test_nested() { + run_query_test( + &common_test_tree(), + "@root [TreeNode ... @z [DelimitedIdentifier] [_] ]", + query_results! { + {root: ["ABCDE"], z: ["C"]} + }, + ); +} From 9426eb56184d238b522003677e7ce955cd5456cf Mon Sep 17 00:00:00 2001 From: Igor Matuszewski Date: Tue, 9 Apr 2024 11:56:32 +0200 Subject: [PATCH 3/9] refactor: Get rid of ToJS trait and use our own NAPI wrappers in functions (#920) Follow-up to #907 I imagine we did not do that before because we had no idea how `Either` works in napi and that using these `#[napi]`-adorned types in the type signatures Just Works^TM. We could go one step further and flatten the `namespace` hierarchy in order to get rid of the manual `ts_return type = ` attributes (napi would automatically infer the types but does not have namespace information) that duplicate the type and also get rid of the manually added ```ts // index.d.ts.jinja2 export namespace cst { export type Node = RuleNode | TokenNode; } ``` But having an ability to refer to `cst.Node` by the users is, I feel, more important than our convenience here. --- .../parser/runtime/src/napi_interface/cst.rs | 54 +- .../runtime/src/napi_interface/cursor.rs | 18 +- .../src/napi_interface/parse_output.rs | 10 +- .../runtime/src/napi_interface/query.rs | 29 +- .../templates/ast_selectors.rs.jinja2 | 44 +- .../generated/napi_interface/ast_selectors.rs | 486 +++++++++--------- .../src/generated/napi_interface/cst.rs | 54 +- .../src/generated/napi_interface/cursor.rs | 18 +- .../generated/napi_interface/parse_output.rs | 10 +- .../src/generated/napi_interface/query.rs | 29 +- .../generated/napi_interface/ast_selectors.rs | 68 +-- .../src/generated/napi_interface/cst.rs | 54 +- .../src/generated/napi_interface/cursor.rs | 18 +- .../generated/napi_interface/parse_output.rs | 10 +- .../src/generated/napi_interface/query.rs | 29 +- 15 files changed, 455 insertions(+), 476 deletions(-) diff --git a/crates/codegen/parser/runtime/src/napi_interface/cst.rs b/crates/codegen/parser/runtime/src/napi_interface/cst.rs index ad19bfa629..18e309851d 100644 --- a/crates/codegen/parser/runtime/src/napi_interface/cst.rs +++ b/crates/codegen/parser/runtime/src/napi_interface/cst.rs @@ -1,7 +1,6 @@ use std::rc::Rc; -use napi::bindgen_prelude::Env; -use napi::JsObject; +use napi::Either; use napi_derive::napi; use crate::napi_interface::cursor::Cursor; @@ -16,6 +15,22 @@ pub enum NodeType { Token, } +impl RustNode { + /// Converts the node into `napi` wrapper for `RuleNode | TokenNode` JS object. + pub fn into_js_either_node(self) -> Either { + match self { + RustNode::Rule(rule) => Either::A(RuleNode(rule)), + RustNode::Token(token) => Either::B(TokenNode(token)), + } + } +} + +impl From for Either { + fn from(value: RustNode) -> Self { + value.into_js_either_node() + } +} + #[napi(namespace = "cst")] pub struct RuleNode(pub(crate) Rc); @@ -50,11 +65,11 @@ impl RuleNode { } #[napi(ts_return_type = "Array", catch_unwind)] - pub fn children(&self, env: Env) -> Vec { + pub fn children(&self) -> Vec> { self.0 .children .iter() - .map(|child| child.to_js(env)) + .map(|child| child.node.clone().into()) .collect() } @@ -117,34 +132,3 @@ impl TokenNode { .into() } } - -pub(crate) trait ToJS { - fn to_js(&self, env: Env) -> JsObject; -} - -impl ToJS for Rc { - fn to_js(&self, env: Env) -> JsObject { - RuleNode(self.clone()) - .into_instance(env) - .expect("Class constructor to be defined by #[napi]") - .as_object(env) - } -} - -impl ToJS for Rc { - fn to_js(&self, env: Env) -> JsObject { - TokenNode(self.clone()) - .into_instance(env) - .expect("Class constructor to be defined by #[napi]") - .as_object(env) - } -} - -impl ToJS for RustNode { - fn to_js(&self, env: Env) -> JsObject { - match self { - RustNode::Rule(rust_rule_node) => rust_rule_node.to_js(env), - RustNode::Token(rust_token_node) => rust_token_node.to_js(env), - } - } -} diff --git a/crates/codegen/parser/runtime/src/napi_interface/cursor.rs b/crates/codegen/parser/runtime/src/napi_interface/cursor.rs index a91cfaeaa5..f3c91feaa4 100644 --- a/crates/codegen/parser/runtime/src/napi_interface/cursor.rs +++ b/crates/codegen/parser/runtime/src/napi_interface/cursor.rs @@ -3,13 +3,12 @@ // The functions are meant to be definitions for export, so they're not really used #![allow(clippy::return_self_not_must_use)] -use cst::ToJS; -use napi::bindgen_prelude::Env; -use napi::JsObject; +use napi::Either; use napi_derive::napi; use text_index::{TextIndex, TextRange}; -use crate::napi_interface::{cst, text_index, NodeLabel, RuleKind, RustCursor, TokenKind}; +use crate::napi_interface::cst::{self, RuleNode, TokenNode}; +use crate::napi_interface::{text_index, NodeLabel, RuleKind, RustCursor, TokenKind}; #[napi(namespace = "cursor")] pub struct Cursor(pub(super) RustCursor); @@ -53,8 +52,8 @@ impl Cursor { } #[napi(ts_return_type = "cst.Node", catch_unwind)] - pub fn node(&self, env: Env) -> JsObject { - self.0.node().to_js(env) + pub fn node(&self) -> Either { + self.0.node().into() } #[napi(getter, ts_return_type = "kinds.NodeLabel", catch_unwind)] @@ -79,11 +78,8 @@ impl Cursor { } #[napi(ts_return_type = "Array", catch_unwind)] - pub fn ancestors(&self, env: Env) -> Vec { - self.0 - .ancestors() - .map(|rust_rule_node| rust_rule_node.to_js(env)) - .collect() + pub fn ancestors(&self) -> Vec { + self.0.ancestors().map(cst::RuleNode).collect() } #[napi(catch_unwind)] diff --git a/crates/codegen/parser/runtime/src/napi_interface/parse_output.rs b/crates/codegen/parser/runtime/src/napi_interface/parse_output.rs index d1804af45b..aa2cb6c7a6 100644 --- a/crates/codegen/parser/runtime/src/napi_interface/parse_output.rs +++ b/crates/codegen/parser/runtime/src/napi_interface/parse_output.rs @@ -1,8 +1,8 @@ -use cst::ToJS; -use napi::bindgen_prelude::Env; +use napi::Either; use napi_derive::napi; -use crate::napi_interface::{cst, cursor, parse_error, RustParseOutput}; +use crate::napi_interface::cst::{RuleNode, TokenNode}; +use crate::napi_interface::{cursor, parse_error, RustParseOutput}; #[napi(namespace = "parse_output")] pub struct ParseOutput(RustParseOutput); @@ -16,8 +16,8 @@ impl From for ParseOutput { #[napi(namespace = "parse_output")] impl ParseOutput { #[napi(ts_return_type = "cst.Node", catch_unwind)] - pub fn tree(&self, env: Env) -> napi::JsObject { - self.0.tree().to_js(env) + pub fn tree(&self) -> Either { + self.0.tree().into() } #[napi(ts_return_type = "Array", catch_unwind)] diff --git a/crates/codegen/parser/runtime/src/napi_interface/query.rs b/crates/codegen/parser/runtime/src/napi_interface/query.rs index 0a91717a97..f9042073db 100644 --- a/crates/codegen/parser/runtime/src/napi_interface/query.rs +++ b/crates/codegen/parser/runtime/src/napi_interface/query.rs @@ -3,7 +3,10 @@ // The functions are meant to be definitions for export, so they're not really used #![allow(clippy::return_self_not_must_use)] -use napi::{Env, JsObject}; +use std::collections::HashMap; + +use napi::bindgen_prelude::ClassInstance; +use napi::Env; use napi_derive::napi; use crate::napi_interface::cursor::Cursor; @@ -36,22 +39,28 @@ pub struct QueryResultIterator(RustQueryResultIterator); pub struct QueryResult { pub query_number: u32, #[napi(ts_type = "{ [key: string]: cursor.Cursor[] }")] - pub bindings: JsObject, + pub bindings: HashMap>>, } impl QueryResult { fn new(env: Env, result: RustQueryResult) -> napi::Result { #[allow(clippy::cast_possible_truncation)] let query_number = result.query_number as u32; - let mut bindings = env.create_object()?; - // transer all of the bindings eagerly on the assumption + // transfer all of the bindings eagerly on the assumption // that they've all been explicitly requested. - for (key, value) in result.bindings { - bindings.set_named_property( - &key, - value.into_iter().map(|x| x.into()).collect::>(), - )?; - } + let bindings = result + .bindings + .into_iter() + .map(|(key, values)| { + let instances = values + .into_iter() + .map(|cursor| Cursor(cursor).into_instance(env)) + .collect::>()?; + + Ok((key, instances)) + }) + .collect::>()?; + Ok(Self { query_number, bindings, diff --git a/crates/codegen/parser/runtime/src/napi_interface/templates/ast_selectors.rs.jinja2 b/crates/codegen/parser/runtime/src/napi_interface/templates/ast_selectors.rs.jinja2 index 9d3e5ef8aa..679afca8b0 100644 --- a/crates/codegen/parser/runtime/src/napi_interface/templates/ast_selectors.rs.jinja2 +++ b/crates/codegen/parser/runtime/src/napi_interface/templates/ast_selectors.rs.jinja2 @@ -2,10 +2,10 @@ use std::rc::Rc; -use napi::{Env, JsObject}; +use napi::Either; use napi_derive::napi; -use crate::napi_interface::cst::{RuleNode, ToJS}; +use crate::napi_interface::cst::{RuleNode, TokenNode}; use crate::napi_interface::{RuleKind, RustLabeledNode, RustNode, RustRuleNode, TokenKind}; // @@ -19,9 +19,8 @@ use crate::napi_interface::{RuleKind, RustLabeledNode, RustNode, RustRuleNode, T )] pub fn select_sequence( #[napi(ts_arg_type = "cst.RuleNode")] node: &RuleNode, - env: Env, -) -> Result>> { - let mut selector = Selector::new(node, env); +) -> Result>>> { + let mut selector = Selector::new(node); let result = match node.kind() { {%- for sequence in ast_model.sequences -%} @@ -40,7 +39,7 @@ pub fn select_sequence( {% for sequence in ast_model.sequences %} impl Selector { - fn {{ sequence.name | snake_case }}(&mut self) -> Result>> { + fn {{ sequence.name | snake_case }}(&mut self) -> Result>>> { Ok(vec![ {%- for field in sequence.fields -%} {%- if field.is_optional -%} @@ -81,9 +80,8 @@ pub fn select_sequence( )] pub fn select_choice( #[napi(ts_arg_type = "cst.RuleNode")] node: &RuleNode, - env: Env, -) -> Result { - let mut selector = Selector::new(node, env); +) -> Result> { + let mut selector = Selector::new(node); let result = match node.kind() { {%- for choice in ast_model.choices -%} @@ -102,7 +100,7 @@ pub fn select_choice( {% for choice in ast_model.choices %} impl Selector { - fn {{ choice.name | snake_case }}(&mut self) -> Result { + fn {{ choice.name | snake_case }}(&mut self) -> Result> { self.select(|node| { {%- set non_terminals_len = choice.non_terminals | length -%} {%- set terminals_len = choice.terminals | length -%} @@ -146,9 +144,8 @@ pub fn select_choice( )] pub fn select_repeated( #[napi(ts_arg_type = "cst.RuleNode")] node: &RuleNode, - env: Env, -) -> Result> { - let mut selector = Selector::new(node, env); +) -> Result>> { + let mut selector = Selector::new(node); let result = match node.kind() { {%- for repeated in ast_model.repeated -%} @@ -167,7 +164,7 @@ pub fn select_repeated( {% for repeated in ast_model.repeated %} impl Selector { - fn {{ repeated.name | snake_case }}(&mut self) -> Result> { + fn {{ repeated.name | snake_case }}(&mut self) -> Result>> { let mut items = vec![]; while let Some(item) = self.try_select(|node| { @@ -196,9 +193,8 @@ pub fn select_repeated( )] pub fn select_separated( #[napi(ts_arg_type = "cst.RuleNode")] node: &RuleNode, - env: Env, -) -> Result>> { - let mut selector = Selector::new(node, env); +) -> Result>>> { + let mut selector = Selector::new(node); let result = match node.kind() { {%- for separated in ast_model.separated -%} @@ -217,7 +213,7 @@ pub fn select_separated( {% for separated in ast_model.separated %} impl Selector { - fn {{ separated.name | snake_case }}(&mut self) -> Result>> { + fn {{ separated.name | snake_case }}(&mut self) -> Result>>> { let mut separated = vec![]; let mut separators = vec![]; @@ -253,28 +249,26 @@ pub fn select_separated( // struct Selector { - env: Env, node: Rc, index: usize, } impl Selector { - fn new(node: &RuleNode, env: Env) -> Self { + fn new(node: &RuleNode) -> Self { Self { - env, node: node.0.clone(), index: 0, } } - fn select(&mut self, filter: impl FnOnce(&RustNode) -> bool) -> Result { + fn select(&mut self, filter: impl FnOnce(&RustNode) -> bool) -> Result> { match self.try_select(filter)? { Some(node) => Ok(node), None => Error::MissingChild(self.index).into(), } } - fn try_select(&mut self, filter: impl FnOnce(&RustNode) -> bool) -> Result> { + fn try_select(&mut self, filter: impl FnOnce(&RustNode) -> bool) -> Result>> { while let Some(child) = self.node.children.get(self.index) { match child { node if node.is_trivia() => { @@ -288,9 +282,9 @@ impl Selector { } if matches!(token.kind, TokenKind::SKIPPED) => { return Error::SkippedToken(self.index).into(); } - node if filter(node) => { + labeled if filter(labeled) => { self.index += 1; - return Ok(Some(node.to_js(self.env))); + return Ok(Some(labeled.node.clone().into_js_either_node())); } _ => { break; diff --git a/crates/solidity/outputs/cargo/slang_solidity/src/generated/napi_interface/ast_selectors.rs b/crates/solidity/outputs/cargo/slang_solidity/src/generated/napi_interface/ast_selectors.rs index 27c971e25e..efa50fbd10 100644 --- a/crates/solidity/outputs/cargo/slang_solidity/src/generated/napi_interface/ast_selectors.rs +++ b/crates/solidity/outputs/cargo/slang_solidity/src/generated/napi_interface/ast_selectors.rs @@ -4,10 +4,10 @@ use std::rc::Rc; -use napi::{Env, JsObject}; +use napi::Either; use napi_derive::napi; -use crate::napi_interface::cst::{RuleNode, ToJS}; +use crate::napi_interface::cst::{RuleNode, TokenNode}; use crate::napi_interface::{RuleKind, RustLabeledNode, RustNode, RustRuleNode, TokenKind}; // @@ -21,9 +21,8 @@ use crate::napi_interface::{RuleKind, RustLabeledNode, RustNode, RustRuleNode, T )] pub fn select_sequence( #[napi(ts_arg_type = "cst.RuleNode")] node: &RuleNode, - env: Env, -) -> Result>> { - let mut selector = Selector::new(node, env); +) -> Result>>> { + let mut selector = Selector::new(node); let result = match node.kind() { RuleKind::SourceUnit => selector.source_unit()?, @@ -168,7 +167,7 @@ pub fn select_sequence( } impl Selector { - fn source_unit(&mut self) -> Result>> { + fn source_unit(&mut self) -> Result>>> { Ok(vec![Some(self.select(|node| { node.is_rule_with_kind(RuleKind::SourceUnitMembers) })?)]) @@ -176,7 +175,7 @@ impl Selector { } impl Selector { - fn pragma_directive(&mut self) -> Result>> { + fn pragma_directive(&mut self) -> Result>>> { Ok(vec![ Some(self.select(|node| node.is_token_with_kind(TokenKind::PragmaKeyword))?), Some(self.select(|node| node.is_rule_with_kind(RuleKind::Pragma))?), @@ -186,7 +185,7 @@ impl Selector { } impl Selector { - fn abi_coder_pragma(&mut self) -> Result>> { + fn abi_coder_pragma(&mut self) -> Result>>> { Ok(vec![ Some(self.select(|node| node.is_token_with_kind(TokenKind::AbicoderKeyword))?), Some(self.select(|node| node.is_token_with_kind(TokenKind::Identifier))?), @@ -195,7 +194,7 @@ impl Selector { } impl Selector { - fn experimental_pragma(&mut self) -> Result>> { + fn experimental_pragma(&mut self) -> Result>>> { Ok(vec![ Some(self.select(|node| node.is_token_with_kind(TokenKind::ExperimentalKeyword))?), Some(self.select(|node| node.is_rule_with_kind(RuleKind::ExperimentalFeature))?), @@ -204,7 +203,7 @@ impl Selector { } impl Selector { - fn version_pragma(&mut self) -> Result>> { + fn version_pragma(&mut self) -> Result>>> { Ok(vec![ Some(self.select(|node| node.is_token_with_kind(TokenKind::SolidityKeyword))?), Some(self.select(|node| node.is_rule_with_kind(RuleKind::VersionPragmaExpressions))?), @@ -213,7 +212,7 @@ impl Selector { } impl Selector { - fn version_pragma_or_expression(&mut self) -> Result>> { + fn version_pragma_or_expression(&mut self) -> Result>>> { Ok(vec![ Some(self.select(|node| node.is_rule_with_kind(RuleKind::VersionPragmaExpression))?), Some(self.select(|node| node.is_token_with_kind(TokenKind::BarBar))?), @@ -223,7 +222,9 @@ impl Selector { } impl Selector { - fn version_pragma_range_expression(&mut self) -> Result>> { + fn version_pragma_range_expression( + &mut self, + ) -> Result>>> { Ok(vec![ Some(self.select(|node| node.is_rule_with_kind(RuleKind::VersionPragmaExpression))?), Some(self.select(|node| node.is_token_with_kind(TokenKind::Minus))?), @@ -233,7 +234,9 @@ impl Selector { } impl Selector { - fn version_pragma_prefix_expression(&mut self) -> Result>> { + fn version_pragma_prefix_expression( + &mut self, + ) -> Result>>> { Ok(vec![ Some(self.select(|node| node.is_token_with_kind(TokenKind::Caret))?), Some(self.select(|node| node.is_rule_with_kind(RuleKind::VersionPragmaExpression))?), @@ -242,7 +245,7 @@ impl Selector { } impl Selector { - fn import_directive(&mut self) -> Result>> { + fn import_directive(&mut self) -> Result>>> { Ok(vec![ Some(self.select(|node| node.is_token_with_kind(TokenKind::ImportKeyword))?), Some(self.select(|node| node.is_rule_with_kind(RuleKind::ImportClause))?), @@ -252,7 +255,7 @@ impl Selector { } impl Selector { - fn path_import(&mut self) -> Result>> { + fn path_import(&mut self) -> Result>>> { Ok(vec![ Some(self.select(|node| node.is_rule_with_kind(RuleKind::StringLiteral))?), self.try_select(|node| node.is_rule_with_kind(RuleKind::ImportAlias))?, @@ -261,7 +264,7 @@ impl Selector { } impl Selector { - fn named_import(&mut self) -> Result>> { + fn named_import(&mut self) -> Result>>> { Ok(vec![ Some(self.select(|node| node.is_token_with_kind(TokenKind::Asterisk))?), Some(self.select(|node| node.is_rule_with_kind(RuleKind::ImportAlias))?), @@ -272,7 +275,7 @@ impl Selector { } impl Selector { - fn import_deconstruction(&mut self) -> Result>> { + fn import_deconstruction(&mut self) -> Result>>> { Ok(vec![ Some(self.select(|node| node.is_token_with_kind(TokenKind::OpenBrace))?), Some( @@ -286,7 +289,7 @@ impl Selector { } impl Selector { - fn import_deconstruction_symbol(&mut self) -> Result>> { + fn import_deconstruction_symbol(&mut self) -> Result>>> { Ok(vec![ Some(self.select(|node| node.is_token_with_kind(TokenKind::Identifier))?), self.try_select(|node| node.is_rule_with_kind(RuleKind::ImportAlias))?, @@ -295,7 +298,7 @@ impl Selector { } impl Selector { - fn import_alias(&mut self) -> Result>> { + fn import_alias(&mut self) -> Result>>> { Ok(vec![ Some(self.select(|node| node.is_token_with_kind(TokenKind::AsKeyword))?), Some(self.select(|node| node.is_token_with_kind(TokenKind::Identifier))?), @@ -304,7 +307,7 @@ impl Selector { } impl Selector { - fn using_directive(&mut self) -> Result>> { + fn using_directive(&mut self) -> Result>>> { Ok(vec![ Some(self.select(|node| node.is_token_with_kind(TokenKind::UsingKeyword))?), Some(self.select(|node| node.is_rule_with_kind(RuleKind::UsingClause))?), @@ -317,7 +320,7 @@ impl Selector { } impl Selector { - fn using_deconstruction(&mut self) -> Result>> { + fn using_deconstruction(&mut self) -> Result>>> { Ok(vec![ Some(self.select(|node| node.is_token_with_kind(TokenKind::OpenBrace))?), Some(self.select(|node| node.is_rule_with_kind(RuleKind::UsingDeconstructionSymbols))?), @@ -327,7 +330,7 @@ impl Selector { } impl Selector { - fn using_deconstruction_symbol(&mut self) -> Result>> { + fn using_deconstruction_symbol(&mut self) -> Result>>> { Ok(vec![ Some(self.select(|node| node.is_rule_with_kind(RuleKind::IdentifierPath))?), self.try_select(|node| node.is_rule_with_kind(RuleKind::UsingAlias))?, @@ -336,7 +339,7 @@ impl Selector { } impl Selector { - fn using_alias(&mut self) -> Result>> { + fn using_alias(&mut self) -> Result>>> { Ok(vec![ Some(self.select(|node| node.is_token_with_kind(TokenKind::AsKeyword))?), Some(self.select(|node| node.is_rule_with_kind(RuleKind::UsingOperator))?), @@ -345,7 +348,7 @@ impl Selector { } impl Selector { - fn contract_definition(&mut self) -> Result>> { + fn contract_definition(&mut self) -> Result>>> { Ok(vec![ self.try_select(|node| node.is_token_with_kind(TokenKind::AbstractKeyword))?, Some(self.select(|node| node.is_token_with_kind(TokenKind::ContractKeyword))?), @@ -359,7 +362,7 @@ impl Selector { } impl Selector { - fn inheritance_specifier(&mut self) -> Result>> { + fn inheritance_specifier(&mut self) -> Result>>> { Ok(vec![ Some(self.select(|node| node.is_token_with_kind(TokenKind::IsKeyword))?), Some(self.select(|node| node.is_rule_with_kind(RuleKind::InheritanceTypes))?), @@ -368,7 +371,7 @@ impl Selector { } impl Selector { - fn inheritance_type(&mut self) -> Result>> { + fn inheritance_type(&mut self) -> Result>>> { Ok(vec![ Some(self.select(|node| node.is_rule_with_kind(RuleKind::IdentifierPath))?), self.try_select(|node| node.is_rule_with_kind(RuleKind::ArgumentsDeclaration))?, @@ -377,7 +380,7 @@ impl Selector { } impl Selector { - fn interface_definition(&mut self) -> Result>> { + fn interface_definition(&mut self) -> Result>>> { Ok(vec![ Some(self.select(|node| node.is_token_with_kind(TokenKind::InterfaceKeyword))?), Some(self.select(|node| node.is_token_with_kind(TokenKind::Identifier))?), @@ -390,7 +393,7 @@ impl Selector { } impl Selector { - fn library_definition(&mut self) -> Result>> { + fn library_definition(&mut self) -> Result>>> { Ok(vec![ Some(self.select(|node| node.is_token_with_kind(TokenKind::LibraryKeyword))?), Some(self.select(|node| node.is_token_with_kind(TokenKind::Identifier))?), @@ -402,7 +405,7 @@ impl Selector { } impl Selector { - fn struct_definition(&mut self) -> Result>> { + fn struct_definition(&mut self) -> Result>>> { Ok(vec![ Some(self.select(|node| node.is_token_with_kind(TokenKind::StructKeyword))?), Some(self.select(|node| node.is_token_with_kind(TokenKind::Identifier))?), @@ -414,7 +417,7 @@ impl Selector { } impl Selector { - fn struct_member(&mut self) -> Result>> { + fn struct_member(&mut self) -> Result>>> { Ok(vec![ Some(self.select(|node| node.is_rule_with_kind(RuleKind::TypeName))?), Some(self.select(|node| node.is_token_with_kind(TokenKind::Identifier))?), @@ -424,7 +427,7 @@ impl Selector { } impl Selector { - fn enum_definition(&mut self) -> Result>> { + fn enum_definition(&mut self) -> Result>>> { Ok(vec![ Some(self.select(|node| node.is_token_with_kind(TokenKind::EnumKeyword))?), Some(self.select(|node| node.is_token_with_kind(TokenKind::Identifier))?), @@ -436,7 +439,7 @@ impl Selector { } impl Selector { - fn constant_definition(&mut self) -> Result>> { + fn constant_definition(&mut self) -> Result>>> { Ok(vec![ Some(self.select(|node| node.is_rule_with_kind(RuleKind::TypeName))?), Some(self.select(|node| node.is_token_with_kind(TokenKind::ConstantKeyword))?), @@ -449,7 +452,7 @@ impl Selector { } impl Selector { - fn state_variable_definition(&mut self) -> Result>> { + fn state_variable_definition(&mut self) -> Result>>> { Ok(vec![ Some(self.select(|node| node.is_rule_with_kind(RuleKind::TypeName))?), Some(self.select(|node| node.is_rule_with_kind(RuleKind::StateVariableAttributes))?), @@ -461,7 +464,9 @@ impl Selector { } impl Selector { - fn state_variable_definition_value(&mut self) -> Result>> { + fn state_variable_definition_value( + &mut self, + ) -> Result>>> { Ok(vec![ Some(self.select(|node| node.is_token_with_kind(TokenKind::Equal))?), Some(self.select(|node| node.is_rule_with_kind(RuleKind::Expression))?), @@ -470,7 +475,7 @@ impl Selector { } impl Selector { - fn function_definition(&mut self) -> Result>> { + fn function_definition(&mut self) -> Result>>> { Ok(vec![ Some(self.select(|node| node.is_token_with_kind(TokenKind::FunctionKeyword))?), Some(self.select(|node| node.is_rule_with_kind(RuleKind::FunctionName))?), @@ -483,7 +488,7 @@ impl Selector { } impl Selector { - fn parameters_declaration(&mut self) -> Result>> { + fn parameters_declaration(&mut self) -> Result>>> { Ok(vec![ Some(self.select(|node| node.is_token_with_kind(TokenKind::OpenParen))?), Some(self.select(|node| node.is_rule_with_kind(RuleKind::Parameters))?), @@ -493,7 +498,7 @@ impl Selector { } impl Selector { - fn parameter(&mut self) -> Result>> { + fn parameter(&mut self) -> Result>>> { Ok(vec![ Some(self.select(|node| node.is_rule_with_kind(RuleKind::TypeName))?), self.try_select(|node| node.is_rule_with_kind(RuleKind::StorageLocation))?, @@ -503,7 +508,7 @@ impl Selector { } impl Selector { - fn override_specifier(&mut self) -> Result>> { + fn override_specifier(&mut self) -> Result>>> { Ok(vec![ Some(self.select(|node| node.is_token_with_kind(TokenKind::OverrideKeyword))?), self.try_select(|node| node.is_rule_with_kind(RuleKind::OverridePathsDeclaration))?, @@ -512,7 +517,7 @@ impl Selector { } impl Selector { - fn override_paths_declaration(&mut self) -> Result>> { + fn override_paths_declaration(&mut self) -> Result>>> { Ok(vec![ Some(self.select(|node| node.is_token_with_kind(TokenKind::OpenParen))?), Some(self.select(|node| node.is_rule_with_kind(RuleKind::OverridePaths))?), @@ -522,7 +527,7 @@ impl Selector { } impl Selector { - fn returns_declaration(&mut self) -> Result>> { + fn returns_declaration(&mut self) -> Result>>> { Ok(vec![ Some(self.select(|node| node.is_token_with_kind(TokenKind::ReturnsKeyword))?), Some(self.select(|node| node.is_rule_with_kind(RuleKind::ParametersDeclaration))?), @@ -531,7 +536,7 @@ impl Selector { } impl Selector { - fn constructor_definition(&mut self) -> Result>> { + fn constructor_definition(&mut self) -> Result>>> { Ok(vec![ Some(self.select(|node| node.is_token_with_kind(TokenKind::ConstructorKeyword))?), Some(self.select(|node| node.is_rule_with_kind(RuleKind::ParametersDeclaration))?), @@ -542,7 +547,7 @@ impl Selector { } impl Selector { - fn unnamed_function_definition(&mut self) -> Result>> { + fn unnamed_function_definition(&mut self) -> Result>>> { Ok(vec![ Some(self.select(|node| node.is_token_with_kind(TokenKind::FunctionKeyword))?), Some(self.select(|node| node.is_rule_with_kind(RuleKind::ParametersDeclaration))?), @@ -553,7 +558,7 @@ impl Selector { } impl Selector { - fn fallback_function_definition(&mut self) -> Result>> { + fn fallback_function_definition(&mut self) -> Result>>> { Ok(vec![ Some(self.select(|node| node.is_token_with_kind(TokenKind::FallbackKeyword))?), Some(self.select(|node| node.is_rule_with_kind(RuleKind::ParametersDeclaration))?), @@ -565,7 +570,7 @@ impl Selector { } impl Selector { - fn receive_function_definition(&mut self) -> Result>> { + fn receive_function_definition(&mut self) -> Result>>> { Ok(vec![ Some(self.select(|node| node.is_token_with_kind(TokenKind::ReceiveKeyword))?), Some(self.select(|node| node.is_rule_with_kind(RuleKind::ParametersDeclaration))?), @@ -576,7 +581,7 @@ impl Selector { } impl Selector { - fn modifier_definition(&mut self) -> Result>> { + fn modifier_definition(&mut self) -> Result>>> { Ok(vec![ Some(self.select(|node| node.is_token_with_kind(TokenKind::ModifierKeyword))?), Some(self.select(|node| node.is_token_with_kind(TokenKind::Identifier))?), @@ -588,7 +593,7 @@ impl Selector { } impl Selector { - fn modifier_invocation(&mut self) -> Result>> { + fn modifier_invocation(&mut self) -> Result>>> { Ok(vec![ Some(self.select(|node| node.is_rule_with_kind(RuleKind::IdentifierPath))?), self.try_select(|node| node.is_rule_with_kind(RuleKind::ArgumentsDeclaration))?, @@ -597,7 +602,7 @@ impl Selector { } impl Selector { - fn event_definition(&mut self) -> Result>> { + fn event_definition(&mut self) -> Result>>> { Ok(vec![ Some(self.select(|node| node.is_token_with_kind(TokenKind::EventKeyword))?), Some(self.select(|node| node.is_token_with_kind(TokenKind::Identifier))?), @@ -609,7 +614,7 @@ impl Selector { } impl Selector { - fn event_parameters_declaration(&mut self) -> Result>> { + fn event_parameters_declaration(&mut self) -> Result>>> { Ok(vec![ Some(self.select(|node| node.is_token_with_kind(TokenKind::OpenParen))?), Some(self.select(|node| node.is_rule_with_kind(RuleKind::EventParameters))?), @@ -619,7 +624,7 @@ impl Selector { } impl Selector { - fn event_parameter(&mut self) -> Result>> { + fn event_parameter(&mut self) -> Result>>> { Ok(vec![ Some(self.select(|node| node.is_rule_with_kind(RuleKind::TypeName))?), self.try_select(|node| node.is_token_with_kind(TokenKind::IndexedKeyword))?, @@ -629,7 +634,9 @@ impl Selector { } impl Selector { - fn user_defined_value_type_definition(&mut self) -> Result>> { + fn user_defined_value_type_definition( + &mut self, + ) -> Result>>> { Ok(vec![ Some(self.select(|node| node.is_token_with_kind(TokenKind::TypeKeyword))?), Some(self.select(|node| node.is_token_with_kind(TokenKind::Identifier))?), @@ -641,7 +648,7 @@ impl Selector { } impl Selector { - fn error_definition(&mut self) -> Result>> { + fn error_definition(&mut self) -> Result>>> { Ok(vec![ Some(self.select(|node| node.is_token_with_kind(TokenKind::ErrorKeyword))?), Some(self.select(|node| node.is_token_with_kind(TokenKind::Identifier))?), @@ -652,7 +659,7 @@ impl Selector { } impl Selector { - fn error_parameters_declaration(&mut self) -> Result>> { + fn error_parameters_declaration(&mut self) -> Result>>> { Ok(vec![ Some(self.select(|node| node.is_token_with_kind(TokenKind::OpenParen))?), Some(self.select(|node| node.is_rule_with_kind(RuleKind::ErrorParameters))?), @@ -662,7 +669,7 @@ impl Selector { } impl Selector { - fn error_parameter(&mut self) -> Result>> { + fn error_parameter(&mut self) -> Result>>> { Ok(vec![ Some(self.select(|node| node.is_rule_with_kind(RuleKind::TypeName))?), self.try_select(|node| node.is_token_with_kind(TokenKind::Identifier))?, @@ -671,7 +678,7 @@ impl Selector { } impl Selector { - fn array_type_name(&mut self) -> Result>> { + fn array_type_name(&mut self) -> Result>>> { Ok(vec![ Some(self.select(|node| node.is_rule_with_kind(RuleKind::TypeName))?), Some(self.select(|node| node.is_token_with_kind(TokenKind::OpenBracket))?), @@ -682,7 +689,7 @@ impl Selector { } impl Selector { - fn function_type(&mut self) -> Result>> { + fn function_type(&mut self) -> Result>>> { Ok(vec![ Some(self.select(|node| node.is_token_with_kind(TokenKind::FunctionKeyword))?), Some(self.select(|node| node.is_rule_with_kind(RuleKind::ParametersDeclaration))?), @@ -693,7 +700,7 @@ impl Selector { } impl Selector { - fn mapping_type(&mut self) -> Result>> { + fn mapping_type(&mut self) -> Result>>> { Ok(vec![ Some(self.select(|node| node.is_token_with_kind(TokenKind::MappingKeyword))?), Some(self.select(|node| node.is_token_with_kind(TokenKind::OpenParen))?), @@ -706,7 +713,7 @@ impl Selector { } impl Selector { - fn mapping_key(&mut self) -> Result>> { + fn mapping_key(&mut self) -> Result>>> { Ok(vec![ Some(self.select(|node| node.is_rule_with_kind(RuleKind::MappingKeyType))?), self.try_select(|node| node.is_token_with_kind(TokenKind::Identifier))?, @@ -715,7 +722,7 @@ impl Selector { } impl Selector { - fn mapping_value(&mut self) -> Result>> { + fn mapping_value(&mut self) -> Result>>> { Ok(vec![ Some(self.select(|node| node.is_rule_with_kind(RuleKind::TypeName))?), self.try_select(|node| node.is_token_with_kind(TokenKind::Identifier))?, @@ -724,7 +731,7 @@ impl Selector { } impl Selector { - fn address_type(&mut self) -> Result>> { + fn address_type(&mut self) -> Result>>> { Ok(vec![ Some(self.select(|node| node.is_token_with_kind(TokenKind::AddressKeyword))?), self.try_select(|node| node.is_token_with_kind(TokenKind::PayableKeyword))?, @@ -733,7 +740,7 @@ impl Selector { } impl Selector { - fn block(&mut self) -> Result>> { + fn block(&mut self) -> Result>>> { Ok(vec![ Some(self.select(|node| node.is_token_with_kind(TokenKind::OpenBrace))?), Some(self.select(|node| node.is_rule_with_kind(RuleKind::Statements))?), @@ -743,7 +750,7 @@ impl Selector { } impl Selector { - fn unchecked_block(&mut self) -> Result>> { + fn unchecked_block(&mut self) -> Result>>> { Ok(vec![ Some(self.select(|node| node.is_token_with_kind(TokenKind::UncheckedKeyword))?), Some(self.select(|node| node.is_rule_with_kind(RuleKind::Block))?), @@ -752,7 +759,7 @@ impl Selector { } impl Selector { - fn expression_statement(&mut self) -> Result>> { + fn expression_statement(&mut self) -> Result>>> { Ok(vec![ Some(self.select(|node| node.is_rule_with_kind(RuleKind::Expression))?), Some(self.select(|node| node.is_token_with_kind(TokenKind::Semicolon))?), @@ -761,7 +768,7 @@ impl Selector { } impl Selector { - fn assembly_statement(&mut self) -> Result>> { + fn assembly_statement(&mut self) -> Result>>> { Ok(vec![ Some(self.select(|node| node.is_token_with_kind(TokenKind::AssemblyKeyword))?), self.try_select(|node| node.is_rule_with_kind(RuleKind::StringLiteral))?, @@ -772,7 +779,7 @@ impl Selector { } impl Selector { - fn assembly_flags_declaration(&mut self) -> Result>> { + fn assembly_flags_declaration(&mut self) -> Result>>> { Ok(vec![ Some(self.select(|node| node.is_token_with_kind(TokenKind::OpenParen))?), Some(self.select(|node| node.is_rule_with_kind(RuleKind::AssemblyFlags))?), @@ -782,7 +789,9 @@ impl Selector { } impl Selector { - fn tuple_deconstruction_statement(&mut self) -> Result>> { + fn tuple_deconstruction_statement( + &mut self, + ) -> Result>>> { Ok(vec![ self.try_select(|node| node.is_token_with_kind(TokenKind::VarKeyword))?, Some(self.select(|node| node.is_token_with_kind(TokenKind::OpenParen))?), @@ -798,7 +807,7 @@ impl Selector { } impl Selector { - fn tuple_deconstruction_element(&mut self) -> Result>> { + fn tuple_deconstruction_element(&mut self) -> Result>>> { Ok(vec![self.try_select(|node| { node.is_rule_with_kind(RuleKind::TupleMember) })?]) @@ -806,7 +815,7 @@ impl Selector { } impl Selector { - fn typed_tuple_member(&mut self) -> Result>> { + fn typed_tuple_member(&mut self) -> Result>>> { Ok(vec![ Some(self.select(|node| node.is_rule_with_kind(RuleKind::TypeName))?), self.try_select(|node| node.is_rule_with_kind(RuleKind::StorageLocation))?, @@ -816,7 +825,7 @@ impl Selector { } impl Selector { - fn untyped_tuple_member(&mut self) -> Result>> { + fn untyped_tuple_member(&mut self) -> Result>>> { Ok(vec![ self.try_select(|node| node.is_rule_with_kind(RuleKind::StorageLocation))?, Some(self.select(|node| node.is_token_with_kind(TokenKind::Identifier))?), @@ -825,7 +834,9 @@ impl Selector { } impl Selector { - fn variable_declaration_statement(&mut self) -> Result>> { + fn variable_declaration_statement( + &mut self, + ) -> Result>>> { Ok(vec![ Some(self.select(|node| node.is_rule_with_kind(RuleKind::VariableDeclarationType))?), self.try_select(|node| node.is_rule_with_kind(RuleKind::StorageLocation))?, @@ -837,7 +848,7 @@ impl Selector { } impl Selector { - fn variable_declaration_value(&mut self) -> Result>> { + fn variable_declaration_value(&mut self) -> Result>>> { Ok(vec![ Some(self.select(|node| node.is_token_with_kind(TokenKind::Equal))?), Some(self.select(|node| node.is_rule_with_kind(RuleKind::Expression))?), @@ -846,7 +857,7 @@ impl Selector { } impl Selector { - fn if_statement(&mut self) -> Result>> { + fn if_statement(&mut self) -> Result>>> { Ok(vec![ Some(self.select(|node| node.is_token_with_kind(TokenKind::IfKeyword))?), Some(self.select(|node| node.is_token_with_kind(TokenKind::OpenParen))?), @@ -859,7 +870,7 @@ impl Selector { } impl Selector { - fn else_branch(&mut self) -> Result>> { + fn else_branch(&mut self) -> Result>>> { Ok(vec![ Some(self.select(|node| node.is_token_with_kind(TokenKind::ElseKeyword))?), Some(self.select(|node| node.is_rule_with_kind(RuleKind::Statement))?), @@ -868,7 +879,7 @@ impl Selector { } impl Selector { - fn for_statement(&mut self) -> Result>> { + fn for_statement(&mut self) -> Result>>> { Ok(vec![ Some(self.select(|node| node.is_token_with_kind(TokenKind::ForKeyword))?), Some(self.select(|node| node.is_token_with_kind(TokenKind::OpenParen))?), @@ -882,7 +893,7 @@ impl Selector { } impl Selector { - fn while_statement(&mut self) -> Result>> { + fn while_statement(&mut self) -> Result>>> { Ok(vec![ Some(self.select(|node| node.is_token_with_kind(TokenKind::WhileKeyword))?), Some(self.select(|node| node.is_token_with_kind(TokenKind::OpenParen))?), @@ -894,7 +905,7 @@ impl Selector { } impl Selector { - fn do_while_statement(&mut self) -> Result>> { + fn do_while_statement(&mut self) -> Result>>> { Ok(vec![ Some(self.select(|node| node.is_token_with_kind(TokenKind::DoKeyword))?), Some(self.select(|node| node.is_rule_with_kind(RuleKind::Statement))?), @@ -908,7 +919,7 @@ impl Selector { } impl Selector { - fn continue_statement(&mut self) -> Result>> { + fn continue_statement(&mut self) -> Result>>> { Ok(vec![ Some(self.select(|node| node.is_token_with_kind(TokenKind::ContinueKeyword))?), Some(self.select(|node| node.is_token_with_kind(TokenKind::Semicolon))?), @@ -917,7 +928,7 @@ impl Selector { } impl Selector { - fn break_statement(&mut self) -> Result>> { + fn break_statement(&mut self) -> Result>>> { Ok(vec![ Some(self.select(|node| node.is_token_with_kind(TokenKind::BreakKeyword))?), Some(self.select(|node| node.is_token_with_kind(TokenKind::Semicolon))?), @@ -926,7 +937,7 @@ impl Selector { } impl Selector { - fn return_statement(&mut self) -> Result>> { + fn return_statement(&mut self) -> Result>>> { Ok(vec![ Some(self.select(|node| node.is_token_with_kind(TokenKind::ReturnKeyword))?), self.try_select(|node| node.is_rule_with_kind(RuleKind::Expression))?, @@ -936,7 +947,7 @@ impl Selector { } impl Selector { - fn emit_statement(&mut self) -> Result>> { + fn emit_statement(&mut self) -> Result>>> { Ok(vec![ Some(self.select(|node| node.is_token_with_kind(TokenKind::EmitKeyword))?), Some(self.select(|node| node.is_rule_with_kind(RuleKind::IdentifierPath))?), @@ -947,7 +958,7 @@ impl Selector { } impl Selector { - fn try_statement(&mut self) -> Result>> { + fn try_statement(&mut self) -> Result>>> { Ok(vec![ Some(self.select(|node| node.is_token_with_kind(TokenKind::TryKeyword))?), Some(self.select(|node| node.is_rule_with_kind(RuleKind::Expression))?), @@ -959,7 +970,7 @@ impl Selector { } impl Selector { - fn catch_clause(&mut self) -> Result>> { + fn catch_clause(&mut self) -> Result>>> { Ok(vec![ Some(self.select(|node| node.is_token_with_kind(TokenKind::CatchKeyword))?), self.try_select(|node| node.is_rule_with_kind(RuleKind::CatchClauseError))?, @@ -969,7 +980,7 @@ impl Selector { } impl Selector { - fn catch_clause_error(&mut self) -> Result>> { + fn catch_clause_error(&mut self) -> Result>>> { Ok(vec![ self.try_select(|node| node.is_token_with_kind(TokenKind::Identifier))?, Some(self.select(|node| node.is_rule_with_kind(RuleKind::ParametersDeclaration))?), @@ -978,7 +989,7 @@ impl Selector { } impl Selector { - fn revert_statement(&mut self) -> Result>> { + fn revert_statement(&mut self) -> Result>>> { Ok(vec![ Some(self.select(|node| node.is_token_with_kind(TokenKind::RevertKeyword))?), self.try_select(|node| node.is_rule_with_kind(RuleKind::IdentifierPath))?, @@ -989,7 +1000,7 @@ impl Selector { } impl Selector { - fn throw_statement(&mut self) -> Result>> { + fn throw_statement(&mut self) -> Result>>> { Ok(vec![ Some(self.select(|node| node.is_token_with_kind(TokenKind::ThrowKeyword))?), Some(self.select(|node| node.is_token_with_kind(TokenKind::Semicolon))?), @@ -998,7 +1009,7 @@ impl Selector { } impl Selector { - fn assignment_expression(&mut self) -> Result>> { + fn assignment_expression(&mut self) -> Result>>> { Ok(vec![ Some(self.select(|node| node.is_rule_with_kind(RuleKind::Expression))?), Some(self.select(|node| node.is_token_with_kind(TokenKind::Equal))?), @@ -1008,7 +1019,7 @@ impl Selector { } impl Selector { - fn conditional_expression(&mut self) -> Result>> { + fn conditional_expression(&mut self) -> Result>>> { Ok(vec![ Some(self.select(|node| node.is_rule_with_kind(RuleKind::Expression))?), Some(self.select(|node| node.is_token_with_kind(TokenKind::QuestionMark))?), @@ -1020,7 +1031,7 @@ impl Selector { } impl Selector { - fn or_expression(&mut self) -> Result>> { + fn or_expression(&mut self) -> Result>>> { Ok(vec![ Some(self.select(|node| node.is_rule_with_kind(RuleKind::Expression))?), Some(self.select(|node| node.is_token_with_kind(TokenKind::BarBar))?), @@ -1030,7 +1041,7 @@ impl Selector { } impl Selector { - fn and_expression(&mut self) -> Result>> { + fn and_expression(&mut self) -> Result>>> { Ok(vec![ Some(self.select(|node| node.is_rule_with_kind(RuleKind::Expression))?), Some(self.select(|node| node.is_token_with_kind(TokenKind::AmpersandAmpersand))?), @@ -1040,7 +1051,7 @@ impl Selector { } impl Selector { - fn equality_expression(&mut self) -> Result>> { + fn equality_expression(&mut self) -> Result>>> { Ok(vec![ Some(self.select(|node| node.is_rule_with_kind(RuleKind::Expression))?), Some(self.select(|node| node.is_token_with_kind(TokenKind::EqualEqual))?), @@ -1050,7 +1061,7 @@ impl Selector { } impl Selector { - fn comparison_expression(&mut self) -> Result>> { + fn comparison_expression(&mut self) -> Result>>> { Ok(vec![ Some(self.select(|node| node.is_rule_with_kind(RuleKind::Expression))?), Some(self.select(|node| node.is_token_with_kind(TokenKind::LessThan))?), @@ -1060,7 +1071,7 @@ impl Selector { } impl Selector { - fn bitwise_or_expression(&mut self) -> Result>> { + fn bitwise_or_expression(&mut self) -> Result>>> { Ok(vec![ Some(self.select(|node| node.is_rule_with_kind(RuleKind::Expression))?), Some(self.select(|node| node.is_token_with_kind(TokenKind::Bar))?), @@ -1070,7 +1081,7 @@ impl Selector { } impl Selector { - fn bitwise_xor_expression(&mut self) -> Result>> { + fn bitwise_xor_expression(&mut self) -> Result>>> { Ok(vec![ Some(self.select(|node| node.is_rule_with_kind(RuleKind::Expression))?), Some(self.select(|node| node.is_token_with_kind(TokenKind::Caret))?), @@ -1080,7 +1091,7 @@ impl Selector { } impl Selector { - fn bitwise_and_expression(&mut self) -> Result>> { + fn bitwise_and_expression(&mut self) -> Result>>> { Ok(vec![ Some(self.select(|node| node.is_rule_with_kind(RuleKind::Expression))?), Some(self.select(|node| node.is_token_with_kind(TokenKind::Ampersand))?), @@ -1090,7 +1101,7 @@ impl Selector { } impl Selector { - fn shift_expression(&mut self) -> Result>> { + fn shift_expression(&mut self) -> Result>>> { Ok(vec![ Some(self.select(|node| node.is_rule_with_kind(RuleKind::Expression))?), Some(self.select(|node| node.is_token_with_kind(TokenKind::LessThanLessThan))?), @@ -1100,7 +1111,7 @@ impl Selector { } impl Selector { - fn additive_expression(&mut self) -> Result>> { + fn additive_expression(&mut self) -> Result>>> { Ok(vec![ Some(self.select(|node| node.is_rule_with_kind(RuleKind::Expression))?), Some(self.select(|node| node.is_token_with_kind(TokenKind::Plus))?), @@ -1110,7 +1121,7 @@ impl Selector { } impl Selector { - fn multiplicative_expression(&mut self) -> Result>> { + fn multiplicative_expression(&mut self) -> Result>>> { Ok(vec![ Some(self.select(|node| node.is_rule_with_kind(RuleKind::Expression))?), Some(self.select(|node| node.is_token_with_kind(TokenKind::Asterisk))?), @@ -1120,7 +1131,7 @@ impl Selector { } impl Selector { - fn exponentiation_expression(&mut self) -> Result>> { + fn exponentiation_expression(&mut self) -> Result>>> { Ok(vec![ Some(self.select(|node| node.is_rule_with_kind(RuleKind::Expression))?), Some(self.select(|node| node.is_token_with_kind(TokenKind::AsteriskAsterisk))?), @@ -1130,7 +1141,7 @@ impl Selector { } impl Selector { - fn postfix_expression(&mut self) -> Result>> { + fn postfix_expression(&mut self) -> Result>>> { Ok(vec![ Some(self.select(|node| node.is_rule_with_kind(RuleKind::Expression))?), Some(self.select(|node| node.is_token_with_kind(TokenKind::PlusPlus))?), @@ -1139,7 +1150,7 @@ impl Selector { } impl Selector { - fn prefix_expression(&mut self) -> Result>> { + fn prefix_expression(&mut self) -> Result>>> { Ok(vec![ Some(self.select(|node| node.is_token_with_kind(TokenKind::PlusPlus))?), Some(self.select(|node| node.is_rule_with_kind(RuleKind::Expression))?), @@ -1148,7 +1159,7 @@ impl Selector { } impl Selector { - fn function_call_expression(&mut self) -> Result>> { + fn function_call_expression(&mut self) -> Result>>> { Ok(vec![ Some(self.select(|node| node.is_rule_with_kind(RuleKind::Expression))?), Some(self.select(|node| node.is_rule_with_kind(RuleKind::ArgumentsDeclaration))?), @@ -1157,7 +1168,7 @@ impl Selector { } impl Selector { - fn call_options_expression(&mut self) -> Result>> { + fn call_options_expression(&mut self) -> Result>>> { Ok(vec![ Some(self.select(|node| node.is_rule_with_kind(RuleKind::Expression))?), Some(self.select(|node| node.is_token_with_kind(TokenKind::OpenBrace))?), @@ -1168,7 +1179,7 @@ impl Selector { } impl Selector { - fn member_access_expression(&mut self) -> Result>> { + fn member_access_expression(&mut self) -> Result>>> { Ok(vec![ Some(self.select(|node| node.is_rule_with_kind(RuleKind::Expression))?), Some(self.select(|node| node.is_token_with_kind(TokenKind::Period))?), @@ -1178,7 +1189,7 @@ impl Selector { } impl Selector { - fn index_access_expression(&mut self) -> Result>> { + fn index_access_expression(&mut self) -> Result>>> { Ok(vec![ Some(self.select(|node| node.is_rule_with_kind(RuleKind::Expression))?), Some(self.select(|node| node.is_token_with_kind(TokenKind::OpenBracket))?), @@ -1190,7 +1201,7 @@ impl Selector { } impl Selector { - fn index_access_end(&mut self) -> Result>> { + fn index_access_end(&mut self) -> Result>>> { Ok(vec![ Some(self.select(|node| node.is_token_with_kind(TokenKind::Colon))?), self.try_select(|node| node.is_rule_with_kind(RuleKind::Expression))?, @@ -1199,7 +1210,9 @@ impl Selector { } impl Selector { - fn positional_arguments_declaration(&mut self) -> Result>> { + fn positional_arguments_declaration( + &mut self, + ) -> Result>>> { Ok(vec![ Some(self.select(|node| node.is_token_with_kind(TokenKind::OpenParen))?), Some(self.select(|node| node.is_rule_with_kind(RuleKind::PositionalArguments))?), @@ -1209,7 +1222,7 @@ impl Selector { } impl Selector { - fn named_arguments_declaration(&mut self) -> Result>> { + fn named_arguments_declaration(&mut self) -> Result>>> { Ok(vec![ Some(self.select(|node| node.is_token_with_kind(TokenKind::OpenParen))?), self.try_select(|node| node.is_rule_with_kind(RuleKind::NamedArgumentGroup))?, @@ -1219,7 +1232,7 @@ impl Selector { } impl Selector { - fn named_argument_group(&mut self) -> Result>> { + fn named_argument_group(&mut self) -> Result>>> { Ok(vec![ Some(self.select(|node| node.is_token_with_kind(TokenKind::OpenBrace))?), Some(self.select(|node| node.is_rule_with_kind(RuleKind::NamedArguments))?), @@ -1229,7 +1242,7 @@ impl Selector { } impl Selector { - fn named_argument(&mut self) -> Result>> { + fn named_argument(&mut self) -> Result>>> { Ok(vec![ Some(self.select(|node| node.is_token_with_kind(TokenKind::Identifier))?), Some(self.select(|node| node.is_token_with_kind(TokenKind::Colon))?), @@ -1239,7 +1252,7 @@ impl Selector { } impl Selector { - fn type_expression(&mut self) -> Result>> { + fn type_expression(&mut self) -> Result>>> { Ok(vec![ Some(self.select(|node| node.is_token_with_kind(TokenKind::TypeKeyword))?), Some(self.select(|node| node.is_token_with_kind(TokenKind::OpenParen))?), @@ -1250,7 +1263,7 @@ impl Selector { } impl Selector { - fn new_expression(&mut self) -> Result>> { + fn new_expression(&mut self) -> Result>>> { Ok(vec![ Some(self.select(|node| node.is_token_with_kind(TokenKind::NewKeyword))?), Some(self.select(|node| node.is_rule_with_kind(RuleKind::TypeName))?), @@ -1259,7 +1272,7 @@ impl Selector { } impl Selector { - fn tuple_expression(&mut self) -> Result>> { + fn tuple_expression(&mut self) -> Result>>> { Ok(vec![ Some(self.select(|node| node.is_token_with_kind(TokenKind::OpenParen))?), Some(self.select(|node| node.is_rule_with_kind(RuleKind::TupleValues))?), @@ -1269,7 +1282,7 @@ impl Selector { } impl Selector { - fn tuple_value(&mut self) -> Result>> { + fn tuple_value(&mut self) -> Result>>> { Ok(vec![self.try_select(|node| { node.is_rule_with_kind(RuleKind::Expression) })?]) @@ -1277,7 +1290,7 @@ impl Selector { } impl Selector { - fn array_expression(&mut self) -> Result>> { + fn array_expression(&mut self) -> Result>>> { Ok(vec![ Some(self.select(|node| node.is_token_with_kind(TokenKind::OpenBracket))?), Some(self.select(|node| node.is_rule_with_kind(RuleKind::ArrayValues))?), @@ -1287,7 +1300,7 @@ impl Selector { } impl Selector { - fn hex_number_expression(&mut self) -> Result>> { + fn hex_number_expression(&mut self) -> Result>>> { Ok(vec![ Some(self.select(|node| node.is_token_with_kind(TokenKind::HexLiteral))?), self.try_select(|node| node.is_rule_with_kind(RuleKind::NumberUnit))?, @@ -1296,7 +1309,7 @@ impl Selector { } impl Selector { - fn decimal_number_expression(&mut self) -> Result>> { + fn decimal_number_expression(&mut self) -> Result>>> { Ok(vec![ Some(self.select(|node| node.is_token_with_kind(TokenKind::DecimalLiteral))?), self.try_select(|node| node.is_rule_with_kind(RuleKind::NumberUnit))?, @@ -1305,7 +1318,7 @@ impl Selector { } impl Selector { - fn yul_block(&mut self) -> Result>> { + fn yul_block(&mut self) -> Result>>> { Ok(vec![ Some(self.select(|node| node.is_token_with_kind(TokenKind::OpenBrace))?), Some(self.select(|node| node.is_rule_with_kind(RuleKind::YulStatements))?), @@ -1315,7 +1328,7 @@ impl Selector { } impl Selector { - fn yul_function_definition(&mut self) -> Result>> { + fn yul_function_definition(&mut self) -> Result>>> { Ok(vec![ Some(self.select(|node| node.is_token_with_kind(TokenKind::YulFunctionKeyword))?), Some(self.select(|node| node.is_token_with_kind(TokenKind::YulIdentifier))?), @@ -1327,7 +1340,7 @@ impl Selector { } impl Selector { - fn yul_parameters_declaration(&mut self) -> Result>> { + fn yul_parameters_declaration(&mut self) -> Result>>> { Ok(vec![ Some(self.select(|node| node.is_token_with_kind(TokenKind::OpenParen))?), Some(self.select(|node| node.is_rule_with_kind(RuleKind::YulParameters))?), @@ -1337,7 +1350,7 @@ impl Selector { } impl Selector { - fn yul_returns_declaration(&mut self) -> Result>> { + fn yul_returns_declaration(&mut self) -> Result>>> { Ok(vec![ Some(self.select(|node| node.is_token_with_kind(TokenKind::MinusGreaterThan))?), Some(self.select(|node| node.is_rule_with_kind(RuleKind::YulReturnVariables))?), @@ -1346,7 +1359,9 @@ impl Selector { } impl Selector { - fn yul_variable_declaration_statement(&mut self) -> Result>> { + fn yul_variable_declaration_statement( + &mut self, + ) -> Result>>> { Ok(vec![ Some(self.select(|node| node.is_token_with_kind(TokenKind::YulLetKeyword))?), Some(self.select(|node| node.is_rule_with_kind(RuleKind::YulIdentifierPaths))?), @@ -1356,7 +1371,9 @@ impl Selector { } impl Selector { - fn yul_variable_declaration_value(&mut self) -> Result>> { + fn yul_variable_declaration_value( + &mut self, + ) -> Result>>> { Ok(vec![ Some(self.select(|node| node.is_rule_with_kind(RuleKind::YulAssignmentOperator))?), Some(self.select(|node| node.is_rule_with_kind(RuleKind::YulExpression))?), @@ -1365,7 +1382,7 @@ impl Selector { } impl Selector { - fn yul_assignment_statement(&mut self) -> Result>> { + fn yul_assignment_statement(&mut self) -> Result>>> { Ok(vec![ Some(self.select(|node| node.is_rule_with_kind(RuleKind::YulIdentifierPaths))?), Some(self.select(|node| node.is_rule_with_kind(RuleKind::YulAssignmentOperator))?), @@ -1375,7 +1392,7 @@ impl Selector { } impl Selector { - fn yul_colon_and_equal(&mut self) -> Result>> { + fn yul_colon_and_equal(&mut self) -> Result>>> { Ok(vec![ Some(self.select(|node| node.is_token_with_kind(TokenKind::Colon))?), Some(self.select(|node| node.is_token_with_kind(TokenKind::Equal))?), @@ -1384,7 +1401,7 @@ impl Selector { } impl Selector { - fn yul_if_statement(&mut self) -> Result>> { + fn yul_if_statement(&mut self) -> Result>>> { Ok(vec![ Some(self.select(|node| node.is_token_with_kind(TokenKind::YulIfKeyword))?), Some(self.select(|node| node.is_rule_with_kind(RuleKind::YulExpression))?), @@ -1394,7 +1411,7 @@ impl Selector { } impl Selector { - fn yul_for_statement(&mut self) -> Result>> { + fn yul_for_statement(&mut self) -> Result>>> { Ok(vec![ Some(self.select(|node| node.is_token_with_kind(TokenKind::YulForKeyword))?), Some(self.select(|node| node.is_rule_with_kind(RuleKind::YulBlock))?), @@ -1406,7 +1423,7 @@ impl Selector { } impl Selector { - fn yul_switch_statement(&mut self) -> Result>> { + fn yul_switch_statement(&mut self) -> Result>>> { Ok(vec![ Some(self.select(|node| node.is_token_with_kind(TokenKind::YulSwitchKeyword))?), Some(self.select(|node| node.is_rule_with_kind(RuleKind::YulExpression))?), @@ -1416,7 +1433,7 @@ impl Selector { } impl Selector { - fn yul_default_case(&mut self) -> Result>> { + fn yul_default_case(&mut self) -> Result>>> { Ok(vec![ Some(self.select(|node| node.is_token_with_kind(TokenKind::YulDefaultKeyword))?), Some(self.select(|node| node.is_rule_with_kind(RuleKind::YulBlock))?), @@ -1425,7 +1442,7 @@ impl Selector { } impl Selector { - fn yul_value_case(&mut self) -> Result>> { + fn yul_value_case(&mut self) -> Result>>> { Ok(vec![ Some(self.select(|node| node.is_token_with_kind(TokenKind::YulCaseKeyword))?), Some(self.select(|node| node.is_rule_with_kind(RuleKind::YulLiteral))?), @@ -1435,7 +1452,7 @@ impl Selector { } impl Selector { - fn yul_leave_statement(&mut self) -> Result>> { + fn yul_leave_statement(&mut self) -> Result>>> { Ok(vec![Some(self.select(|node| { node.is_token_with_kind(TokenKind::YulLeaveKeyword) })?)]) @@ -1443,7 +1460,7 @@ impl Selector { } impl Selector { - fn yul_break_statement(&mut self) -> Result>> { + fn yul_break_statement(&mut self) -> Result>>> { Ok(vec![Some(self.select(|node| { node.is_token_with_kind(TokenKind::YulBreakKeyword) })?)]) @@ -1451,7 +1468,7 @@ impl Selector { } impl Selector { - fn yul_continue_statement(&mut self) -> Result>> { + fn yul_continue_statement(&mut self) -> Result>>> { Ok(vec![Some(self.select(|node| { node.is_token_with_kind(TokenKind::YulContinueKeyword) })?)]) @@ -1459,7 +1476,7 @@ impl Selector { } impl Selector { - fn yul_label(&mut self) -> Result>> { + fn yul_label(&mut self) -> Result>>> { Ok(vec![ Some(self.select(|node| node.is_token_with_kind(TokenKind::YulIdentifier))?), Some(self.select(|node| node.is_token_with_kind(TokenKind::Colon))?), @@ -1468,7 +1485,7 @@ impl Selector { } impl Selector { - fn yul_function_call_expression(&mut self) -> Result>> { + fn yul_function_call_expression(&mut self) -> Result>>> { Ok(vec![ Some(self.select(|node| node.is_rule_with_kind(RuleKind::YulExpression))?), Some(self.select(|node| node.is_token_with_kind(TokenKind::OpenParen))?), @@ -1485,9 +1502,8 @@ impl Selector { #[napi(namespace = "ast_internal", ts_return_type = "cst.Node", catch_unwind)] pub fn select_choice( #[napi(ts_arg_type = "cst.RuleNode")] node: &RuleNode, - env: Env, -) -> Result { - let mut selector = Selector::new(node, env); +) -> Result> { + let mut selector = Selector::new(node); let result = match node.kind() { RuleKind::SourceUnitMember => selector.source_unit_member()?, @@ -1542,7 +1558,7 @@ pub fn select_choice( } impl Selector { - fn source_unit_member(&mut self) -> Result { + fn source_unit_member(&mut self) -> Result> { self.select(|node| { node.is_rule_with_kinds(&[ RuleKind::PragmaDirective, @@ -1564,7 +1580,7 @@ impl Selector { } impl Selector { - fn pragma(&mut self) -> Result { + fn pragma(&mut self) -> Result> { self.select(|node| { node.is_rule_with_kinds(&[ RuleKind::ABICoderPragma, @@ -1576,7 +1592,7 @@ impl Selector { } impl Selector { - fn experimental_feature(&mut self) -> Result { + fn experimental_feature(&mut self) -> Result> { self.select(|node| { node.is_rule_with_kind(RuleKind::StringLiteral) || node.is_token_with_kind(TokenKind::Identifier) @@ -1585,7 +1601,7 @@ impl Selector { } impl Selector { - fn version_pragma_expression(&mut self) -> Result { + fn version_pragma_expression(&mut self) -> Result> { self.select(|node| { node.is_rule_with_kinds(&[ RuleKind::VersionPragmaOrExpression, @@ -1598,7 +1614,7 @@ impl Selector { } impl Selector { - fn import_clause(&mut self) -> Result { + fn import_clause(&mut self) -> Result> { self.select(|node| { node.is_rule_with_kinds(&[ RuleKind::PathImport, @@ -1610,7 +1626,7 @@ impl Selector { } impl Selector { - fn using_clause(&mut self) -> Result { + fn using_clause(&mut self) -> Result> { self.select(|node| { node.is_rule_with_kinds(&[RuleKind::IdentifierPath, RuleKind::UsingDeconstruction]) }) @@ -1618,7 +1634,7 @@ impl Selector { } impl Selector { - fn using_operator(&mut self) -> Result { + fn using_operator(&mut self) -> Result> { self.select(|node| { node.is_token_with_kinds(&[ TokenKind::Ampersand, @@ -1642,7 +1658,7 @@ impl Selector { } impl Selector { - fn using_target(&mut self) -> Result { + fn using_target(&mut self) -> Result> { self.select(|node| { node.is_rule_with_kind(RuleKind::TypeName) || node.is_token_with_kind(TokenKind::Asterisk) @@ -1651,7 +1667,7 @@ impl Selector { } impl Selector { - fn contract_member(&mut self) -> Result { + fn contract_member(&mut self) -> Result> { self.select(|node| { node.is_rule_with_kinds(&[ RuleKind::UsingDirective, @@ -1673,7 +1689,7 @@ impl Selector { } impl Selector { - fn state_variable_attribute(&mut self) -> Result { + fn state_variable_attribute(&mut self) -> Result> { self.select(|node| { node.is_rule_with_kind(RuleKind::OverrideSpecifier) || node.is_token_with_kinds(&[ @@ -1688,7 +1704,7 @@ impl Selector { } impl Selector { - fn function_name(&mut self) -> Result { + fn function_name(&mut self) -> Result> { self.select(|node| { node.is_token_with_kinds(&[ TokenKind::Identifier, @@ -1700,7 +1716,7 @@ impl Selector { } impl Selector { - fn function_attribute(&mut self) -> Result { + fn function_attribute(&mut self) -> Result> { self.select(|node| { node.is_rule_with_kinds(&[RuleKind::ModifierInvocation, RuleKind::OverrideSpecifier]) || node.is_token_with_kinds(&[ @@ -1719,7 +1735,7 @@ impl Selector { } impl Selector { - fn function_body(&mut self) -> Result { + fn function_body(&mut self) -> Result> { self.select(|node| { node.is_rule_with_kind(RuleKind::Block) || node.is_token_with_kind(TokenKind::Semicolon) }) @@ -1727,7 +1743,7 @@ impl Selector { } impl Selector { - fn constructor_attribute(&mut self) -> Result { + fn constructor_attribute(&mut self) -> Result> { self.select(|node| { node.is_rule_with_kind(RuleKind::ModifierInvocation) || node.is_token_with_kinds(&[ @@ -1742,7 +1758,7 @@ impl Selector { } impl Selector { - fn unnamed_function_attribute(&mut self) -> Result { + fn unnamed_function_attribute(&mut self) -> Result> { self.select(|node| { node.is_rule_with_kind(RuleKind::ModifierInvocation) || node.is_token_with_kinds(&[ @@ -1760,7 +1776,7 @@ impl Selector { } impl Selector { - fn fallback_function_attribute(&mut self) -> Result { + fn fallback_function_attribute(&mut self) -> Result> { self.select(|node| { node.is_rule_with_kinds(&[RuleKind::ModifierInvocation, RuleKind::OverrideSpecifier]) || node.is_token_with_kinds(&[ @@ -1775,7 +1791,7 @@ impl Selector { } impl Selector { - fn receive_function_attribute(&mut self) -> Result { + fn receive_function_attribute(&mut self) -> Result> { self.select(|node| { node.is_rule_with_kinds(&[RuleKind::ModifierInvocation, RuleKind::OverrideSpecifier]) || node.is_token_with_kinds(&[ @@ -1788,7 +1804,7 @@ impl Selector { } impl Selector { - fn modifier_attribute(&mut self) -> Result { + fn modifier_attribute(&mut self) -> Result> { self.select(|node| { node.is_rule_with_kind(RuleKind::OverrideSpecifier) || node.is_token_with_kind(TokenKind::VirtualKeyword) @@ -1797,7 +1813,7 @@ impl Selector { } impl Selector { - fn type_name(&mut self) -> Result { + fn type_name(&mut self) -> Result> { self.select(|node| { node.is_rule_with_kinds(&[ RuleKind::ArrayTypeName, @@ -1811,7 +1827,7 @@ impl Selector { } impl Selector { - fn function_type_attribute(&mut self) -> Result { + fn function_type_attribute(&mut self) -> Result> { self.select(|node| { node.is_token_with_kinds(&[ TokenKind::InternalKeyword, @@ -1828,7 +1844,7 @@ impl Selector { } impl Selector { - fn mapping_key_type(&mut self) -> Result { + fn mapping_key_type(&mut self) -> Result> { self.select(|node| { node.is_rule_with_kinds(&[RuleKind::ElementaryType, RuleKind::IdentifierPath]) }) @@ -1836,7 +1852,7 @@ impl Selector { } impl Selector { - fn elementary_type(&mut self) -> Result { + fn elementary_type(&mut self) -> Result> { self.select(|node| { node.is_rule_with_kind(RuleKind::AddressType) || node.is_token_with_kinds(&[ @@ -1854,7 +1870,7 @@ impl Selector { } impl Selector { - fn statement(&mut self) -> Result { + fn statement(&mut self) -> Result> { self.select(|node| { node.is_rule_with_kinds(&[ RuleKind::ExpressionStatement, @@ -1880,7 +1896,7 @@ impl Selector { } impl Selector { - fn tuple_member(&mut self) -> Result { + fn tuple_member(&mut self) -> Result> { self.select(|node| { node.is_rule_with_kinds(&[RuleKind::TypedTupleMember, RuleKind::UntypedTupleMember]) }) @@ -1888,7 +1904,7 @@ impl Selector { } impl Selector { - fn variable_declaration_type(&mut self) -> Result { + fn variable_declaration_type(&mut self) -> Result> { self.select(|node| { node.is_rule_with_kind(RuleKind::TypeName) || node.is_token_with_kind(TokenKind::VarKeyword) @@ -1897,7 +1913,7 @@ impl Selector { } impl Selector { - fn storage_location(&mut self) -> Result { + fn storage_location(&mut self) -> Result> { self.select(|node| { node.is_token_with_kinds(&[ TokenKind::MemoryKeyword, @@ -1909,7 +1925,7 @@ impl Selector { } impl Selector { - fn for_statement_initialization(&mut self) -> Result { + fn for_statement_initialization(&mut self) -> Result> { self.select(|node| { node.is_rule_with_kinds(&[ RuleKind::ExpressionStatement, @@ -1921,7 +1937,7 @@ impl Selector { } impl Selector { - fn for_statement_condition(&mut self) -> Result { + fn for_statement_condition(&mut self) -> Result> { self.select(|node| { node.is_rule_with_kind(RuleKind::ExpressionStatement) || node.is_token_with_kind(TokenKind::Semicolon) @@ -1930,7 +1946,7 @@ impl Selector { } impl Selector { - fn expression(&mut self) -> Result { + fn expression(&mut self) -> Result> { self.select(|node| { node.is_rule_with_kinds(&[ RuleKind::AssignmentExpression, @@ -1971,7 +1987,7 @@ impl Selector { } impl Selector { - fn member_access(&mut self) -> Result { + fn member_access(&mut self) -> Result> { self.select(|node| { node.is_token_with_kinds(&[TokenKind::Identifier, TokenKind::AddressKeyword]) }) @@ -1979,7 +1995,7 @@ impl Selector { } impl Selector { - fn arguments_declaration(&mut self) -> Result { + fn arguments_declaration(&mut self) -> Result> { self.select(|node| { node.is_rule_with_kinds(&[ RuleKind::PositionalArgumentsDeclaration, @@ -1990,7 +2006,7 @@ impl Selector { } impl Selector { - fn number_unit(&mut self) -> Result { + fn number_unit(&mut self) -> Result> { self.select(|node| { node.is_token_with_kinds(&[ TokenKind::WeiKeyword, @@ -2010,7 +2026,7 @@ impl Selector { } impl Selector { - fn string_expression(&mut self) -> Result { + fn string_expression(&mut self) -> Result> { self.select(|node| { node.is_rule_with_kinds(&[ RuleKind::StringLiteral, @@ -2024,7 +2040,7 @@ impl Selector { } impl Selector { - fn string_literal(&mut self) -> Result { + fn string_literal(&mut self) -> Result> { self.select(|node| { node.is_token_with_kinds(&[ TokenKind::SingleQuotedStringLiteral, @@ -2035,7 +2051,7 @@ impl Selector { } impl Selector { - fn hex_string_literal(&mut self) -> Result { + fn hex_string_literal(&mut self) -> Result> { self.select(|node| { node.is_token_with_kinds(&[ TokenKind::SingleQuotedHexStringLiteral, @@ -2046,7 +2062,7 @@ impl Selector { } impl Selector { - fn unicode_string_literal(&mut self) -> Result { + fn unicode_string_literal(&mut self) -> Result> { self.select(|node| { node.is_token_with_kinds(&[ TokenKind::SingleQuotedUnicodeStringLiteral, @@ -2057,7 +2073,7 @@ impl Selector { } impl Selector { - fn yul_statement(&mut self) -> Result { + fn yul_statement(&mut self) -> Result> { self.select(|node| { node.is_rule_with_kinds(&[ RuleKind::YulBlock, @@ -2078,7 +2094,7 @@ impl Selector { } impl Selector { - fn yul_assignment_operator(&mut self) -> Result { + fn yul_assignment_operator(&mut self) -> Result> { self.select(|node| { node.is_rule_with_kind(RuleKind::YulColonAndEqual) || node.is_token_with_kind(TokenKind::ColonEqual) @@ -2087,7 +2103,7 @@ impl Selector { } impl Selector { - fn yul_switch_case(&mut self) -> Result { + fn yul_switch_case(&mut self) -> Result> { self.select(|node| { node.is_rule_with_kinds(&[RuleKind::YulDefaultCase, RuleKind::YulValueCase]) }) @@ -2095,7 +2111,7 @@ impl Selector { } impl Selector { - fn yul_expression(&mut self) -> Result { + fn yul_expression(&mut self) -> Result> { self.select(|node| { node.is_rule_with_kinds(&[ RuleKind::YulFunctionCallExpression, @@ -2108,7 +2124,7 @@ impl Selector { } impl Selector { - fn yul_built_in_function(&mut self) -> Result { + fn yul_built_in_function(&mut self) -> Result> { self.select(|node| { node.is_token_with_kinds(&[ TokenKind::YulAddKeyword, @@ -2193,7 +2209,7 @@ impl Selector { } impl Selector { - fn yul_literal(&mut self) -> Result { + fn yul_literal(&mut self) -> Result> { self.select(|node| { node.is_rule_with_kinds(&[RuleKind::HexStringLiteral, RuleKind::StringLiteral]) || node.is_token_with_kinds(&[ @@ -2217,9 +2233,8 @@ impl Selector { )] pub fn select_repeated( #[napi(ts_arg_type = "cst.RuleNode")] node: &RuleNode, - env: Env, -) -> Result> { - let mut selector = Selector::new(node, env); +) -> Result>> { + let mut selector = Selector::new(node); let result = match node.kind() { RuleKind::SourceUnitMembers => selector.source_unit_members()?, @@ -2253,7 +2268,7 @@ pub fn select_repeated( } impl Selector { - fn source_unit_members(&mut self) -> Result> { + fn source_unit_members(&mut self) -> Result>> { let mut items = vec![]; while let Some(item) = @@ -2267,7 +2282,7 @@ impl Selector { } impl Selector { - fn version_pragma_expressions(&mut self) -> Result> { + fn version_pragma_expressions(&mut self) -> Result>> { let mut items = vec![]; while let Some(item) = @@ -2281,7 +2296,7 @@ impl Selector { } impl Selector { - fn contract_members(&mut self) -> Result> { + fn contract_members(&mut self) -> Result>> { let mut items = vec![]; while let Some(item) = @@ -2295,7 +2310,7 @@ impl Selector { } impl Selector { - fn interface_members(&mut self) -> Result> { + fn interface_members(&mut self) -> Result>> { let mut items = vec![]; while let Some(item) = @@ -2309,7 +2324,7 @@ impl Selector { } impl Selector { - fn library_members(&mut self) -> Result> { + fn library_members(&mut self) -> Result>> { let mut items = vec![]; while let Some(item) = @@ -2323,7 +2338,7 @@ impl Selector { } impl Selector { - fn struct_members(&mut self) -> Result> { + fn struct_members(&mut self) -> Result>> { let mut items = vec![]; while let Some(item) = @@ -2337,7 +2352,7 @@ impl Selector { } impl Selector { - fn state_variable_attributes(&mut self) -> Result> { + fn state_variable_attributes(&mut self) -> Result>> { let mut items = vec![]; while let Some(item) = @@ -2351,7 +2366,7 @@ impl Selector { } impl Selector { - fn function_attributes(&mut self) -> Result> { + fn function_attributes(&mut self) -> Result>> { let mut items = vec![]; while let Some(item) = @@ -2365,7 +2380,7 @@ impl Selector { } impl Selector { - fn constructor_attributes(&mut self) -> Result> { + fn constructor_attributes(&mut self) -> Result>> { let mut items = vec![]; while let Some(item) = @@ -2379,7 +2394,7 @@ impl Selector { } impl Selector { - fn unnamed_function_attributes(&mut self) -> Result> { + fn unnamed_function_attributes(&mut self) -> Result>> { let mut items = vec![]; while let Some(item) = @@ -2393,7 +2408,7 @@ impl Selector { } impl Selector { - fn fallback_function_attributes(&mut self) -> Result> { + fn fallback_function_attributes(&mut self) -> Result>> { let mut items = vec![]; while let Some(item) = @@ -2407,7 +2422,7 @@ impl Selector { } impl Selector { - fn receive_function_attributes(&mut self) -> Result> { + fn receive_function_attributes(&mut self) -> Result>> { let mut items = vec![]; while let Some(item) = @@ -2421,7 +2436,7 @@ impl Selector { } impl Selector { - fn modifier_attributes(&mut self) -> Result> { + fn modifier_attributes(&mut self) -> Result>> { let mut items = vec![]; while let Some(item) = @@ -2435,7 +2450,7 @@ impl Selector { } impl Selector { - fn function_type_attributes(&mut self) -> Result> { + fn function_type_attributes(&mut self) -> Result>> { let mut items = vec![]; while let Some(item) = @@ -2449,7 +2464,7 @@ impl Selector { } impl Selector { - fn statements(&mut self) -> Result> { + fn statements(&mut self) -> Result>> { let mut items = vec![]; while let Some(item) = @@ -2463,7 +2478,7 @@ impl Selector { } impl Selector { - fn catch_clauses(&mut self) -> Result> { + fn catch_clauses(&mut self) -> Result>> { let mut items = vec![]; while let Some(item) = @@ -2477,7 +2492,7 @@ impl Selector { } impl Selector { - fn string_literals(&mut self) -> Result> { + fn string_literals(&mut self) -> Result>> { let mut items = vec![]; while let Some(item) = @@ -2491,7 +2506,7 @@ impl Selector { } impl Selector { - fn hex_string_literals(&mut self) -> Result> { + fn hex_string_literals(&mut self) -> Result>> { let mut items = vec![]; while let Some(item) = @@ -2505,7 +2520,7 @@ impl Selector { } impl Selector { - fn unicode_string_literals(&mut self) -> Result> { + fn unicode_string_literals(&mut self) -> Result>> { let mut items = vec![]; while let Some(item) = @@ -2519,7 +2534,7 @@ impl Selector { } impl Selector { - fn yul_statements(&mut self) -> Result> { + fn yul_statements(&mut self) -> Result>> { let mut items = vec![]; while let Some(item) = @@ -2533,7 +2548,7 @@ impl Selector { } impl Selector { - fn yul_switch_cases(&mut self) -> Result> { + fn yul_switch_cases(&mut self) -> Result>> { let mut items = vec![]; while let Some(item) = @@ -2557,9 +2572,8 @@ impl Selector { )] pub fn select_separated( #[napi(ts_arg_type = "cst.RuleNode")] node: &RuleNode, - env: Env, -) -> Result>> { - let mut selector = Selector::new(node, env); +) -> Result>>> { + let mut selector = Selector::new(node); let result = match node.kind() { RuleKind::VersionPragmaSpecifier => selector.version_pragma_specifier()?, @@ -2594,7 +2608,7 @@ pub fn select_separated( } impl Selector { - fn version_pragma_specifier(&mut self) -> Result>> { + fn version_pragma_specifier(&mut self) -> Result>>> { let mut separated = vec![]; let mut separators = vec![]; @@ -2619,7 +2633,7 @@ impl Selector { } impl Selector { - fn import_deconstruction_symbols(&mut self) -> Result>> { + fn import_deconstruction_symbols(&mut self) -> Result>>> { let mut separated = vec![]; let mut separators = vec![]; @@ -2646,7 +2660,7 @@ impl Selector { } impl Selector { - fn using_deconstruction_symbols(&mut self) -> Result>> { + fn using_deconstruction_symbols(&mut self) -> Result>>> { let mut separated = vec![]; let mut separators = vec![]; @@ -2673,7 +2687,7 @@ impl Selector { } impl Selector { - fn inheritance_types(&mut self) -> Result>> { + fn inheritance_types(&mut self) -> Result>>> { let mut separated = vec![]; let mut separators = vec![]; @@ -2697,7 +2711,7 @@ impl Selector { } impl Selector { - fn enum_members(&mut self) -> Result>> { + fn enum_members(&mut self) -> Result>>> { let mut separated = vec![]; let mut separators = vec![]; @@ -2720,7 +2734,7 @@ impl Selector { } impl Selector { - fn parameters(&mut self) -> Result>> { + fn parameters(&mut self) -> Result>>> { let mut separated = vec![]; let mut separators = vec![]; @@ -2741,7 +2755,7 @@ impl Selector { } impl Selector { - fn override_paths(&mut self) -> Result>> { + fn override_paths(&mut self) -> Result>>> { let mut separated = vec![]; let mut separators = vec![]; @@ -2765,7 +2779,7 @@ impl Selector { } impl Selector { - fn event_parameters(&mut self) -> Result>> { + fn event_parameters(&mut self) -> Result>>> { let mut separated = vec![]; let mut separators = vec![]; @@ -2789,7 +2803,7 @@ impl Selector { } impl Selector { - fn error_parameters(&mut self) -> Result>> { + fn error_parameters(&mut self) -> Result>>> { let mut separated = vec![]; let mut separators = vec![]; @@ -2813,7 +2827,7 @@ impl Selector { } impl Selector { - fn assembly_flags(&mut self) -> Result>> { + fn assembly_flags(&mut self) -> Result>>> { let mut separated = vec![]; let mut separators = vec![]; @@ -2837,7 +2851,7 @@ impl Selector { } impl Selector { - fn tuple_deconstruction_elements(&mut self) -> Result>> { + fn tuple_deconstruction_elements(&mut self) -> Result>>> { let mut separated = vec![]; let mut separators = vec![]; @@ -2864,7 +2878,7 @@ impl Selector { } impl Selector { - fn positional_arguments(&mut self) -> Result>> { + fn positional_arguments(&mut self) -> Result>>> { let mut separated = vec![]; let mut separators = vec![]; @@ -2885,7 +2899,7 @@ impl Selector { } impl Selector { - fn named_arguments(&mut self) -> Result>> { + fn named_arguments(&mut self) -> Result>>> { let mut separated = vec![]; let mut separators = vec![]; @@ -2909,7 +2923,7 @@ impl Selector { } impl Selector { - fn call_options(&mut self) -> Result>> { + fn call_options(&mut self) -> Result>>> { let mut separated = vec![]; let mut separators = vec![]; @@ -2933,7 +2947,7 @@ impl Selector { } impl Selector { - fn tuple_values(&mut self) -> Result>> { + fn tuple_values(&mut self) -> Result>>> { let mut separated = vec![]; let mut separators = vec![]; @@ -2954,7 +2968,7 @@ impl Selector { } impl Selector { - fn array_values(&mut self) -> Result>> { + fn array_values(&mut self) -> Result>>> { let mut separated = vec![]; let mut separators = vec![]; @@ -2975,7 +2989,7 @@ impl Selector { } impl Selector { - fn identifier_path(&mut self) -> Result>> { + fn identifier_path(&mut self) -> Result>>> { let mut separated = vec![]; let mut separators = vec![]; @@ -2998,7 +3012,7 @@ impl Selector { } impl Selector { - fn yul_parameters(&mut self) -> Result>> { + fn yul_parameters(&mut self) -> Result>>> { let mut separated = vec![]; let mut separators = vec![]; @@ -3022,7 +3036,7 @@ impl Selector { } impl Selector { - fn yul_return_variables(&mut self) -> Result>> { + fn yul_return_variables(&mut self) -> Result>>> { let mut separated = vec![]; let mut separators = vec![]; @@ -3046,7 +3060,7 @@ impl Selector { } impl Selector { - fn yul_arguments(&mut self) -> Result>> { + fn yul_arguments(&mut self) -> Result>>> { let mut separated = vec![]; let mut separators = vec![]; @@ -3070,7 +3084,7 @@ impl Selector { } impl Selector { - fn yul_identifier_paths(&mut self) -> Result>> { + fn yul_identifier_paths(&mut self) -> Result>>> { let mut separated = vec![]; let mut separators = vec![]; @@ -3094,7 +3108,7 @@ impl Selector { } impl Selector { - fn yul_identifier_path(&mut self) -> Result>> { + fn yul_identifier_path(&mut self) -> Result>>> { let mut separated = vec![]; let mut separators = vec![]; @@ -3122,28 +3136,32 @@ impl Selector { // struct Selector { - env: Env, node: Rc, index: usize, } impl Selector { - fn new(node: &RuleNode, env: Env) -> Self { + fn new(node: &RuleNode) -> Self { Self { - env, node: node.0.clone(), index: 0, } } - fn select(&mut self, filter: impl FnOnce(&RustNode) -> bool) -> Result { + fn select( + &mut self, + filter: impl FnOnce(&RustNode) -> bool, + ) -> Result> { match self.try_select(filter)? { Some(node) => Ok(node), None => Error::MissingChild(self.index).into(), } } - fn try_select(&mut self, filter: impl FnOnce(&RustNode) -> bool) -> Result> { + fn try_select( + &mut self, + filter: impl FnOnce(&RustNode) -> bool, + ) -> Result>> { while let Some(child) = self.node.children.get(self.index) { match child { node if node.is_trivia() => { @@ -3157,9 +3175,9 @@ impl Selector { } if matches!(token.kind, TokenKind::SKIPPED) => { return Error::SkippedToken(self.index).into(); } - node if filter(node) => { + labeled if filter(labeled) => { self.index += 1; - return Ok(Some(node.to_js(self.env))); + return Ok(Some(labeled.node.clone().into_js_either_node())); } _ => { break; diff --git a/crates/solidity/outputs/cargo/slang_solidity/src/generated/napi_interface/cst.rs b/crates/solidity/outputs/cargo/slang_solidity/src/generated/napi_interface/cst.rs index a942ae4a0a..20f0a13157 100644 --- a/crates/solidity/outputs/cargo/slang_solidity/src/generated/napi_interface/cst.rs +++ b/crates/solidity/outputs/cargo/slang_solidity/src/generated/napi_interface/cst.rs @@ -2,8 +2,7 @@ use std::rc::Rc; -use napi::bindgen_prelude::Env; -use napi::JsObject; +use napi::Either; use napi_derive::napi; use crate::napi_interface::cursor::Cursor; @@ -18,6 +17,22 @@ pub enum NodeType { Token, } +impl RustNode { + /// Converts the node into `napi` wrapper for `RuleNode | TokenNode` JS object. + pub fn into_js_either_node(self) -> Either { + match self { + RustNode::Rule(rule) => Either::A(RuleNode(rule)), + RustNode::Token(token) => Either::B(TokenNode(token)), + } + } +} + +impl From for Either { + fn from(value: RustNode) -> Self { + value.into_js_either_node() + } +} + #[napi(namespace = "cst")] pub struct RuleNode(pub(crate) Rc); @@ -52,11 +67,11 @@ impl RuleNode { } #[napi(ts_return_type = "Array", catch_unwind)] - pub fn children(&self, env: Env) -> Vec { + pub fn children(&self) -> Vec> { self.0 .children .iter() - .map(|child| child.to_js(env)) + .map(|child| child.node.clone().into()) .collect() } @@ -119,34 +134,3 @@ impl TokenNode { .into() } } - -pub(crate) trait ToJS { - fn to_js(&self, env: Env) -> JsObject; -} - -impl ToJS for Rc { - fn to_js(&self, env: Env) -> JsObject { - RuleNode(self.clone()) - .into_instance(env) - .expect("Class constructor to be defined by #[napi]") - .as_object(env) - } -} - -impl ToJS for Rc { - fn to_js(&self, env: Env) -> JsObject { - TokenNode(self.clone()) - .into_instance(env) - .expect("Class constructor to be defined by #[napi]") - .as_object(env) - } -} - -impl ToJS for RustNode { - fn to_js(&self, env: Env) -> JsObject { - match self { - RustNode::Rule(rust_rule_node) => rust_rule_node.to_js(env), - RustNode::Token(rust_token_node) => rust_token_node.to_js(env), - } - } -} diff --git a/crates/solidity/outputs/cargo/slang_solidity/src/generated/napi_interface/cursor.rs b/crates/solidity/outputs/cargo/slang_solidity/src/generated/napi_interface/cursor.rs index d837dcfb5e..623cdfb7c6 100644 --- a/crates/solidity/outputs/cargo/slang_solidity/src/generated/napi_interface/cursor.rs +++ b/crates/solidity/outputs/cargo/slang_solidity/src/generated/napi_interface/cursor.rs @@ -5,13 +5,12 @@ // The functions are meant to be definitions for export, so they're not really used #![allow(clippy::return_self_not_must_use)] -use cst::ToJS; -use napi::bindgen_prelude::Env; -use napi::JsObject; +use napi::Either; use napi_derive::napi; use text_index::{TextIndex, TextRange}; -use crate::napi_interface::{cst, text_index, NodeLabel, RuleKind, RustCursor, TokenKind}; +use crate::napi_interface::cst::{self, RuleNode, TokenNode}; +use crate::napi_interface::{text_index, NodeLabel, RuleKind, RustCursor, TokenKind}; #[napi(namespace = "cursor")] pub struct Cursor(pub(super) RustCursor); @@ -55,8 +54,8 @@ impl Cursor { } #[napi(ts_return_type = "cst.Node", catch_unwind)] - pub fn node(&self, env: Env) -> JsObject { - self.0.node().to_js(env) + pub fn node(&self) -> Either { + self.0.node().into() } #[napi(getter, ts_return_type = "kinds.NodeLabel", catch_unwind)] @@ -81,11 +80,8 @@ impl Cursor { } #[napi(ts_return_type = "Array", catch_unwind)] - pub fn ancestors(&self, env: Env) -> Vec { - self.0 - .ancestors() - .map(|rust_rule_node| rust_rule_node.to_js(env)) - .collect() + pub fn ancestors(&self) -> Vec { + self.0.ancestors().map(cst::RuleNode).collect() } #[napi(catch_unwind)] diff --git a/crates/solidity/outputs/cargo/slang_solidity/src/generated/napi_interface/parse_output.rs b/crates/solidity/outputs/cargo/slang_solidity/src/generated/napi_interface/parse_output.rs index 7f276a0ddc..994cf7de26 100644 --- a/crates/solidity/outputs/cargo/slang_solidity/src/generated/napi_interface/parse_output.rs +++ b/crates/solidity/outputs/cargo/slang_solidity/src/generated/napi_interface/parse_output.rs @@ -1,10 +1,10 @@ // This file is generated automatically by infrastructure scripts. Please don't edit by hand. -use cst::ToJS; -use napi::bindgen_prelude::Env; +use napi::Either; use napi_derive::napi; -use crate::napi_interface::{cst, cursor, parse_error, RustParseOutput}; +use crate::napi_interface::cst::{RuleNode, TokenNode}; +use crate::napi_interface::{cursor, parse_error, RustParseOutput}; #[napi(namespace = "parse_output")] pub struct ParseOutput(RustParseOutput); @@ -18,8 +18,8 @@ impl From for ParseOutput { #[napi(namespace = "parse_output")] impl ParseOutput { #[napi(ts_return_type = "cst.Node", catch_unwind)] - pub fn tree(&self, env: Env) -> napi::JsObject { - self.0.tree().to_js(env) + pub fn tree(&self) -> Either { + self.0.tree().into() } #[napi(ts_return_type = "Array", catch_unwind)] diff --git a/crates/solidity/outputs/cargo/slang_solidity/src/generated/napi_interface/query.rs b/crates/solidity/outputs/cargo/slang_solidity/src/generated/napi_interface/query.rs index bd5daaba67..795651013b 100644 --- a/crates/solidity/outputs/cargo/slang_solidity/src/generated/napi_interface/query.rs +++ b/crates/solidity/outputs/cargo/slang_solidity/src/generated/napi_interface/query.rs @@ -5,7 +5,10 @@ // The functions are meant to be definitions for export, so they're not really used #![allow(clippy::return_self_not_must_use)] -use napi::{Env, JsObject}; +use std::collections::HashMap; + +use napi::bindgen_prelude::ClassInstance; +use napi::Env; use napi_derive::napi; use crate::napi_interface::cursor::Cursor; @@ -38,22 +41,28 @@ pub struct QueryResultIterator(RustQueryResultIterator); pub struct QueryResult { pub query_number: u32, #[napi(ts_type = "{ [key: string]: cursor.Cursor[] }")] - pub bindings: JsObject, + pub bindings: HashMap>>, } impl QueryResult { fn new(env: Env, result: RustQueryResult) -> napi::Result { #[allow(clippy::cast_possible_truncation)] let query_number = result.query_number as u32; - let mut bindings = env.create_object()?; - // transer all of the bindings eagerly on the assumption + // transfer all of the bindings eagerly on the assumption // that they've all been explicitly requested. - for (key, value) in result.bindings { - bindings.set_named_property( - &key, - value.into_iter().map(|x| x.into()).collect::>(), - )?; - } + let bindings = result + .bindings + .into_iter() + .map(|(key, values)| { + let instances = values + .into_iter() + .map(|cursor| Cursor(cursor).into_instance(env)) + .collect::>()?; + + Ok((key, instances)) + }) + .collect::>()?; + Ok(Self { query_number, bindings, diff --git a/crates/testlang/outputs/cargo/slang_testlang/src/generated/napi_interface/ast_selectors.rs b/crates/testlang/outputs/cargo/slang_testlang/src/generated/napi_interface/ast_selectors.rs index 7cea58e359..508abba30d 100644 --- a/crates/testlang/outputs/cargo/slang_testlang/src/generated/napi_interface/ast_selectors.rs +++ b/crates/testlang/outputs/cargo/slang_testlang/src/generated/napi_interface/ast_selectors.rs @@ -4,10 +4,10 @@ use std::rc::Rc; -use napi::{Env, JsObject}; +use napi::Either; use napi_derive::napi; -use crate::napi_interface::cst::{RuleNode, ToJS}; +use crate::napi_interface::cst::{RuleNode, TokenNode}; use crate::napi_interface::{RuleKind, RustLabeledNode, RustNode, RustRuleNode, TokenKind}; // @@ -21,9 +21,8 @@ use crate::napi_interface::{RuleKind, RustLabeledNode, RustNode, RustRuleNode, T )] pub fn select_sequence( #[napi(ts_arg_type = "cst.RuleNode")] node: &RuleNode, - env: Env, -) -> Result>> { - let mut selector = Selector::new(node, env); +) -> Result>>> { + let mut selector = Selector::new(node); let result = match node.kind() { RuleKind::SourceUnit => selector.source_unit()?, @@ -42,7 +41,7 @@ pub fn select_sequence( } impl Selector { - fn source_unit(&mut self) -> Result>> { + fn source_unit(&mut self) -> Result>>> { Ok(vec![Some(self.select(|node| { node.is_rule_with_kind(RuleKind::SourceUnitMembers) })?)]) @@ -50,7 +49,7 @@ impl Selector { } impl Selector { - fn tree(&mut self) -> Result>> { + fn tree(&mut self) -> Result>>> { Ok(vec![ Some(self.select(|node| node.is_token_with_kind(TokenKind::TreeKeyword))?), self.try_select(|node| node.is_token_with_kind(TokenKind::Identifier))?, @@ -61,7 +60,7 @@ impl Selector { } impl Selector { - fn tree_node(&mut self) -> Result>> { + fn tree_node(&mut self) -> Result>>> { Ok(vec![ Some(self.select(|node| node.is_token_with_kind(TokenKind::OpenBracket))?), Some(self.select(|node| node.is_rule_with_kind(RuleKind::TreeNodeChildren))?), @@ -71,7 +70,7 @@ impl Selector { } impl Selector { - fn addition_expression(&mut self) -> Result>> { + fn addition_expression(&mut self) -> Result>>> { Ok(vec![ Some(self.select(|node| node.is_rule_with_kind(RuleKind::Expression))?), Some(self.select(|node| node.is_token_with_kind(TokenKind::Plus))?), @@ -81,7 +80,7 @@ impl Selector { } impl Selector { - fn negation_expression(&mut self) -> Result>> { + fn negation_expression(&mut self) -> Result>>> { Ok(vec![ Some(self.select(|node| node.is_token_with_kind(TokenKind::Bang))?), Some(self.select(|node| node.is_rule_with_kind(RuleKind::Expression))?), @@ -90,7 +89,7 @@ impl Selector { } impl Selector { - fn member_access_expression(&mut self) -> Result>> { + fn member_access_expression(&mut self) -> Result>>> { Ok(vec![ Some(self.select(|node| node.is_rule_with_kind(RuleKind::Expression))?), Some(self.select(|node| node.is_token_with_kind(TokenKind::Period))?), @@ -106,9 +105,8 @@ impl Selector { #[napi(namespace = "ast_internal", ts_return_type = "cst.Node", catch_unwind)] pub fn select_choice( #[napi(ts_arg_type = "cst.RuleNode")] node: &RuleNode, - env: Env, -) -> Result { - let mut selector = Selector::new(node, env); +) -> Result> { + let mut selector = Selector::new(node); let result = match node.kind() { RuleKind::SourceUnitMember => selector.source_unit_member()?, @@ -125,7 +123,7 @@ pub fn select_choice( } impl Selector { - fn source_unit_member(&mut self) -> Result { + fn source_unit_member(&mut self) -> Result> { self.select(|node| { node.is_rule_with_kinds(&[ RuleKind::Tree, @@ -138,7 +136,7 @@ impl Selector { } impl Selector { - fn tree_node_child(&mut self) -> Result { + fn tree_node_child(&mut self) -> Result> { self.select(|node| { node.is_rule_with_kind(RuleKind::TreeNode) || node.is_token_with_kind(TokenKind::DelimitedIdentifier) @@ -147,7 +145,7 @@ impl Selector { } impl Selector { - fn expression(&mut self) -> Result { + fn expression(&mut self) -> Result> { self.select(|node| { node.is_rule_with_kinds(&[ RuleKind::AdditionExpression, @@ -159,7 +157,7 @@ impl Selector { } impl Selector { - fn literal(&mut self) -> Result { + fn literal(&mut self) -> Result> { self.select(|node| node.is_token_with_kind(TokenKind::StringLiteral)) } } @@ -175,9 +173,8 @@ impl Selector { )] pub fn select_repeated( #[napi(ts_arg_type = "cst.RuleNode")] node: &RuleNode, - env: Env, -) -> Result> { - let mut selector = Selector::new(node, env); +) -> Result>> { + let mut selector = Selector::new(node); let result = match node.kind() { RuleKind::SourceUnitMembers => selector.source_unit_members()?, @@ -192,7 +189,7 @@ pub fn select_repeated( } impl Selector { - fn source_unit_members(&mut self) -> Result> { + fn source_unit_members(&mut self) -> Result>> { let mut items = vec![]; while let Some(item) = @@ -206,7 +203,7 @@ impl Selector { } impl Selector { - fn tree_node_children(&mut self) -> Result> { + fn tree_node_children(&mut self) -> Result>> { let mut items = vec![]; while let Some(item) = @@ -230,9 +227,8 @@ impl Selector { )] pub fn select_separated( #[napi(ts_arg_type = "cst.RuleNode")] node: &RuleNode, - env: Env, -) -> Result>> { - let mut selector = Selector::new(node, env); +) -> Result>>> { + let mut selector = Selector::new(node); let result = match node.kind() { RuleKind::SeparatedIdentifiers => selector.separated_identifiers()?, @@ -246,7 +242,7 @@ pub fn select_separated( } impl Selector { - fn separated_identifiers(&mut self) -> Result>> { + fn separated_identifiers(&mut self) -> Result>>> { let mut separated = vec![]; let mut separators = vec![]; @@ -273,28 +269,32 @@ impl Selector { // struct Selector { - env: Env, node: Rc, index: usize, } impl Selector { - fn new(node: &RuleNode, env: Env) -> Self { + fn new(node: &RuleNode) -> Self { Self { - env, node: node.0.clone(), index: 0, } } - fn select(&mut self, filter: impl FnOnce(&RustNode) -> bool) -> Result { + fn select( + &mut self, + filter: impl FnOnce(&RustNode) -> bool, + ) -> Result> { match self.try_select(filter)? { Some(node) => Ok(node), None => Error::MissingChild(self.index).into(), } } - fn try_select(&mut self, filter: impl FnOnce(&RustNode) -> bool) -> Result> { + fn try_select( + &mut self, + filter: impl FnOnce(&RustNode) -> bool, + ) -> Result>> { while let Some(child) = self.node.children.get(self.index) { match child { node if node.is_trivia() => { @@ -308,9 +308,9 @@ impl Selector { } if matches!(token.kind, TokenKind::SKIPPED) => { return Error::SkippedToken(self.index).into(); } - node if filter(node) => { + labeled if filter(labeled) => { self.index += 1; - return Ok(Some(node.to_js(self.env))); + return Ok(Some(labeled.node.clone().into_js_either_node())); } _ => { break; diff --git a/crates/testlang/outputs/cargo/slang_testlang/src/generated/napi_interface/cst.rs b/crates/testlang/outputs/cargo/slang_testlang/src/generated/napi_interface/cst.rs index a942ae4a0a..20f0a13157 100644 --- a/crates/testlang/outputs/cargo/slang_testlang/src/generated/napi_interface/cst.rs +++ b/crates/testlang/outputs/cargo/slang_testlang/src/generated/napi_interface/cst.rs @@ -2,8 +2,7 @@ use std::rc::Rc; -use napi::bindgen_prelude::Env; -use napi::JsObject; +use napi::Either; use napi_derive::napi; use crate::napi_interface::cursor::Cursor; @@ -18,6 +17,22 @@ pub enum NodeType { Token, } +impl RustNode { + /// Converts the node into `napi` wrapper for `RuleNode | TokenNode` JS object. + pub fn into_js_either_node(self) -> Either { + match self { + RustNode::Rule(rule) => Either::A(RuleNode(rule)), + RustNode::Token(token) => Either::B(TokenNode(token)), + } + } +} + +impl From for Either { + fn from(value: RustNode) -> Self { + value.into_js_either_node() + } +} + #[napi(namespace = "cst")] pub struct RuleNode(pub(crate) Rc); @@ -52,11 +67,11 @@ impl RuleNode { } #[napi(ts_return_type = "Array", catch_unwind)] - pub fn children(&self, env: Env) -> Vec { + pub fn children(&self) -> Vec> { self.0 .children .iter() - .map(|child| child.to_js(env)) + .map(|child| child.node.clone().into()) .collect() } @@ -119,34 +134,3 @@ impl TokenNode { .into() } } - -pub(crate) trait ToJS { - fn to_js(&self, env: Env) -> JsObject; -} - -impl ToJS for Rc { - fn to_js(&self, env: Env) -> JsObject { - RuleNode(self.clone()) - .into_instance(env) - .expect("Class constructor to be defined by #[napi]") - .as_object(env) - } -} - -impl ToJS for Rc { - fn to_js(&self, env: Env) -> JsObject { - TokenNode(self.clone()) - .into_instance(env) - .expect("Class constructor to be defined by #[napi]") - .as_object(env) - } -} - -impl ToJS for RustNode { - fn to_js(&self, env: Env) -> JsObject { - match self { - RustNode::Rule(rust_rule_node) => rust_rule_node.to_js(env), - RustNode::Token(rust_token_node) => rust_token_node.to_js(env), - } - } -} diff --git a/crates/testlang/outputs/cargo/slang_testlang/src/generated/napi_interface/cursor.rs b/crates/testlang/outputs/cargo/slang_testlang/src/generated/napi_interface/cursor.rs index d837dcfb5e..623cdfb7c6 100644 --- a/crates/testlang/outputs/cargo/slang_testlang/src/generated/napi_interface/cursor.rs +++ b/crates/testlang/outputs/cargo/slang_testlang/src/generated/napi_interface/cursor.rs @@ -5,13 +5,12 @@ // The functions are meant to be definitions for export, so they're not really used #![allow(clippy::return_self_not_must_use)] -use cst::ToJS; -use napi::bindgen_prelude::Env; -use napi::JsObject; +use napi::Either; use napi_derive::napi; use text_index::{TextIndex, TextRange}; -use crate::napi_interface::{cst, text_index, NodeLabel, RuleKind, RustCursor, TokenKind}; +use crate::napi_interface::cst::{self, RuleNode, TokenNode}; +use crate::napi_interface::{text_index, NodeLabel, RuleKind, RustCursor, TokenKind}; #[napi(namespace = "cursor")] pub struct Cursor(pub(super) RustCursor); @@ -55,8 +54,8 @@ impl Cursor { } #[napi(ts_return_type = "cst.Node", catch_unwind)] - pub fn node(&self, env: Env) -> JsObject { - self.0.node().to_js(env) + pub fn node(&self) -> Either { + self.0.node().into() } #[napi(getter, ts_return_type = "kinds.NodeLabel", catch_unwind)] @@ -81,11 +80,8 @@ impl Cursor { } #[napi(ts_return_type = "Array", catch_unwind)] - pub fn ancestors(&self, env: Env) -> Vec { - self.0 - .ancestors() - .map(|rust_rule_node| rust_rule_node.to_js(env)) - .collect() + pub fn ancestors(&self) -> Vec { + self.0.ancestors().map(cst::RuleNode).collect() } #[napi(catch_unwind)] diff --git a/crates/testlang/outputs/cargo/slang_testlang/src/generated/napi_interface/parse_output.rs b/crates/testlang/outputs/cargo/slang_testlang/src/generated/napi_interface/parse_output.rs index 7f276a0ddc..994cf7de26 100644 --- a/crates/testlang/outputs/cargo/slang_testlang/src/generated/napi_interface/parse_output.rs +++ b/crates/testlang/outputs/cargo/slang_testlang/src/generated/napi_interface/parse_output.rs @@ -1,10 +1,10 @@ // This file is generated automatically by infrastructure scripts. Please don't edit by hand. -use cst::ToJS; -use napi::bindgen_prelude::Env; +use napi::Either; use napi_derive::napi; -use crate::napi_interface::{cst, cursor, parse_error, RustParseOutput}; +use crate::napi_interface::cst::{RuleNode, TokenNode}; +use crate::napi_interface::{cursor, parse_error, RustParseOutput}; #[napi(namespace = "parse_output")] pub struct ParseOutput(RustParseOutput); @@ -18,8 +18,8 @@ impl From for ParseOutput { #[napi(namespace = "parse_output")] impl ParseOutput { #[napi(ts_return_type = "cst.Node", catch_unwind)] - pub fn tree(&self, env: Env) -> napi::JsObject { - self.0.tree().to_js(env) + pub fn tree(&self) -> Either { + self.0.tree().into() } #[napi(ts_return_type = "Array", catch_unwind)] diff --git a/crates/testlang/outputs/cargo/slang_testlang/src/generated/napi_interface/query.rs b/crates/testlang/outputs/cargo/slang_testlang/src/generated/napi_interface/query.rs index bd5daaba67..795651013b 100644 --- a/crates/testlang/outputs/cargo/slang_testlang/src/generated/napi_interface/query.rs +++ b/crates/testlang/outputs/cargo/slang_testlang/src/generated/napi_interface/query.rs @@ -5,7 +5,10 @@ // The functions are meant to be definitions for export, so they're not really used #![allow(clippy::return_self_not_must_use)] -use napi::{Env, JsObject}; +use std::collections::HashMap; + +use napi::bindgen_prelude::ClassInstance; +use napi::Env; use napi_derive::napi; use crate::napi_interface::cursor::Cursor; @@ -38,22 +41,28 @@ pub struct QueryResultIterator(RustQueryResultIterator); pub struct QueryResult { pub query_number: u32, #[napi(ts_type = "{ [key: string]: cursor.Cursor[] }")] - pub bindings: JsObject, + pub bindings: HashMap>>, } impl QueryResult { fn new(env: Env, result: RustQueryResult) -> napi::Result { #[allow(clippy::cast_possible_truncation)] let query_number = result.query_number as u32; - let mut bindings = env.create_object()?; - // transer all of the bindings eagerly on the assumption + // transfer all of the bindings eagerly on the assumption // that they've all been explicitly requested. - for (key, value) in result.bindings { - bindings.set_named_property( - &key, - value.into_iter().map(|x| x.into()).collect::>(), - )?; - } + let bindings = result + .bindings + .into_iter() + .map(|(key, values)| { + let instances = values + .into_iter() + .map(|cursor| Cursor(cursor).into_instance(env)) + .collect::>()?; + + Ok((key, instances)) + }) + .collect::>()?; + Ok(Self { query_number, bindings, From 2d698ebe469110b85f539d6e0c75b503cd4ce57e Mon Sep 17 00:00:00 2001 From: Omar Tawfik <15987992+OmarTawfik@users.noreply.github.com> Date: Wed, 10 Apr 2024 09:15:07 +0200 Subject: [PATCH 4/9] support string literals in version pragmas (#839) - the new grammar makes sure the structure of string literals matches the parent productions, so that it can be parsed using the same parser for later analysis. - also fixed a minor grammar bug where `||` was a precedence binary expression, instead of a separator of comparator sets (repeated list of base expressions). - removed the internal `extract_version_pragmas` API for now, since it is not used. Later, we will introduce the same functionality as a public API, based on the Rust AST when is ready. --- .changeset/tidy-vans-enjoy.md | 5 + Cargo.lock | 17 +- Cargo.toml | 2 - .../inputs/language/src/definition.rs | 84 +++++-- .../slang_solidity/src/generated/kinds.rs | 18 +- .../slang_solidity/src/generated/language.rs | 229 ++++++++++-------- .../generated/napi_interface/ast_selectors.rs | 85 ++++--- .../solidity/outputs/cargo/tests/Cargo.toml | 5 +- .../cst_output/generated/version_pragma.rs | 15 ++ .../outputs/cargo/tests/src/cst_output/mod.rs | 1 + .../cargo/tests/src/cst_output/renderer.rs} | 20 +- .../cargo/tests/src/cst_output/runner.rs | 4 +- .../package/src/ast/generated/ast_types.ts | 125 +++++----- .../npm/package/src/generated/index.d.ts | 18 +- .../outputs/spec/generated/grammar.ebnf | 25 +- .../01-file-structure/03-pragma-directives.md | 42 +++- .../version/generated/0.4.11-success.yml | 17 +- .../everything/generated/0.4.11-failure.yml | 17 +- .../everything/generated/0.6.0-failure.yml | 17 +- .../everything/generated/0.7.1-failure.yml | 17 +- .../everything/generated/0.7.4-failure.yml | 17 +- .../everything/generated/0.8.0-failure.yml | 17 +- .../everything/generated/0.8.13-failure.yml | 17 +- .../everything/generated/0.8.22-success.yml | 17 +- .../everything/generated/0.8.4-failure.yml | 17 +- .../everything/generated/0.8.8-failure.yml | 17 +- .../generated/0.4.11-failure.yml | 21 +- .../generated/0.6.0-failure.yml | 21 +- .../generated/0.7.1-failure.yml | 21 +- .../generated/0.7.4-failure.yml | 21 +- .../generated/0.8.0-failure.yml | 21 +- .../generated/0.8.13-success.yml | 21 +- .../generated/0.8.4-failure.yml | 21 +- .../generated/0.8.8-failure.yml | 21 +- .../alternatives/generated/0.4.11-success.yml | 53 ++-- .../generated/0.4.11-success.yml | 16 ++ .../double_quotes_string/input.sol | 1 + .../generated/0.4.11-success.yml | 21 +- .../generated/0.4.11-success.yml | 17 +- .../generated/0.4.11-success.yml | 21 +- .../generated/0.4.11-success.yml | 31 +-- .../generated/0.4.11-success.yml | 27 +++ .../VersionPragma/multiple_strings/input.sol | 1 + .../generated/0.4.11-success.yml | 37 +-- .../ranges/generated/0.4.11-success.yml | 37 +-- .../generated/0.4.11-success.yml | 16 ++ .../single_quote_string/input.sol | 1 + .../with_trivia/generated/0.4.11-success.yml | 41 ++-- crates/solidity/testing/utils/Cargo.toml | 19 -- crates/solidity/testing/utils/src/lib.rs | 3 - .../testing/utils/src/node_extensions/mod.rs | 33 --- .../utils/src/node_extensions/tests.rs | 28 --- .../testing/utils/src/version_pragmas/mod.rs | 153 ------------ .../utils/src/version_pragmas/tests.rs | 109 --------- 54 files changed, 768 insertions(+), 930 deletions(-) create mode 100644 .changeset/tidy-vans-enjoy.md rename crates/solidity/{testing/utils/src/cst_snapshots/mod.rs => outputs/cargo/tests/src/cst_output/renderer.rs} (93%) create mode 100644 crates/solidity/testing/snapshots/cst_output/VersionPragma/double_quotes_string/generated/0.4.11-success.yml create mode 100644 crates/solidity/testing/snapshots/cst_output/VersionPragma/double_quotes_string/input.sol create mode 100644 crates/solidity/testing/snapshots/cst_output/VersionPragma/multiple_strings/generated/0.4.11-success.yml create mode 100644 crates/solidity/testing/snapshots/cst_output/VersionPragma/multiple_strings/input.sol create mode 100644 crates/solidity/testing/snapshots/cst_output/VersionPragma/single_quote_string/generated/0.4.11-success.yml create mode 100644 crates/solidity/testing/snapshots/cst_output/VersionPragma/single_quote_string/input.sol delete mode 100644 crates/solidity/testing/utils/Cargo.toml delete mode 100644 crates/solidity/testing/utils/src/lib.rs delete mode 100644 crates/solidity/testing/utils/src/node_extensions/mod.rs delete mode 100644 crates/solidity/testing/utils/src/node_extensions/tests.rs delete mode 100644 crates/solidity/testing/utils/src/version_pragmas/mod.rs delete mode 100644 crates/solidity/testing/utils/src/version_pragmas/tests.rs diff --git a/.changeset/tidy-vans-enjoy.md b/.changeset/tidy-vans-enjoy.md new file mode 100644 index 0000000000..e99830abd7 --- /dev/null +++ b/.changeset/tidy-vans-enjoy.md @@ -0,0 +1,5 @@ +--- +"@nomicfoundation/slang": patch +--- + +support string literals in version pragmas diff --git a/Cargo.lock b/Cargo.lock index 120d004eb0..83022c585d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1853,13 +1853,15 @@ dependencies = [ name = "solidity_cargo_tests" version = "0.13.1" dependencies = [ + "Inflector", "anyhow", + "codegen_language_definition", "codegen_testing", "infra_utils", + "once_cell", "semver", "slang_solidity", "solidity_language", - "solidity_testing_utils", "strum_macros", ] @@ -1937,19 +1939,6 @@ dependencies = [ "url", ] -[[package]] -name = "solidity_testing_utils" -version = "0.13.1" -dependencies = [ - "Inflector", - "anyhow", - "codegen_language_definition", - "once_cell", - "semver", - "slang_solidity", - "solidity_language", -] - [[package]] name = "strsim" version = "0.11.0" diff --git a/Cargo.toml b/Cargo.toml index 52aa35a89c..5abcad0b97 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -29,7 +29,6 @@ members = [ "crates/solidity/testing/sanctuary", "crates/solidity/testing/snapshots", "crates/solidity/testing/solc", - "crates/solidity/testing/utils", "crates/testlang/inputs/language", "crates/testlang/outputs/cargo/slang_testlang_node_addon", @@ -64,7 +63,6 @@ solidity_spec = { path = "crates/solidity/outputs/spec" } solidity_testing_sanctuary = { path = "crates/solidity/testing/sanctuary" } solidity_testing_snapshots = { path = "crates/solidity/testing/snapshots" } solidity_testing_solc = { path = "crates/solidity/testing/solc" } -solidity_testing_utils = { path = "crates/solidity/testing/utils" } slang_testlang = { path = "crates/testlang/outputs/cargo/slang_testlang" } slang_testlang_node_addon = { path = "crates/testlang/outputs/cargo/slang_testlang_node_addon" } diff --git a/crates/solidity/inputs/language/src/definition.rs b/crates/solidity/inputs/language/src/definition.rs index afc260a449..d3b2dcedc3 100644 --- a/crates/solidity/inputs/language/src/definition.rs +++ b/crates/solidity/inputs/language/src/definition.rs @@ -122,32 +122,27 @@ codegen_language_macros::compile!(Language( name = VersionPragma, fields = ( solidity_keyword = Required(SolidityKeyword), - expressions = Required(VersionPragmaExpressions) + sets = Required(VersionExpressionSets) ) ), - Repeated( - name = VersionPragmaExpressions, - reference = VersionPragmaExpression + Separated( + name = VersionExpressionSets, + reference = VersionExpressionSet, + separator = BarBar ), + Repeated(name = VersionExpressionSet, reference = VersionExpression), Precedence( - name = VersionPragmaExpression, + name = VersionExpression, precedence_expressions = [ PrecedenceExpression( - name = VersionPragmaOrExpression, - operators = [PrecedenceOperator( - model = BinaryLeftAssociative, - fields = (operator = Required(BarBar)) - )] - ), - PrecedenceExpression( - name = VersionPragmaRangeExpression, + name = VersionRange, operators = [PrecedenceOperator( model = BinaryLeftAssociative, fields = (operator = Required(Minus)) )] ), PrecedenceExpression( - name = VersionPragmaPrefixExpression, + name = VersionComparator, operators = [ PrecedenceOperator( model = Prefix, @@ -180,25 +175,64 @@ codegen_language_macros::compile!(Language( ] ) ], - primary_expressions = - [PrimaryExpression(reference = VersionPragmaSpecifier)] + primary_expressions = [ + PrimaryExpression(reference = VersionSpecifiers), + PrimaryExpression(reference = SingleQuotedVersionLiteral), + PrimaryExpression(reference = DoubleQuotedVersionLiteral) + ] ), Separated( - name = VersionPragmaSpecifier, - reference = VersionPragmaValue, + // __SLANG_VERSION_SPECIFIER_SYNTAX__ (keep in sync) + name = VersionSpecifiers, + reference = VersionSpecifier, separator = Period ), Token( - name = VersionPragmaValue, + // __SLANG_VERSION_SPECIFIER_SYNTAX__ (keep in sync) + name = VersionSpecifier, definitions = [TokenDefinition( - scanner = OneOrMore(Choice([ - Range(inclusive_start = '0', inclusive_end = '9'), - Atom("x"), - Atom("X"), - Atom("*") - ])) + scanner = Fragment(VersionSpecifierFragment) )] ), + Token( + // __SLANG_VERSION_SPECIFIER_SYNTAX__ (keep in sync) + name = SingleQuotedVersionLiteral, + definitions = [TokenDefinition( + scanner = Sequence([ + Atom("'"), + Fragment(VersionSpecifierFragment), + ZeroOrMore(Sequence([ + Atom("."), + Fragment(VersionSpecifierFragment) + ])), + Atom("'") + ]) + )] + ), + Token( + // __SLANG_VERSION_SPECIFIER_SYNTAX__ (keep in sync) + name = DoubleQuotedVersionLiteral, + definitions = [TokenDefinition( + scanner = Sequence([ + Atom("\""), + Fragment(VersionSpecifierFragment), + ZeroOrMore(Sequence([ + Atom("."), + Fragment(VersionSpecifierFragment) + ])), + Atom("\"") + ]) + )] + ), + Fragment( + name = VersionSpecifierFragment, + scanner = OneOrMore(Choice([ + Range(inclusive_start = '0', inclusive_end = '9'), + Atom("x"), + Atom("X"), + Atom("*") + ])) + ), Keyword( name = AbicoderKeyword, identifier = Identifier, diff --git a/crates/solidity/outputs/cargo/slang_solidity/src/generated/kinds.rs b/crates/solidity/outputs/cargo/slang_solidity/src/generated/kinds.rs index e32d5c8a93..887df1cf41 100644 --- a/crates/solidity/outputs/cargo/slang_solidity/src/generated/kinds.rs +++ b/crates/solidity/outputs/cargo/slang_solidity/src/generated/kinds.rs @@ -192,13 +192,13 @@ pub enum RuleKind { VariableDeclarationStatement, VariableDeclarationType, VariableDeclarationValue, + VersionComparator, + VersionExpression, + VersionExpressionSet, + VersionExpressionSets, VersionPragma, - VersionPragmaExpression, - VersionPragmaExpressions, - VersionPragmaOrExpression, - VersionPragmaPrefixExpression, - VersionPragmaRangeExpression, - VersionPragmaSpecifier, + VersionRange, + VersionSpecifiers, WhileStatement, YulArguments, YulAssignmentOperator, @@ -303,7 +303,6 @@ pub enum NodeLabel { EventKeyword, ExperimentalKeyword, Expression, - Expressions, FallbackKeyword, FalseExpression, Feature, @@ -358,6 +357,7 @@ pub enum NodeLabel { ReturnsKeyword, RevertKeyword, Semicolon, + Sets, SolidityKeyword, Start, Statements, @@ -450,6 +450,7 @@ pub enum TokenKind { DoubleQuotedHexStringLiteral, DoubleQuotedStringLiteral, DoubleQuotedUnicodeStringLiteral, + DoubleQuotedVersionLiteral, ElseKeyword, EmitKeyword, EndOfLine, @@ -547,6 +548,7 @@ pub enum TokenKind { SingleQuotedHexStringLiteral, SingleQuotedStringLiteral, SingleQuotedUnicodeStringLiteral, + SingleQuotedVersionLiteral, SizeOfKeyword, Slash, SlashEqual, @@ -570,7 +572,7 @@ pub enum TokenKind { UncheckedKeyword, UsingKeyword, VarKeyword, - VersionPragmaValue, + VersionSpecifier, ViewKeyword, VirtualKeyword, WeeksKeyword, diff --git a/crates/solidity/outputs/cargo/slang_solidity/src/generated/language.rs b/crates/solidity/outputs/cargo/slang_solidity/src/generated/language.rs index 911e545699..cdb315933b 100644 --- a/crates/solidity/outputs/cargo/slang_solidity/src/generated/language.rs +++ b/crates/solidity/outputs/cargo/slang_solidity/src/generated/language.rs @@ -5534,51 +5534,43 @@ impl Language { } #[allow(unused_assignments, unused_parens)] - fn version_pragma(&self, input: &mut ParserContext<'_>) -> ParserResult { - SequenceHelper::run(|mut seq| { - seq.elem_labeled( - NodeLabel::SolidityKeyword, - self.parse_token_with_trivia::( - input, - TokenKind::SolidityKeyword, - ), - )?; - seq.elem_labeled( - NodeLabel::Expressions, - self.version_pragma_expressions(input), - )?; - seq.finish() - }) - .with_kind(RuleKind::VersionPragma) + fn version_comparator(&self, input: &mut ParserContext<'_>) -> ParserResult { + let result = self.version_expression(input); + let ParserResult::Match(r#match) = &result else { + return result; + }; + match &r#match.nodes[..] { + [cst::LabeledNode { + label: _, + node: cst::Node::Rule(node), + }] if node.kind == RuleKind::VersionExpression => match &node.children[..] { + [inner @ cst::LabeledNode { + label: _, + node: cst::Node::Rule(rule), + }] if rule.kind == RuleKind::VersionComparator => { + ParserResult::r#match(vec![inner.clone()], r#match.expected_tokens.clone()) + } + _ => ParserResult::no_match(vec![]), + }, + _ => ParserResult::no_match(vec![]), + } } #[allow(unused_assignments, unused_parens)] - fn version_pragma_expression(&self, input: &mut ParserContext<'_>) -> ParserResult { - let parse_left_version_pragma_or_expression = |input: &mut ParserContext<'_>| { + fn version_expression(&self, input: &mut ParserContext<'_>) -> ParserResult { + let parse_left_version_range = |input: &mut ParserContext<'_>| { PrecedenceHelper::to_binary_operator( - RuleKind::VersionPragmaOrExpression, + RuleKind::VersionRange, 1u8, 1u8 + 1, - self.parse_token_with_trivia::( - input, - TokenKind::BarBar, - ) - .with_label(NodeLabel::Operator), - ) - }; - let parse_left_version_pragma_range_expression = |input: &mut ParserContext<'_>| { - PrecedenceHelper::to_binary_operator( - RuleKind::VersionPragmaRangeExpression, - 3u8, - 3u8 + 1, self.parse_token_with_trivia::(input, TokenKind::Minus) .with_label(NodeLabel::Operator), ) }; - let parse_prefix_version_pragma_prefix_expression = |input: &mut ParserContext<'_>| { + let parse_prefix_version_comparator = |input: &mut ParserContext<'_>| { PrecedenceHelper::to_prefix_operator( - RuleKind::VersionPragmaPrefixExpression, - 5u8, + RuleKind::VersionComparator, + 3u8, ChoiceHelper::run(input, |mut choice, input| { let result = self .parse_token_with_trivia::( @@ -5635,14 +5627,24 @@ impl Language { }; let prefix_operator_parser = |input: &mut ParserContext<'_>| { ChoiceHelper::run(input, |mut choice, input| { - let result = parse_prefix_version_pragma_prefix_expression(input); + let result = parse_prefix_version_comparator(input); choice.consider(input, result)?; choice.finish(input) }) }; let primary_expression_parser = |input: &mut ParserContext<'_>| { ChoiceHelper::run(input, |mut choice, input| { - let result = self.version_pragma_specifier(input); + let result = self.version_specifiers(input); + choice.consider(input, result)?; + let result = self.parse_token_with_trivia::( + input, + TokenKind::SingleQuotedVersionLiteral, + ); + choice.consider(input, result)?; + let result = self.parse_token_with_trivia::( + input, + TokenKind::DoubleQuotedVersionLiteral, + ); choice.consider(input, result)?; choice.finish(input) }) @@ -5657,9 +5659,7 @@ impl Language { }; let binary_operator_parser = |input: &mut ParserContext<'_>| { ChoiceHelper::run(input, |mut choice, input| { - let result = parse_left_version_pragma_or_expression(input); - choice.consider(input, result)?; - let result = parse_left_version_pragma_range_expression(input); + let result = parse_left_version_range(input); choice.consider(input, result)?; choice.finish(input) }) @@ -5678,70 +5678,54 @@ impl Language { }) }; PrecedenceHelper::reduce_precedence_result( - RuleKind::VersionPragmaExpression, + RuleKind::VersionExpression, linear_expression_parser(input), ) - .with_kind(RuleKind::VersionPragmaExpression) + .with_kind(RuleKind::VersionExpression) } #[allow(unused_assignments, unused_parens)] - fn version_pragma_expressions(&self, input: &mut ParserContext<'_>) -> ParserResult { + fn version_expression_set(&self, input: &mut ParserContext<'_>) -> ParserResult { OneOrMoreHelper::run(input, |input| { - self.version_pragma_expression(input) - .with_label(NodeLabel::Item) + self.version_expression(input).with_label(NodeLabel::Item) }) - .with_kind(RuleKind::VersionPragmaExpressions) + .with_kind(RuleKind::VersionExpressionSet) } #[allow(unused_assignments, unused_parens)] - fn version_pragma_or_expression(&self, input: &mut ParserContext<'_>) -> ParserResult { - let result = self.version_pragma_expression(input); - let ParserResult::Match(r#match) = &result else { - return result; - }; - match &r#match.nodes[..] { - [cst::LabeledNode { - label: _, - node: cst::Node::Rule(node), - }] if node.kind == RuleKind::VersionPragmaExpression => match &node.children[..] { - [inner @ cst::LabeledNode { - label: _, - node: cst::Node::Rule(rule), - }] if rule.kind == RuleKind::VersionPragmaOrExpression => { - ParserResult::r#match(vec![inner.clone()], r#match.expected_tokens.clone()) - } - _ => ParserResult::no_match(vec![]), + fn version_expression_sets(&self, input: &mut ParserContext<'_>) -> ParserResult { + SeparatedHelper::run::<_, LexicalContextType::Pragma>( + input, + self, + |input| { + self.version_expression_set(input) + .with_label(NodeLabel::Item) }, - _ => ParserResult::no_match(vec![]), - } + TokenKind::BarBar, + NodeLabel::Separator, + ) + .with_kind(RuleKind::VersionExpressionSets) } #[allow(unused_assignments, unused_parens)] - fn version_pragma_prefix_expression(&self, input: &mut ParserContext<'_>) -> ParserResult { - let result = self.version_pragma_expression(input); - let ParserResult::Match(r#match) = &result else { - return result; - }; - match &r#match.nodes[..] { - [cst::LabeledNode { - label: _, - node: cst::Node::Rule(node), - }] if node.kind == RuleKind::VersionPragmaExpression => match &node.children[..] { - [inner @ cst::LabeledNode { - label: _, - node: cst::Node::Rule(rule), - }] if rule.kind == RuleKind::VersionPragmaPrefixExpression => { - ParserResult::r#match(vec![inner.clone()], r#match.expected_tokens.clone()) - } - _ => ParserResult::no_match(vec![]), - }, - _ => ParserResult::no_match(vec![]), - } + fn version_pragma(&self, input: &mut ParserContext<'_>) -> ParserResult { + SequenceHelper::run(|mut seq| { + seq.elem_labeled( + NodeLabel::SolidityKeyword, + self.parse_token_with_trivia::( + input, + TokenKind::SolidityKeyword, + ), + )?; + seq.elem_labeled(NodeLabel::Sets, self.version_expression_sets(input))?; + seq.finish() + }) + .with_kind(RuleKind::VersionPragma) } #[allow(unused_assignments, unused_parens)] - fn version_pragma_range_expression(&self, input: &mut ParserContext<'_>) -> ParserResult { - let result = self.version_pragma_expression(input); + fn version_range(&self, input: &mut ParserContext<'_>) -> ParserResult { + let result = self.version_expression(input); let ParserResult::Match(r#match) = &result else { return result; }; @@ -5749,11 +5733,11 @@ impl Language { [cst::LabeledNode { label: _, node: cst::Node::Rule(node), - }] if node.kind == RuleKind::VersionPragmaExpression => match &node.children[..] { + }] if node.kind == RuleKind::VersionExpression => match &node.children[..] { [inner @ cst::LabeledNode { label: _, node: cst::Node::Rule(rule), - }] if rule.kind == RuleKind::VersionPragmaRangeExpression => { + }] if rule.kind == RuleKind::VersionRange => { ParserResult::r#match(vec![inner.clone()], r#match.expected_tokens.clone()) } _ => ParserResult::no_match(vec![]), @@ -5763,21 +5747,21 @@ impl Language { } #[allow(unused_assignments, unused_parens)] - fn version_pragma_specifier(&self, input: &mut ParserContext<'_>) -> ParserResult { + fn version_specifiers(&self, input: &mut ParserContext<'_>) -> ParserResult { SeparatedHelper::run::<_, LexicalContextType::Pragma>( input, self, |input| { self.parse_token_with_trivia::( input, - TokenKind::VersionPragmaValue, + TokenKind::VersionSpecifier, ) .with_label(NodeLabel::Item) }, TokenKind::Period, NodeLabel::Separator, ) - .with_kind(RuleKind::VersionPragmaSpecifier) + .with_kind(RuleKind::VersionSpecifiers) } #[allow(unused_assignments, unused_parens)] @@ -7083,6 +7067,22 @@ impl Language { } } + #[allow(unused_assignments, unused_parens)] + fn double_quoted_version_literal(&self, input: &mut ParserContext<'_>) -> bool { + scan_sequence!( + scan_chars!(input, '"'), + self.version_specifier_fragment(input), + scan_zero_or_more!( + input, + scan_sequence!( + scan_chars!(input, '.'), + self.version_specifier_fragment(input) + ) + ), + scan_chars!(input, '"') + ) + } + #[allow(unused_assignments, unused_parens)] fn end_of_line(&self, input: &mut ParserContext<'_>) -> bool { scan_choice!( @@ -7334,6 +7334,22 @@ impl Language { } } + #[allow(unused_assignments, unused_parens)] + fn single_quoted_version_literal(&self, input: &mut ParserContext<'_>) -> bool { + scan_sequence!( + scan_chars!(input, '\''), + self.version_specifier_fragment(input), + scan_zero_or_more!( + input, + scan_sequence!( + scan_chars!(input, '.'), + self.version_specifier_fragment(input) + ) + ), + scan_chars!(input, '\'') + ) + } + #[allow(unused_assignments, unused_parens)] fn slash(&self, input: &mut ParserContext<'_>) -> bool { scan_not_followed_by!( @@ -7360,7 +7376,12 @@ impl Language { } #[allow(unused_assignments, unused_parens)] - fn version_pragma_value(&self, input: &mut ParserContext<'_>) -> bool { + fn version_specifier(&self, input: &mut ParserContext<'_>) -> bool { + self.version_specifier_fragment(input) + } + + #[allow(unused_assignments, unused_parens)] + fn version_specifier_fragment(&self, input: &mut ParserContext<'_>) -> bool { scan_one_or_more!( input, scan_choice!( @@ -9210,21 +9231,13 @@ impl Language { RuleKind::VariableDeclarationValue => { Self::variable_declaration_value.parse(self, input) } + RuleKind::VersionComparator => Self::version_comparator.parse(self, input), + RuleKind::VersionExpression => Self::version_expression.parse(self, input), + RuleKind::VersionExpressionSet => Self::version_expression_set.parse(self, input), + RuleKind::VersionExpressionSets => Self::version_expression_sets.parse(self, input), RuleKind::VersionPragma => Self::version_pragma.parse(self, input), - RuleKind::VersionPragmaExpression => Self::version_pragma_expression.parse(self, input), - RuleKind::VersionPragmaExpressions => { - Self::version_pragma_expressions.parse(self, input) - } - RuleKind::VersionPragmaOrExpression => { - Self::version_pragma_or_expression.parse(self, input) - } - RuleKind::VersionPragmaPrefixExpression => { - Self::version_pragma_prefix_expression.parse(self, input) - } - RuleKind::VersionPragmaRangeExpression => { - Self::version_pragma_range_expression.parse(self, input) - } - RuleKind::VersionPragmaSpecifier => Self::version_pragma_specifier.parse(self, input), + RuleKind::VersionRange => Self::version_range.parse(self, input), + RuleKind::VersionSpecifiers => Self::version_specifiers.parse(self, input), RuleKind::WhileStatement => Self::while_statement.parse(self, input), RuleKind::YulArguments => Self::yul_arguments.parse(self, input), RuleKind::YulAssignmentOperator => Self::yul_assignment_operator.parse(self, input), @@ -10752,7 +10765,9 @@ impl Lexer for Language { input.set_position(save); longest_match! { - { VersionPragmaValue = version_pragma_value } + { DoubleQuotedVersionLiteral = double_quoted_version_literal } + { SingleQuotedVersionLiteral = single_quoted_version_literal } + { VersionSpecifier = version_specifier } } // Make sure promotable identifiers are last so they don't grab other things longest_match! { diff --git a/crates/solidity/outputs/cargo/slang_solidity/src/generated/napi_interface/ast_selectors.rs b/crates/solidity/outputs/cargo/slang_solidity/src/generated/napi_interface/ast_selectors.rs index efa50fbd10..ddfd8d859d 100644 --- a/crates/solidity/outputs/cargo/slang_solidity/src/generated/napi_interface/ast_selectors.rs +++ b/crates/solidity/outputs/cargo/slang_solidity/src/generated/napi_interface/ast_selectors.rs @@ -30,9 +30,8 @@ pub fn select_sequence( RuleKind::ABICoderPragma => selector.abi_coder_pragma()?, RuleKind::ExperimentalPragma => selector.experimental_pragma()?, RuleKind::VersionPragma => selector.version_pragma()?, - RuleKind::VersionPragmaOrExpression => selector.version_pragma_or_expression()?, - RuleKind::VersionPragmaRangeExpression => selector.version_pragma_range_expression()?, - RuleKind::VersionPragmaPrefixExpression => selector.version_pragma_prefix_expression()?, + RuleKind::VersionRange => selector.version_range()?, + RuleKind::VersionComparator => selector.version_comparator()?, RuleKind::ImportDirective => selector.import_directive()?, RuleKind::PathImport => selector.path_import()?, RuleKind::NamedImport => selector.named_import()?, @@ -206,40 +205,26 @@ impl Selector { fn version_pragma(&mut self) -> Result>>> { Ok(vec![ Some(self.select(|node| node.is_token_with_kind(TokenKind::SolidityKeyword))?), - Some(self.select(|node| node.is_rule_with_kind(RuleKind::VersionPragmaExpressions))?), + Some(self.select(|node| node.is_rule_with_kind(RuleKind::VersionExpressionSets))?), ]) } } impl Selector { - fn version_pragma_or_expression(&mut self) -> Result>>> { + fn version_range(&mut self) -> Result>>> { Ok(vec![ - Some(self.select(|node| node.is_rule_with_kind(RuleKind::VersionPragmaExpression))?), - Some(self.select(|node| node.is_token_with_kind(TokenKind::BarBar))?), - Some(self.select(|node| node.is_rule_with_kind(RuleKind::VersionPragmaExpression))?), - ]) - } -} - -impl Selector { - fn version_pragma_range_expression( - &mut self, - ) -> Result>>> { - Ok(vec![ - Some(self.select(|node| node.is_rule_with_kind(RuleKind::VersionPragmaExpression))?), + Some(self.select(|node| node.is_rule_with_kind(RuleKind::VersionExpression))?), Some(self.select(|node| node.is_token_with_kind(TokenKind::Minus))?), - Some(self.select(|node| node.is_rule_with_kind(RuleKind::VersionPragmaExpression))?), + Some(self.select(|node| node.is_rule_with_kind(RuleKind::VersionExpression))?), ]) } } impl Selector { - fn version_pragma_prefix_expression( - &mut self, - ) -> Result>>> { + fn version_comparator(&mut self) -> Result>>> { Ok(vec![ Some(self.select(|node| node.is_token_with_kind(TokenKind::Caret))?), - Some(self.select(|node| node.is_rule_with_kind(RuleKind::VersionPragmaExpression))?), + Some(self.select(|node| node.is_rule_with_kind(RuleKind::VersionExpression))?), ]) } } @@ -1509,7 +1494,7 @@ pub fn select_choice( RuleKind::SourceUnitMember => selector.source_unit_member()?, RuleKind::Pragma => selector.pragma()?, RuleKind::ExperimentalFeature => selector.experimental_feature()?, - RuleKind::VersionPragmaExpression => selector.version_pragma_expression()?, + RuleKind::VersionExpression => selector.version_expression()?, RuleKind::ImportClause => selector.import_clause()?, RuleKind::UsingClause => selector.using_clause()?, RuleKind::UsingOperator => selector.using_operator()?, @@ -1601,13 +1586,15 @@ impl Selector { } impl Selector { - fn version_pragma_expression(&mut self) -> Result> { + fn version_expression(&mut self) -> Result> { self.select(|node| { node.is_rule_with_kinds(&[ - RuleKind::VersionPragmaOrExpression, - RuleKind::VersionPragmaRangeExpression, - RuleKind::VersionPragmaPrefixExpression, - RuleKind::VersionPragmaSpecifier, + RuleKind::VersionRange, + RuleKind::VersionComparator, + RuleKind::VersionSpecifiers, + ]) || node.is_token_with_kinds(&[ + TokenKind::SingleQuotedVersionLiteral, + TokenKind::DoubleQuotedVersionLiteral, ]) }) } @@ -2238,7 +2225,7 @@ pub fn select_repeated( let result = match node.kind() { RuleKind::SourceUnitMembers => selector.source_unit_members()?, - RuleKind::VersionPragmaExpressions => selector.version_pragma_expressions()?, + RuleKind::VersionExpressionSet => selector.version_expression_set()?, RuleKind::ContractMembers => selector.contract_members()?, RuleKind::InterfaceMembers => selector.interface_members()?, RuleKind::LibraryMembers => selector.library_members()?, @@ -2282,11 +2269,11 @@ impl Selector { } impl Selector { - fn version_pragma_expressions(&mut self) -> Result>> { + fn version_expression_set(&mut self) -> Result>> { let mut items = vec![]; while let Some(item) = - self.try_select(|node| node.is_rule_with_kind(RuleKind::VersionPragmaExpression))? + self.try_select(|node| node.is_rule_with_kind(RuleKind::VersionExpression))? { items.push(item); } @@ -2576,7 +2563,8 @@ pub fn select_separated( let mut selector = Selector::new(node); let result = match node.kind() { - RuleKind::VersionPragmaSpecifier => selector.version_pragma_specifier()?, + RuleKind::VersionExpressionSets => selector.version_expression_sets()?, + RuleKind::VersionSpecifiers => selector.version_specifiers()?, RuleKind::ImportDeconstructionSymbols => selector.import_deconstruction_symbols()?, RuleKind::UsingDeconstructionSymbols => selector.using_deconstruction_symbols()?, RuleKind::InheritanceTypes => selector.inheritance_types()?, @@ -2608,12 +2596,37 @@ pub fn select_separated( } impl Selector { - fn version_pragma_specifier(&mut self) -> Result>>> { + fn version_expression_sets(&mut self) -> Result>>> { + let mut separated = vec![]; + let mut separators = vec![]; + + if let Some(first) = + self.try_select(|node| node.is_rule_with_kind(RuleKind::VersionExpressionSet))? + { + separated.push(first); + + while let Some(separator) = + self.try_select(|node| node.is_token_with_kind(TokenKind::BarBar))? + { + separators.push(separator); + + separated.push( + self.select(|node| node.is_rule_with_kind(RuleKind::VersionExpressionSet))?, + ); + } + } + + Ok(vec![separated, separators]) + } +} + +impl Selector { + fn version_specifiers(&mut self) -> Result>>> { let mut separated = vec![]; let mut separators = vec![]; if let Some(first) = - self.try_select(|node| node.is_token_with_kind(TokenKind::VersionPragmaValue))? + self.try_select(|node| node.is_token_with_kind(TokenKind::VersionSpecifier))? { separated.push(first); @@ -2623,7 +2636,7 @@ impl Selector { separators.push(separator); separated.push( - self.select(|node| node.is_token_with_kind(TokenKind::VersionPragmaValue))?, + self.select(|node| node.is_token_with_kind(TokenKind::VersionSpecifier))?, ); } } diff --git a/crates/solidity/outputs/cargo/tests/Cargo.toml b/crates/solidity/outputs/cargo/tests/Cargo.toml index eeda098afe..e4a1903815 100644 --- a/crates/solidity/outputs/cargo/tests/Cargo.toml +++ b/crates/solidity/outputs/cargo/tests/Cargo.toml @@ -13,10 +13,13 @@ solidity_language = { workspace = true } [dev-dependencies] anyhow = { workspace = true } +codegen_language_definition = { workspace = true } +Inflector = { workspace = true } infra_utils = { workspace = true } +once_cell = { workspace = true } semver = { workspace = true } slang_solidity = { workspace = true } -solidity_testing_utils = { workspace = true } +solidity_language = { workspace = true } strum_macros = { workspace = true } [lints] diff --git a/crates/solidity/outputs/cargo/tests/src/cst_output/generated/version_pragma.rs b/crates/solidity/outputs/cargo/tests/src/cst_output/generated/version_pragma.rs index c5c4a4bff2..6ab143f69c 100644 --- a/crates/solidity/outputs/cargo/tests/src/cst_output/generated/version_pragma.rs +++ b/crates/solidity/outputs/cargo/tests/src/cst_output/generated/version_pragma.rs @@ -9,6 +9,11 @@ fn alternatives() -> Result<()> { run("VersionPragma", "alternatives") } +#[test] +fn double_quotes_string() -> Result<()> { + run("VersionPragma", "double_quotes_string") +} + #[test] fn equal_operator() -> Result<()> { run("VersionPragma", "equal_operator") @@ -29,6 +34,11 @@ fn multiple_exact_versions() -> Result<()> { run("VersionPragma", "multiple_exact_versions") } +#[test] +fn multiple_strings() -> Result<()> { + run("VersionPragma", "multiple_strings") +} + #[test] fn nested_expressions() -> Result<()> { run("VersionPragma", "nested_expressions") @@ -39,6 +49,11 @@ fn ranges() -> Result<()> { run("VersionPragma", "ranges") } +#[test] +fn single_quote_string() -> Result<()> { + run("VersionPragma", "single_quote_string") +} + #[test] fn with_trivia() -> Result<()> { run("VersionPragma", "with_trivia") diff --git a/crates/solidity/outputs/cargo/tests/src/cst_output/mod.rs b/crates/solidity/outputs/cargo/tests/src/cst_output/mod.rs index cce71d6609..63faf74747 100644 --- a/crates/solidity/outputs/cargo/tests/src/cst_output/mod.rs +++ b/crates/solidity/outputs/cargo/tests/src/cst_output/mod.rs @@ -1,2 +1,3 @@ mod generated; +mod renderer; mod runner; diff --git a/crates/solidity/testing/utils/src/cst_snapshots/mod.rs b/crates/solidity/outputs/cargo/tests/src/cst_output/renderer.rs similarity index 93% rename from crates/solidity/testing/utils/src/cst_snapshots/mod.rs rename to crates/solidity/outputs/cargo/tests/src/cst_output/renderer.rs index 85ab932854..2349e74fc3 100644 --- a/crates/solidity/testing/utils/src/cst_snapshots/mod.rs +++ b/crates/solidity/outputs/cargo/tests/src/cst_output/renderer.rs @@ -13,22 +13,18 @@ use slang_solidity::kinds::RuleKind; use slang_solidity::text_index::TextRangeExtensions; use solidity_language::SolidityDefinition; -pub struct CstSnapshots; +pub fn render(source: &str, errors: &Vec, cursor: CursorWithLabels) -> Result { + let mut w = String::new(); -impl CstSnapshots { - pub fn render(source: &str, errors: &Vec, cursor: CursorWithLabels) -> Result { - let mut w = String::new(); + write_source(&mut w, source)?; + writeln!(&mut w)?; - write_source(&mut w, source)?; - writeln!(&mut w)?; + write_errors(&mut w, errors)?; + writeln!(&mut w)?; - write_errors(&mut w, errors)?; - writeln!(&mut w)?; + write_tree(&mut w, cursor, source)?; - write_tree(&mut w, cursor, source)?; - - Ok(w) - } + Ok(w) } fn write_source(w: &mut String, source: &str) -> Result<()> { diff --git a/crates/solidity/outputs/cargo/tests/src/cst_output/runner.rs b/crates/solidity/outputs/cargo/tests/src/cst_output/runner.rs index 185399caff..ca19fd5fac 100644 --- a/crates/solidity/outputs/cargo/tests/src/cst_output/runner.rs +++ b/crates/solidity/outputs/cargo/tests/src/cst_output/runner.rs @@ -6,10 +6,10 @@ use infra_utils::codegen::Codegen; use infra_utils::paths::PathExtensions; use slang_solidity::kinds::RuleKind; use slang_solidity::language::Language; -use solidity_testing_utils::cst_snapshots::CstSnapshots; use strum_macros::Display; use crate::cst_output::generated::VERSION_BREAKS; +use crate::cst_output::renderer::render; #[derive(Display)] #[strum(serialize_all = "kebab_case")] @@ -60,7 +60,7 @@ pub fn run(parser_name: &str, test_name: &str) -> Result<()> { TestStatus::Failure }; - let snapshot = CstSnapshots::render(&source, &errors, cursor)?; + let snapshot = render(&source, &errors, cursor)?; let snapshot_path = test_dir .join("generated") diff --git a/crates/solidity/outputs/npm/package/src/ast/generated/ast_types.ts b/crates/solidity/outputs/npm/package/src/ast/generated/ast_types.ts index b85a9e15b2..38072a88c0 100644 --- a/crates/solidity/outputs/npm/package/src/ast/generated/ast_types.ts +++ b/crates/solidity/outputs/npm/package/src/ast/generated/ast_types.ts @@ -103,11 +103,11 @@ export class ExperimentalPragma { export class VersionPragma { private readonly fetch = once(() => { - const [$solidityKeyword, $expressions] = ast_internal.selectSequence(this.cst); + const [$solidityKeyword, $sets] = ast_internal.selectSequence(this.cst); return { solidityKeyword: $solidityKeyword as TokenNode, - expressions: new VersionPragmaExpressions($expressions as RuleNode), + sets: new VersionExpressionSets($sets as RuleNode), }; }); @@ -119,27 +119,27 @@ export class VersionPragma { return this.fetch().solidityKeyword; } - public get expressions(): VersionPragmaExpressions { - return this.fetch().expressions; + public get sets(): VersionExpressionSets { + return this.fetch().sets; } } -export class VersionPragmaOrExpression { +export class VersionRange { private readonly fetch = once(() => { const [$leftOperand, $operator, $rightOperand] = ast_internal.selectSequence(this.cst); return { - leftOperand: new VersionPragmaExpression($leftOperand as RuleNode), + leftOperand: new VersionExpression($leftOperand as RuleNode), operator: $operator as TokenNode, - rightOperand: new VersionPragmaExpression($rightOperand as RuleNode), + rightOperand: new VersionExpression($rightOperand as RuleNode), }; }); public constructor(public readonly cst: RuleNode) { - assertKind(this.cst.kind, RuleKind.VersionPragmaOrExpression); + assertKind(this.cst.kind, RuleKind.VersionRange); } - public get leftOperand(): VersionPragmaExpression { + public get leftOperand(): VersionExpression { return this.fetch().leftOperand; } @@ -147,58 +147,30 @@ export class VersionPragmaOrExpression { return this.fetch().operator; } - public get rightOperand(): VersionPragmaExpression { + public get rightOperand(): VersionExpression { return this.fetch().rightOperand; } } -export class VersionPragmaRangeExpression { - private readonly fetch = once(() => { - const [$leftOperand, $operator, $rightOperand] = ast_internal.selectSequence(this.cst); - - return { - leftOperand: new VersionPragmaExpression($leftOperand as RuleNode), - operator: $operator as TokenNode, - rightOperand: new VersionPragmaExpression($rightOperand as RuleNode), - }; - }); - - public constructor(public readonly cst: RuleNode) { - assertKind(this.cst.kind, RuleKind.VersionPragmaRangeExpression); - } - - public get leftOperand(): VersionPragmaExpression { - return this.fetch().leftOperand; - } - - public get operator(): TokenNode { - return this.fetch().operator; - } - - public get rightOperand(): VersionPragmaExpression { - return this.fetch().rightOperand; - } -} - -export class VersionPragmaPrefixExpression { +export class VersionComparator { private readonly fetch = once(() => { const [$operator, $operand] = ast_internal.selectSequence(this.cst); return { operator: $operator as TokenNode, - operand: new VersionPragmaExpression($operand as RuleNode), + operand: new VersionExpression($operand as RuleNode), }; }); public constructor(public readonly cst: RuleNode) { - assertKind(this.cst.kind, RuleKind.VersionPragmaPrefixExpression); + assertKind(this.cst.kind, RuleKind.VersionComparator); } public get operator(): TokenNode { return this.fetch().operator; } - public get operand(): VersionPragmaExpression { + public get operand(): VersionExpression { return this.fetch().operand; } } @@ -3864,23 +3836,21 @@ export class ExperimentalFeature { } } -export class VersionPragmaExpression { - private readonly fetch: () => - | VersionPragmaOrExpression - | VersionPragmaRangeExpression - | VersionPragmaPrefixExpression - | VersionPragmaSpecifier = once(() => { +export class VersionExpression { + private readonly fetch: () => VersionRange | VersionComparator | VersionSpecifiers | TokenNode = once(() => { const variant = ast_internal.selectChoice(this.cst); switch (variant.kind) { - case RuleKind.VersionPragmaOrExpression: - return new VersionPragmaOrExpression(variant as RuleNode); - case RuleKind.VersionPragmaRangeExpression: - return new VersionPragmaRangeExpression(variant as RuleNode); - case RuleKind.VersionPragmaPrefixExpression: - return new VersionPragmaPrefixExpression(variant as RuleNode); - case RuleKind.VersionPragmaSpecifier: - return new VersionPragmaSpecifier(variant as RuleNode); + case RuleKind.VersionRange: + return new VersionRange(variant as RuleNode); + case RuleKind.VersionComparator: + return new VersionComparator(variant as RuleNode); + case RuleKind.VersionSpecifiers: + return new VersionSpecifiers(variant as RuleNode); + + case TokenKind.SingleQuotedVersionLiteral: + case TokenKind.DoubleQuotedVersionLiteral: + return variant as TokenNode; default: assert.fail(`Unexpected variant: ${variant.kind}`); @@ -3888,14 +3858,10 @@ export class VersionPragmaExpression { }); public constructor(public readonly cst: RuleNode) { - assertKind(this.cst.kind, RuleKind.VersionPragmaExpression); + assertKind(this.cst.kind, RuleKind.VersionExpression); } - public get variant(): - | VersionPragmaOrExpression - | VersionPragmaRangeExpression - | VersionPragmaPrefixExpression - | VersionPragmaSpecifier { + public get variant(): VersionRange | VersionComparator | VersionSpecifiers | TokenNode { return this.fetch(); } } @@ -5290,17 +5256,17 @@ export class SourceUnitMembers { } } -export class VersionPragmaExpressions { +export class VersionExpressionSet { private readonly fetch = once(() => { const items = ast_internal.selectRepeated(this.cst); - return items.map((item) => new VersionPragmaExpression(item as RuleNode)); + return items.map((item) => new VersionExpression(item as RuleNode)); }); public constructor(public readonly cst: RuleNode) { - assertKind(this.cst.kind, RuleKind.VersionPragmaExpressions); + assertKind(this.cst.kind, RuleKind.VersionExpressionSet); } - public get items(): readonly VersionPragmaExpression[] { + public get items(): readonly VersionExpression[] { return this.fetch(); } } @@ -5594,7 +5560,30 @@ export class YulSwitchCases { * Separated: */ -export class VersionPragmaSpecifier { +export class VersionExpressionSets { + private readonly fetch = once(() => { + const [items, separators] = ast_internal.selectSeparated(this.cst); + + return { + items: items.map((item) => new VersionExpressionSet(item as RuleNode)), + separators: separators as TokenNode[], + }; + }); + + public constructor(public readonly cst: RuleNode) { + assertKind(this.cst.kind, RuleKind.VersionExpressionSets); + } + + public get items(): readonly VersionExpressionSet[] { + return this.fetch().items; + } + + public get separators(): readonly TokenNode[] { + return this.fetch().separators; + } +} + +export class VersionSpecifiers { private readonly fetch = once(() => { const [items, separators] = ast_internal.selectSeparated(this.cst); @@ -5602,7 +5591,7 @@ export class VersionPragmaSpecifier { }); public constructor(public readonly cst: RuleNode) { - assertKind(this.cst.kind, RuleKind.VersionPragmaSpecifier); + assertKind(this.cst.kind, RuleKind.VersionSpecifiers); } public get items(): readonly TokenNode[] { diff --git a/crates/solidity/outputs/npm/package/src/generated/index.d.ts b/crates/solidity/outputs/npm/package/src/generated/index.d.ts index 9d31b9bc2e..9c5d7c7112 100644 --- a/crates/solidity/outputs/npm/package/src/generated/index.d.ts +++ b/crates/solidity/outputs/npm/package/src/generated/index.d.ts @@ -184,13 +184,13 @@ export namespace kinds { VariableDeclarationStatement = "VariableDeclarationStatement", VariableDeclarationType = "VariableDeclarationType", VariableDeclarationValue = "VariableDeclarationValue", + VersionComparator = "VersionComparator", + VersionExpression = "VersionExpression", + VersionExpressionSet = "VersionExpressionSet", + VersionExpressionSets = "VersionExpressionSets", VersionPragma = "VersionPragma", - VersionPragmaExpression = "VersionPragmaExpression", - VersionPragmaExpressions = "VersionPragmaExpressions", - VersionPragmaOrExpression = "VersionPragmaOrExpression", - VersionPragmaPrefixExpression = "VersionPragmaPrefixExpression", - VersionPragmaRangeExpression = "VersionPragmaRangeExpression", - VersionPragmaSpecifier = "VersionPragmaSpecifier", + VersionRange = "VersionRange", + VersionSpecifiers = "VersionSpecifiers", WhileStatement = "WhileStatement", YulArguments = "YulArguments", YulAssignmentOperator = "YulAssignmentOperator", @@ -277,7 +277,6 @@ export namespace kinds { EventKeyword = "EventKeyword", ExperimentalKeyword = "ExperimentalKeyword", Expression = "Expression", - Expressions = "Expressions", FallbackKeyword = "FallbackKeyword", FalseExpression = "FalseExpression", Feature = "Feature", @@ -332,6 +331,7 @@ export namespace kinds { ReturnsKeyword = "ReturnsKeyword", RevertKeyword = "RevertKeyword", Semicolon = "Semicolon", + Sets = "Sets", SolidityKeyword = "SolidityKeyword", Start = "Start", Statements = "Statements", @@ -409,6 +409,7 @@ export namespace kinds { DoubleQuotedHexStringLiteral = "DoubleQuotedHexStringLiteral", DoubleQuotedStringLiteral = "DoubleQuotedStringLiteral", DoubleQuotedUnicodeStringLiteral = "DoubleQuotedUnicodeStringLiteral", + DoubleQuotedVersionLiteral = "DoubleQuotedVersionLiteral", ElseKeyword = "ElseKeyword", EmitKeyword = "EmitKeyword", EndOfLine = "EndOfLine", @@ -506,6 +507,7 @@ export namespace kinds { SingleQuotedHexStringLiteral = "SingleQuotedHexStringLiteral", SingleQuotedStringLiteral = "SingleQuotedStringLiteral", SingleQuotedUnicodeStringLiteral = "SingleQuotedUnicodeStringLiteral", + SingleQuotedVersionLiteral = "SingleQuotedVersionLiteral", SizeOfKeyword = "SizeOfKeyword", Slash = "Slash", SlashEqual = "SlashEqual", @@ -529,7 +531,7 @@ export namespace kinds { UncheckedKeyword = "UncheckedKeyword", UsingKeyword = "UsingKeyword", VarKeyword = "VarKeyword", - VersionPragmaValue = "VersionPragmaValue", + VersionSpecifier = "VersionSpecifier", ViewKeyword = "ViewKeyword", VirtualKeyword = "VirtualKeyword", WeeksKeyword = "WeeksKeyword", diff --git a/crates/solidity/outputs/spec/generated/grammar.ebnf b/crates/solidity/outputs/spec/generated/grammar.ebnf index cdc23d019f..0ef9e87807 100644 --- a/crates/solidity/outputs/spec/generated/grammar.ebnf +++ b/crates/solidity/outputs/spec/generated/grammar.ebnf @@ -48,18 +48,27 @@ ExperimentalFeature = IDENTIFIER | StringLiteral; VersionPragma = SOLIDITY_KEYWORD - VersionPragmaExpressions; + VersionExpressionSets; -VersionPragmaExpressions = VersionPragmaExpression+; +VersionExpressionSets = VersionExpressionSet (BAR_BAR VersionExpressionSet)*; -VersionPragmaExpression = VersionPragmaOrExpression - | VersionPragmaRangeExpression - | VersionPragmaPrefixExpression - | VersionPragmaSpecifier; +VersionExpressionSet = VersionExpression+; -VersionPragmaSpecifier = VERSION_PRAGMA_VALUE (PERIOD VERSION_PRAGMA_VALUE)*; +VersionExpression = VersionRange + | VersionComparator + | VersionSpecifiers + | SINGLE_QUOTED_VERSION_LITERAL + | DOUBLE_QUOTED_VERSION_LITERAL; -VERSION_PRAGMA_VALUE = (("0"…"9") | "x" | "X" | "*")+; +VersionSpecifiers = VERSION_SPECIFIER (PERIOD VERSION_SPECIFIER)*; + +VERSION_SPECIFIER = «VERSION_SPECIFIER_FRAGMENT»; + +SINGLE_QUOTED_VERSION_LITERAL = "'" «VERSION_SPECIFIER_FRAGMENT» ("." «VERSION_SPECIFIER_FRAGMENT»)* "'"; + +DOUBLE_QUOTED_VERSION_LITERAL = '"' «VERSION_SPECIFIER_FRAGMENT» ("." «VERSION_SPECIFIER_FRAGMENT»)* '"'; + +«VERSION_SPECIFIER_FRAGMENT» = (("0"…"9") | "x" | "X" | "*")+; (* Never reserved *) ABICODER_KEYWORD = "abicoder"; diff --git a/crates/solidity/outputs/spec/generated/public/01-file-structure/03-pragma-directives.md b/crates/solidity/outputs/spec/generated/public/01-file-structure/03-pragma-directives.md index 975eff3916..7a03870375 100644 --- a/crates/solidity/outputs/spec/generated/public/01-file-structure/03-pragma-directives.md +++ b/crates/solidity/outputs/spec/generated/public/01-file-structure/03-pragma-directives.md @@ -38,31 +38,55 @@ ``` -
VersionPragma = SOLIDITY_KEYWORD
VersionPragmaExpressions;
+
VersionPragma = SOLIDITY_KEYWORD
VersionExpressionSets;
-```{ .ebnf #VersionPragmaExpressions } +```{ .ebnf #VersionExpressionSets } ``` -
VersionPragmaExpressions = VersionPragmaExpression+;
+
VersionExpressionSets = VersionExpressionSet (BAR_BAR VersionExpressionSet)*;
-```{ .ebnf #VersionPragmaExpression } +```{ .ebnf #VersionExpressionSet } ``` -
VersionPragmaExpression = VersionPragmaOrExpression
| VersionPragmaRangeExpression
| VersionPragmaPrefixExpression
| VersionPragmaSpecifier;
+
VersionExpressionSet = VersionExpression+;
-```{ .ebnf #VersionPragmaSpecifier } +```{ .ebnf #VersionExpression } ``` -
VersionPragmaSpecifier = VERSION_PRAGMA_VALUE (PERIOD VERSION_PRAGMA_VALUE)*;
+
VersionExpression = VersionRange
| VersionComparator
| VersionSpecifiers
| SINGLE_QUOTED_VERSION_LITERAL
| DOUBLE_QUOTED_VERSION_LITERAL;
-```{ .ebnf #VersionPragmaValue } +```{ .ebnf #VersionSpecifiers } ``` -
VERSION_PRAGMA_VALUE = (("0""9") | "x" | "X" | "*")+;
+
VersionSpecifiers = VERSION_SPECIFIER (PERIOD VERSION_SPECIFIER)*;
+ +```{ .ebnf #VersionSpecifier } + +``` + +
VERSION_SPECIFIER = «VERSION_SPECIFIER_FRAGMENT»;
+ +```{ .ebnf #SingleQuotedVersionLiteral } + +``` + +
SINGLE_QUOTED_VERSION_LITERAL = "'" «VERSION_SPECIFIER_FRAGMENT» ("." «VERSION_SPECIFIER_FRAGMENT»)* "'";
+ +```{ .ebnf #DoubleQuotedVersionLiteral } + +``` + +
DOUBLE_QUOTED_VERSION_LITERAL = '"' «VERSION_SPECIFIER_FRAGMENT» ("." «VERSION_SPECIFIER_FRAGMENT»)* '"';
+ +```{ .ebnf #VersionSpecifierFragment } + +``` + +
«VERSION_SPECIFIER_FRAGMENT» = (("0""9") | "x" | "X" | "*")+;
```{ .ebnf #AbicoderKeyword } diff --git a/crates/solidity/testing/snapshots/cst_output/PragmaDirective/version/generated/0.4.11-success.yml b/crates/solidity/testing/snapshots/cst_output/PragmaDirective/version/generated/0.4.11-success.yml index d9b7520ae0..5e73915f8a 100644 --- a/crates/solidity/testing/snapshots/cst_output/PragmaDirective/version/generated/0.4.11-success.yml +++ b/crates/solidity/testing/snapshots/cst_output/PragmaDirective/version/generated/0.4.11-success.yml @@ -11,12 +11,13 @@ Tree: - (pragma꞉ Pragma) ► (variant꞉ VersionPragma): # " solidity 1.0.0" (6..21) - (leading_trivia꞉ Whitespace): " " # (6..7) - (solidity_keyword꞉ SolidityKeyword): "solidity" # (7..15) - - (expressions꞉ VersionPragmaExpressions): # " 1.0.0" (15..21) - - (item꞉ VersionPragmaExpression) ► (variant꞉ VersionPragmaSpecifier): # " 1.0.0" (15..21) - - (leading_trivia꞉ Whitespace): " " # (15..16) - - (item꞉ VersionPragmaValue): "1" # (16..17) - - (separator꞉ Period): "." # (17..18) - - (item꞉ VersionPragmaValue): "0" # (18..19) - - (separator꞉ Period): "." # (19..20) - - (item꞉ VersionPragmaValue): "0" # (20..21) + - (sets꞉ VersionExpressionSets): # " 1.0.0" (15..21) + - (item꞉ VersionExpressionSet): # " 1.0.0" (15..21) + - (item꞉ VersionExpression) ► (variant꞉ VersionSpecifiers): # " 1.0.0" (15..21) + - (leading_trivia꞉ Whitespace): " " # (15..16) + - (item꞉ VersionSpecifier): "1" # (16..17) + - (separator꞉ Period): "." # (17..18) + - (item꞉ VersionSpecifier): "0" # (18..19) + - (separator꞉ Period): "." # (19..20) + - (item꞉ VersionSpecifier): "0" # (20..21) - (semicolon꞉ Semicolon): ";" # (21..22) diff --git a/crates/solidity/testing/snapshots/cst_output/SourceUnit/everything/generated/0.4.11-failure.yml b/crates/solidity/testing/snapshots/cst_output/SourceUnit/everything/generated/0.4.11-failure.yml index f5c4988e85..cd1903e2b2 100644 --- a/crates/solidity/testing/snapshots/cst_output/SourceUnit/everything/generated/0.4.11-failure.yml +++ b/crates/solidity/testing/snapshots/cst_output/SourceUnit/everything/generated/0.4.11-failure.yml @@ -47,14 +47,15 @@ Tree: - (pragma꞉ Pragma) ► (variant꞉ VersionPragma): # " solidity 0.0.0" (6..21) - (leading_trivia꞉ Whitespace): " " # (6..7) - (solidity_keyword꞉ SolidityKeyword): "solidity" # (7..15) - - (expressions꞉ VersionPragmaExpressions): # " 0.0.0" (15..21) - - (item꞉ VersionPragmaExpression) ► (variant꞉ VersionPragmaSpecifier): # " 0.0.0" (15..21) - - (leading_trivia꞉ Whitespace): " " # (15..16) - - (item꞉ VersionPragmaValue): "0" # (16..17) - - (separator꞉ Period): "." # (17..18) - - (item꞉ VersionPragmaValue): "0" # (18..19) - - (separator꞉ Period): "." # (19..20) - - (item꞉ VersionPragmaValue): "0" # (20..21) + - (sets꞉ VersionExpressionSets): # " 0.0.0" (15..21) + - (item꞉ VersionExpressionSet): # " 0.0.0" (15..21) + - (item꞉ VersionExpression) ► (variant꞉ VersionSpecifiers): # " 0.0.0" (15..21) + - (leading_trivia꞉ Whitespace): " " # (15..16) + - (item꞉ VersionSpecifier): "0" # (16..17) + - (separator꞉ Period): "." # (17..18) + - (item꞉ VersionSpecifier): "0" # (18..19) + - (separator꞉ Period): "." # (19..20) + - (item꞉ VersionSpecifier): "0" # (20..21) - (semicolon꞉ Semicolon): ";" # (21..22) - (trailing_trivia꞉ EndOfLine): "\n" # (22..23) - (item꞉ SourceUnitMember) ► (variant꞉ ImportDirective): # '\nimport "foo.sol";\n' (23..42) diff --git a/crates/solidity/testing/snapshots/cst_output/SourceUnit/everything/generated/0.6.0-failure.yml b/crates/solidity/testing/snapshots/cst_output/SourceUnit/everything/generated/0.6.0-failure.yml index 968c4b6538..9cd961ec98 100644 --- a/crates/solidity/testing/snapshots/cst_output/SourceUnit/everything/generated/0.6.0-failure.yml +++ b/crates/solidity/testing/snapshots/cst_output/SourceUnit/everything/generated/0.6.0-failure.yml @@ -47,14 +47,15 @@ Tree: - (pragma꞉ Pragma) ► (variant꞉ VersionPragma): # " solidity 0.0.0" (6..21) - (leading_trivia꞉ Whitespace): " " # (6..7) - (solidity_keyword꞉ SolidityKeyword): "solidity" # (7..15) - - (expressions꞉ VersionPragmaExpressions): # " 0.0.0" (15..21) - - (item꞉ VersionPragmaExpression) ► (variant꞉ VersionPragmaSpecifier): # " 0.0.0" (15..21) - - (leading_trivia꞉ Whitespace): " " # (15..16) - - (item꞉ VersionPragmaValue): "0" # (16..17) - - (separator꞉ Period): "." # (17..18) - - (item꞉ VersionPragmaValue): "0" # (18..19) - - (separator꞉ Period): "." # (19..20) - - (item꞉ VersionPragmaValue): "0" # (20..21) + - (sets꞉ VersionExpressionSets): # " 0.0.0" (15..21) + - (item꞉ VersionExpressionSet): # " 0.0.0" (15..21) + - (item꞉ VersionExpression) ► (variant꞉ VersionSpecifiers): # " 0.0.0" (15..21) + - (leading_trivia꞉ Whitespace): " " # (15..16) + - (item꞉ VersionSpecifier): "0" # (16..17) + - (separator꞉ Period): "." # (17..18) + - (item꞉ VersionSpecifier): "0" # (18..19) + - (separator꞉ Period): "." # (19..20) + - (item꞉ VersionSpecifier): "0" # (20..21) - (semicolon꞉ Semicolon): ";" # (21..22) - (trailing_trivia꞉ EndOfLine): "\n" # (22..23) - (item꞉ SourceUnitMember) ► (variant꞉ ImportDirective): # '\nimport "foo.sol";\n' (23..42) diff --git a/crates/solidity/testing/snapshots/cst_output/SourceUnit/everything/generated/0.7.1-failure.yml b/crates/solidity/testing/snapshots/cst_output/SourceUnit/everything/generated/0.7.1-failure.yml index 4b6523041a..eca8821abe 100644 --- a/crates/solidity/testing/snapshots/cst_output/SourceUnit/everything/generated/0.7.1-failure.yml +++ b/crates/solidity/testing/snapshots/cst_output/SourceUnit/everything/generated/0.7.1-failure.yml @@ -47,14 +47,15 @@ Tree: - (pragma꞉ Pragma) ► (variant꞉ VersionPragma): # " solidity 0.0.0" (6..21) - (leading_trivia꞉ Whitespace): " " # (6..7) - (solidity_keyword꞉ SolidityKeyword): "solidity" # (7..15) - - (expressions꞉ VersionPragmaExpressions): # " 0.0.0" (15..21) - - (item꞉ VersionPragmaExpression) ► (variant꞉ VersionPragmaSpecifier): # " 0.0.0" (15..21) - - (leading_trivia꞉ Whitespace): " " # (15..16) - - (item꞉ VersionPragmaValue): "0" # (16..17) - - (separator꞉ Period): "." # (17..18) - - (item꞉ VersionPragmaValue): "0" # (18..19) - - (separator꞉ Period): "." # (19..20) - - (item꞉ VersionPragmaValue): "0" # (20..21) + - (sets꞉ VersionExpressionSets): # " 0.0.0" (15..21) + - (item꞉ VersionExpressionSet): # " 0.0.0" (15..21) + - (item꞉ VersionExpression) ► (variant꞉ VersionSpecifiers): # " 0.0.0" (15..21) + - (leading_trivia꞉ Whitespace): " " # (15..16) + - (item꞉ VersionSpecifier): "0" # (16..17) + - (separator꞉ Period): "." # (17..18) + - (item꞉ VersionSpecifier): "0" # (18..19) + - (separator꞉ Period): "." # (19..20) + - (item꞉ VersionSpecifier): "0" # (20..21) - (semicolon꞉ Semicolon): ";" # (21..22) - (trailing_trivia꞉ EndOfLine): "\n" # (22..23) - (item꞉ SourceUnitMember) ► (variant꞉ ImportDirective): # '\nimport "foo.sol";\n' (23..42) diff --git a/crates/solidity/testing/snapshots/cst_output/SourceUnit/everything/generated/0.7.4-failure.yml b/crates/solidity/testing/snapshots/cst_output/SourceUnit/everything/generated/0.7.4-failure.yml index dc95563b2d..79c6680041 100644 --- a/crates/solidity/testing/snapshots/cst_output/SourceUnit/everything/generated/0.7.4-failure.yml +++ b/crates/solidity/testing/snapshots/cst_output/SourceUnit/everything/generated/0.7.4-failure.yml @@ -47,14 +47,15 @@ Tree: - (pragma꞉ Pragma) ► (variant꞉ VersionPragma): # " solidity 0.0.0" (6..21) - (leading_trivia꞉ Whitespace): " " # (6..7) - (solidity_keyword꞉ SolidityKeyword): "solidity" # (7..15) - - (expressions꞉ VersionPragmaExpressions): # " 0.0.0" (15..21) - - (item꞉ VersionPragmaExpression) ► (variant꞉ VersionPragmaSpecifier): # " 0.0.0" (15..21) - - (leading_trivia꞉ Whitespace): " " # (15..16) - - (item꞉ VersionPragmaValue): "0" # (16..17) - - (separator꞉ Period): "." # (17..18) - - (item꞉ VersionPragmaValue): "0" # (18..19) - - (separator꞉ Period): "." # (19..20) - - (item꞉ VersionPragmaValue): "0" # (20..21) + - (sets꞉ VersionExpressionSets): # " 0.0.0" (15..21) + - (item꞉ VersionExpressionSet): # " 0.0.0" (15..21) + - (item꞉ VersionExpression) ► (variant꞉ VersionSpecifiers): # " 0.0.0" (15..21) + - (leading_trivia꞉ Whitespace): " " # (15..16) + - (item꞉ VersionSpecifier): "0" # (16..17) + - (separator꞉ Period): "." # (17..18) + - (item꞉ VersionSpecifier): "0" # (18..19) + - (separator꞉ Period): "." # (19..20) + - (item꞉ VersionSpecifier): "0" # (20..21) - (semicolon꞉ Semicolon): ";" # (21..22) - (trailing_trivia꞉ EndOfLine): "\n" # (22..23) - (item꞉ SourceUnitMember) ► (variant꞉ ImportDirective): # '\nimport "foo.sol";\n' (23..42) diff --git a/crates/solidity/testing/snapshots/cst_output/SourceUnit/everything/generated/0.8.0-failure.yml b/crates/solidity/testing/snapshots/cst_output/SourceUnit/everything/generated/0.8.0-failure.yml index 96a7dab5a7..8c852828c1 100644 --- a/crates/solidity/testing/snapshots/cst_output/SourceUnit/everything/generated/0.8.0-failure.yml +++ b/crates/solidity/testing/snapshots/cst_output/SourceUnit/everything/generated/0.8.0-failure.yml @@ -47,14 +47,15 @@ Tree: - (pragma꞉ Pragma) ► (variant꞉ VersionPragma): # " solidity 0.0.0" (6..21) - (leading_trivia꞉ Whitespace): " " # (6..7) - (solidity_keyword꞉ SolidityKeyword): "solidity" # (7..15) - - (expressions꞉ VersionPragmaExpressions): # " 0.0.0" (15..21) - - (item꞉ VersionPragmaExpression) ► (variant꞉ VersionPragmaSpecifier): # " 0.0.0" (15..21) - - (leading_trivia꞉ Whitespace): " " # (15..16) - - (item꞉ VersionPragmaValue): "0" # (16..17) - - (separator꞉ Period): "." # (17..18) - - (item꞉ VersionPragmaValue): "0" # (18..19) - - (separator꞉ Period): "." # (19..20) - - (item꞉ VersionPragmaValue): "0" # (20..21) + - (sets꞉ VersionExpressionSets): # " 0.0.0" (15..21) + - (item꞉ VersionExpressionSet): # " 0.0.0" (15..21) + - (item꞉ VersionExpression) ► (variant꞉ VersionSpecifiers): # " 0.0.0" (15..21) + - (leading_trivia꞉ Whitespace): " " # (15..16) + - (item꞉ VersionSpecifier): "0" # (16..17) + - (separator꞉ Period): "." # (17..18) + - (item꞉ VersionSpecifier): "0" # (18..19) + - (separator꞉ Period): "." # (19..20) + - (item꞉ VersionSpecifier): "0" # (20..21) - (semicolon꞉ Semicolon): ";" # (21..22) - (trailing_trivia꞉ EndOfLine): "\n" # (22..23) - (item꞉ SourceUnitMember) ► (variant꞉ ImportDirective): # '\nimport "foo.sol";\n' (23..42) diff --git a/crates/solidity/testing/snapshots/cst_output/SourceUnit/everything/generated/0.8.13-failure.yml b/crates/solidity/testing/snapshots/cst_output/SourceUnit/everything/generated/0.8.13-failure.yml index 52a607be44..684f085ae7 100644 --- a/crates/solidity/testing/snapshots/cst_output/SourceUnit/everything/generated/0.8.13-failure.yml +++ b/crates/solidity/testing/snapshots/cst_output/SourceUnit/everything/generated/0.8.13-failure.yml @@ -45,14 +45,15 @@ Tree: - (pragma꞉ Pragma) ► (variant꞉ VersionPragma): # " solidity 0.0.0" (6..21) - (leading_trivia꞉ Whitespace): " " # (6..7) - (solidity_keyword꞉ SolidityKeyword): "solidity" # (7..15) - - (expressions꞉ VersionPragmaExpressions): # " 0.0.0" (15..21) - - (item꞉ VersionPragmaExpression) ► (variant꞉ VersionPragmaSpecifier): # " 0.0.0" (15..21) - - (leading_trivia꞉ Whitespace): " " # (15..16) - - (item꞉ VersionPragmaValue): "0" # (16..17) - - (separator꞉ Period): "." # (17..18) - - (item꞉ VersionPragmaValue): "0" # (18..19) - - (separator꞉ Period): "." # (19..20) - - (item꞉ VersionPragmaValue): "0" # (20..21) + - (sets꞉ VersionExpressionSets): # " 0.0.0" (15..21) + - (item꞉ VersionExpressionSet): # " 0.0.0" (15..21) + - (item꞉ VersionExpression) ► (variant꞉ VersionSpecifiers): # " 0.0.0" (15..21) + - (leading_trivia꞉ Whitespace): " " # (15..16) + - (item꞉ VersionSpecifier): "0" # (16..17) + - (separator꞉ Period): "." # (17..18) + - (item꞉ VersionSpecifier): "0" # (18..19) + - (separator꞉ Period): "." # (19..20) + - (item꞉ VersionSpecifier): "0" # (20..21) - (semicolon꞉ Semicolon): ";" # (21..22) - (trailing_trivia꞉ EndOfLine): "\n" # (22..23) - (item꞉ SourceUnitMember) ► (variant꞉ ImportDirective): # '\nimport "foo.sol";\n' (23..42) diff --git a/crates/solidity/testing/snapshots/cst_output/SourceUnit/everything/generated/0.8.22-success.yml b/crates/solidity/testing/snapshots/cst_output/SourceUnit/everything/generated/0.8.22-success.yml index 04f5200116..ac0c334c66 100644 --- a/crates/solidity/testing/snapshots/cst_output/SourceUnit/everything/generated/0.8.22-success.yml +++ b/crates/solidity/testing/snapshots/cst_output/SourceUnit/everything/generated/0.8.22-success.yml @@ -36,14 +36,15 @@ Tree: - (pragma꞉ Pragma) ► (variant꞉ VersionPragma): # " solidity 0.0.0" (6..21) - (leading_trivia꞉ Whitespace): " " # (6..7) - (solidity_keyword꞉ SolidityKeyword): "solidity" # (7..15) - - (expressions꞉ VersionPragmaExpressions): # " 0.0.0" (15..21) - - (item꞉ VersionPragmaExpression) ► (variant꞉ VersionPragmaSpecifier): # " 0.0.0" (15..21) - - (leading_trivia꞉ Whitespace): " " # (15..16) - - (item꞉ VersionPragmaValue): "0" # (16..17) - - (separator꞉ Period): "." # (17..18) - - (item꞉ VersionPragmaValue): "0" # (18..19) - - (separator꞉ Period): "." # (19..20) - - (item꞉ VersionPragmaValue): "0" # (20..21) + - (sets꞉ VersionExpressionSets): # " 0.0.0" (15..21) + - (item꞉ VersionExpressionSet): # " 0.0.0" (15..21) + - (item꞉ VersionExpression) ► (variant꞉ VersionSpecifiers): # " 0.0.0" (15..21) + - (leading_trivia꞉ Whitespace): " " # (15..16) + - (item꞉ VersionSpecifier): "0" # (16..17) + - (separator꞉ Period): "." # (17..18) + - (item꞉ VersionSpecifier): "0" # (18..19) + - (separator꞉ Period): "." # (19..20) + - (item꞉ VersionSpecifier): "0" # (20..21) - (semicolon꞉ Semicolon): ";" # (21..22) - (trailing_trivia꞉ EndOfLine): "\n" # (22..23) - (item꞉ SourceUnitMember) ► (variant꞉ ImportDirective): # '\nimport "foo.sol";\n' (23..42) diff --git a/crates/solidity/testing/snapshots/cst_output/SourceUnit/everything/generated/0.8.4-failure.yml b/crates/solidity/testing/snapshots/cst_output/SourceUnit/everything/generated/0.8.4-failure.yml index 591df0284e..df687ea088 100644 --- a/crates/solidity/testing/snapshots/cst_output/SourceUnit/everything/generated/0.8.4-failure.yml +++ b/crates/solidity/testing/snapshots/cst_output/SourceUnit/everything/generated/0.8.4-failure.yml @@ -47,14 +47,15 @@ Tree: - (pragma꞉ Pragma) ► (variant꞉ VersionPragma): # " solidity 0.0.0" (6..21) - (leading_trivia꞉ Whitespace): " " # (6..7) - (solidity_keyword꞉ SolidityKeyword): "solidity" # (7..15) - - (expressions꞉ VersionPragmaExpressions): # " 0.0.0" (15..21) - - (item꞉ VersionPragmaExpression) ► (variant꞉ VersionPragmaSpecifier): # " 0.0.0" (15..21) - - (leading_trivia꞉ Whitespace): " " # (15..16) - - (item꞉ VersionPragmaValue): "0" # (16..17) - - (separator꞉ Period): "." # (17..18) - - (item꞉ VersionPragmaValue): "0" # (18..19) - - (separator꞉ Period): "." # (19..20) - - (item꞉ VersionPragmaValue): "0" # (20..21) + - (sets꞉ VersionExpressionSets): # " 0.0.0" (15..21) + - (item꞉ VersionExpressionSet): # " 0.0.0" (15..21) + - (item꞉ VersionExpression) ► (variant꞉ VersionSpecifiers): # " 0.0.0" (15..21) + - (leading_trivia꞉ Whitespace): " " # (15..16) + - (item꞉ VersionSpecifier): "0" # (16..17) + - (separator꞉ Period): "." # (17..18) + - (item꞉ VersionSpecifier): "0" # (18..19) + - (separator꞉ Period): "." # (19..20) + - (item꞉ VersionSpecifier): "0" # (20..21) - (semicolon꞉ Semicolon): ";" # (21..22) - (trailing_trivia꞉ EndOfLine): "\n" # (22..23) - (item꞉ SourceUnitMember) ► (variant꞉ ImportDirective): # '\nimport "foo.sol";\n' (23..42) diff --git a/crates/solidity/testing/snapshots/cst_output/SourceUnit/everything/generated/0.8.8-failure.yml b/crates/solidity/testing/snapshots/cst_output/SourceUnit/everything/generated/0.8.8-failure.yml index ab90aa1113..ee7a888c08 100644 --- a/crates/solidity/testing/snapshots/cst_output/SourceUnit/everything/generated/0.8.8-failure.yml +++ b/crates/solidity/testing/snapshots/cst_output/SourceUnit/everything/generated/0.8.8-failure.yml @@ -47,14 +47,15 @@ Tree: - (pragma꞉ Pragma) ► (variant꞉ VersionPragma): # " solidity 0.0.0" (6..21) - (leading_trivia꞉ Whitespace): " " # (6..7) - (solidity_keyword꞉ SolidityKeyword): "solidity" # (7..15) - - (expressions꞉ VersionPragmaExpressions): # " 0.0.0" (15..21) - - (item꞉ VersionPragmaExpression) ► (variant꞉ VersionPragmaSpecifier): # " 0.0.0" (15..21) - - (leading_trivia꞉ Whitespace): " " # (15..16) - - (item꞉ VersionPragmaValue): "0" # (16..17) - - (separator꞉ Period): "." # (17..18) - - (item꞉ VersionPragmaValue): "0" # (18..19) - - (separator꞉ Period): "." # (19..20) - - (item꞉ VersionPragmaValue): "0" # (20..21) + - (sets꞉ VersionExpressionSets): # " 0.0.0" (15..21) + - (item꞉ VersionExpressionSet): # " 0.0.0" (15..21) + - (item꞉ VersionExpression) ► (variant꞉ VersionSpecifiers): # " 0.0.0" (15..21) + - (leading_trivia꞉ Whitespace): " " # (15..16) + - (item꞉ VersionSpecifier): "0" # (16..17) + - (separator꞉ Period): "." # (17..18) + - (item꞉ VersionSpecifier): "0" # (18..19) + - (separator꞉ Period): "." # (19..20) + - (item꞉ VersionSpecifier): "0" # (20..21) - (semicolon꞉ Semicolon): ";" # (21..22) - (trailing_trivia꞉ EndOfLine): "\n" # (22..23) - (item꞉ SourceUnitMember) ► (variant꞉ ImportDirective): # '\nimport "foo.sol";\n' (23..42) diff --git a/crates/solidity/testing/snapshots/cst_output/SourceUnit/using_directive/generated/0.4.11-failure.yml b/crates/solidity/testing/snapshots/cst_output/SourceUnit/using_directive/generated/0.4.11-failure.yml index 9527a7e2b3..fab722c59d 100644 --- a/crates/solidity/testing/snapshots/cst_output/SourceUnit/using_directive/generated/0.4.11-failure.yml +++ b/crates/solidity/testing/snapshots/cst_output/SourceUnit/using_directive/generated/0.4.11-failure.yml @@ -47,16 +47,17 @@ Tree: - (pragma꞉ Pragma) ► (variant꞉ VersionPragma): # " solidity ^0.8.0" (38..54) - (leading_trivia꞉ Whitespace): " " # (38..39) - (solidity_keyword꞉ SolidityKeyword): "solidity" # (39..47) - - (expressions꞉ VersionPragmaExpressions): # " ^0.8.0" (47..54) - - (item꞉ VersionPragmaExpression) ► (variant꞉ VersionPragmaPrefixExpression): # " ^0.8.0" (47..54) - - (leading_trivia꞉ Whitespace): " " # (47..48) - - (operator꞉ Caret): "^" # (48..49) - - (operand꞉ VersionPragmaExpression) ► (variant꞉ VersionPragmaSpecifier): # "0.8.0" (49..54) - - (item꞉ VersionPragmaValue): "0" # (49..50) - - (separator꞉ Period): "." # (50..51) - - (item꞉ VersionPragmaValue): "8" # (51..52) - - (separator꞉ Period): "." # (52..53) - - (item꞉ VersionPragmaValue): "0" # (53..54) + - (sets꞉ VersionExpressionSets): # " ^0.8.0" (47..54) + - (item꞉ VersionExpressionSet): # " ^0.8.0" (47..54) + - (item꞉ VersionExpression) ► (variant꞉ VersionComparator): # " ^0.8.0" (47..54) + - (leading_trivia꞉ Whitespace): " " # (47..48) + - (operator꞉ Caret): "^" # (48..49) + - (operand꞉ VersionExpression) ► (variant꞉ VersionSpecifiers): # "0.8.0" (49..54) + - (item꞉ VersionSpecifier): "0" # (49..50) + - (separator꞉ Period): "." # (50..51) + - (item꞉ VersionSpecifier): "8" # (51..52) + - (separator꞉ Period): "." # (52..53) + - (item꞉ VersionSpecifier): "0" # (53..54) - (semicolon꞉ Semicolon): ";" # (54..55) - (trailing_trivia꞉ EndOfLine): "\n" # (55..56) - (leading_trivia꞉ EndOfLine): "\n" # (56..57) diff --git a/crates/solidity/testing/snapshots/cst_output/SourceUnit/using_directive/generated/0.6.0-failure.yml b/crates/solidity/testing/snapshots/cst_output/SourceUnit/using_directive/generated/0.6.0-failure.yml index dacd3ea6b5..95a87335ec 100644 --- a/crates/solidity/testing/snapshots/cst_output/SourceUnit/using_directive/generated/0.6.0-failure.yml +++ b/crates/solidity/testing/snapshots/cst_output/SourceUnit/using_directive/generated/0.6.0-failure.yml @@ -47,16 +47,17 @@ Tree: - (pragma꞉ Pragma) ► (variant꞉ VersionPragma): # " solidity ^0.8.0" (38..54) - (leading_trivia꞉ Whitespace): " " # (38..39) - (solidity_keyword꞉ SolidityKeyword): "solidity" # (39..47) - - (expressions꞉ VersionPragmaExpressions): # " ^0.8.0" (47..54) - - (item꞉ VersionPragmaExpression) ► (variant꞉ VersionPragmaPrefixExpression): # " ^0.8.0" (47..54) - - (leading_trivia꞉ Whitespace): " " # (47..48) - - (operator꞉ Caret): "^" # (48..49) - - (operand꞉ VersionPragmaExpression) ► (variant꞉ VersionPragmaSpecifier): # "0.8.0" (49..54) - - (item꞉ VersionPragmaValue): "0" # (49..50) - - (separator꞉ Period): "." # (50..51) - - (item꞉ VersionPragmaValue): "8" # (51..52) - - (separator꞉ Period): "." # (52..53) - - (item꞉ VersionPragmaValue): "0" # (53..54) + - (sets꞉ VersionExpressionSets): # " ^0.8.0" (47..54) + - (item꞉ VersionExpressionSet): # " ^0.8.0" (47..54) + - (item꞉ VersionExpression) ► (variant꞉ VersionComparator): # " ^0.8.0" (47..54) + - (leading_trivia꞉ Whitespace): " " # (47..48) + - (operator꞉ Caret): "^" # (48..49) + - (operand꞉ VersionExpression) ► (variant꞉ VersionSpecifiers): # "0.8.0" (49..54) + - (item꞉ VersionSpecifier): "0" # (49..50) + - (separator꞉ Period): "." # (50..51) + - (item꞉ VersionSpecifier): "8" # (51..52) + - (separator꞉ Period): "." # (52..53) + - (item꞉ VersionSpecifier): "0" # (53..54) - (semicolon꞉ Semicolon): ";" # (54..55) - (trailing_trivia꞉ EndOfLine): "\n" # (55..56) - (leading_trivia꞉ EndOfLine): "\n" # (56..57) diff --git a/crates/solidity/testing/snapshots/cst_output/SourceUnit/using_directive/generated/0.7.1-failure.yml b/crates/solidity/testing/snapshots/cst_output/SourceUnit/using_directive/generated/0.7.1-failure.yml index c613c6bd8e..55abd9cb8b 100644 --- a/crates/solidity/testing/snapshots/cst_output/SourceUnit/using_directive/generated/0.7.1-failure.yml +++ b/crates/solidity/testing/snapshots/cst_output/SourceUnit/using_directive/generated/0.7.1-failure.yml @@ -47,16 +47,17 @@ Tree: - (pragma꞉ Pragma) ► (variant꞉ VersionPragma): # " solidity ^0.8.0" (38..54) - (leading_trivia꞉ Whitespace): " " # (38..39) - (solidity_keyword꞉ SolidityKeyword): "solidity" # (39..47) - - (expressions꞉ VersionPragmaExpressions): # " ^0.8.0" (47..54) - - (item꞉ VersionPragmaExpression) ► (variant꞉ VersionPragmaPrefixExpression): # " ^0.8.0" (47..54) - - (leading_trivia꞉ Whitespace): " " # (47..48) - - (operator꞉ Caret): "^" # (48..49) - - (operand꞉ VersionPragmaExpression) ► (variant꞉ VersionPragmaSpecifier): # "0.8.0" (49..54) - - (item꞉ VersionPragmaValue): "0" # (49..50) - - (separator꞉ Period): "." # (50..51) - - (item꞉ VersionPragmaValue): "8" # (51..52) - - (separator꞉ Period): "." # (52..53) - - (item꞉ VersionPragmaValue): "0" # (53..54) + - (sets꞉ VersionExpressionSets): # " ^0.8.0" (47..54) + - (item꞉ VersionExpressionSet): # " ^0.8.0" (47..54) + - (item꞉ VersionExpression) ► (variant꞉ VersionComparator): # " ^0.8.0" (47..54) + - (leading_trivia꞉ Whitespace): " " # (47..48) + - (operator꞉ Caret): "^" # (48..49) + - (operand꞉ VersionExpression) ► (variant꞉ VersionSpecifiers): # "0.8.0" (49..54) + - (item꞉ VersionSpecifier): "0" # (49..50) + - (separator꞉ Period): "." # (50..51) + - (item꞉ VersionSpecifier): "8" # (51..52) + - (separator꞉ Period): "." # (52..53) + - (item꞉ VersionSpecifier): "0" # (53..54) - (semicolon꞉ Semicolon): ";" # (54..55) - (trailing_trivia꞉ EndOfLine): "\n" # (55..56) - (leading_trivia꞉ EndOfLine): "\n" # (56..57) diff --git a/crates/solidity/testing/snapshots/cst_output/SourceUnit/using_directive/generated/0.7.4-failure.yml b/crates/solidity/testing/snapshots/cst_output/SourceUnit/using_directive/generated/0.7.4-failure.yml index 99c1bb2532..5c9f4aad2e 100644 --- a/crates/solidity/testing/snapshots/cst_output/SourceUnit/using_directive/generated/0.7.4-failure.yml +++ b/crates/solidity/testing/snapshots/cst_output/SourceUnit/using_directive/generated/0.7.4-failure.yml @@ -47,16 +47,17 @@ Tree: - (pragma꞉ Pragma) ► (variant꞉ VersionPragma): # " solidity ^0.8.0" (38..54) - (leading_trivia꞉ Whitespace): " " # (38..39) - (solidity_keyword꞉ SolidityKeyword): "solidity" # (39..47) - - (expressions꞉ VersionPragmaExpressions): # " ^0.8.0" (47..54) - - (item꞉ VersionPragmaExpression) ► (variant꞉ VersionPragmaPrefixExpression): # " ^0.8.0" (47..54) - - (leading_trivia꞉ Whitespace): " " # (47..48) - - (operator꞉ Caret): "^" # (48..49) - - (operand꞉ VersionPragmaExpression) ► (variant꞉ VersionPragmaSpecifier): # "0.8.0" (49..54) - - (item꞉ VersionPragmaValue): "0" # (49..50) - - (separator꞉ Period): "." # (50..51) - - (item꞉ VersionPragmaValue): "8" # (51..52) - - (separator꞉ Period): "." # (52..53) - - (item꞉ VersionPragmaValue): "0" # (53..54) + - (sets꞉ VersionExpressionSets): # " ^0.8.0" (47..54) + - (item꞉ VersionExpressionSet): # " ^0.8.0" (47..54) + - (item꞉ VersionExpression) ► (variant꞉ VersionComparator): # " ^0.8.0" (47..54) + - (leading_trivia꞉ Whitespace): " " # (47..48) + - (operator꞉ Caret): "^" # (48..49) + - (operand꞉ VersionExpression) ► (variant꞉ VersionSpecifiers): # "0.8.0" (49..54) + - (item꞉ VersionSpecifier): "0" # (49..50) + - (separator꞉ Period): "." # (50..51) + - (item꞉ VersionSpecifier): "8" # (51..52) + - (separator꞉ Period): "." # (52..53) + - (item꞉ VersionSpecifier): "0" # (53..54) - (semicolon꞉ Semicolon): ";" # (54..55) - (trailing_trivia꞉ EndOfLine): "\n" # (55..56) - (leading_trivia꞉ EndOfLine): "\n" # (56..57) diff --git a/crates/solidity/testing/snapshots/cst_output/SourceUnit/using_directive/generated/0.8.0-failure.yml b/crates/solidity/testing/snapshots/cst_output/SourceUnit/using_directive/generated/0.8.0-failure.yml index 41b0dde086..ab446c9ab6 100644 --- a/crates/solidity/testing/snapshots/cst_output/SourceUnit/using_directive/generated/0.8.0-failure.yml +++ b/crates/solidity/testing/snapshots/cst_output/SourceUnit/using_directive/generated/0.8.0-failure.yml @@ -47,16 +47,17 @@ Tree: - (pragma꞉ Pragma) ► (variant꞉ VersionPragma): # " solidity ^0.8.0" (38..54) - (leading_trivia꞉ Whitespace): " " # (38..39) - (solidity_keyword꞉ SolidityKeyword): "solidity" # (39..47) - - (expressions꞉ VersionPragmaExpressions): # " ^0.8.0" (47..54) - - (item꞉ VersionPragmaExpression) ► (variant꞉ VersionPragmaPrefixExpression): # " ^0.8.0" (47..54) - - (leading_trivia꞉ Whitespace): " " # (47..48) - - (operator꞉ Caret): "^" # (48..49) - - (operand꞉ VersionPragmaExpression) ► (variant꞉ VersionPragmaSpecifier): # "0.8.0" (49..54) - - (item꞉ VersionPragmaValue): "0" # (49..50) - - (separator꞉ Period): "." # (50..51) - - (item꞉ VersionPragmaValue): "8" # (51..52) - - (separator꞉ Period): "." # (52..53) - - (item꞉ VersionPragmaValue): "0" # (53..54) + - (sets꞉ VersionExpressionSets): # " ^0.8.0" (47..54) + - (item꞉ VersionExpressionSet): # " ^0.8.0" (47..54) + - (item꞉ VersionExpression) ► (variant꞉ VersionComparator): # " ^0.8.0" (47..54) + - (leading_trivia꞉ Whitespace): " " # (47..48) + - (operator꞉ Caret): "^" # (48..49) + - (operand꞉ VersionExpression) ► (variant꞉ VersionSpecifiers): # "0.8.0" (49..54) + - (item꞉ VersionSpecifier): "0" # (49..50) + - (separator꞉ Period): "." # (50..51) + - (item꞉ VersionSpecifier): "8" # (51..52) + - (separator꞉ Period): "." # (52..53) + - (item꞉ VersionSpecifier): "0" # (53..54) - (semicolon꞉ Semicolon): ";" # (54..55) - (trailing_trivia꞉ EndOfLine): "\n" # (55..56) - (leading_trivia꞉ EndOfLine): "\n" # (56..57) diff --git a/crates/solidity/testing/snapshots/cst_output/SourceUnit/using_directive/generated/0.8.13-success.yml b/crates/solidity/testing/snapshots/cst_output/SourceUnit/using_directive/generated/0.8.13-success.yml index 85dcf2674f..9b1fd2f929 100644 --- a/crates/solidity/testing/snapshots/cst_output/SourceUnit/using_directive/generated/0.8.13-success.yml +++ b/crates/solidity/testing/snapshots/cst_output/SourceUnit/using_directive/generated/0.8.13-success.yml @@ -36,16 +36,17 @@ Tree: - (pragma꞉ Pragma) ► (variant꞉ VersionPragma): # " solidity ^0.8.0" (38..54) - (leading_trivia꞉ Whitespace): " " # (38..39) - (solidity_keyword꞉ SolidityKeyword): "solidity" # (39..47) - - (expressions꞉ VersionPragmaExpressions): # " ^0.8.0" (47..54) - - (item꞉ VersionPragmaExpression) ► (variant꞉ VersionPragmaPrefixExpression): # " ^0.8.0" (47..54) - - (leading_trivia꞉ Whitespace): " " # (47..48) - - (operator꞉ Caret): "^" # (48..49) - - (operand꞉ VersionPragmaExpression) ► (variant꞉ VersionPragmaSpecifier): # "0.8.0" (49..54) - - (item꞉ VersionPragmaValue): "0" # (49..50) - - (separator꞉ Period): "." # (50..51) - - (item꞉ VersionPragmaValue): "8" # (51..52) - - (separator꞉ Period): "." # (52..53) - - (item꞉ VersionPragmaValue): "0" # (53..54) + - (sets꞉ VersionExpressionSets): # " ^0.8.0" (47..54) + - (item꞉ VersionExpressionSet): # " ^0.8.0" (47..54) + - (item꞉ VersionExpression) ► (variant꞉ VersionComparator): # " ^0.8.0" (47..54) + - (leading_trivia꞉ Whitespace): " " # (47..48) + - (operator꞉ Caret): "^" # (48..49) + - (operand꞉ VersionExpression) ► (variant꞉ VersionSpecifiers): # "0.8.0" (49..54) + - (item꞉ VersionSpecifier): "0" # (49..50) + - (separator꞉ Period): "." # (50..51) + - (item꞉ VersionSpecifier): "8" # (51..52) + - (separator꞉ Period): "." # (52..53) + - (item꞉ VersionSpecifier): "0" # (53..54) - (semicolon꞉ Semicolon): ";" # (54..55) - (trailing_trivia꞉ EndOfLine): "\n" # (55..56) - (item꞉ SourceUnitMember) ► (variant꞉ UsingDirective): # "\nusing EnvelopeUtils for Envelope global;\n" (56..98) diff --git a/crates/solidity/testing/snapshots/cst_output/SourceUnit/using_directive/generated/0.8.4-failure.yml b/crates/solidity/testing/snapshots/cst_output/SourceUnit/using_directive/generated/0.8.4-failure.yml index 69e8a7c2ab..912173442f 100644 --- a/crates/solidity/testing/snapshots/cst_output/SourceUnit/using_directive/generated/0.8.4-failure.yml +++ b/crates/solidity/testing/snapshots/cst_output/SourceUnit/using_directive/generated/0.8.4-failure.yml @@ -47,16 +47,17 @@ Tree: - (pragma꞉ Pragma) ► (variant꞉ VersionPragma): # " solidity ^0.8.0" (38..54) - (leading_trivia꞉ Whitespace): " " # (38..39) - (solidity_keyword꞉ SolidityKeyword): "solidity" # (39..47) - - (expressions꞉ VersionPragmaExpressions): # " ^0.8.0" (47..54) - - (item꞉ VersionPragmaExpression) ► (variant꞉ VersionPragmaPrefixExpression): # " ^0.8.0" (47..54) - - (leading_trivia꞉ Whitespace): " " # (47..48) - - (operator꞉ Caret): "^" # (48..49) - - (operand꞉ VersionPragmaExpression) ► (variant꞉ VersionPragmaSpecifier): # "0.8.0" (49..54) - - (item꞉ VersionPragmaValue): "0" # (49..50) - - (separator꞉ Period): "." # (50..51) - - (item꞉ VersionPragmaValue): "8" # (51..52) - - (separator꞉ Period): "." # (52..53) - - (item꞉ VersionPragmaValue): "0" # (53..54) + - (sets꞉ VersionExpressionSets): # " ^0.8.0" (47..54) + - (item꞉ VersionExpressionSet): # " ^0.8.0" (47..54) + - (item꞉ VersionExpression) ► (variant꞉ VersionComparator): # " ^0.8.0" (47..54) + - (leading_trivia꞉ Whitespace): " " # (47..48) + - (operator꞉ Caret): "^" # (48..49) + - (operand꞉ VersionExpression) ► (variant꞉ VersionSpecifiers): # "0.8.0" (49..54) + - (item꞉ VersionSpecifier): "0" # (49..50) + - (separator꞉ Period): "." # (50..51) + - (item꞉ VersionSpecifier): "8" # (51..52) + - (separator꞉ Period): "." # (52..53) + - (item꞉ VersionSpecifier): "0" # (53..54) - (semicolon꞉ Semicolon): ";" # (54..55) - (trailing_trivia꞉ EndOfLine): "\n" # (55..56) - (leading_trivia꞉ EndOfLine): "\n" # (56..57) diff --git a/crates/solidity/testing/snapshots/cst_output/SourceUnit/using_directive/generated/0.8.8-failure.yml b/crates/solidity/testing/snapshots/cst_output/SourceUnit/using_directive/generated/0.8.8-failure.yml index 782b597956..c0b61c24f4 100644 --- a/crates/solidity/testing/snapshots/cst_output/SourceUnit/using_directive/generated/0.8.8-failure.yml +++ b/crates/solidity/testing/snapshots/cst_output/SourceUnit/using_directive/generated/0.8.8-failure.yml @@ -47,16 +47,17 @@ Tree: - (pragma꞉ Pragma) ► (variant꞉ VersionPragma): # " solidity ^0.8.0" (38..54) - (leading_trivia꞉ Whitespace): " " # (38..39) - (solidity_keyword꞉ SolidityKeyword): "solidity" # (39..47) - - (expressions꞉ VersionPragmaExpressions): # " ^0.8.0" (47..54) - - (item꞉ VersionPragmaExpression) ► (variant꞉ VersionPragmaPrefixExpression): # " ^0.8.0" (47..54) - - (leading_trivia꞉ Whitespace): " " # (47..48) - - (operator꞉ Caret): "^" # (48..49) - - (operand꞉ VersionPragmaExpression) ► (variant꞉ VersionPragmaSpecifier): # "0.8.0" (49..54) - - (item꞉ VersionPragmaValue): "0" # (49..50) - - (separator꞉ Period): "." # (50..51) - - (item꞉ VersionPragmaValue): "8" # (51..52) - - (separator꞉ Period): "." # (52..53) - - (item꞉ VersionPragmaValue): "0" # (53..54) + - (sets꞉ VersionExpressionSets): # " ^0.8.0" (47..54) + - (item꞉ VersionExpressionSet): # " ^0.8.0" (47..54) + - (item꞉ VersionExpression) ► (variant꞉ VersionComparator): # " ^0.8.0" (47..54) + - (leading_trivia꞉ Whitespace): " " # (47..48) + - (operator꞉ Caret): "^" # (48..49) + - (operand꞉ VersionExpression) ► (variant꞉ VersionSpecifiers): # "0.8.0" (49..54) + - (item꞉ VersionSpecifier): "0" # (49..50) + - (separator꞉ Period): "." # (50..51) + - (item꞉ VersionSpecifier): "8" # (51..52) + - (separator꞉ Period): "." # (52..53) + - (item꞉ VersionSpecifier): "0" # (53..54) - (semicolon꞉ Semicolon): ";" # (54..55) - (trailing_trivia꞉ EndOfLine): "\n" # (55..56) - (leading_trivia꞉ EndOfLine): "\n" # (56..57) diff --git a/crates/solidity/testing/snapshots/cst_output/VersionPragma/alternatives/generated/0.4.11-success.yml b/crates/solidity/testing/snapshots/cst_output/VersionPragma/alternatives/generated/0.4.11-success.yml index ed5c09619c..eb0c21496d 100644 --- a/crates/solidity/testing/snapshots/cst_output/VersionPragma/alternatives/generated/0.4.11-success.yml +++ b/crates/solidity/testing/snapshots/cst_output/VersionPragma/alternatives/generated/0.4.11-success.yml @@ -8,33 +8,34 @@ Errors: [] Tree: - (VersionPragma): # "solidity 0.5.0 || 0.6.0 || ^0.7.0" (0..33) - (solidity_keyword꞉ SolidityKeyword): "solidity" # (0..8) - - (expressions꞉ VersionPragmaExpressions): # " 0.5.0 || 0.6.0 || ^0.7.0" (8..33) - - (item꞉ VersionPragmaExpression) ► (variant꞉ VersionPragmaOrExpression): # " 0.5.0 || 0.6.0 || ^0.7.0" (8..33) - - (left_operand꞉ VersionPragmaExpression) ► (variant꞉ VersionPragmaOrExpression): # " 0.5.0 || 0.6.0" (8..23) - - (left_operand꞉ VersionPragmaExpression) ► (variant꞉ VersionPragmaSpecifier): # " 0.5.0" (8..14) - - (leading_trivia꞉ Whitespace): " " # (8..9) - - (item꞉ VersionPragmaValue): "0" # (9..10) - - (separator꞉ Period): "." # (10..11) - - (item꞉ VersionPragmaValue): "5" # (11..12) - - (separator꞉ Period): "." # (12..13) - - (item꞉ VersionPragmaValue): "0" # (13..14) - - (leading_trivia꞉ Whitespace): " " # (14..15) - - (operator꞉ BarBar): "||" # (15..17) - - (right_operand꞉ VersionPragmaExpression) ► (variant꞉ VersionPragmaSpecifier): # " 0.6.0" (17..23) - - (leading_trivia꞉ Whitespace): " " # (17..18) - - (item꞉ VersionPragmaValue): "0" # (18..19) - - (separator꞉ Period): "." # (19..20) - - (item꞉ VersionPragmaValue): "6" # (20..21) - - (separator꞉ Period): "." # (21..22) - - (item꞉ VersionPragmaValue): "0" # (22..23) - - (leading_trivia꞉ Whitespace): " " # (23..24) - - (operator꞉ BarBar): "||" # (24..26) - - (right_operand꞉ VersionPragmaExpression) ► (variant꞉ VersionPragmaPrefixExpression): # " ^0.7.0" (26..33) + - (sets꞉ VersionExpressionSets): # " 0.5.0 || 0.6.0 || ^0.7.0" (8..33) + - (item꞉ VersionExpressionSet): # " 0.5.0" (8..14) + - (item꞉ VersionExpression) ► (variant꞉ VersionSpecifiers): # " 0.5.0" (8..14) + - (leading_trivia꞉ Whitespace): " " # (8..9) + - (item꞉ VersionSpecifier): "0" # (9..10) + - (separator꞉ Period): "." # (10..11) + - (item꞉ VersionSpecifier): "5" # (11..12) + - (separator꞉ Period): "." # (12..13) + - (item꞉ VersionSpecifier): "0" # (13..14) + - (leading_trivia꞉ Whitespace): " " # (14..15) + - (separator꞉ BarBar): "||" # (15..17) + - (item꞉ VersionExpressionSet): # " 0.6.0" (17..23) + - (item꞉ VersionExpression) ► (variant꞉ VersionSpecifiers): # " 0.6.0" (17..23) + - (leading_trivia꞉ Whitespace): " " # (17..18) + - (item꞉ VersionSpecifier): "0" # (18..19) + - (separator꞉ Period): "." # (19..20) + - (item꞉ VersionSpecifier): "6" # (20..21) + - (separator꞉ Period): "." # (21..22) + - (item꞉ VersionSpecifier): "0" # (22..23) + - (leading_trivia꞉ Whitespace): " " # (23..24) + - (separator꞉ BarBar): "||" # (24..26) + - (item꞉ VersionExpressionSet): # " ^0.7.0" (26..33) + - (item꞉ VersionExpression) ► (variant꞉ VersionComparator): # " ^0.7.0" (26..33) - (leading_trivia꞉ Whitespace): " " # (26..27) - (operator꞉ Caret): "^" # (27..28) - - (operand꞉ VersionPragmaExpression) ► (variant꞉ VersionPragmaSpecifier): # "0.7.0" (28..33) - - (item꞉ VersionPragmaValue): "0" # (28..29) + - (operand꞉ VersionExpression) ► (variant꞉ VersionSpecifiers): # "0.7.0" (28..33) + - (item꞉ VersionSpecifier): "0" # (28..29) - (separator꞉ Period): "." # (29..30) - - (item꞉ VersionPragmaValue): "7" # (30..31) + - (item꞉ VersionSpecifier): "7" # (30..31) - (separator꞉ Period): "." # (31..32) - - (item꞉ VersionPragmaValue): "0" # (32..33) + - (item꞉ VersionSpecifier): "0" # (32..33) diff --git a/crates/solidity/testing/snapshots/cst_output/VersionPragma/double_quotes_string/generated/0.4.11-success.yml b/crates/solidity/testing/snapshots/cst_output/VersionPragma/double_quotes_string/generated/0.4.11-success.yml new file mode 100644 index 0000000000..03b706242f --- /dev/null +++ b/crates/solidity/testing/snapshots/cst_output/VersionPragma/double_quotes_string/generated/0.4.11-success.yml @@ -0,0 +1,16 @@ +# This file is generated automatically by infrastructure scripts. Please don't edit by hand. + +Source: > + 1 │ solidity "1.2.3" │ 0..16 + +Errors: [] + +Tree: + - (VersionPragma): # 'solidity "1.2.3"\n' (0..17) + - (solidity_keyword꞉ SolidityKeyword): "solidity" # (0..8) + - (sets꞉ VersionExpressionSets): # ' "1.2.3"\n' (8..17) + - (item꞉ VersionExpressionSet): # ' "1.2.3"\n' (8..17) + - (item꞉ VersionExpression): # ' "1.2.3"\n' (8..17) + - (leading_trivia꞉ Whitespace): " " # (8..9) + - (variant꞉ DoubleQuotedVersionLiteral): '"1.2.3"' # (9..16) + - (trailing_trivia꞉ EndOfLine): "\n" # (16..17) diff --git a/crates/solidity/testing/snapshots/cst_output/VersionPragma/double_quotes_string/input.sol b/crates/solidity/testing/snapshots/cst_output/VersionPragma/double_quotes_string/input.sol new file mode 100644 index 0000000000..7ca6ae858b --- /dev/null +++ b/crates/solidity/testing/snapshots/cst_output/VersionPragma/double_quotes_string/input.sol @@ -0,0 +1 @@ +solidity "1.2.3" diff --git a/crates/solidity/testing/snapshots/cst_output/VersionPragma/equal_operator/generated/0.4.11-success.yml b/crates/solidity/testing/snapshots/cst_output/VersionPragma/equal_operator/generated/0.4.11-success.yml index 2670cbec1e..488ac256b9 100644 --- a/crates/solidity/testing/snapshots/cst_output/VersionPragma/equal_operator/generated/0.4.11-success.yml +++ b/crates/solidity/testing/snapshots/cst_output/VersionPragma/equal_operator/generated/0.4.11-success.yml @@ -8,13 +8,14 @@ Errors: [] Tree: - (VersionPragma): # "solidity =0.8.0" (0..15) - (solidity_keyword꞉ SolidityKeyword): "solidity" # (0..8) - - (expressions꞉ VersionPragmaExpressions): # " =0.8.0" (8..15) - - (item꞉ VersionPragmaExpression) ► (variant꞉ VersionPragmaPrefixExpression): # " =0.8.0" (8..15) - - (leading_trivia꞉ Whitespace): " " # (8..9) - - (operator꞉ Equal): "=" # (9..10) - - (operand꞉ VersionPragmaExpression) ► (variant꞉ VersionPragmaSpecifier): # "0.8.0" (10..15) - - (item꞉ VersionPragmaValue): "0" # (10..11) - - (separator꞉ Period): "." # (11..12) - - (item꞉ VersionPragmaValue): "8" # (12..13) - - (separator꞉ Period): "." # (13..14) - - (item꞉ VersionPragmaValue): "0" # (14..15) + - (sets꞉ VersionExpressionSets): # " =0.8.0" (8..15) + - (item꞉ VersionExpressionSet): # " =0.8.0" (8..15) + - (item꞉ VersionExpression) ► (variant꞉ VersionComparator): # " =0.8.0" (8..15) + - (leading_trivia꞉ Whitespace): " " # (8..9) + - (operator꞉ Equal): "=" # (9..10) + - (operand꞉ VersionExpression) ► (variant꞉ VersionSpecifiers): # "0.8.0" (10..15) + - (item꞉ VersionSpecifier): "0" # (10..11) + - (separator꞉ Period): "." # (11..12) + - (item꞉ VersionSpecifier): "8" # (12..13) + - (separator꞉ Period): "." # (13..14) + - (item꞉ VersionSpecifier): "0" # (14..15) diff --git a/crates/solidity/testing/snapshots/cst_output/VersionPragma/exact_version/generated/0.4.11-success.yml b/crates/solidity/testing/snapshots/cst_output/VersionPragma/exact_version/generated/0.4.11-success.yml index 2ac823bcff..b92900987a 100644 --- a/crates/solidity/testing/snapshots/cst_output/VersionPragma/exact_version/generated/0.4.11-success.yml +++ b/crates/solidity/testing/snapshots/cst_output/VersionPragma/exact_version/generated/0.4.11-success.yml @@ -8,11 +8,12 @@ Errors: [] Tree: - (VersionPragma): # "solidity 0.8.0" (0..14) - (solidity_keyword꞉ SolidityKeyword): "solidity" # (0..8) - - (expressions꞉ VersionPragmaExpressions): # " 0.8.0" (8..14) - - (item꞉ VersionPragmaExpression) ► (variant꞉ VersionPragmaSpecifier): # " 0.8.0" (8..14) - - (leading_trivia꞉ Whitespace): " " # (8..9) - - (item꞉ VersionPragmaValue): "0" # (9..10) - - (separator꞉ Period): "." # (10..11) - - (item꞉ VersionPragmaValue): "8" # (11..12) - - (separator꞉ Period): "." # (12..13) - - (item꞉ VersionPragmaValue): "0" # (13..14) + - (sets꞉ VersionExpressionSets): # " 0.8.0" (8..14) + - (item꞉ VersionExpressionSet): # " 0.8.0" (8..14) + - (item꞉ VersionExpression) ► (variant꞉ VersionSpecifiers): # " 0.8.0" (8..14) + - (leading_trivia꞉ Whitespace): " " # (8..9) + - (item꞉ VersionSpecifier): "0" # (9..10) + - (separator꞉ Period): "." # (10..11) + - (item꞉ VersionSpecifier): "8" # (11..12) + - (separator꞉ Period): "." # (12..13) + - (item꞉ VersionSpecifier): "0" # (13..14) diff --git a/crates/solidity/testing/snapshots/cst_output/VersionPragma/less_than_operator/generated/0.4.11-success.yml b/crates/solidity/testing/snapshots/cst_output/VersionPragma/less_than_operator/generated/0.4.11-success.yml index ce15a907f9..f1d70431b9 100644 --- a/crates/solidity/testing/snapshots/cst_output/VersionPragma/less_than_operator/generated/0.4.11-success.yml +++ b/crates/solidity/testing/snapshots/cst_output/VersionPragma/less_than_operator/generated/0.4.11-success.yml @@ -8,13 +8,14 @@ Errors: [] Tree: - (VersionPragma): # "solidity <1.0.0" (0..15) - (solidity_keyword꞉ SolidityKeyword): "solidity" # (0..8) - - (expressions꞉ VersionPragmaExpressions): # " <1.0.0" (8..15) - - (item꞉ VersionPragmaExpression) ► (variant꞉ VersionPragmaPrefixExpression): # " <1.0.0" (8..15) - - (leading_trivia꞉ Whitespace): " " # (8..9) - - (operator꞉ LessThan): "<" # (9..10) - - (operand꞉ VersionPragmaExpression) ► (variant꞉ VersionPragmaSpecifier): # "1.0.0" (10..15) - - (item꞉ VersionPragmaValue): "1" # (10..11) - - (separator꞉ Period): "." # (11..12) - - (item꞉ VersionPragmaValue): "0" # (12..13) - - (separator꞉ Period): "." # (13..14) - - (item꞉ VersionPragmaValue): "0" # (14..15) + - (sets꞉ VersionExpressionSets): # " <1.0.0" (8..15) + - (item꞉ VersionExpressionSet): # " <1.0.0" (8..15) + - (item꞉ VersionExpression) ► (variant꞉ VersionComparator): # " <1.0.0" (8..15) + - (leading_trivia꞉ Whitespace): " " # (8..9) + - (operator꞉ LessThan): "<" # (9..10) + - (operand꞉ VersionExpression) ► (variant꞉ VersionSpecifiers): # "1.0.0" (10..15) + - (item꞉ VersionSpecifier): "1" # (10..11) + - (separator꞉ Period): "." # (11..12) + - (item꞉ VersionSpecifier): "0" # (12..13) + - (separator꞉ Period): "." # (13..14) + - (item꞉ VersionSpecifier): "0" # (14..15) diff --git a/crates/solidity/testing/snapshots/cst_output/VersionPragma/multiple_exact_versions/generated/0.4.11-success.yml b/crates/solidity/testing/snapshots/cst_output/VersionPragma/multiple_exact_versions/generated/0.4.11-success.yml index 89c034aacc..da2d0685bc 100644 --- a/crates/solidity/testing/snapshots/cst_output/VersionPragma/multiple_exact_versions/generated/0.4.11-success.yml +++ b/crates/solidity/testing/snapshots/cst_output/VersionPragma/multiple_exact_versions/generated/0.4.11-success.yml @@ -8,18 +8,19 @@ Errors: [] Tree: - (VersionPragma): # "solidity 0.7.0 0.8.0" (0..20) - (solidity_keyword꞉ SolidityKeyword): "solidity" # (0..8) - - (expressions꞉ VersionPragmaExpressions): # " 0.7.0 0.8.0" (8..20) - - (item꞉ VersionPragmaExpression) ► (variant꞉ VersionPragmaSpecifier): # " 0.7.0" (8..14) - - (leading_trivia꞉ Whitespace): " " # (8..9) - - (item꞉ VersionPragmaValue): "0" # (9..10) - - (separator꞉ Period): "." # (10..11) - - (item꞉ VersionPragmaValue): "7" # (11..12) - - (separator꞉ Period): "." # (12..13) - - (item꞉ VersionPragmaValue): "0" # (13..14) - - (item꞉ VersionPragmaExpression) ► (variant꞉ VersionPragmaSpecifier): # " 0.8.0" (14..20) - - (leading_trivia꞉ Whitespace): " " # (14..15) - - (item꞉ VersionPragmaValue): "0" # (15..16) - - (separator꞉ Period): "." # (16..17) - - (item꞉ VersionPragmaValue): "8" # (17..18) - - (separator꞉ Period): "." # (18..19) - - (item꞉ VersionPragmaValue): "0" # (19..20) + - (sets꞉ VersionExpressionSets): # " 0.7.0 0.8.0" (8..20) + - (item꞉ VersionExpressionSet): # " 0.7.0 0.8.0" (8..20) + - (item꞉ VersionExpression) ► (variant꞉ VersionSpecifiers): # " 0.7.0" (8..14) + - (leading_trivia꞉ Whitespace): " " # (8..9) + - (item꞉ VersionSpecifier): "0" # (9..10) + - (separator꞉ Period): "." # (10..11) + - (item꞉ VersionSpecifier): "7" # (11..12) + - (separator꞉ Period): "." # (12..13) + - (item꞉ VersionSpecifier): "0" # (13..14) + - (item꞉ VersionExpression) ► (variant꞉ VersionSpecifiers): # " 0.8.0" (14..20) + - (leading_trivia꞉ Whitespace): " " # (14..15) + - (item꞉ VersionSpecifier): "0" # (15..16) + - (separator꞉ Period): "." # (16..17) + - (item꞉ VersionSpecifier): "8" # (17..18) + - (separator꞉ Period): "." # (18..19) + - (item꞉ VersionSpecifier): "0" # (19..20) diff --git a/crates/solidity/testing/snapshots/cst_output/VersionPragma/multiple_strings/generated/0.4.11-success.yml b/crates/solidity/testing/snapshots/cst_output/VersionPragma/multiple_strings/generated/0.4.11-success.yml new file mode 100644 index 0000000000..f9024589f9 --- /dev/null +++ b/crates/solidity/testing/snapshots/cst_output/VersionPragma/multiple_strings/generated/0.4.11-success.yml @@ -0,0 +1,27 @@ +# This file is generated automatically by infrastructure scripts. Please don't edit by hand. + +Source: > + 1 │ solidity ^"1.2.3" || "4.5.6"-'7.8.9' │ 0..36 + +Errors: [] + +Tree: + - (VersionPragma): # 'solidity ^"1.2.3" || "4.5.6"-''7.8.9''\n' (0..37) + - (solidity_keyword꞉ SolidityKeyword): "solidity" # (0..8) + - (sets꞉ VersionExpressionSets): # ' ^"1.2.3" || "4.5.6"-''7.8.9''\n' (8..37) + - (item꞉ VersionExpressionSet): # ' ^"1.2.3"' (8..17) + - (item꞉ VersionExpression) ► (variant꞉ VersionComparator): # ' ^"1.2.3"' (8..17) + - (leading_trivia꞉ Whitespace): " " # (8..9) + - (operator꞉ Caret): "^" # (9..10) + - (operand꞉ VersionExpression) ► (variant꞉ DoubleQuotedVersionLiteral): '"1.2.3"' # (10..17) + - (leading_trivia꞉ Whitespace): " " # (17..18) + - (separator꞉ BarBar): "||" # (18..20) + - (item꞉ VersionExpressionSet): # ' "4.5.6"-''7.8.9''\n' (20..37) + - (item꞉ VersionExpression) ► (variant꞉ VersionRange): # ' "4.5.6"-''7.8.9''\n' (20..37) + - (left_operand꞉ VersionExpression): # ' "4.5.6"' (20..28) + - (leading_trivia꞉ Whitespace): " " # (20..21) + - (variant꞉ DoubleQuotedVersionLiteral): '"4.5.6"' # (21..28) + - (operator꞉ Minus): "-" # (28..29) + - (right_operand꞉ VersionExpression): # "'7.8.9'\n" (29..37) + - (variant꞉ SingleQuotedVersionLiteral): "'7.8.9'" # (29..36) + - (trailing_trivia꞉ EndOfLine): "\n" # (36..37) diff --git a/crates/solidity/testing/snapshots/cst_output/VersionPragma/multiple_strings/input.sol b/crates/solidity/testing/snapshots/cst_output/VersionPragma/multiple_strings/input.sol new file mode 100644 index 0000000000..acd8d2c03e --- /dev/null +++ b/crates/solidity/testing/snapshots/cst_output/VersionPragma/multiple_strings/input.sol @@ -0,0 +1 @@ +solidity ^"1.2.3" || "4.5.6"-'7.8.9' diff --git a/crates/solidity/testing/snapshots/cst_output/VersionPragma/nested_expressions/generated/0.4.11-success.yml b/crates/solidity/testing/snapshots/cst_output/VersionPragma/nested_expressions/generated/0.4.11-success.yml index 500dc5cc2e..a47062b1f5 100644 --- a/crates/solidity/testing/snapshots/cst_output/VersionPragma/nested_expressions/generated/0.4.11-success.yml +++ b/crates/solidity/testing/snapshots/cst_output/VersionPragma/nested_expressions/generated/0.4.11-success.yml @@ -8,31 +8,32 @@ Errors: [] Tree: - (VersionPragma): # "solidity ^1.0.0 || 2.0.0-3.0.0" (0..30) - (solidity_keyword꞉ SolidityKeyword): "solidity" # (0..8) - - (expressions꞉ VersionPragmaExpressions): # " ^1.0.0 || 2.0.0-3.0.0" (8..30) - - (item꞉ VersionPragmaExpression) ► (variant꞉ VersionPragmaOrExpression): # " ^1.0.0 || 2.0.0-3.0.0" (8..30) - - (left_operand꞉ VersionPragmaExpression) ► (variant꞉ VersionPragmaPrefixExpression): # " ^1.0.0" (8..15) + - (sets꞉ VersionExpressionSets): # " ^1.0.0 || 2.0.0-3.0.0" (8..30) + - (item꞉ VersionExpressionSet): # " ^1.0.0" (8..15) + - (item꞉ VersionExpression) ► (variant꞉ VersionComparator): # " ^1.0.0" (8..15) - (leading_trivia꞉ Whitespace): " " # (8..9) - (operator꞉ Caret): "^" # (9..10) - - (operand꞉ VersionPragmaExpression) ► (variant꞉ VersionPragmaSpecifier): # "1.0.0" (10..15) - - (item꞉ VersionPragmaValue): "1" # (10..11) + - (operand꞉ VersionExpression) ► (variant꞉ VersionSpecifiers): # "1.0.0" (10..15) + - (item꞉ VersionSpecifier): "1" # (10..11) - (separator꞉ Period): "." # (11..12) - - (item꞉ VersionPragmaValue): "0" # (12..13) + - (item꞉ VersionSpecifier): "0" # (12..13) - (separator꞉ Period): "." # (13..14) - - (item꞉ VersionPragmaValue): "0" # (14..15) - - (leading_trivia꞉ Whitespace): " " # (15..16) - - (operator꞉ BarBar): "||" # (16..18) - - (right_operand꞉ VersionPragmaExpression) ► (variant꞉ VersionPragmaRangeExpression): # " 2.0.0-3.0.0" (18..30) - - (left_operand꞉ VersionPragmaExpression) ► (variant꞉ VersionPragmaSpecifier): # " 2.0.0" (18..24) + - (item꞉ VersionSpecifier): "0" # (14..15) + - (leading_trivia꞉ Whitespace): " " # (15..16) + - (separator꞉ BarBar): "||" # (16..18) + - (item꞉ VersionExpressionSet): # " 2.0.0-3.0.0" (18..30) + - (item꞉ VersionExpression) ► (variant꞉ VersionRange): # " 2.0.0-3.0.0" (18..30) + - (left_operand꞉ VersionExpression) ► (variant꞉ VersionSpecifiers): # " 2.0.0" (18..24) - (leading_trivia꞉ Whitespace): " " # (18..19) - - (item꞉ VersionPragmaValue): "2" # (19..20) + - (item꞉ VersionSpecifier): "2" # (19..20) - (separator꞉ Period): "." # (20..21) - - (item꞉ VersionPragmaValue): "0" # (21..22) + - (item꞉ VersionSpecifier): "0" # (21..22) - (separator꞉ Period): "." # (22..23) - - (item꞉ VersionPragmaValue): "0" # (23..24) + - (item꞉ VersionSpecifier): "0" # (23..24) - (operator꞉ Minus): "-" # (24..25) - - (right_operand꞉ VersionPragmaExpression) ► (variant꞉ VersionPragmaSpecifier): # "3.0.0" (25..30) - - (item꞉ VersionPragmaValue): "3" # (25..26) + - (right_operand꞉ VersionExpression) ► (variant꞉ VersionSpecifiers): # "3.0.0" (25..30) + - (item꞉ VersionSpecifier): "3" # (25..26) - (separator꞉ Period): "." # (26..27) - - (item꞉ VersionPragmaValue): "0" # (27..28) + - (item꞉ VersionSpecifier): "0" # (27..28) - (separator꞉ Period): "." # (28..29) - - (item꞉ VersionPragmaValue): "0" # (29..30) + - (item꞉ VersionSpecifier): "0" # (29..30) diff --git a/crates/solidity/testing/snapshots/cst_output/VersionPragma/ranges/generated/0.4.11-success.yml b/crates/solidity/testing/snapshots/cst_output/VersionPragma/ranges/generated/0.4.11-success.yml index cb378715e1..1409cd2ce4 100644 --- a/crates/solidity/testing/snapshots/cst_output/VersionPragma/ranges/generated/0.4.11-success.yml +++ b/crates/solidity/testing/snapshots/cst_output/VersionPragma/ranges/generated/0.4.11-success.yml @@ -8,21 +8,22 @@ Errors: [] Tree: - (VersionPragma): # "solidity 0.6.0 - 0.7.0" (0..22) - (solidity_keyword꞉ SolidityKeyword): "solidity" # (0..8) - - (expressions꞉ VersionPragmaExpressions): # " 0.6.0 - 0.7.0" (8..22) - - (item꞉ VersionPragmaExpression) ► (variant꞉ VersionPragmaRangeExpression): # " 0.6.0 - 0.7.0" (8..22) - - (left_operand꞉ VersionPragmaExpression) ► (variant꞉ VersionPragmaSpecifier): # " 0.6.0" (8..14) - - (leading_trivia꞉ Whitespace): " " # (8..9) - - (item꞉ VersionPragmaValue): "0" # (9..10) - - (separator꞉ Period): "." # (10..11) - - (item꞉ VersionPragmaValue): "6" # (11..12) - - (separator꞉ Period): "." # (12..13) - - (item꞉ VersionPragmaValue): "0" # (13..14) - - (leading_trivia꞉ Whitespace): " " # (14..15) - - (operator꞉ Minus): "-" # (15..16) - - (right_operand꞉ VersionPragmaExpression) ► (variant꞉ VersionPragmaSpecifier): # " 0.7.0" (16..22) - - (leading_trivia꞉ Whitespace): " " # (16..17) - - (item꞉ VersionPragmaValue): "0" # (17..18) - - (separator꞉ Period): "." # (18..19) - - (item꞉ VersionPragmaValue): "7" # (19..20) - - (separator꞉ Period): "." # (20..21) - - (item꞉ VersionPragmaValue): "0" # (21..22) + - (sets꞉ VersionExpressionSets): # " 0.6.0 - 0.7.0" (8..22) + - (item꞉ VersionExpressionSet): # " 0.6.0 - 0.7.0" (8..22) + - (item꞉ VersionExpression) ► (variant꞉ VersionRange): # " 0.6.0 - 0.7.0" (8..22) + - (left_operand꞉ VersionExpression) ► (variant꞉ VersionSpecifiers): # " 0.6.0" (8..14) + - (leading_trivia꞉ Whitespace): " " # (8..9) + - (item꞉ VersionSpecifier): "0" # (9..10) + - (separator꞉ Period): "." # (10..11) + - (item꞉ VersionSpecifier): "6" # (11..12) + - (separator꞉ Period): "." # (12..13) + - (item꞉ VersionSpecifier): "0" # (13..14) + - (leading_trivia꞉ Whitespace): " " # (14..15) + - (operator꞉ Minus): "-" # (15..16) + - (right_operand꞉ VersionExpression) ► (variant꞉ VersionSpecifiers): # " 0.7.0" (16..22) + - (leading_trivia꞉ Whitespace): " " # (16..17) + - (item꞉ VersionSpecifier): "0" # (17..18) + - (separator꞉ Period): "." # (18..19) + - (item꞉ VersionSpecifier): "7" # (19..20) + - (separator꞉ Period): "." # (20..21) + - (item꞉ VersionSpecifier): "0" # (21..22) diff --git a/crates/solidity/testing/snapshots/cst_output/VersionPragma/single_quote_string/generated/0.4.11-success.yml b/crates/solidity/testing/snapshots/cst_output/VersionPragma/single_quote_string/generated/0.4.11-success.yml new file mode 100644 index 0000000000..ba1bd3e79a --- /dev/null +++ b/crates/solidity/testing/snapshots/cst_output/VersionPragma/single_quote_string/generated/0.4.11-success.yml @@ -0,0 +1,16 @@ +# This file is generated automatically by infrastructure scripts. Please don't edit by hand. + +Source: > + 1 │ solidity '1.2.3' │ 0..16 + +Errors: [] + +Tree: + - (VersionPragma): # "solidity '1.2.3'\n" (0..17) + - (solidity_keyword꞉ SolidityKeyword): "solidity" # (0..8) + - (sets꞉ VersionExpressionSets): # " '1.2.3'\n" (8..17) + - (item꞉ VersionExpressionSet): # " '1.2.3'\n" (8..17) + - (item꞉ VersionExpression): # " '1.2.3'\n" (8..17) + - (leading_trivia꞉ Whitespace): " " # (8..9) + - (variant꞉ SingleQuotedVersionLiteral): "'1.2.3'" # (9..16) + - (trailing_trivia꞉ EndOfLine): "\n" # (16..17) diff --git a/crates/solidity/testing/snapshots/cst_output/VersionPragma/single_quote_string/input.sol b/crates/solidity/testing/snapshots/cst_output/VersionPragma/single_quote_string/input.sol new file mode 100644 index 0000000000..01b69c607d --- /dev/null +++ b/crates/solidity/testing/snapshots/cst_output/VersionPragma/single_quote_string/input.sol @@ -0,0 +1 @@ +solidity '1.2.3' diff --git a/crates/solidity/testing/snapshots/cst_output/VersionPragma/with_trivia/generated/0.4.11-success.yml b/crates/solidity/testing/snapshots/cst_output/VersionPragma/with_trivia/generated/0.4.11-success.yml index 3932575c84..88a6d800f7 100644 --- a/crates/solidity/testing/snapshots/cst_output/VersionPragma/with_trivia/generated/0.4.11-success.yml +++ b/crates/solidity/testing/snapshots/cst_output/VersionPragma/with_trivia/generated/0.4.11-success.yml @@ -8,23 +8,24 @@ Errors: [] Tree: - (VersionPragma): # "solidity /* comments */ 0 /* are */ . /* allowed *..." (0..68) - (solidity_keyword꞉ SolidityKeyword): "solidity" # (0..8) - - (expressions꞉ VersionPragmaExpressions): # " /* comments */ 0 /* are */ . /* allowed */ 0 . /*..." (8..68) - - (item꞉ VersionPragmaExpression) ► (variant꞉ VersionPragmaSpecifier): # " /* comments */ 0 /* are */ . /* allowed */ 0 . /*..." (8..68) - - (leading_trivia꞉ Whitespace): " " # (8..9) - - (leading_trivia꞉ MultiLineComment): "/* comments */" # (9..23) - - (leading_trivia꞉ Whitespace): " " # (23..24) - - (item꞉ VersionPragmaValue): "0" # (24..25) - - (leading_trivia꞉ Whitespace): " " # (25..26) - - (leading_trivia꞉ MultiLineComment): "/* are */" # (26..35) - - (leading_trivia꞉ Whitespace): " " # (35..36) - - (separator꞉ Period): "." # (36..37) - - (leading_trivia꞉ Whitespace): " " # (37..38) - - (leading_trivia꞉ MultiLineComment): "/* allowed */" # (38..51) - - (leading_trivia꞉ Whitespace): " " # (51..52) - - (item꞉ VersionPragmaValue): "0" # (52..53) - - (leading_trivia꞉ Whitespace): " " # (53..54) - - (separator꞉ Period): "." # (54..55) - - (leading_trivia꞉ Whitespace): " " # (55..56) - - (leading_trivia꞉ MultiLineComment): "/* here */" # (56..66) - - (leading_trivia꞉ Whitespace): " " # (66..67) - - (item꞉ VersionPragmaValue): "0" # (67..68) + - (sets꞉ VersionExpressionSets): # " /* comments */ 0 /* are */ . /* allowed */ 0 . /*..." (8..68) + - (item꞉ VersionExpressionSet): # " /* comments */ 0 /* are */ . /* allowed */ 0 . /*..." (8..68) + - (item꞉ VersionExpression) ► (variant꞉ VersionSpecifiers): # " /* comments */ 0 /* are */ . /* allowed */ 0 . /*..." (8..68) + - (leading_trivia꞉ Whitespace): " " # (8..9) + - (leading_trivia꞉ MultiLineComment): "/* comments */" # (9..23) + - (leading_trivia꞉ Whitespace): " " # (23..24) + - (item꞉ VersionSpecifier): "0" # (24..25) + - (leading_trivia꞉ Whitespace): " " # (25..26) + - (leading_trivia꞉ MultiLineComment): "/* are */" # (26..35) + - (leading_trivia꞉ Whitespace): " " # (35..36) + - (separator꞉ Period): "." # (36..37) + - (leading_trivia꞉ Whitespace): " " # (37..38) + - (leading_trivia꞉ MultiLineComment): "/* allowed */" # (38..51) + - (leading_trivia꞉ Whitespace): " " # (51..52) + - (item꞉ VersionSpecifier): "0" # (52..53) + - (leading_trivia꞉ Whitespace): " " # (53..54) + - (separator꞉ Period): "." # (54..55) + - (leading_trivia꞉ Whitespace): " " # (55..56) + - (leading_trivia꞉ MultiLineComment): "/* here */" # (56..66) + - (leading_trivia꞉ Whitespace): " " # (66..67) + - (item꞉ VersionSpecifier): "0" # (67..68) diff --git a/crates/solidity/testing/utils/Cargo.toml b/crates/solidity/testing/utils/Cargo.toml deleted file mode 100644 index cff80bc7b4..0000000000 --- a/crates/solidity/testing/utils/Cargo.toml +++ /dev/null @@ -1,19 +0,0 @@ -[package] -name = "solidity_testing_utils" -version.workspace = true -rust-version.workspace = true -edition.workspace = true -publish = false - -[dependencies] -anyhow = { workspace = true } -codegen_language_definition = { workspace = true } -Inflector = { workspace = true } -once_cell = { workspace = true } -semver = { workspace = true } -slang_solidity = { workspace = true } -solidity_language = { workspace = true } - -[lints] -workspace = true - diff --git a/crates/solidity/testing/utils/src/lib.rs b/crates/solidity/testing/utils/src/lib.rs deleted file mode 100644 index 5f51910049..0000000000 --- a/crates/solidity/testing/utils/src/lib.rs +++ /dev/null @@ -1,3 +0,0 @@ -pub mod cst_snapshots; -pub mod node_extensions; -pub mod version_pragmas; diff --git a/crates/solidity/testing/utils/src/node_extensions/mod.rs b/crates/solidity/testing/utils/src/node_extensions/mod.rs deleted file mode 100644 index 5132a4e389..0000000000 --- a/crates/solidity/testing/utils/src/node_extensions/mod.rs +++ /dev/null @@ -1,33 +0,0 @@ -#[cfg(test)] -mod tests; - -use slang_solidity::cst::{Node, RuleNode, TokenNode}; - -pub trait NodeExtensions { - fn extract_non_trivia(&self) -> String; -} - -impl NodeExtensions for Node { - fn extract_non_trivia(&self) -> String { - match self { - Node::Token(token) => token.extract_non_trivia(), - Node::Rule(rule) => rule.extract_non_trivia(), - } - } -} - -impl NodeExtensions for RuleNode { - fn extract_non_trivia(&self) -> String { - self.children - .iter() - .filter(|child| !child.is_trivia()) - .map(|child| child.extract_non_trivia()) - .collect() - } -} - -impl NodeExtensions for TokenNode { - fn extract_non_trivia(&self) -> String { - self.text.clone() - } -} diff --git a/crates/solidity/testing/utils/src/node_extensions/tests.rs b/crates/solidity/testing/utils/src/node_extensions/tests.rs deleted file mode 100644 index 0141f990ff..0000000000 --- a/crates/solidity/testing/utils/src/node_extensions/tests.rs +++ /dev/null @@ -1,28 +0,0 @@ -use anyhow::Result; -use semver::Version; -use slang_solidity::kinds::RuleKind; -use slang_solidity::language::Language; - -use crate::node_extensions::NodeExtensions; - -#[test] -fn extract_non_trivia() -> Result<()> { - let source = "x = ( - // comment - 1 + - // another comment - 2 - )"; - - let language = Language::new(Version::parse("0.8.0")?)?; - let output = language.parse(RuleKind::Expression, source); - - assert_eq!(output.errors().len(), 0); - - let parse_tree = output.tree(); - let value = parse_tree.extract_non_trivia(); - - assert_eq!(value, "x=(1+2)"); - - Ok(()) -} diff --git a/crates/solidity/testing/utils/src/version_pragmas/mod.rs b/crates/solidity/testing/utils/src/version_pragmas/mod.rs deleted file mode 100644 index d06309eff9..0000000000 --- a/crates/solidity/testing/utils/src/version_pragmas/mod.rs +++ /dev/null @@ -1,153 +0,0 @@ -#[cfg(test)] -mod tests; - -use std::str::FromStr; - -use anyhow::{bail, ensure, Context, Result}; -use semver::{Comparator, Op, Version}; -use slang_solidity::cst::{LabeledNode, Node}; -use slang_solidity::kinds::RuleKind; -use slang_solidity::language::Language; - -use crate::node_extensions::NodeExtensions; - -pub fn extract_version_pragmas( - source: &str, - latest_version: &Version, -) -> Result> { - let language = &Language::new(latest_version.to_owned())?; - let output = language.parse(RuleKind::SourceUnit, source); - - let mut pragmas = vec![]; - let mut cursor = output.create_tree_cursor(); - - while !cursor.is_completed() { - let node = &cursor.node(); - - if matches!(node, Node::Rule(rule) if rule.kind == RuleKind::VersionPragmaExpression) { - pragmas.push(extract_pragma(node).with_context(|| { - format!( - "Failed to extract pragma at {range:?}: '{value}'", - range = cursor.text_range(), - value = node.extract_non_trivia() - ) - })?); - - // Skip other VersionPragmaExpression nodes under the same node: - cursor.go_to_next_non_descendent(); - } else { - cursor.go_to_next_rule(); - } - } - - Ok(pragmas) -} - -fn extract_pragma(expression_node: &Node) -> Result { - let Node::Rule(expression_rule) = expression_node else { - bail!("Expected rule: {expression_node:?}") - }; - - ensure!( - expression_rule.kind == RuleKind::VersionPragmaExpression, - "Expected VersionPragmaExpression: {expression_rule:?}", - ); - - let inner_expression = match &expression_rule.children[..] { - [LabeledNode { - label: _, - node: Node::Rule(rule), - }] => rule, - [LabeledNode { - label: _, - node: Node::Token(token), - }] => bail!("Expected rule: {token:?}"), - _ => unreachable!("Expected single child: {expression_rule:?}"), - }; - - let inner_children: Vec<_> = inner_expression - .children - .iter() - .filter(|child| !child.is_trivia()) - .collect(); - - match inner_expression.kind { - RuleKind::VersionPragmaOrExpression => { - let [left, _, right] = &inner_children[..] else { - bail!("Expected 3 children: {inner_expression:?}"); - }; - - let left = extract_pragma(left)?; - let right = extract_pragma(right)?; - - Ok(VersionPragma::or(left, right)) - } - RuleKind::VersionPragmaRangeExpression => { - let [left, _, right] = &inner_children[..] else { - bail!("Expected 3 children: {inner_expression:?}"); - }; - - let mut left = extract_pragma(left)?.comparator()?; - let mut right = extract_pragma(right)?.comparator()?; - - // Simulate solc bug: - // https://github.com/ethereum/solidity/issues/13920 - left.op = Op::GreaterEq; - right.op = Op::LessEq; - - Ok(VersionPragma::and( - VersionPragma::single(left), - VersionPragma::single(right), - )) - } - RuleKind::VersionPragmaPrefixExpression => { - let value = inner_expression.extract_non_trivia(); - let comparator = Comparator::from_str(&value)?; - - Ok(VersionPragma::single(comparator)) - } - RuleKind::VersionPragmaSpecifier => { - let specifier = inner_expression.extract_non_trivia(); - let comparator = Comparator::from_str(&format!("={specifier}"))?; - - Ok(VersionPragma::single(comparator)) - } - _ => bail!("Unexpected inner expression: {inner_expression:?}"), - } -} - -#[derive(Debug)] -pub enum VersionPragma { - Or(Box, Box), - And(Box, Box), - Single(Comparator), -} - -impl VersionPragma { - pub fn or(left: Self, right: Self) -> Self { - Self::Or(Box::new(left), Box::new(right)) - } - - pub fn and(left: Self, right: Self) -> Self { - Self::And(Box::new(left), Box::new(right)) - } - - pub fn single(comparator: Comparator) -> Self { - Self::Single(comparator) - } - - pub fn matches(&self, version: &Version) -> bool { - match self { - Self::Or(left, right) => left.matches(version) || right.matches(version), - Self::And(left, right) => left.matches(version) && right.matches(version), - Self::Single(comparator) => comparator.matches(version), - } - } - - fn comparator(self) -> Result { - match self { - Self::Single(comparator) => Ok(comparator), - _ => bail!("Expected Single Comparator: {self:?}"), - } - } -} diff --git a/crates/solidity/testing/utils/src/version_pragmas/tests.rs b/crates/solidity/testing/utils/src/version_pragmas/tests.rs deleted file mode 100644 index 2edc95da4b..0000000000 --- a/crates/solidity/testing/utils/src/version_pragmas/tests.rs +++ /dev/null @@ -1,109 +0,0 @@ -use anyhow::{bail, Result}; -use semver::Version; - -use crate::version_pragmas::extract_version_pragmas; - -#[test] -fn exact_single_version() -> Result<()> { - test_aux( - &["0.6.0", "0.7.0", "0.8.0"], - " - pragma solidity 0.7.0; - ", - &["0.7.0"], - ) -} - -#[test] -fn multiple_versions() -> Result<()> { - test_aux( - &[ - "0.7.0", "0.7.1", "0.7.2", "0.7.3", "0.7.4", "0.7.5", "0.7.6", - ], - " - pragma solidity >=0.7.2 <=0.7.4; - ", - &["0.7.2", "0.7.3", "0.7.4"], - ) -} - -#[test] -fn multiple_version_pragmas() -> Result<()> { - test_aux( - &[ - "0.8.0", "0.8.1", "0.8.2", "0.8.3", "0.8.4", "0.8.5", "0.8.6", "0.8.7", "0.8.8", - "0.8.9", - ], - " - pragma solidity ^0.8.3; - pragma solidity <0.8.7; - ", - &["0.8.3", "0.8.4", "0.8.5", "0.8.6"], - ) -} - -#[test] -fn version_alternatives() -> Result<()> { - test_aux( - &[ - "0.8.0", "0.8.1", "0.8.2", "0.8.3", "0.8.4", "0.8.5", "0.8.6", "0.8.7", "0.8.8", - "0.8.9", - ], - " - pragma solidity 0.8.3 || 0.8.7; - ", - &["0.8.3", "0.8.7"], - ) -} - -#[test] -fn version_range() -> Result<()> { - test_aux( - &[ - "0.8.0", "0.8.1", "0.8.2", "0.8.3", "0.8.4", "0.8.5", "0.8.6", "0.8.7", "0.8.8", - "0.8.9", - ], - " - pragma solidity 0.8.3 - 0.8.7; - ", - &["0.8.3", "0.8.4", "0.8.5", "0.8.6", "0.8.7"], - ) -} - -#[test] -fn nested_expressions() -> Result<()> { - test_aux( - &[ - "0.8.0", "0.8.1", "0.8.2", "0.8.3", "0.8.4", "0.8.5", "0.8.6", "0.8.7", "0.8.8", - "0.8.9", - ], - " - pragma solidity 0.8.1 || 0.8.4 - 0.8.6; - ", - &["0.8.1", "0.8.4", "0.8.5", "0.8.6"], - ) -} - -fn test_aux(all_versions: &[&str], source: &str, expected: &[&str]) -> Result<()> { - let all_versions = all_versions - .iter() - .map(|version| Version::parse(version)) - .collect::, semver::Error>>()?; - - let latest_version = all_versions.iter().max().unwrap(); - let pragmas = extract_version_pragmas(source, latest_version)?; - - if pragmas.is_empty() { - bail!("Failed to extract version pragmas."); - } - - let actual = all_versions - .iter() - .filter(|version| pragmas.iter().all(|pragma| pragma.matches(version))) - .map(|version| version.to_string()) - .collect::>(); - - assert_eq!(expected, actual); - - Ok(()) -} From bb30fc1e28a0fe806f8954a0d2779d903f3f4da7 Mon Sep 17 00:00:00 2001 From: Igor Matuszewski Date: Wed, 10 Apr 2024 16:46:00 +0200 Subject: [PATCH 5/9] fix: Support arbitrary escapes until 0.4.25 (#923) See https://github.com/NomicFoundation/slang/pull/896#discussion_r1551845740 Arbitrary here means anything that's not `\u` (Unicode escape sequence) nor `\x` (hex escape sequence). Before 0.4.25, the arbitrary escapes likes `\a` are allowed in the string but evaluate to `a`, after 0.4.25 it is a parse error in solc. Known/valid escapes like `\n` should still work correctly across all of the versions. --- .changeset/poor-lemons-hammer.md | 5 ++ .../inputs/language/src/definition.rs | 46 ++++++++++++++-- .../slang_solidity/src/generated/language.rs | 55 ++++++++++++++++++- .../tests/src/cst_output/generated/mod.rs | 3 +- .../cst_output/generated/string_literal.rs | 35 ++++++++++++ .../outputs/spec/generated/grammar.ebnf | 13 ++++- .../public/05-expressions/05-strings.md | 10 +++- .../generated/public/supported-versions.md | 4 +- .../generated/0.4.11-success.yml | 14 +++++ .../generated/0.4.25-failure.yml | 19 +++++++ .../escape_arbitrary_ascii/input.sol | 2 + .../generated/0.4.11-success.yml | 14 +++++ .../generated/0.4.25-failure.yml | 19 +++++++ .../escape_arbitrary_unicode/input.sol | 2 + .../escape_ascii/generated/0.4.11-success.yml | 11 ++++ .../StringLiteral/escape_ascii/input.sol | 1 + .../escape_hex/generated/0.4.11-success.yml | 11 ++++ .../StringLiteral/escape_hex/input.sol | 1 + .../generated/0.4.11-failure.yml | 17 ++++++ .../escape_hex_invalid/input.sol | 1 + .../generated/0.4.11-success.yml | 11 ++++ .../StringLiteral/escape_unicode/input.sol | 1 + .../generated/0.4.11-failure.yml | 17 ++++++ .../escape_unicode_invalid/input.sol | 1 + 24 files changed, 300 insertions(+), 13 deletions(-) create mode 100644 .changeset/poor-lemons-hammer.md create mode 100644 crates/solidity/testing/snapshots/cst_output/StringLiteral/escape_arbitrary_ascii/generated/0.4.11-success.yml create mode 100644 crates/solidity/testing/snapshots/cst_output/StringLiteral/escape_arbitrary_ascii/generated/0.4.25-failure.yml create mode 100644 crates/solidity/testing/snapshots/cst_output/StringLiteral/escape_arbitrary_ascii/input.sol create mode 100644 crates/solidity/testing/snapshots/cst_output/StringLiteral/escape_arbitrary_unicode/generated/0.4.11-success.yml create mode 100644 crates/solidity/testing/snapshots/cst_output/StringLiteral/escape_arbitrary_unicode/generated/0.4.25-failure.yml create mode 100644 crates/solidity/testing/snapshots/cst_output/StringLiteral/escape_arbitrary_unicode/input.sol create mode 100644 crates/solidity/testing/snapshots/cst_output/StringLiteral/escape_ascii/generated/0.4.11-success.yml create mode 100644 crates/solidity/testing/snapshots/cst_output/StringLiteral/escape_ascii/input.sol create mode 100644 crates/solidity/testing/snapshots/cst_output/StringLiteral/escape_hex/generated/0.4.11-success.yml create mode 100644 crates/solidity/testing/snapshots/cst_output/StringLiteral/escape_hex/input.sol create mode 100644 crates/solidity/testing/snapshots/cst_output/StringLiteral/escape_hex_invalid/generated/0.4.11-failure.yml create mode 100644 crates/solidity/testing/snapshots/cst_output/StringLiteral/escape_hex_invalid/input.sol create mode 100644 crates/solidity/testing/snapshots/cst_output/StringLiteral/escape_unicode/generated/0.4.11-success.yml create mode 100644 crates/solidity/testing/snapshots/cst_output/StringLiteral/escape_unicode/input.sol create mode 100644 crates/solidity/testing/snapshots/cst_output/StringLiteral/escape_unicode_invalid/generated/0.4.11-failure.yml create mode 100644 crates/solidity/testing/snapshots/cst_output/StringLiteral/escape_unicode_invalid/input.sol diff --git a/.changeset/poor-lemons-hammer.md b/.changeset/poor-lemons-hammer.md new file mode 100644 index 0000000000..1c014f9ec3 --- /dev/null +++ b/.changeset/poor-lemons-hammer.md @@ -0,0 +1,5 @@ +--- +"@nomicfoundation/slang": patch +--- + +Support arbitrary ASCII escape sequences in string literals until 0.4.25 diff --git a/crates/solidity/inputs/language/src/definition.rs b/crates/solidity/inputs/language/src/definition.rs index d3b2dcedc3..ea36c22408 100644 --- a/crates/solidity/inputs/language/src/definition.rs +++ b/crates/solidity/inputs/language/src/definition.rs @@ -3854,9 +3854,21 @@ codegen_language_macros::compile!(Language( Token( name = SingleQuotedStringLiteral, definitions = [ - // Allows unicode characters: + // Allows unicode characters and arbitrary escape sequences: TokenDefinition( - enabled = Till("0.7.0"), + enabled = Till("0.4.25"), + scanner = Sequence([ + Atom("'"), + ZeroOrMore(Choice([ + Fragment(EscapeSequenceArbitrary), + Not(['\'', '\\', '\r', '\n']) + ])), + Atom("'") + ]) + ), + // Allows unicode characters but allows only known ASCII escape sequences: + TokenDefinition( + enabled = Range(from = "0.4.25", till = "0.7.0"), scanner = Sequence([ Atom("'"), ZeroOrMore(Choice([ @@ -3884,9 +3896,21 @@ codegen_language_macros::compile!(Language( Token( name = DoubleQuotedStringLiteral, definitions = [ - // Allows unicode characters: + // Allows unicode characters and arbitrary escape sequences: TokenDefinition( - enabled = Till("0.7.0"), + enabled = Till("0.4.25"), + scanner = Sequence([ + Atom("\""), + ZeroOrMore(Choice([ + Fragment(EscapeSequenceArbitrary), + Not(['"', '\\', '\r', '\n']) + ])), + Atom("\"") + ]) + ), + // Allows unicode characters but allows only known ASCII escape sequences: + TokenDefinition( + enabled = Range(from = "0.4.25", till = "0.7.0"), scanner = Sequence([ Atom("\""), ZeroOrMore(Choice([ @@ -4015,6 +4039,20 @@ codegen_language_macros::compile!(Language( ]) ]) ), + Fragment( + name = EscapeSequenceArbitrary, + enabled = Till("0.4.25"), + scanner = Sequence([ + Atom("\\"), + Choice([ + // Prior to 0.4.25, it was legal to "escape" any character (incl. unicode), + // however only the ones from `AsciiEscape` were escaped in practice. + Not(['x', 'u']), + Fragment(HexByteEscape), + Fragment(UnicodeEscape) + ]) + ]) + ), Fragment( name = AsciiEscape, scanner = Choice([ diff --git a/crates/solidity/outputs/cargo/slang_solidity/src/generated/language.rs b/crates/solidity/outputs/cargo/slang_solidity/src/generated/language.rs index cdb315933b..6db535c322 100644 --- a/crates/solidity/outputs/cargo/slang_solidity/src/generated/language.rs +++ b/crates/solidity/outputs/cargo/slang_solidity/src/generated/language.rs @@ -36,6 +36,7 @@ pub struct Language { pub(crate) version_is_at_least_0_4_16: bool, pub(crate) version_is_at_least_0_4_21: bool, pub(crate) version_is_at_least_0_4_22: bool, + pub(crate) version_is_at_least_0_4_25: bool, pub(crate) version_is_at_least_0_5_0: bool, pub(crate) version_is_at_least_0_5_3: bool, pub(crate) version_is_at_least_0_5_5: bool, @@ -168,6 +169,7 @@ impl Language { version_is_at_least_0_4_16: Version::new(0, 4, 16) <= version, version_is_at_least_0_4_21: Version::new(0, 4, 21) <= version, version_is_at_least_0_4_22: Version::new(0, 4, 22) <= version, + version_is_at_least_0_4_25: Version::new(0, 4, 25) <= version, version_is_at_least_0_5_0: Version::new(0, 5, 0) <= version, version_is_at_least_0_5_3: Version::new(0, 5, 3) <= version, version_is_at_least_0_5_5: Version::new(0, 5, 5) <= version, @@ -7014,7 +7016,23 @@ impl Language { fn double_quoted_string_literal(&self, input: &mut ParserContext<'_>) -> bool { scan_choice!( input, - if !self.version_is_at_least_0_7_0 { + if !self.version_is_at_least_0_4_25 { + scan_sequence!( + scan_chars!(input, '"'), + scan_zero_or_more!( + input, + scan_choice!( + input, + self.escape_sequence_arbitrary(input), + scan_none_of!(input, '"', '\\', '\r', '\n') + ) + ), + scan_chars!(input, '"') + ) + } else { + false + }, + if self.version_is_at_least_0_4_25 && !self.version_is_at_least_0_7_0 { scan_sequence!( scan_chars!(input, '"'), scan_zero_or_more!( @@ -7108,6 +7126,23 @@ impl Language { ) } + #[allow(unused_assignments, unused_parens)] + fn escape_sequence_arbitrary(&self, input: &mut ParserContext<'_>) -> bool { + if !self.version_is_at_least_0_4_25 { + scan_sequence!( + scan_chars!(input, '\\'), + scan_choice!( + input, + scan_none_of!(input, 'x', 'u'), + self.hex_byte_escape(input), + self.unicode_escape(input) + ) + ) + } else { + false + } + } + #[allow(unused_assignments, unused_parens)] fn hex_byte_escape(&self, input: &mut ParserContext<'_>) -> bool { scan_sequence!( @@ -7281,7 +7316,23 @@ impl Language { fn single_quoted_string_literal(&self, input: &mut ParserContext<'_>) -> bool { scan_choice!( input, - if !self.version_is_at_least_0_7_0 { + if !self.version_is_at_least_0_4_25 { + scan_sequence!( + scan_chars!(input, '\''), + scan_zero_or_more!( + input, + scan_choice!( + input, + self.escape_sequence_arbitrary(input), + scan_none_of!(input, '\'', '\\', '\r', '\n') + ) + ), + scan_chars!(input, '\'') + ) + } else { + false + }, + if self.version_is_at_least_0_4_25 && !self.version_is_at_least_0_7_0 { scan_sequence!( scan_chars!(input, '\''), scan_zero_or_more!( diff --git a/crates/solidity/outputs/cargo/tests/src/cst_output/generated/mod.rs b/crates/solidity/outputs/cargo/tests/src/cst_output/generated/mod.rs index 7596da4a3d..2594d5f48b 100644 --- a/crates/solidity/outputs/cargo/tests/src/cst_output/generated/mod.rs +++ b/crates/solidity/outputs/cargo/tests/src/cst_output/generated/mod.rs @@ -54,13 +54,14 @@ mod yul_label; mod yul_leave_statement; mod yul_variable_declaration_statement; -pub const VERSION_BREAKS: [Version; 30] = [ +pub const VERSION_BREAKS: [Version; 31] = [ Version::new(0, 4, 11), Version::new(0, 4, 12), Version::new(0, 4, 14), Version::new(0, 4, 16), Version::new(0, 4, 21), Version::new(0, 4, 22), + Version::new(0, 4, 25), Version::new(0, 5, 0), Version::new(0, 5, 3), Version::new(0, 5, 5), diff --git a/crates/solidity/outputs/cargo/tests/src/cst_output/generated/string_literal.rs b/crates/solidity/outputs/cargo/tests/src/cst_output/generated/string_literal.rs index 31f9ee08fc..64f11dfa87 100644 --- a/crates/solidity/outputs/cargo/tests/src/cst_output/generated/string_literal.rs +++ b/crates/solidity/outputs/cargo/tests/src/cst_output/generated/string_literal.rs @@ -9,6 +9,21 @@ fn double_quote_unicode() -> Result<()> { run("StringLiteral", "double_quote_unicode") } +#[test] +fn escape_arbitrary_ascii() -> Result<()> { + run("StringLiteral", "escape_arbitrary_ascii") +} + +#[test] +fn escape_arbitrary_unicode() -> Result<()> { + run("StringLiteral", "escape_arbitrary_unicode") +} + +#[test] +fn escape_ascii() -> Result<()> { + run("StringLiteral", "escape_ascii") +} + #[test] fn escape_cr_double_quote() -> Result<()> { run("StringLiteral", "escape_cr_double_quote") @@ -29,6 +44,16 @@ fn escape_crlf_single_quote() -> Result<()> { run("StringLiteral", "escape_crlf_single_quote") } +#[test] +fn escape_hex() -> Result<()> { + run("StringLiteral", "escape_hex") +} + +#[test] +fn escape_hex_invalid() -> Result<()> { + run("StringLiteral", "escape_hex_invalid") +} + #[test] fn escape_lf_double_quote() -> Result<()> { run("StringLiteral", "escape_lf_double_quote") @@ -39,6 +64,16 @@ fn escape_lf_single_quote() -> Result<()> { run("StringLiteral", "escape_lf_single_quote") } +#[test] +fn escape_unicode() -> Result<()> { + run("StringLiteral", "escape_unicode") +} + +#[test] +fn escape_unicode_invalid() -> Result<()> { + run("StringLiteral", "escape_unicode_invalid") +} + #[test] fn single_quote_unicode() -> Result<()> { run("StringLiteral", "single_quote_unicode") diff --git a/crates/solidity/outputs/spec/generated/grammar.ebnf b/crates/solidity/outputs/spec/generated/grammar.ebnf index 0ef9e87807..815cd317e4 100644 --- a/crates/solidity/outputs/spec/generated/grammar.ebnf +++ b/crates/solidity/outputs/spec/generated/grammar.ebnf @@ -1265,12 +1265,18 @@ StringLiterals = StringLiteral+; StringLiteral = SINGLE_QUOTED_STRING_LITERAL | DOUBLE_QUOTED_STRING_LITERAL; -(* Deprecated in 0.7.0 *) +(* Deprecated in 0.4.25 *) +SINGLE_QUOTED_STRING_LITERAL = "'" («ESCAPE_SEQUENCE_ARBITRARY» | !("'" "\\" "\r" "\n"))* "'"; + +(* Introduced in 0.4.25 and deprecated in 0.7.0. *) SINGLE_QUOTED_STRING_LITERAL = "'" («ESCAPE_SEQUENCE» | !("'" "\\" "\r" "\n"))* "'"; SINGLE_QUOTED_STRING_LITERAL = "'" («ESCAPE_SEQUENCE» | (" "…"&") | ("("…"[") | ("]"…"~"))* "'"; -(* Deprecated in 0.7.0 *) +(* Deprecated in 0.4.25 *) +DOUBLE_QUOTED_STRING_LITERAL = '"' («ESCAPE_SEQUENCE_ARBITRARY» | !('"' "\\" "\r" "\n"))* '"'; + +(* Introduced in 0.4.25 and deprecated in 0.7.0. *) DOUBLE_QUOTED_STRING_LITERAL = '"' («ESCAPE_SEQUENCE» | !('"' "\\" "\r" "\n"))* '"'; DOUBLE_QUOTED_STRING_LITERAL = '"' («ESCAPE_SEQUENCE» | (" "…"!") | ("#"…"[") | ("]"…"~"))* '"'; @@ -1304,6 +1310,9 @@ DOUBLE_QUOTED_UNICODE_STRING_LITERAL = 'unicode"' («ESCAPE_SEQUENCE» | !('"' " «ESCAPE_SEQUENCE» = "\\" («ASCII_ESCAPE» | «HEX_BYTE_ESCAPE» | «UNICODE_ESCAPE»); +(* Deprecated in 0.4.25 *) +«ESCAPE_SEQUENCE_ARBITRARY» = "\\" (!("x" "u") | «HEX_BYTE_ESCAPE» | «UNICODE_ESCAPE»); + «ASCII_ESCAPE» = "n" | "r" | "t" | "'" | '"' | "\\" | "\r\n" | "\r" | "\n"; «HEX_BYTE_ESCAPE» = "x" «HEX_CHARACTER» «HEX_CHARACTER»; diff --git a/crates/solidity/outputs/spec/generated/public/05-expressions/05-strings.md b/crates/solidity/outputs/spec/generated/public/05-expressions/05-strings.md index 601d1ebeb3..031a95d445 100644 --- a/crates/solidity/outputs/spec/generated/public/05-expressions/05-strings.md +++ b/crates/solidity/outputs/spec/generated/public/05-expressions/05-strings.md @@ -26,13 +26,13 @@ ``` -
(* Deprecated in 0.7.0 *)
SINGLE_QUOTED_STRING_LITERAL = "'" («ESCAPE_SEQUENCE» | !("'" "\\" "\r" "\n"))* "'";

SINGLE_QUOTED_STRING_LITERAL = "'" («ESCAPE_SEQUENCE» | (" ""&") | ("(""[") | ("]""~"))* "'";
+
(* Deprecated in 0.4.25 *)
SINGLE_QUOTED_STRING_LITERAL = "'" («ESCAPE_SEQUENCE_ARBITRARY» | !("'" "\\" "\r" "\n"))* "'";

(* Introduced in 0.4.25 and deprecated in 0.7.0. *)
SINGLE_QUOTED_STRING_LITERAL = "'" («ESCAPE_SEQUENCE» | !("'" "\\" "\r" "\n"))* "'";

SINGLE_QUOTED_STRING_LITERAL = "'" («ESCAPE_SEQUENCE» | (" ""&") | ("(""[") | ("]""~"))* "'";
```{ .ebnf #DoubleQuotedStringLiteral } ``` -
(* Deprecated in 0.7.0 *)
DOUBLE_QUOTED_STRING_LITERAL = '"' («ESCAPE_SEQUENCE» | !('"' "\\" "\r" "\n"))* '"';

DOUBLE_QUOTED_STRING_LITERAL = '"' («ESCAPE_SEQUENCE» | (" ""!") | ("#""[") | ("]""~"))* '"';
+
(* Deprecated in 0.4.25 *)
DOUBLE_QUOTED_STRING_LITERAL = '"' («ESCAPE_SEQUENCE_ARBITRARY» | !('"' "\\" "\r" "\n"))* '"';

(* Introduced in 0.4.25 and deprecated in 0.7.0. *)
DOUBLE_QUOTED_STRING_LITERAL = '"' («ESCAPE_SEQUENCE» | !('"' "\\" "\r" "\n"))* '"';

DOUBLE_QUOTED_STRING_LITERAL = '"' («ESCAPE_SEQUENCE» | (" ""!") | ("#""[") | ("]""~"))* '"';
```{ .ebnf #HexStringLiterals } @@ -100,6 +100,12 @@
«ESCAPE_SEQUENCE» = "\\" («ASCII_ESCAPE» | «HEX_BYTE_ESCAPE» | «UNICODE_ESCAPE»);
+```{ .ebnf #EscapeSequenceArbitrary } + +``` + +
(* Deprecated in 0.4.25 *)
«ESCAPE_SEQUENCE_ARBITRARY» = "\\" (!("x" "u") | «HEX_BYTE_ESCAPE» | «UNICODE_ESCAPE»);
+ ```{ .ebnf #AsciiEscape } ``` diff --git a/crates/solidity/outputs/spec/generated/public/supported-versions.md b/crates/solidity/outputs/spec/generated/public/supported-versions.md index 4424d2a841..a81ad3a072 100644 --- a/crates/solidity/outputs/spec/generated/public/supported-versions.md +++ b/crates/solidity/outputs/spec/generated/public/supported-versions.md @@ -4,6 +4,6 @@ This specification compiles information from 77 publicly released versions of So `0.4.11` `0.4.12` `0.4.13` `0.4.14` `0.4.15` `0.4.16` `0.4.17` `0.4.18` `0.4.19` `0.4.20` `0.4.21` `0.4.22` `0.4.23` `0.4.24` `0.4.25` `0.4.26` `0.5.0` `0.5.1` `0.5.2` `0.5.3` `0.5.4` `0.5.5` `0.5.6` `0.5.7` `0.5.8` `0.5.9` `0.5.10` `0.5.11` `0.5.12` `0.5.13` `0.5.14` `0.5.15` `0.5.16` `0.5.17` `0.6.0` `0.6.1` `0.6.2` `0.6.3` `0.6.4` `0.6.5` `0.6.6` `0.6.7` `0.6.8` `0.6.9` `0.6.10` `0.6.11` `0.6.12` `0.7.0` `0.7.1` `0.7.2` `0.7.3` `0.7.4` `0.7.5` `0.7.6` `0.8.0` `0.8.1` `0.8.2` `0.8.3` `0.8.4` `0.8.5` `0.8.6` `0.8.7` `0.8.8` `0.8.9` `0.8.10` `0.8.11` `0.8.12` `0.8.13` `0.8.14` `0.8.15` `0.8.16` `0.8.17` `0.8.18` `0.8.19` `0.8.20` `0.8.21` `0.8.22` -Among which, 30 versions have breaking changes: +Among which, 31 versions have breaking changes: -`0.4.11` `0.4.12` `0.4.14` `0.4.16` `0.4.21` `0.4.22` `0.5.0` `0.5.3` `0.5.5` `0.5.8` `0.5.10` `0.5.12` `0.5.14` `0.6.0` `0.6.2` `0.6.5` `0.6.7` `0.6.8` `0.6.11` `0.7.0` `0.7.1` `0.7.4` `0.8.0` `0.8.4` `0.8.7` `0.8.8` `0.8.13` `0.8.18` `0.8.19` `0.8.22` +`0.4.11` `0.4.12` `0.4.14` `0.4.16` `0.4.21` `0.4.22` `0.4.25` `0.5.0` `0.5.3` `0.5.5` `0.5.8` `0.5.10` `0.5.12` `0.5.14` `0.6.0` `0.6.2` `0.6.5` `0.6.7` `0.6.8` `0.6.11` `0.7.0` `0.7.1` `0.7.4` `0.8.0` `0.8.4` `0.8.7` `0.8.8` `0.8.13` `0.8.18` `0.8.19` `0.8.22` diff --git a/crates/solidity/testing/snapshots/cst_output/StringLiteral/escape_arbitrary_ascii/generated/0.4.11-success.yml b/crates/solidity/testing/snapshots/cst_output/StringLiteral/escape_arbitrary_ascii/generated/0.4.11-success.yml new file mode 100644 index 0000000000..352f1d3f31 --- /dev/null +++ b/crates/solidity/testing/snapshots/cst_output/StringLiteral/escape_arbitrary_ascii/generated/0.4.11-success.yml @@ -0,0 +1,14 @@ +# This file is generated automatically by infrastructure scripts. Please don't edit by hand. + +Source: > + 1 │ // Disallowed post 0.4.25 │ 0..25 + 2 │ "\a" │ 26..30 + +Errors: [] + +Tree: + - (StringLiteral): # '// Disallowed post 0.4.25\n"\a"\n' (0..31) + - (leading_trivia꞉ SingleLineComment): "// Disallowed post 0.4.25" # (0..25) + - (leading_trivia꞉ EndOfLine): "\n" # (25..26) + - (variant꞉ DoubleQuotedStringLiteral): '"\a"' # (26..30) + - (trailing_trivia꞉ EndOfLine): "\n" # (30..31) diff --git a/crates/solidity/testing/snapshots/cst_output/StringLiteral/escape_arbitrary_ascii/generated/0.4.25-failure.yml b/crates/solidity/testing/snapshots/cst_output/StringLiteral/escape_arbitrary_ascii/generated/0.4.25-failure.yml new file mode 100644 index 0000000000..cf490591b7 --- /dev/null +++ b/crates/solidity/testing/snapshots/cst_output/StringLiteral/escape_arbitrary_ascii/generated/0.4.25-failure.yml @@ -0,0 +1,19 @@ +# This file is generated automatically by infrastructure scripts. Please don't edit by hand. + +Source: > + 1 │ // Disallowed post 0.4.25 │ 0..25 + 2 │ "\a" │ 26..30 + +Errors: # 1 total + - > + Error: Expected DoubleQuotedStringLiteral or SingleQuotedStringLiteral. + ╭─[crates/solidity/testing/snapshots/cst_output/StringLiteral/escape_arbitrary_ascii/input.sol:1:1] + │ + 1 │ ╭─▶ // Disallowed post 0.4.25 + 2 │ ├─▶ "\a" + │ │ + │ ╰────────── Error occurred here. + ───╯ + +Tree: + - (SKIPPED): '// Disallowed post 0.4.25\n"\a"\n' # (0..31) diff --git a/crates/solidity/testing/snapshots/cst_output/StringLiteral/escape_arbitrary_ascii/input.sol b/crates/solidity/testing/snapshots/cst_output/StringLiteral/escape_arbitrary_ascii/input.sol new file mode 100644 index 0000000000..31a30566c4 --- /dev/null +++ b/crates/solidity/testing/snapshots/cst_output/StringLiteral/escape_arbitrary_ascii/input.sol @@ -0,0 +1,2 @@ +// Disallowed post 0.4.25 +"\a" diff --git a/crates/solidity/testing/snapshots/cst_output/StringLiteral/escape_arbitrary_unicode/generated/0.4.11-success.yml b/crates/solidity/testing/snapshots/cst_output/StringLiteral/escape_arbitrary_unicode/generated/0.4.11-success.yml new file mode 100644 index 0000000000..7d71206e04 --- /dev/null +++ b/crates/solidity/testing/snapshots/cst_output/StringLiteral/escape_arbitrary_unicode/generated/0.4.11-success.yml @@ -0,0 +1,14 @@ +# This file is generated automatically by infrastructure scripts. Please don't edit by hand. + +Source: > + 1 │ // Disallowed post 0.4.25 │ 0..25 + 2 │ "\✅" │ 26..32 + +Errors: [] + +Tree: + - (StringLiteral): # '// Disallowed post 0.4.25\n"\✅"\n' (0..33) + - (leading_trivia꞉ SingleLineComment): "// Disallowed post 0.4.25" # (0..25) + - (leading_trivia꞉ EndOfLine): "\n" # (25..26) + - (variant꞉ DoubleQuotedStringLiteral): '"\✅"' # (26..32) + - (trailing_trivia꞉ EndOfLine): "\n" # (32..33) diff --git a/crates/solidity/testing/snapshots/cst_output/StringLiteral/escape_arbitrary_unicode/generated/0.4.25-failure.yml b/crates/solidity/testing/snapshots/cst_output/StringLiteral/escape_arbitrary_unicode/generated/0.4.25-failure.yml new file mode 100644 index 0000000000..0d27f5e4ad --- /dev/null +++ b/crates/solidity/testing/snapshots/cst_output/StringLiteral/escape_arbitrary_unicode/generated/0.4.25-failure.yml @@ -0,0 +1,19 @@ +# This file is generated automatically by infrastructure scripts. Please don't edit by hand. + +Source: > + 1 │ // Disallowed post 0.4.25 │ 0..25 + 2 │ "\✅" │ 26..32 + +Errors: # 1 total + - > + Error: Expected DoubleQuotedStringLiteral or SingleQuotedStringLiteral. + ╭─[crates/solidity/testing/snapshots/cst_output/StringLiteral/escape_arbitrary_unicode/input.sol:1:1] + │ + 1 │ ╭─▶ // Disallowed post 0.4.25 + 2 │ ├─▶ "\✅" + │ │ + │ ╰─────────── Error occurred here. + ───╯ + +Tree: + - (SKIPPED): '// Disallowed post 0.4.25\n"\✅"\n' # (0..33) diff --git a/crates/solidity/testing/snapshots/cst_output/StringLiteral/escape_arbitrary_unicode/input.sol b/crates/solidity/testing/snapshots/cst_output/StringLiteral/escape_arbitrary_unicode/input.sol new file mode 100644 index 0000000000..16e114a848 --- /dev/null +++ b/crates/solidity/testing/snapshots/cst_output/StringLiteral/escape_arbitrary_unicode/input.sol @@ -0,0 +1,2 @@ +// Disallowed post 0.4.25 +"\✅" diff --git a/crates/solidity/testing/snapshots/cst_output/StringLiteral/escape_ascii/generated/0.4.11-success.yml b/crates/solidity/testing/snapshots/cst_output/StringLiteral/escape_ascii/generated/0.4.11-success.yml new file mode 100644 index 0000000000..a714c11932 --- /dev/null +++ b/crates/solidity/testing/snapshots/cst_output/StringLiteral/escape_ascii/generated/0.4.11-success.yml @@ -0,0 +1,11 @@ +# This file is generated automatically by infrastructure scripts. Please don't edit by hand. + +Source: > + 1 │ "\n" │ 0..4 + +Errors: [] + +Tree: + - (StringLiteral): # '"\n"\n' (0..5) + - (variant꞉ DoubleQuotedStringLiteral): '"\n"' # (0..4) + - (trailing_trivia꞉ EndOfLine): "\n" # (4..5) diff --git a/crates/solidity/testing/snapshots/cst_output/StringLiteral/escape_ascii/input.sol b/crates/solidity/testing/snapshots/cst_output/StringLiteral/escape_ascii/input.sol new file mode 100644 index 0000000000..a6edaba19b --- /dev/null +++ b/crates/solidity/testing/snapshots/cst_output/StringLiteral/escape_ascii/input.sol @@ -0,0 +1 @@ +"\n" diff --git a/crates/solidity/testing/snapshots/cst_output/StringLiteral/escape_hex/generated/0.4.11-success.yml b/crates/solidity/testing/snapshots/cst_output/StringLiteral/escape_hex/generated/0.4.11-success.yml new file mode 100644 index 0000000000..1954ed03f1 --- /dev/null +++ b/crates/solidity/testing/snapshots/cst_output/StringLiteral/escape_hex/generated/0.4.11-success.yml @@ -0,0 +1,11 @@ +# This file is generated automatically by infrastructure scripts. Please don't edit by hand. + +Source: > + 1 │ "\x0a" │ 0..6 + +Errors: [] + +Tree: + - (StringLiteral): # '"\x0a"\n' (0..7) + - (variant꞉ DoubleQuotedStringLiteral): '"\x0a"' # (0..6) + - (trailing_trivia꞉ EndOfLine): "\n" # (6..7) diff --git a/crates/solidity/testing/snapshots/cst_output/StringLiteral/escape_hex/input.sol b/crates/solidity/testing/snapshots/cst_output/StringLiteral/escape_hex/input.sol new file mode 100644 index 0000000000..7e7d55dfb5 --- /dev/null +++ b/crates/solidity/testing/snapshots/cst_output/StringLiteral/escape_hex/input.sol @@ -0,0 +1 @@ +"\x0a" diff --git a/crates/solidity/testing/snapshots/cst_output/StringLiteral/escape_hex_invalid/generated/0.4.11-failure.yml b/crates/solidity/testing/snapshots/cst_output/StringLiteral/escape_hex_invalid/generated/0.4.11-failure.yml new file mode 100644 index 0000000000..bb1094026d --- /dev/null +++ b/crates/solidity/testing/snapshots/cst_output/StringLiteral/escape_hex_invalid/generated/0.4.11-failure.yml @@ -0,0 +1,17 @@ +# This file is generated automatically by infrastructure scripts. Please don't edit by hand. + +Source: > + 1 │ "\x1" │ 0..5 + +Errors: # 1 total + - > + Error: Expected DoubleQuotedStringLiteral or SingleQuotedStringLiteral. + ╭─[crates/solidity/testing/snapshots/cst_output/StringLiteral/escape_hex_invalid/input.sol:1:1] + │ + 1 │ "\x1" + │ ───┬── + │ ╰──── Error occurred here. + ───╯ + +Tree: + - (SKIPPED): '"\x1"\n' # (0..6) diff --git a/crates/solidity/testing/snapshots/cst_output/StringLiteral/escape_hex_invalid/input.sol b/crates/solidity/testing/snapshots/cst_output/StringLiteral/escape_hex_invalid/input.sol new file mode 100644 index 0000000000..dcc5589d27 --- /dev/null +++ b/crates/solidity/testing/snapshots/cst_output/StringLiteral/escape_hex_invalid/input.sol @@ -0,0 +1 @@ +"\x1" diff --git a/crates/solidity/testing/snapshots/cst_output/StringLiteral/escape_unicode/generated/0.4.11-success.yml b/crates/solidity/testing/snapshots/cst_output/StringLiteral/escape_unicode/generated/0.4.11-success.yml new file mode 100644 index 0000000000..65ad4e4bd3 --- /dev/null +++ b/crates/solidity/testing/snapshots/cst_output/StringLiteral/escape_unicode/generated/0.4.11-success.yml @@ -0,0 +1,11 @@ +# This file is generated automatically by infrastructure scripts. Please don't edit by hand. + +Source: > + 1 │ "\u263A" │ 0..8 + +Errors: [] + +Tree: + - (StringLiteral): # '"\u263A"\n' (0..9) + - (variant꞉ DoubleQuotedStringLiteral): '"\u263A"' # (0..8) + - (trailing_trivia꞉ EndOfLine): "\n" # (8..9) diff --git a/crates/solidity/testing/snapshots/cst_output/StringLiteral/escape_unicode/input.sol b/crates/solidity/testing/snapshots/cst_output/StringLiteral/escape_unicode/input.sol new file mode 100644 index 0000000000..927cb0f99c --- /dev/null +++ b/crates/solidity/testing/snapshots/cst_output/StringLiteral/escape_unicode/input.sol @@ -0,0 +1 @@ +"\u263A" diff --git a/crates/solidity/testing/snapshots/cst_output/StringLiteral/escape_unicode_invalid/generated/0.4.11-failure.yml b/crates/solidity/testing/snapshots/cst_output/StringLiteral/escape_unicode_invalid/generated/0.4.11-failure.yml new file mode 100644 index 0000000000..5ba9d6169e --- /dev/null +++ b/crates/solidity/testing/snapshots/cst_output/StringLiteral/escape_unicode_invalid/generated/0.4.11-failure.yml @@ -0,0 +1,17 @@ +# This file is generated automatically by infrastructure scripts. Please don't edit by hand. + +Source: > + 1 │ "\u123" │ 0..7 + +Errors: # 1 total + - > + Error: Expected DoubleQuotedStringLiteral or SingleQuotedStringLiteral. + ╭─[crates/solidity/testing/snapshots/cst_output/StringLiteral/escape_unicode_invalid/input.sol:1:1] + │ + 1 │ "\u123" + │ ────┬─── + │ ╰───── Error occurred here. + ───╯ + +Tree: + - (SKIPPED): '"\u123"\n' # (0..8) diff --git a/crates/solidity/testing/snapshots/cst_output/StringLiteral/escape_unicode_invalid/input.sol b/crates/solidity/testing/snapshots/cst_output/StringLiteral/escape_unicode_invalid/input.sol new file mode 100644 index 0000000000..8eb3920a4b --- /dev/null +++ b/crates/solidity/testing/snapshots/cst_output/StringLiteral/escape_unicode_invalid/input.sol @@ -0,0 +1 @@ +"\u123" From e94656b0bcdedf806a8f576397914853274a647c Mon Sep 17 00:00:00 2001 From: Igor Matuszewski Date: Wed, 10 Apr 2024 16:46:10 +0200 Subject: [PATCH 6/9] Add another contract to the sanctuary blocklist (#933) See https://github.com/NomicFoundation/slang/pull/921#issuecomment-2046952672 --- crates/solidity/testing/sanctuary/src/tests.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/crates/solidity/testing/sanctuary/src/tests.rs b/crates/solidity/testing/sanctuary/src/tests.rs index 4c94e46982..afd24bef5e 100644 --- a/crates/solidity/testing/sanctuary/src/tests.rs +++ b/crates/solidity/testing/sanctuary/src/tests.rs @@ -149,6 +149,9 @@ fn uses_exotic_parser_bug(file: &Path) -> bool { // 0.4.18: // Accepts unfinished multi-line comments at the end of the file: // Fixed in 0.4.25: https://github.com/ethereum/solidity/pull/4937 "ethereum/contracts/mainnet/7d/7d81c361d6ac60634117dd81ab1b01b8dc795a9d_LILITHCOIN.sol", + // 0.8.15: Relies on invalidly accepting `indexed indexed` in the event declaration: + // Fixed in 0.8.18: https://github.com/ethereum/solidity/pull/13816 + "ethereum/contracts/mainnet/d4/d4559E5F507eD935F19208A5D50637898c192Ab3_Factory.sol", ]; CONTRACTS_WITH_EXOTIC_PARSER_BUGS From c625d22d2b84df5db797fd3cfc199751e22c4071 Mon Sep 17 00:00:00 2001 From: Omar Tawfik <15987992+OmarTawfik@users.noreply.github.com> Date: Thu, 11 Apr 2024 03:04:13 +0200 Subject: [PATCH 7/9] fix mkdocs broken links (#932) - added index pages for sub-directories, with the contents of that directory. - turned on more strict link checking, introduced in `mkdocs@1.5` - fixed the few broken links here and there. --- .../codegen/spec/src/generators/navigation.rs | 111 ++++++++++++++---- crates/codegen/spec/src/lib.rs | 48 ++++---- crates/infra/cli/src/toolchains/mkdocs/mod.rs | 1 + .../docs/01-file-structure/06-trivia.md | 2 +- .../public/{NAV.md => .navigation.md} | 1 + .../public/01-file-structure/.navigation.md | 12 ++ .../01-file-structure/{NAV.md => index.md} | 2 + .../public/02-definitions/.navigation.md | 15 +++ .../02-definitions/{NAV.md => index.md} | 2 + .../generated/public/03-types/.navigation.md | 5 + .../public/03-types/{NAV.md => index.md} | 2 + .../public/04-statements/.navigation.md | 7 ++ .../public/04-statements/{NAV.md => index.md} | 2 + .../public/05-expressions/.navigation.md | 9 ++ .../05-expressions/{NAV.md => index.md} | 2 + .../generated/public/06-yul/.navigation.md | 6 + .../public/06-yul/{NAV.md => index.md} | 2 + .../outputs/spec/generated/public/index.md | 11 ++ documentation/mkdocs.yml | 15 ++- .../public/{NAV.md => .navigation.md} | 0 .../internals/{NAV.md => .navigation.md} | 1 + .../internals/design-docs/.navigation.md | 2 + .../design-docs/{NAV.md => index.md} | 2 + documentation/public/internals/index.md | 5 + .../user-guide/{NAV.md => .navigation.md} | 1 + documentation/public/user-guide/index.md | 6 + .../public/user-guide/introduction.md | 2 +- .../user-guide/npm-package/.navigation.md | 5 + .../npm-package/{NAV.md => index.md} | 2 + .../user-guide/rust-crate/.navigation.md | 5 + .../rust-crate/{NAV.md => index.md} | 2 + 31 files changed, 240 insertions(+), 48 deletions(-) rename crates/solidity/outputs/spec/generated/public/{NAV.md => .navigation.md} (89%) create mode 100644 crates/solidity/outputs/spec/generated/public/01-file-structure/.navigation.md rename crates/solidity/outputs/spec/generated/public/01-file-structure/{NAV.md => index.md} (96%) create mode 100644 crates/solidity/outputs/spec/generated/public/02-definitions/.navigation.md rename crates/solidity/outputs/spec/generated/public/02-definitions/{NAV.md => index.md} (97%) create mode 100644 crates/solidity/outputs/spec/generated/public/03-types/.navigation.md rename crates/solidity/outputs/spec/generated/public/03-types/{NAV.md => index.md} (94%) create mode 100644 crates/solidity/outputs/spec/generated/public/04-statements/.navigation.md rename crates/solidity/outputs/spec/generated/public/04-statements/{NAV.md => index.md} (94%) create mode 100644 crates/solidity/outputs/spec/generated/public/05-expressions/.navigation.md rename crates/solidity/outputs/spec/generated/public/05-expressions/{NAV.md => index.md} (95%) create mode 100644 crates/solidity/outputs/spec/generated/public/06-yul/.navigation.md rename crates/solidity/outputs/spec/generated/public/06-yul/{NAV.md => index.md} (96%) create mode 100644 crates/solidity/outputs/spec/generated/public/index.md rename documentation/public/{NAV.md => .navigation.md} (100%) rename documentation/public/internals/{NAV.md => .navigation.md} (81%) create mode 100644 documentation/public/internals/design-docs/.navigation.md rename documentation/public/internals/design-docs/{NAV.md => index.md} (79%) create mode 100644 documentation/public/internals/index.md rename documentation/public/user-guide/{NAV.md => .navigation.md} (82%) create mode 100644 documentation/public/user-guide/index.md create mode 100644 documentation/public/user-guide/npm-package/.navigation.md rename documentation/public/user-guide/npm-package/{NAV.md => index.md} (91%) create mode 100644 documentation/public/user-guide/rust-crate/.navigation.md rename documentation/public/user-guide/rust-crate/{NAV.md => index.md} (92%) diff --git a/crates/codegen/spec/src/generators/navigation.rs b/crates/codegen/spec/src/generators/navigation.rs index 192c09b798..ef941fccbc 100644 --- a/crates/codegen/spec/src/generators/navigation.rs +++ b/crates/codegen/spec/src/generators/navigation.rs @@ -1,37 +1,102 @@ use std::fmt::Write; +use std::path::Path; use anyhow::Result; +use infra_utils::codegen::CodegenWriteOnly; -use crate::model::SpecModel; +pub enum SpecEntry { + Dir(SpecDir), + Page(SpecPage), +} -pub fn generate_top_navigation(model: &SpecModel) -> Result { - let mut buffer = String::new(); +pub struct SpecDir { + title: String, + slug: String, + entries: Vec, +} - writeln!(buffer, "- [Supported Versions](./supported-versions.md)")?; +impl SpecDir { + pub fn new(title: impl Into, slug: impl Into) -> Self { + SpecDir { + title: title.into(), + slug: slug.into(), + entries: vec![], + } + } - for section in &model.sections { - writeln!( - buffer, - "- [{section_title}](./{section_slug}/)", - section_title = section.title, - section_slug = section.slug, - )?; + pub fn add_dir(&mut self, dir: SpecDir) { + self.entries.push(SpecEntry::Dir(dir)); } - Ok(buffer) -} + pub fn add_page(&mut self, page: SpecPage) { + self.entries.push(SpecEntry::Page(page)); + } + + pub fn write_to_disk(&self, codegen: &mut CodegenWriteOnly, parent_dir: &Path) -> Result<()> { + let SpecDir { + title, + slug, + entries, + } = self; + + let current_dir = parent_dir.join(slug); + + let mut index = String::new(); + writeln!(index, "# {title}")?; + writeln!(index)?; -pub fn generate_section_navigation(model: &SpecModel, section_index: usize) -> Result { - let mut buffer = String::new(); + let mut navigation = String::new(); + writeln!(navigation, "- [{title}](./index.md)")?; - for topic in &model.sections[section_index].topics { - writeln!( - buffer, - "- [{topic_title}](./{topic_slug}.md)", - topic_title = topic.title, - topic_slug = topic.slug, - )?; + for entry in entries { + match entry { + SpecEntry::Dir( + child @ SpecDir { + title: child_title, + slug: child_slug, + entries: _, + }, + ) => { + writeln!(index, "- [{child_title}](./{child_slug}/index.md)")?; + writeln!(navigation, "- [{child_title}](./{child_slug}/)")?; + + child.write_to_disk(codegen, ¤t_dir)?; + } + SpecEntry::Page(SpecPage { + title: child_title, + slug: child_slug, + contents, + }) => { + writeln!(index, "- [{child_title}](./{child_slug}.md)")?; + writeln!(navigation, "- [{child_title}](./{child_slug}.md)")?; + + codegen.write_file(current_dir.join(format!("{child_slug}.md")), contents)?; + } + } + } + + codegen.write_file(current_dir.join("index.md"), index)?; + codegen.write_file(current_dir.join(".navigation.md"), navigation)?; + Ok(()) } +} - Ok(buffer) +pub struct SpecPage { + title: String, + slug: String, + contents: String, +} + +impl SpecPage { + pub fn new( + title: impl Into, + slug: impl Into, + contents: impl Into, + ) -> Self { + SpecPage { + title: title.into(), + slug: slug.into(), + contents: contents.into(), + } + } } diff --git a/crates/codegen/spec/src/lib.rs b/crates/codegen/spec/src/lib.rs index a5666e548d..611d6109f6 100644 --- a/crates/codegen/spec/src/lib.rs +++ b/crates/codegen/spec/src/lib.rs @@ -17,7 +17,7 @@ use codegen_language_definition::model::Language; use infra_utils::codegen::CodegenWriteOnly; use crate::generators::grammar_ebnf::generate_grammar_ebnf; -use crate::generators::navigation::{generate_section_navigation, generate_top_navigation}; +use crate::generators::navigation::{SpecDir, SpecPage}; use crate::generators::supported_versions::generate_supported_versions; use crate::generators::topic_page::generate_topic_page; use crate::model::SpecModel; @@ -30,39 +30,43 @@ impl Spec { let mut codegen = CodegenWriteOnly::new()?; + let public_dir = Self::generate_public_dir(&model)?; + public_dir.write_to_disk(&mut codegen, output_dir)?; + codegen.write_file( output_dir.join("grammar.ebnf"), generate_grammar_ebnf(&model)?, )?; - codegen.write_file( - output_dir.join("public/NAV.md"), - generate_top_navigation(&model)?, - )?; + Ok(()) + } - codegen.write_file( - output_dir.join("public/supported-versions.md"), - generate_supported_versions(&model)?, - )?; + fn generate_public_dir(model: &SpecModel) -> Result { + let mut public_dir = SpecDir::new( + format!("{name} Specification", name = model.language.name), + "public", + ); - for (section_index, section) in model.sections.iter().enumerate() { - let section_slug = §ion.slug; + public_dir.add_page(SpecPage::new( + "Supported Versions", + "supported-versions", + generate_supported_versions(model)?, + )); - codegen.write_file( - output_dir.join(format!("public/{section_slug}/NAV.md")), - generate_section_navigation(&model, section_index)?, - )?; + for (section_index, section) in model.sections.iter().enumerate() { + let mut section_dir = SpecDir::new(§ion.title, §ion.slug); for (topic_index, topic) in section.topics.iter().enumerate() { - let topic_slug = &topic.slug; - - codegen.write_file( - output_dir.join(format!("public/{section_slug}/{topic_slug}.md")), - generate_topic_page(&model, section_index, topic_index)?, - )?; + section_dir.add_page(SpecPage::new( + &topic.title, + &topic.slug, + generate_topic_page(model, section_index, topic_index)?, + )); } + + public_dir.add_dir(section_dir); } - Ok(()) + Ok(public_dir) } } diff --git a/crates/infra/cli/src/toolchains/mkdocs/mod.rs b/crates/infra/cli/src/toolchains/mkdocs/mod.rs index f7b9063d6c..2565891d6e 100644 --- a/crates/infra/cli/src/toolchains/mkdocs/mod.rs +++ b/crates/infra/cli/src/toolchains/mkdocs/mod.rs @@ -21,6 +21,7 @@ impl Mkdocs { mkdocs_command() .arg("serve") + .flag("--clean") .flag("--watch-theme") .property("--dev-addr", format!("localhost:{PORT}")) .run() diff --git a/crates/solidity/inputs/language/docs/01-file-structure/06-trivia.md b/crates/solidity/inputs/language/docs/01-file-structure/06-trivia.md index e50880e2f4..b721740583 100644 --- a/crates/solidity/inputs/language/docs/01-file-structure/06-trivia.md +++ b/crates/solidity/inputs/language/docs/01-file-structure/06-trivia.md @@ -27,6 +27,6 @@ Additionally, there is another type of comment called a NatSpec comment. They ar contract MyContract {} ``` -Please see the [NatSpec Format](../06-nat-spec-format/) section for further information. +Please see the [NatSpec Format](./07-nat-spec-format.md) section for further information. --8<-- "crates/solidity/inputs/language/snippets/under-construction.md" diff --git a/crates/solidity/outputs/spec/generated/public/NAV.md b/crates/solidity/outputs/spec/generated/public/.navigation.md similarity index 89% rename from crates/solidity/outputs/spec/generated/public/NAV.md rename to crates/solidity/outputs/spec/generated/public/.navigation.md index d0cbaaf456..6c219e8c62 100644 --- a/crates/solidity/outputs/spec/generated/public/NAV.md +++ b/crates/solidity/outputs/spec/generated/public/.navigation.md @@ -1,5 +1,6 @@ +- [Solidity Specification](./index.md) - [Supported Versions](./supported-versions.md) - [1. File Structure](./01-file-structure/) - [2. Definitions](./02-definitions/) diff --git a/crates/solidity/outputs/spec/generated/public/01-file-structure/.navigation.md b/crates/solidity/outputs/spec/generated/public/01-file-structure/.navigation.md new file mode 100644 index 0000000000..0a0d53812b --- /dev/null +++ b/crates/solidity/outputs/spec/generated/public/01-file-structure/.navigation.md @@ -0,0 +1,12 @@ + + +- [1. File Structure](./index.md) +- [1.1. License Specifiers](./01-license-specifiers.md) +- [1.2. Source Unit](./02-source-unit.md) +- [1.3. Pragma Directives](./03-pragma-directives.md) +- [1.4. Import Directives](./04-import-directives.md) +- [1.5. Using Directives](./05-using-directives.md) +- [1.6. Trivia](./06-trivia.md) +- [1.7. Nat Spec Format](./07-nat-spec-format.md) +- [1.8. Keywords](./08-keywords.md) +- [1.9. Punctuation](./09-punctuation.md) diff --git a/crates/solidity/outputs/spec/generated/public/01-file-structure/NAV.md b/crates/solidity/outputs/spec/generated/public/01-file-structure/index.md similarity index 96% rename from crates/solidity/outputs/spec/generated/public/01-file-structure/NAV.md rename to crates/solidity/outputs/spec/generated/public/01-file-structure/index.md index 9c60a0973a..ee31da8ef2 100644 --- a/crates/solidity/outputs/spec/generated/public/01-file-structure/NAV.md +++ b/crates/solidity/outputs/spec/generated/public/01-file-structure/index.md @@ -1,5 +1,7 @@ +# 1. File Structure + - [1.1. License Specifiers](./01-license-specifiers.md) - [1.2. Source Unit](./02-source-unit.md) - [1.3. Pragma Directives](./03-pragma-directives.md) diff --git a/crates/solidity/outputs/spec/generated/public/02-definitions/.navigation.md b/crates/solidity/outputs/spec/generated/public/02-definitions/.navigation.md new file mode 100644 index 0000000000..47da427604 --- /dev/null +++ b/crates/solidity/outputs/spec/generated/public/02-definitions/.navigation.md @@ -0,0 +1,15 @@ + + +- [2. Definitions](./index.md) +- [2.1. Contracts](./01-contracts.md) +- [2.2. Interfaces](./02-interfaces.md) +- [2.3. Libraries](./03-libraries.md) +- [2.4. Structs](./04-structs.md) +- [2.5. Enums](./05-enums.md) +- [2.6. Constants](./06-constants.md) +- [2.7. State Variables](./07-state-variables.md) +- [2.8. Functions](./08-functions.md) +- [2.9. Modifiers](./09-modifiers.md) +- [2.10. Events](./10-events.md) +- [2.11. User Defined Value Types](./11-user-defined-value-types.md) +- [2.12. Errors](./12-errors.md) diff --git a/crates/solidity/outputs/spec/generated/public/02-definitions/NAV.md b/crates/solidity/outputs/spec/generated/public/02-definitions/index.md similarity index 97% rename from crates/solidity/outputs/spec/generated/public/02-definitions/NAV.md rename to crates/solidity/outputs/spec/generated/public/02-definitions/index.md index cf5fb1ab76..61264d6fbf 100644 --- a/crates/solidity/outputs/spec/generated/public/02-definitions/NAV.md +++ b/crates/solidity/outputs/spec/generated/public/02-definitions/index.md @@ -1,5 +1,7 @@ +# 2. Definitions + - [2.1. Contracts](./01-contracts.md) - [2.2. Interfaces](./02-interfaces.md) - [2.3. Libraries](./03-libraries.md) diff --git a/crates/solidity/outputs/spec/generated/public/03-types/.navigation.md b/crates/solidity/outputs/spec/generated/public/03-types/.navigation.md new file mode 100644 index 0000000000..c64ad23ceb --- /dev/null +++ b/crates/solidity/outputs/spec/generated/public/03-types/.navigation.md @@ -0,0 +1,5 @@ + + +- [3. Types](./index.md) +- [3.1. Advanced Types](./01-advanced-types.md) +- [3.2. Elementary Types](./02-elementary-types.md) diff --git a/crates/solidity/outputs/spec/generated/public/03-types/NAV.md b/crates/solidity/outputs/spec/generated/public/03-types/index.md similarity index 94% rename from crates/solidity/outputs/spec/generated/public/03-types/NAV.md rename to crates/solidity/outputs/spec/generated/public/03-types/index.md index baf969c9bb..a8c09e3e0c 100644 --- a/crates/solidity/outputs/spec/generated/public/03-types/NAV.md +++ b/crates/solidity/outputs/spec/generated/public/03-types/index.md @@ -1,4 +1,6 @@ +# 3. Types + - [3.1. Advanced Types](./01-advanced-types.md) - [3.2. Elementary Types](./02-elementary-types.md) diff --git a/crates/solidity/outputs/spec/generated/public/04-statements/.navigation.md b/crates/solidity/outputs/spec/generated/public/04-statements/.navigation.md new file mode 100644 index 0000000000..8f03e1bfb7 --- /dev/null +++ b/crates/solidity/outputs/spec/generated/public/04-statements/.navigation.md @@ -0,0 +1,7 @@ + + +- [4. Statements](./index.md) +- [4.1. Blocks](./01-blocks.md) +- [4.2. Declaration Statements](./02-declaration-statements.md) +- [4.3. Control Statements](./03-control-statements.md) +- [4.4. Error Handling](./04-error-handling.md) diff --git a/crates/solidity/outputs/spec/generated/public/04-statements/NAV.md b/crates/solidity/outputs/spec/generated/public/04-statements/index.md similarity index 94% rename from crates/solidity/outputs/spec/generated/public/04-statements/NAV.md rename to crates/solidity/outputs/spec/generated/public/04-statements/index.md index e98adfebda..25a4847f19 100644 --- a/crates/solidity/outputs/spec/generated/public/04-statements/NAV.md +++ b/crates/solidity/outputs/spec/generated/public/04-statements/index.md @@ -1,5 +1,7 @@ +# 4. Statements + - [4.1. Blocks](./01-blocks.md) - [4.2. Declaration Statements](./02-declaration-statements.md) - [4.3. Control Statements](./03-control-statements.md) diff --git a/crates/solidity/outputs/spec/generated/public/05-expressions/.navigation.md b/crates/solidity/outputs/spec/generated/public/05-expressions/.navigation.md new file mode 100644 index 0000000000..9a4c8dd821 --- /dev/null +++ b/crates/solidity/outputs/spec/generated/public/05-expressions/.navigation.md @@ -0,0 +1,9 @@ + + +- [5. Expressions](./index.md) +- [5.1. Base Expressions](./01-base-expressions.md) +- [5.2. Function Calls](./02-function-calls.md) +- [5.3. Primary Expressions](./03-primary-expressions.md) +- [5.4. Numbers](./04-numbers.md) +- [5.5. Strings](./05-strings.md) +- [5.6. Identifiers](./06-identifiers.md) diff --git a/crates/solidity/outputs/spec/generated/public/05-expressions/NAV.md b/crates/solidity/outputs/spec/generated/public/05-expressions/index.md similarity index 95% rename from crates/solidity/outputs/spec/generated/public/05-expressions/NAV.md rename to crates/solidity/outputs/spec/generated/public/05-expressions/index.md index 5ee485f1ad..a7b1e4221a 100644 --- a/crates/solidity/outputs/spec/generated/public/05-expressions/NAV.md +++ b/crates/solidity/outputs/spec/generated/public/05-expressions/index.md @@ -1,5 +1,7 @@ +# 5. Expressions + - [5.1. Base Expressions](./01-base-expressions.md) - [5.2. Function Calls](./02-function-calls.md) - [5.3. Primary Expressions](./03-primary-expressions.md) diff --git a/crates/solidity/outputs/spec/generated/public/06-yul/.navigation.md b/crates/solidity/outputs/spec/generated/public/06-yul/.navigation.md new file mode 100644 index 0000000000..ceefe0e228 --- /dev/null +++ b/crates/solidity/outputs/spec/generated/public/06-yul/.navigation.md @@ -0,0 +1,6 @@ + + +- [6. Yul](./index.md) +- [6.1. Yul Statements](./01-yul-statements.md) +- [6.2. Yul Expressions](./02-yul-expressions.md) +- [6.3. Yul Keywords](./03-yul-keywords.md) diff --git a/crates/solidity/outputs/spec/generated/public/06-yul/NAV.md b/crates/solidity/outputs/spec/generated/public/06-yul/index.md similarity index 96% rename from crates/solidity/outputs/spec/generated/public/06-yul/NAV.md rename to crates/solidity/outputs/spec/generated/public/06-yul/index.md index 3bfa896051..5c995bff7a 100644 --- a/crates/solidity/outputs/spec/generated/public/06-yul/NAV.md +++ b/crates/solidity/outputs/spec/generated/public/06-yul/index.md @@ -1,5 +1,7 @@ +# 6. Yul + - [6.1. Yul Statements](./01-yul-statements.md) - [6.2. Yul Expressions](./02-yul-expressions.md) - [6.3. Yul Keywords](./03-yul-keywords.md) diff --git a/crates/solidity/outputs/spec/generated/public/index.md b/crates/solidity/outputs/spec/generated/public/index.md new file mode 100644 index 0000000000..72f9af4838 --- /dev/null +++ b/crates/solidity/outputs/spec/generated/public/index.md @@ -0,0 +1,11 @@ + + +# Solidity Specification + +- [Supported Versions](./supported-versions.md) +- [1. File Structure](./01-file-structure/index.md) +- [2. Definitions](./02-definitions/index.md) +- [3. Types](./03-types/index.md) +- [4. Statements](./04-statements/index.md) +- [5. Expressions](./05-expressions/index.md) +- [6. Yul](./06-yul/index.md) diff --git a/documentation/mkdocs.yml b/documentation/mkdocs.yml index c6094c920b..0aff27f51c 100644 --- a/documentation/mkdocs.yml +++ b/documentation/mkdocs.yml @@ -1,3 +1,5 @@ +# More Info: https://www.mkdocs.org/user-guide/configuration/ + # # Configuration: # @@ -10,11 +12,22 @@ site_description: > repo_name: "NomicFoundation/slang" repo_url: "https://github.com/NomicFoundation/slang" +site_url: "https://NomicFoundation.github.io/slang" edit_uri: "edit/main/documentation/public" docs_dir: "./public" site_dir: "./target/site" # _SLANG_MKDOCS_DOCUMENTATION_SITE_DIR_ (keep in sync) +validation: + nav: + absolute_links: "warn" + not_found: "warn" + omitted_files: "warn" + links: + absolute_links: "warn" + not_found: "warn" + unrecognized_links: "warn" + # # Footer: # @@ -78,7 +91,7 @@ markdown_extensions: plugins: - "search" - "literate-nav": - nav_file: "NAV.md" + nav_file: ".navigation.md" # use a dot file name, to be excluded from public pages markdown_extensions: [] - "minify": minify_html: true diff --git a/documentation/public/NAV.md b/documentation/public/.navigation.md similarity index 100% rename from documentation/public/NAV.md rename to documentation/public/.navigation.md diff --git a/documentation/public/internals/NAV.md b/documentation/public/internals/.navigation.md similarity index 81% rename from documentation/public/internals/NAV.md rename to documentation/public/internals/.navigation.md index 3b905b2323..16a43f8cbc 100644 --- a/documentation/public/internals/NAV.md +++ b/documentation/public/internals/.navigation.md @@ -1,3 +1,4 @@ +- [Internals](./index.md) - [Repository Structure](./repository-structure.md) - [Development](./development.md) - [Design Docs](./design-docs/) diff --git a/documentation/public/internals/design-docs/.navigation.md b/documentation/public/internals/design-docs/.navigation.md new file mode 100644 index 0000000000..3907a4715c --- /dev/null +++ b/documentation/public/internals/design-docs/.navigation.md @@ -0,0 +1,2 @@ +- [Design Docs](./index.md) +- [Language Definition v2](./language-definition-v2.md) diff --git a/documentation/public/internals/design-docs/NAV.md b/documentation/public/internals/design-docs/index.md similarity index 79% rename from documentation/public/internals/design-docs/NAV.md rename to documentation/public/internals/design-docs/index.md index 415b5e4270..a8c59c640a 100644 --- a/documentation/public/internals/design-docs/NAV.md +++ b/documentation/public/internals/design-docs/index.md @@ -1 +1,3 @@ +# Design Docs + - [Language Definition v2](./language-definition-v2.md) diff --git a/documentation/public/internals/index.md b/documentation/public/internals/index.md new file mode 100644 index 0000000000..a2672cbd3e --- /dev/null +++ b/documentation/public/internals/index.md @@ -0,0 +1,5 @@ +# Internals + +- [Repository Structure](./repository-structure.md) +- [Development](./development.md) +- [Design Docs](./design-docs/index.md) diff --git a/documentation/public/user-guide/NAV.md b/documentation/public/user-guide/.navigation.md similarity index 82% rename from documentation/public/user-guide/NAV.md rename to documentation/public/user-guide/.navigation.md index 9dbc7ac6b6..0c20bcf8ac 100644 --- a/documentation/public/user-guide/NAV.md +++ b/documentation/public/user-guide/.navigation.md @@ -1,3 +1,4 @@ +- [User Guide](./index.md) - [Introduction](./introduction.md) - [Concepts](./concepts.md) - [Rust Crate](./rust-crate/) diff --git a/documentation/public/user-guide/index.md b/documentation/public/user-guide/index.md new file mode 100644 index 0000000000..c9d05fd788 --- /dev/null +++ b/documentation/public/user-guide/index.md @@ -0,0 +1,6 @@ +# User Guide + +- [Introduction](./introduction.md) +- [Concepts](./concepts.md) +- [Rust Crate](./rust-crate/index.md) +- [NPM Package](./npm-package/index.md) diff --git a/documentation/public/user-guide/introduction.md b/documentation/public/user-guide/introduction.md index 3ae9be362a..fef5e7fd72 100644 --- a/documentation/public/user-guide/introduction.md +++ b/documentation/public/user-guide/introduction.md @@ -18,7 +18,7 @@ The Solidity programming language has evolved quite a bit since its inception. S While it's good for a programming language to evolve and better serve the needs of its users, not being able to easily upgrade or re-deploy existing contracts poses a unique challenge. Developer tooling must be able to understand and consume older contracts that are still being used on the blockchain, written in older versions of Solidity. -Because of that, Slang must be able to reason about different versions of Solidity; how the language grammar, name binding rules, and semantics have changed across different versions. One of our goals is to document differences as part of our [Solidity Specification](../../solidity-specification/supported-versions/). +Because of that, Slang must be able to reason about different versions of Solidity; how the language grammar, name binding rules, and semantics have changed [across different versions](../solidity-specification/supported-versions.md). One of our goals is to document differences as part of our [Solidity Specification](../solidity-specification/index.md). This is why, instead of having to download separate versions of the tool for each Solidity version, you can access the Slang language APIs by simply specifying the Solidity version that you want to work with. diff --git a/documentation/public/user-guide/npm-package/.navigation.md b/documentation/public/user-guide/npm-package/.navigation.md new file mode 100644 index 0000000000..fdab4f34ca --- /dev/null +++ b/documentation/public/user-guide/npm-package/.navigation.md @@ -0,0 +1,5 @@ +- [NPM Package](./index.md) +- [Installation](./installation.md) +- [Using the Parser](./using-the-parser.md) +- [Using the Cursor](./using-the-cursor.md) +- [Using the AST](./using-the-ast.md) diff --git a/documentation/public/user-guide/npm-package/NAV.md b/documentation/public/user-guide/npm-package/index.md similarity index 91% rename from documentation/public/user-guide/npm-package/NAV.md rename to documentation/public/user-guide/npm-package/index.md index 5454a7ade8..c1ba707e33 100644 --- a/documentation/public/user-guide/npm-package/NAV.md +++ b/documentation/public/user-guide/npm-package/index.md @@ -1,3 +1,5 @@ +# NPM Package + - [Installation](./installation.md) - [Using the Parser](./using-the-parser.md) - [Using the Cursor](./using-the-cursor.md) diff --git a/documentation/public/user-guide/rust-crate/.navigation.md b/documentation/public/user-guide/rust-crate/.navigation.md new file mode 100644 index 0000000000..10abd23b24 --- /dev/null +++ b/documentation/public/user-guide/rust-crate/.navigation.md @@ -0,0 +1,5 @@ +- [Rust Crate](./index.md) +- [Installation](./installation.md) +- [Using the CLI](./using-the-cli.md) +- [Using the Parser](./using-the-parser.md) +- [Using the Cursor](./using-the-cursor.md) diff --git a/documentation/public/user-guide/rust-crate/NAV.md b/documentation/public/user-guide/rust-crate/index.md similarity index 92% rename from documentation/public/user-guide/rust-crate/NAV.md rename to documentation/public/user-guide/rust-crate/index.md index 77d792714f..18c12f9510 100644 --- a/documentation/public/user-guide/rust-crate/NAV.md +++ b/documentation/public/user-guide/rust-crate/index.md @@ -1,3 +1,5 @@ +# Rust Crate + - [Installation](./installation.md) - [Using the CLI](./using-the-cli.md) - [Using the Parser](./using-the-parser.md) From 29febae76790700d1e035c782ca04f2212c06852 Mon Sep 17 00:00:00 2001 From: Igor Matuszewski Date: Thu, 11 Apr 2024 10:41:24 +0200 Subject: [PATCH 8/9] fixup: Silence unused warnings on non-GNU systems in glibc.rs (#931) Fixes warnings on non-GNU systems introduced with #909 Instead of doing the conditional compilation for the remaining items that are only used for this check, the routines will be compiled in on the other systems for simplicity but only used inside a host GNU system. The alternative is to pepper `#[cfg(target_env = "gnu")]` everywhere but IMO it'd hurt readability and we're talking about the `infra` CLI, should is only executed as part of the local development, so this should be an acceptable trade-off. This was not caught in the CI as we only use a GNU host there, so naturally all of the code was compiled in. Tested with `infra ci` and `infra publish npm --dry-run` on macOS and a Linux GNU. --- crates/infra/cli/src/toolchains/napi/cli.rs | 1 - crates/infra/cli/src/toolchains/napi/glibc.rs | 12 ++++++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/crates/infra/cli/src/toolchains/napi/cli.rs b/crates/infra/cli/src/toolchains/napi/cli.rs index 3a9453a75b..9c9fdb3a2d 100644 --- a/crates/infra/cli/src/toolchains/napi/cli.rs +++ b/crates/infra/cli/src/toolchains/napi/cli.rs @@ -62,7 +62,6 @@ impl NapiCli { command.run()?; - #[cfg(target_env = "gnu")] glibc::ensure_correct_glibc_for_vscode(resolver, output_dir, target)?; let mut source_files = vec![]; diff --git a/crates/infra/cli/src/toolchains/napi/glibc.rs b/crates/infra/cli/src/toolchains/napi/glibc.rs index 1279ad6c25..7fbd26ee34 100644 --- a/crates/infra/cli/src/toolchains/napi/glibc.rs +++ b/crates/infra/cli/src/toolchains/napi/glibc.rs @@ -62,7 +62,6 @@ impl PartialEq for ZigGlibcVersion { } } -#[cfg(target_env = "gnu")] /// On a GNU host, cross-compile the native addon to only target the oldest supported GLIBC version by VS Code. /// /// By default, compiling on the host targets the host's GLIBC version, which is usually newer. @@ -75,6 +74,11 @@ pub fn ensure_correct_glibc_for_vscode( output_dir: &Path, target: &BuildTarget, ) -> Result<()> { + // This is only ever required when host-compiling on a GNU system. + if cfg!(not(target_env = "gnu")) { + return Ok(()); + } + let target_triple = match target { BuildTarget::ReleaseTarget(target) if target.ends_with("-linux-gnu") => target, _ => return Ok(()), @@ -130,8 +134,12 @@ pub fn ensure_correct_glibc_for_vscode( Ok(()) } -#[cfg(target_env = "gnu")] fn fetch_min_supported_glibc_version(lib_path: &str) -> Result { + assert!( + cfg!(target_env = "gnu"), + "This is only supported and expected to only ever run on a host GNU system." + ); + // # Note: `ldd` does not work reliably when inspecting cross-compiled ARM binaries on x86_64 let output = Command::new("objdump") .flag("-T") From ab3688bb99a60862c506566ac6122cd9c1155c57 Mon Sep 17 00:00:00 2001 From: Igor Matuszewski Date: Thu, 11 Apr 2024 11:24:36 +0200 Subject: [PATCH 9/9] Add debugging facilities to RuleNode/TokenNode exposed via N-API (#908) Closes #466 ## JSON serialization Adds the `toJSON` method to the RuleNode/TokenNode classes with the comment stating that it's unstable and for debugging purposes only. I explicitly didn't type it (it's a string) as I didn't want to publicly encode any assumptions about the shape of the data. We can discuss further what we want to explore as part of having pure data external interface (JSON) for Slang, whether that's exporting or importing JSON, but I'd consider this a separate issue as it requires more thought and design; the original issue, from what I understand, was primarily about improving the debugging/inspection experience. ## Debugger Adds hidden getter properties that is only eagerly evaluated by debugger; since it's a getter function, it shouldn't add overhead to the runtime but I have to admit, I didn't double-check that with numbers. It adds both `__children` and `__text`, allowing to quickly explore the tree structure recursively and also the enclosing text scope of the node: ### vscode-js-debug (built-in to VS Code) ![image](https://github.com/NomicFoundation/slang/assets/3093213/193702fa-02b6-4853-9dcd-8af58469cf23) ### Chrome DevTools for Node ![image](https://github.com/NomicFoundation/slang/assets/3093213/a7b81836-ad7e-495c-aded-ebcc48f3bb6b) --- .changeset/pink-bats-lie.md | 5 +++ .changeset/warm-maps-give.md | 5 +++ Cargo.lock | 3 ++ crates/codegen/parser/runtime/Cargo.toml | 3 +- .../parser/runtime/src/napi_interface/cst.rs | 45 ++++++++++++++++++- .../src/generated/napi_interface/cst.rs | 45 ++++++++++++++++++- .../slang_solidity_node_addon/Cargo.toml | 2 + .../npm/package/src/generated/index.d.ts | 12 ++++- .../src/generated/napi_interface/cst.rs | 45 ++++++++++++++++++- .../slang_testlang_node_addon/Cargo.toml | 2 + .../npm/package/src/generated/index.d.ts | 12 ++++- 11 files changed, 171 insertions(+), 8 deletions(-) create mode 100644 .changeset/pink-bats-lie.md create mode 100644 .changeset/warm-maps-give.md diff --git a/.changeset/pink-bats-lie.md b/.changeset/pink-bats-lie.md new file mode 100644 index 0000000000..50c4ac2a88 --- /dev/null +++ b/.changeset/pink-bats-lie.md @@ -0,0 +1,5 @@ +--- +"@nomicfoundation/slang": minor +--- + +Changed the cst.NodeType in TS to use more descriptive string values rather than 0/1 integers diff --git a/.changeset/warm-maps-give.md b/.changeset/warm-maps-give.md new file mode 100644 index 0000000000..808f1acf13 --- /dev/null +++ b/.changeset/warm-maps-give.md @@ -0,0 +1,5 @@ +--- +"@nomicfoundation/slang": minor +--- + +Add RuleNode/TokenNode::toJSON() in the TypeScript API diff --git a/Cargo.lock b/Cargo.lock index 83022c585d..362775360d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -403,6 +403,7 @@ dependencies = [ "napi-derive", "nom", "serde", + "serde_json", "strum", "strum_macros", ] @@ -1780,6 +1781,7 @@ dependencies = [ "nom", "semver", "serde", + "serde_json", "slang_solidity", "strum", "strum_macros", @@ -1814,6 +1816,7 @@ dependencies = [ "nom", "semver", "serde", + "serde_json", "slang_testlang", "strum", "strum_macros", diff --git a/crates/codegen/parser/runtime/Cargo.toml b/crates/codegen/parser/runtime/Cargo.toml index e7754f5aee..9fa7816a75 100644 --- a/crates/codegen/parser/runtime/Cargo.toml +++ b/crates/codegen/parser/runtime/Cargo.toml @@ -13,6 +13,7 @@ napi = { workspace = true, optional = true } napi-derive = { workspace = true, optional = true } nom = { workspace = true } serde = { workspace = true } +serde_json = { workspace = true, optional = true } strum = { workspace = true } strum_macros = { workspace = true } @@ -20,7 +21,7 @@ strum_macros = { workspace = true } # i.e `slang_solidity_node_addon`. [features] default = ["slang_napi_interfaces"] -slang_napi_interfaces = ["dep:napi", "dep:napi-derive"] +slang_napi_interfaces = ["dep:napi", "dep:napi-derive", "dep:serde_json"] [lints] workspace = true diff --git a/crates/codegen/parser/runtime/src/napi_interface/cst.rs b/crates/codegen/parser/runtime/src/napi_interface/cst.rs index 18e309851d..b46da02abf 100644 --- a/crates/codegen/parser/runtime/src/napi_interface/cst.rs +++ b/crates/codegen/parser/runtime/src/napi_interface/cst.rs @@ -9,7 +9,7 @@ use crate::napi_interface::{ RuleKind, RustNode, RustRuleNode, RustTextIndex, RustTokenNode, TokenKind, }; -#[napi(namespace = "cst")] +#[napi(namespace = "cst", string_enum)] pub enum NodeType { Rule, Token, @@ -83,10 +83,45 @@ impl RuleNode { .into() } + #[napi(catch_unwind, js_name = "toJSON")] + /// Serialize the token node to JSON. + pub fn to_json(&self) -> String { + serde_json::to_string(&self.0).unwrap() + } + #[napi(catch_unwind)] pub fn unparse(&self) -> String { self.0.clone().unparse() } + + // Expose the children as a hidden (non-enumerable, don't generate type definition) + // property that's eagerly evaluated (getter) for an inspected parent object in the debugger context. + #[napi( + enumerable = false, + configurable = false, + writable = false, + getter, + js_name = "__children", // Needed; otherwise, the property name would shadow `children`. + skip_typescript, + catch_unwind + )] + pub fn __children(&self) -> Vec> { + Self::children(self) + } + + // Similarly, expose the eagerly evaluated unparsed text in the debugger context. + #[napi( + enumerable = false, + configurable = false, + writable = false, + getter, + js_name = "__text", + skip_typescript, + catch_unwind + )] + pub fn __text(&self) -> String { + self.unparse() + } } #[napi(namespace = "cst")] @@ -122,6 +157,14 @@ impl TokenNode { self.0.text.clone() } + #[napi(catch_unwind, js_name = "toJSON")] + /// Serialize the token node to JSON. + /// + /// This method is intended for debugging purposes and may not be stable. + pub fn to_json(&self) -> String { + serde_json::to_string(&self.0).unwrap() + } + #[napi(ts_return_type = "cursor.Cursor", catch_unwind)] pub fn create_cursor( &self, diff --git a/crates/solidity/outputs/cargo/slang_solidity/src/generated/napi_interface/cst.rs b/crates/solidity/outputs/cargo/slang_solidity/src/generated/napi_interface/cst.rs index 20f0a13157..94b69f82d0 100644 --- a/crates/solidity/outputs/cargo/slang_solidity/src/generated/napi_interface/cst.rs +++ b/crates/solidity/outputs/cargo/slang_solidity/src/generated/napi_interface/cst.rs @@ -11,7 +11,7 @@ use crate::napi_interface::{ RuleKind, RustNode, RustRuleNode, RustTextIndex, RustTokenNode, TokenKind, }; -#[napi(namespace = "cst")] +#[napi(namespace = "cst", string_enum)] pub enum NodeType { Rule, Token, @@ -85,10 +85,45 @@ impl RuleNode { .into() } + #[napi(catch_unwind, js_name = "toJSON")] + /// Serialize the token node to JSON. + pub fn to_json(&self) -> String { + serde_json::to_string(&self.0).unwrap() + } + #[napi(catch_unwind)] pub fn unparse(&self) -> String { self.0.clone().unparse() } + + // Expose the children as a hidden (non-enumerable, don't generate type definition) + // property that's eagerly evaluated (getter) for an inspected parent object in the debugger context. + #[napi( + enumerable = false, + configurable = false, + writable = false, + getter, + js_name = "__children", // Needed; otherwise, the property name would shadow `children`. + skip_typescript, + catch_unwind + )] + pub fn __children(&self) -> Vec> { + Self::children(self) + } + + // Similarly, expose the eagerly evaluated unparsed text in the debugger context. + #[napi( + enumerable = false, + configurable = false, + writable = false, + getter, + js_name = "__text", + skip_typescript, + catch_unwind + )] + pub fn __text(&self) -> String { + self.unparse() + } } #[napi(namespace = "cst")] @@ -124,6 +159,14 @@ impl TokenNode { self.0.text.clone() } + #[napi(catch_unwind, js_name = "toJSON")] + /// Serialize the token node to JSON. + /// + /// This method is intended for debugging purposes and may not be stable. + pub fn to_json(&self) -> String { + serde_json::to_string(&self.0).unwrap() + } + #[napi(ts_return_type = "cursor.Cursor", catch_unwind)] pub fn create_cursor( &self, diff --git a/crates/solidity/outputs/cargo/slang_solidity_node_addon/Cargo.toml b/crates/solidity/outputs/cargo/slang_solidity_node_addon/Cargo.toml index 0d71cef363..bd39d17ecc 100644 --- a/crates/solidity/outputs/cargo/slang_solidity_node_addon/Cargo.toml +++ b/crates/solidity/outputs/cargo/slang_solidity_node_addon/Cargo.toml @@ -29,6 +29,7 @@ crate-type = ["cdylib"] default = ["slang_napi_interfaces"] slang_napi_interfaces = [ # This enables '#[napi]' attributes on the Rust types imported via [lib.path] above. + "dep:serde_json", ] [build-dependencies] @@ -43,6 +44,7 @@ napi-derive = { workspace = true } nom = { workspace = true } semver = { workspace = true } serde = { workspace = true } +serde_json = { workspace = true, optional = true } strum = { workspace = true } strum_macros = { workspace = true } thiserror = { workspace = true } diff --git a/crates/solidity/outputs/npm/package/src/generated/index.d.ts b/crates/solidity/outputs/npm/package/src/generated/index.d.ts index 9c5d7c7112..1f4d7fd1d3 100644 --- a/crates/solidity/outputs/npm/package/src/generated/index.d.ts +++ b/crates/solidity/outputs/npm/package/src/generated/index.d.ts @@ -739,8 +739,8 @@ export namespace ast_internal { } export namespace cst { export enum NodeType { - Rule = 0, - Token = 1, + Rule = "Rule", + Token = "Token", } export class RuleNode { get type(): NodeType.Rule; @@ -748,6 +748,8 @@ export namespace cst { get textLength(): text_index.TextIndex; children(): Array; createCursor(textOffset: text_index.TextIndex): cursor.Cursor; + /** Serialize the token node to JSON. */ + toJSON(): string; unparse(): string; } export class TokenNode { @@ -755,6 +757,12 @@ export namespace cst { get kind(): kinds.TokenKind; get textLength(): text_index.TextIndex; get text(): string; + /** + * Serialize the token node to JSON. + * + * This method is intended for debugging purposes and may not be stable. + */ + toJSON(): string; createCursor(textOffset: text_index.TextIndex): cursor.Cursor; } } diff --git a/crates/testlang/outputs/cargo/slang_testlang/src/generated/napi_interface/cst.rs b/crates/testlang/outputs/cargo/slang_testlang/src/generated/napi_interface/cst.rs index 20f0a13157..94b69f82d0 100644 --- a/crates/testlang/outputs/cargo/slang_testlang/src/generated/napi_interface/cst.rs +++ b/crates/testlang/outputs/cargo/slang_testlang/src/generated/napi_interface/cst.rs @@ -11,7 +11,7 @@ use crate::napi_interface::{ RuleKind, RustNode, RustRuleNode, RustTextIndex, RustTokenNode, TokenKind, }; -#[napi(namespace = "cst")] +#[napi(namespace = "cst", string_enum)] pub enum NodeType { Rule, Token, @@ -85,10 +85,45 @@ impl RuleNode { .into() } + #[napi(catch_unwind, js_name = "toJSON")] + /// Serialize the token node to JSON. + pub fn to_json(&self) -> String { + serde_json::to_string(&self.0).unwrap() + } + #[napi(catch_unwind)] pub fn unparse(&self) -> String { self.0.clone().unparse() } + + // Expose the children as a hidden (non-enumerable, don't generate type definition) + // property that's eagerly evaluated (getter) for an inspected parent object in the debugger context. + #[napi( + enumerable = false, + configurable = false, + writable = false, + getter, + js_name = "__children", // Needed; otherwise, the property name would shadow `children`. + skip_typescript, + catch_unwind + )] + pub fn __children(&self) -> Vec> { + Self::children(self) + } + + // Similarly, expose the eagerly evaluated unparsed text in the debugger context. + #[napi( + enumerable = false, + configurable = false, + writable = false, + getter, + js_name = "__text", + skip_typescript, + catch_unwind + )] + pub fn __text(&self) -> String { + self.unparse() + } } #[napi(namespace = "cst")] @@ -124,6 +159,14 @@ impl TokenNode { self.0.text.clone() } + #[napi(catch_unwind, js_name = "toJSON")] + /// Serialize the token node to JSON. + /// + /// This method is intended for debugging purposes and may not be stable. + pub fn to_json(&self) -> String { + serde_json::to_string(&self.0).unwrap() + } + #[napi(ts_return_type = "cursor.Cursor", catch_unwind)] pub fn create_cursor( &self, diff --git a/crates/testlang/outputs/cargo/slang_testlang_node_addon/Cargo.toml b/crates/testlang/outputs/cargo/slang_testlang_node_addon/Cargo.toml index e325b846ba..9a7652aa0b 100644 --- a/crates/testlang/outputs/cargo/slang_testlang_node_addon/Cargo.toml +++ b/crates/testlang/outputs/cargo/slang_testlang_node_addon/Cargo.toml @@ -29,6 +29,7 @@ crate-type = ["cdylib"] default = ["slang_napi_interfaces"] slang_napi_interfaces = [ # This enables '#[napi]' attributes on the Rust types imported via [lib.path] above. + "dep:serde_json", ] [build-dependencies] @@ -43,6 +44,7 @@ napi-derive = { workspace = true } nom = { workspace = true } semver = { workspace = true } serde = { workspace = true } +serde_json = { workspace = true, optional = true } strum = { workspace = true } strum_macros = { workspace = true } thiserror = { workspace = true } diff --git a/crates/testlang/outputs/npm/package/src/generated/index.d.ts b/crates/testlang/outputs/npm/package/src/generated/index.d.ts index 4fa4bda6db..954405ba8c 100644 --- a/crates/testlang/outputs/npm/package/src/generated/index.d.ts +++ b/crates/testlang/outputs/npm/package/src/generated/index.d.ts @@ -78,8 +78,8 @@ export namespace ast_internal { } export namespace cst { export enum NodeType { - Rule = 0, - Token = 1, + Rule = "Rule", + Token = "Token", } export class RuleNode { get type(): NodeType.Rule; @@ -87,6 +87,8 @@ export namespace cst { get textLength(): text_index.TextIndex; children(): Array; createCursor(textOffset: text_index.TextIndex): cursor.Cursor; + /** Serialize the token node to JSON. */ + toJSON(): string; unparse(): string; } export class TokenNode { @@ -94,6 +96,12 @@ export namespace cst { get kind(): kinds.TokenKind; get textLength(): text_index.TextIndex; get text(): string; + /** + * Serialize the token node to JSON. + * + * This method is intended for debugging purposes and may not be stable. + */ + toJSON(): string; createCursor(textOffset: text_index.TextIndex): cursor.Cursor; } }