diff --git a/.changeset/gold-knives-jump.md b/.changeset/gold-knives-jump.md new file mode 100644 index 0000000000..772659fda2 --- /dev/null +++ b/.changeset/gold-knives-jump.md @@ -0,0 +1,5 @@ +--- +"changelog": patch +--- + +Move `syntax::parser::ProductionKind` to `syntax::nodes` namespace. diff --git a/Cargo.lock b/Cargo.lock index ff174657ba..daa40ab79b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -315,6 +315,7 @@ name = "codegen_syntax" version = "0.8.0" dependencies = [ "Inflector", + "anyhow", "codegen_ebnf", "codegen_schema", "codegen_utils", diff --git a/crates/codegen/legacy_syntax_templates/src/lib.rs b/crates/codegen/legacy_syntax_templates/src/lib.rs index 331919f9c9..df9c31c718 100644 --- a/crates/codegen/legacy_syntax_templates/src/lib.rs +++ b/crates/codegen/legacy_syntax_templates/src/lib.rs @@ -3,3 +3,9 @@ extern crate napi_derive; pub mod napi; pub mod rust; + +pub mod syntax { + pub mod nodes { + pub use crate::napi::kinds::{ProductionKind, RuleKind, TokenKind}; + } +} diff --git a/crates/codegen/legacy_syntax_templates/src/napi/cst_ts_wrappers.rs b/crates/codegen/legacy_syntax_templates/src/napi/cst_ts_wrappers.rs index e9a792bee9..63a1e1a57f 100644 --- a/crates/codegen/legacy_syntax_templates/src/napi/cst_ts_wrappers.rs +++ b/crates/codegen/legacy_syntax_templates/src/napi/cst_ts_wrappers.rs @@ -1,7 +1,6 @@ use super::{ cst::{Node as RustNode, RuleNode as RustRuleNode, TokenNode as RustTokenNode}, cursor_ts_wrappers::Cursor, - kinds::*, text_index::{TextIndex as RustTextIndex, TextRange as RustTextRange}, }; @@ -11,6 +10,8 @@ use napi::bindgen_prelude::*; use napi::JsObject; use napi::NapiValue; +use crate::syntax::nodes::{RuleKind, TokenKind}; + #[napi(object, namespace = "legacy")] #[derive(Copy, Clone)] pub struct TextIndex { diff --git a/crates/codegen/legacy_syntax_templates/src/napi/cursor_ts_wrappers.rs b/crates/codegen/legacy_syntax_templates/src/napi/cursor_ts_wrappers.rs index 7df86b11b7..9e8736f362 100644 --- a/crates/codegen/legacy_syntax_templates/src/napi/cursor_ts_wrappers.rs +++ b/crates/codegen/legacy_syntax_templates/src/napi/cursor_ts_wrappers.rs @@ -1,12 +1,13 @@ use super::{ cst_ts_wrappers::{TextIndex, TextRange, ToJS}, cursor::Cursor as RustCursor, - kinds::*, }; use napi::bindgen_prelude::*; use napi::JsObject; +use crate::syntax::nodes::{RuleKind, TokenKind}; + #[napi(namespace = "legacy")] pub struct Cursor(Box); diff --git a/crates/codegen/legacy_syntax_templates/src/napi/parse_output.rs b/crates/codegen/legacy_syntax_templates/src/napi/parse_output.rs index 74ae6472d8..e517793e44 100644 --- a/crates/codegen/legacy_syntax_templates/src/napi/parse_output.rs +++ b/crates/codegen/legacy_syntax_templates/src/napi/parse_output.rs @@ -1,13 +1,15 @@ use std::collections::BTreeSet; +use napi::bindgen_prelude::*; + use super::{ cst, cst_ts_wrappers::{TextRange, ToJS}, - kinds::TokenKind, parse_error::render_error_report, text_index::TextRange as RustTextRange, }; -use napi::bindgen_prelude::*; + +use crate::syntax::nodes::TokenKind; #[napi(namespace = "legacy")] pub struct ParseOutput { diff --git a/crates/codegen/legacy_syntax_templates/src/rust/parse_output.rs b/crates/codegen/legacy_syntax_templates/src/rust/parse_output.rs index 5b1cff1401..8b78b213ef 100644 --- a/crates/codegen/legacy_syntax_templates/src/rust/parse_output.rs +++ b/crates/codegen/legacy_syntax_templates/src/rust/parse_output.rs @@ -1,6 +1,8 @@ use std::collections::BTreeSet; -use super::{cst, kinds::TokenKind, parse_error::render_error_report, text_index::TextRange}; +use super::{cst, parse_error::render_error_report, text_index::TextRange}; + +use crate::syntax::nodes::TokenKind; #[derive(Debug, PartialEq)] pub struct ParseOutput { diff --git a/crates/codegen/legacy_syntax_templates/src/shared/cst.rs b/crates/codegen/legacy_syntax_templates/src/shared/cst.rs index ecad42f36a..4f2483840a 100644 --- a/crates/codegen/legacy_syntax_templates/src/shared/cst.rs +++ b/crates/codegen/legacy_syntax_templates/src/shared/cst.rs @@ -2,11 +2,9 @@ use std::rc::Rc; use serde::Serialize; -use super::{ - cursor::Cursor, - kinds::{RuleKind, TokenKind}, - text_index::TextIndex, -}; +use super::{cursor::Cursor, text_index::TextIndex}; + +use crate::syntax::nodes::{RuleKind, TokenKind}; #[derive(Clone, Debug, PartialEq, Eq, Serialize)] pub struct RuleNode { diff --git a/crates/codegen/legacy_syntax_templates/src/shared/cursor.rs b/crates/codegen/legacy_syntax_templates/src/shared/cursor.rs index 8933a3b652..bc1a69142c 100644 --- a/crates/codegen/legacy_syntax_templates/src/shared/cursor.rs +++ b/crates/codegen/legacy_syntax_templates/src/shared/cursor.rs @@ -2,10 +2,11 @@ use std::rc::Rc; use super::{ cst::{Node, RuleNode, TokenNode}, - kinds::{RuleKind, TokenKind}, text_index::{TextIndex, TextRange}, }; +use crate::syntax::nodes::{RuleKind, TokenKind}; + #[derive(Clone, Debug, PartialEq, Eq)] struct CursorPathElement { rule_node: Rc, diff --git a/crates/codegen/legacy_syntax_templates/src/shared/language.rs b/crates/codegen/legacy_syntax_templates/src/shared/language.rs index b55d70e01a..c8d18568f6 100644 --- a/crates/codegen/legacy_syntax_templates/src/shared/language.rs +++ b/crates/codegen/legacy_syntax_templates/src/shared/language.rs @@ -2,4 +2,7 @@ use semver::Version; #[allow(unused_imports)] -use super::{kinds::*, parse_output::*, parser_function::*, scanner_function::*}; +use super::{parse_output::*, parser_function::*, scanner_function::*}; + +#[allow(unused_imports)] +use crate::syntax::nodes::{ProductionKind, RuleKind, TokenKind}; diff --git a/crates/codegen/legacy_syntax_templates/src/shared/parse_error.rs b/crates/codegen/legacy_syntax_templates/src/shared/parse_error.rs index f07108abbc..de0ad4a75c 100644 --- a/crates/codegen/legacy_syntax_templates/src/shared/parse_error.rs +++ b/crates/codegen/legacy_syntax_templates/src/shared/parse_error.rs @@ -1,9 +1,10 @@ use super::{ - kinds::*, parse_output::ParseError, text_index::{TextIndex, TextRange}, }; +use crate::syntax::nodes::TokenKind; + impl ParseError { #[allow(dead_code)] pub(crate) fn new_at_position( diff --git a/crates/codegen/legacy_syntax_templates/src/shared/parser_function.rs b/crates/codegen/legacy_syntax_templates/src/shared/parser_function.rs index 71fafeee96..ea72225ca1 100644 --- a/crates/codegen/legacy_syntax_templates/src/shared/parser_function.rs +++ b/crates/codegen/legacy_syntax_templates/src/shared/parser_function.rs @@ -1,11 +1,12 @@ use super::{ cst, - kinds::*, parse_output::{ParseError, ParseOutput}, parser_result::*, stream::Stream, }; +use crate::syntax::nodes::TokenKind; + // Return type of the function has to be a type parameter of the trait pub trait ParserFunction where diff --git a/crates/codegen/legacy_syntax_templates/src/shared/parser_result.rs b/crates/codegen/legacy_syntax_templates/src/shared/parser_result.rs index 311264a55e..58b52c7e27 100644 --- a/crates/codegen/legacy_syntax_templates/src/shared/parser_result.rs +++ b/crates/codegen/legacy_syntax_templates/src/shared/parser_result.rs @@ -1,4 +1,6 @@ -use super::{cst, kinds::*, stream::Stream}; +use super::{cst, stream::Stream}; + +use crate::syntax::nodes::{RuleKind, TokenKind}; #[derive(PartialEq, Eq, Clone, Debug)] pub struct Match { diff --git a/crates/codegen/legacy_syntax_templates/src/shared/scanner_function.rs b/crates/codegen/legacy_syntax_templates/src/shared/scanner_function.rs index b7bf336aa7..d61ad68d0d 100644 --- a/crates/codegen/legacy_syntax_templates/src/shared/scanner_function.rs +++ b/crates/codegen/legacy_syntax_templates/src/shared/scanner_function.rs @@ -1,10 +1,11 @@ use super::{ cst, - kinds::*, parse_output::{ParseError, ParseOutput}, stream::Stream, }; +use crate::syntax::nodes::TokenKind; + // Return type of the function has to be a type parameter of the trait pub trait ScannerFunction where diff --git a/crates/codegen/syntax/Cargo.toml b/crates/codegen/syntax/Cargo.toml index c4696e4d93..dad9c7bf9f 100644 --- a/crates/codegen/syntax/Cargo.toml +++ b/crates/codegen/syntax/Cargo.toml @@ -6,6 +6,7 @@ edition.workspace = true publish = false [dependencies] +anyhow = { workspace = true } codegen_ebnf = { workspace = true } codegen_schema = { workspace = true } codegen_utils = { workspace = true } diff --git a/crates/codegen/syntax/src/legacy/code_generator.rs b/crates/codegen/syntax/src/legacy/code_generator.rs index 2921c074ae..63da5d2043 100644 --- a/crates/codegen/syntax/src/legacy/code_generator.rs +++ b/crates/codegen/syntax/src/legacy/code_generator.rs @@ -148,10 +148,7 @@ pub struct CodeGenerator { pub language: LanguageDefinitionRef, pub first_version: Version, - pub token_kinds: BTreeMap>, pub scanners: BTreeMap, - - pub rule_kinds: BTreeSet, pub parsers: BTreeMap, pub errors: Vec, @@ -163,23 +160,13 @@ impl CodeGenerator { language: language.clone(), first_version: language.versions.first().unwrap().clone(), - token_kinds: Default::default(), scanners: Default::default(), - - rule_kinds: Default::default(), parsers: Default::default(), errors: Default::default(), } } - pub fn add_token_kind(&mut self, name: String) -> Ident { - let name = name; - let ident = format_ident!("{name}"); - self.token_kinds.insert(name, None); - ident - } - pub fn add_scanner( &mut self, name: String, @@ -192,13 +179,6 @@ impl CodeGenerator { .insert(version, definition); } - pub fn add_rule_kind(&mut self, name: String) -> Ident { - let name = name; - let ident = format_ident!("{name}"); - self.rule_kinds.insert(name); - ident - } - pub fn add_parser( &mut self, name: String, @@ -384,46 +364,6 @@ impl CodeGenerator { quote! { #(#invocations),* } } - pub fn token_kinds(&self) -> TokenStream { - let kinds = self - .token_kinds - .iter() - .map(|(name, _)| format_ident!("{name}")); - quote! { - pub enum TokenKind { - SKIPPED, - #(#kinds),* - } - } - } - - pub fn rule_kinds(&self) -> TokenStream { - let kinds = self.rule_kinds.iter().map(|name| format_ident!("{name}")); - quote! { - pub enum RuleKind { - #(#kinds),* - } - } - } - - pub fn production_kinds(&self) -> TokenStream { - let mut kinds: Vec<_> = self - .language - .productions - .values() - .filter(|production| !production.inlined) - .map(|production| format_ident!("{}", production.name)) - .collect(); - - kinds.sort(); - - quote! { - pub enum ProductionKind { - #(#kinds),* - } - } - } - pub fn write_common_sources(&self, codegen: &mut CodegenContext, output_dir: &PathBuf) { // Rebuild if input files are added/removed codegen.track_input_dir( @@ -556,11 +496,12 @@ impl CodeGenerator { let content = format!( " use super::cst; - use super::kinds::*; use super::language::Language; use super::parser_helpers::*; use super::parser_result::*; use super::stream::*; + + use crate::syntax::nodes::{{RuleKind, TokenKind}}; impl Language {{ diff --git a/crates/codegen/syntax/src/legacy/combinator_tree.rs b/crates/codegen/syntax/src/legacy/combinator_tree.rs index 5cb1d40420..71e0f292b8 100644 --- a/crates/codegen/syntax/src/legacy/combinator_tree.rs +++ b/crates/codegen/syntax/src/legacy/combinator_tree.rs @@ -60,7 +60,6 @@ impl<'context> CombinatorTree<'context> { } let name = &self.production.name; - let inlined = &self.production.inlined; let comment = self.generate_comment(); match self.production.definition { @@ -72,19 +71,11 @@ impl<'context> CombinatorTree<'context> { ); } - if !inlined { - code.add_token_kind(name.clone()); - } - (comment, node.to_scanner_code(code)) }); code.add_scanner(name.clone(), version, definition); } ProductionDefinition::TriviaParser { .. } => { - if !inlined { - code.add_rule_kind(name.clone()); - } - let definition = self .root_node .get() @@ -92,10 +83,6 @@ impl<'context> CombinatorTree<'context> { code.add_parser(name.clone(), version, definition); } ProductionDefinition::Parser { .. } | ProductionDefinition::PrecedenceParser { .. } => { - if !inlined { - code.add_rule_kind(name.clone()); - } - let definition = self .root_node .get() diff --git a/crates/codegen/syntax/src/legacy/napi_lib_code_generator.rs b/crates/codegen/syntax/src/legacy/napi_lib_code_generator.rs index e881f9482c..6516d728bc 100644 --- a/crates/codegen/syntax/src/legacy/napi_lib_code_generator.rs +++ b/crates/codegen/syntax/src/legacy/napi_lib_code_generator.rs @@ -32,7 +32,6 @@ impl CodeGenerator { pub mod cst_ts_wrappers; pub mod cursor; pub mod cursor_ts_wrappers; - pub mod kinds; pub mod language; pub mod parse_error; pub mod parse_output; @@ -162,59 +161,5 @@ impl CodeGenerator { .write_file(&output_dir.join("language.rs"), &content) .unwrap(); } - - // Do the kinds last, because the code generation steps above may have added new kinds - { - let content = { - let token_kinds = self.token_kinds(); - let rule_kinds = self.rule_kinds(); - let production_kinds = self.production_kinds(); - quote! { - use serde::Serialize; - use napi::bindgen_prelude::*; - use napi_derive::napi; - - #[napi(string_enum, namespace = "legacy")] - #[derive( - Debug, - PartialEq, - Eq, - Serialize, - strum_macros::EnumString, - strum_macros::AsRefStr, - strum_macros::Display, - )] - #token_kinds - - #[napi(string_enum, namespace = "legacy")] - #[derive( - Debug, - PartialEq, - Eq, - Serialize, - strum_macros::EnumString, - strum_macros::AsRefStr, - strum_macros::Display, - )] - #rule_kinds - - #[napi(string_enum, namespace = "legacy")] - #[derive( - Debug, - PartialEq, - Eq, - Serialize, - strum_macros::EnumString, - strum_macros::AsRefStr, - strum_macros::Display, - )] - #production_kinds - } - }; - - codegen - .write_file(&output_dir.join("kinds.rs"), &content.to_string()) - .unwrap(); - } } } diff --git a/crates/codegen/syntax/src/legacy/rust_lib_code_generator.rs b/crates/codegen/syntax/src/legacy/rust_lib_code_generator.rs index 18da5a89f6..ea0ca0a67d 100644 --- a/crates/codegen/syntax/src/legacy/rust_lib_code_generator.rs +++ b/crates/codegen/syntax/src/legacy/rust_lib_code_generator.rs @@ -30,7 +30,6 @@ impl CodeGenerator { pub mod cst; pub mod cursor; - pub mod kinds; pub mod language; pub mod parse_error; pub mod parse_output; @@ -126,66 +125,5 @@ impl CodeGenerator { .write_file(&output_dir.join("language.rs"), &content) .unwrap(); } - - // Do the kinds last, because the code generation steps above may have added new kinds - { - let content = { - let token_kinds = self.token_kinds(); - let rule_kinds = self.rule_kinds(); - let production_kinds = self.production_kinds(); - quote! { - use serde::Serialize; - - #[derive( - Clone, - Copy, - Debug, - PartialEq, - Eq, - PartialOrd, - Ord, - Serialize, - strum_macros::EnumString, - strum_macros::AsRefStr, - strum_macros::Display, - )] - #token_kinds - - #[derive( - Clone, - Copy, - Debug, - PartialEq, - Eq, - PartialOrd, - Ord, - Serialize, - strum_macros::EnumString, - strum_macros::AsRefStr, - strum_macros::Display, - )] - #rule_kinds - - #[derive( - Clone, - Copy, - Debug, - PartialEq, - Eq, - PartialOrd, - Ord, - Serialize, - strum_macros::EnumString, - strum_macros::AsRefStr, - strum_macros::Display, - )] - #production_kinds - } - }; - - codegen - .write_file(&output_dir.join("kinds.rs"), &content.to_string()) - .unwrap(); - } } } diff --git a/crates/codegen/syntax/src/legacy/to_parser_code.rs b/crates/codegen/syntax/src/legacy/to_parser_code.rs index 58d74c390e..9dd13ae88e 100644 --- a/crates/codegen/syntax/src/legacy/to_parser_code.rs +++ b/crates/codegen/syntax/src/legacy/to_parser_code.rs @@ -256,7 +256,7 @@ fn precedence_expression_to_parser_code( let mut binding_power = 1u8; for expression in operator_expressions.iter() { - let rule_kind = code.add_rule_kind(expression.name.clone()); + let rule_kind = format_ident!("{}", expression.name.clone()); let operator_code = expression.operator.to_parser_code(code, false); match expression.model { diff --git a/crates/codegen/syntax/src/lib.rs b/crates/codegen/syntax/src/lib.rs index 854abcad62..2d6f6f5b89 100644 --- a/crates/codegen/syntax/src/lib.rs +++ b/crates/codegen/syntax/src/lib.rs @@ -1,40 +1,49 @@ mod legacy; +mod nodes; +use std::path::PathBuf; + +use anyhow::Result; use codegen_schema::types::LanguageDefinitionRef; use codegen_utils::context::CodegenContext; -use crate::legacy::language::PrivateSyntaxGeneratorExtensions; +use crate::{legacy::language::PrivateSyntaxGeneratorExtensions, nodes::generate_syntax_nodes_mod}; + +pub struct SyntaxGeneratorPaths { + pub src_dir: PathBuf, + pub syntax_nodes_mod: &'static str, +} pub trait SyntaxGeneratorExtensions { - fn generate_legacy_rust_lib_sources( - &self, - codegen: &mut CodegenContext, - output_dir: &std::path::PathBuf, - ); + fn generate_legacy_rust_lib_sources(&self, codegen: &mut CodegenContext, output_dir: &PathBuf); + + fn generate_legacy_napi_lib_sources(&self, codegen: &mut CodegenContext, output_dir: &PathBuf); - fn generate_legacy_napi_lib_sources( + fn generate_syntax_lib_sources( &self, codegen: &mut CodegenContext, - output_dir: &std::path::PathBuf, - ); + paths: &SyntaxGeneratorPaths, + ) -> Result<()>; } impl SyntaxGeneratorExtensions for LanguageDefinitionRef { - fn generate_legacy_rust_lib_sources( - &self, - codegen: &mut CodegenContext, - output_dir: &std::path::PathBuf, - ) { + fn generate_legacy_rust_lib_sources(&self, codegen: &mut CodegenContext, output_dir: &PathBuf) { self.create_code_generator() .write_rust_lib_sources(self, codegen, output_dir); } - fn generate_legacy_napi_lib_sources( - &self, - codegen: &mut CodegenContext, - output_dir: &std::path::PathBuf, - ) { + fn generate_legacy_napi_lib_sources(&self, codegen: &mut CodegenContext, output_dir: &PathBuf) { self.create_code_generator() .write_napi_lib_sources(self, codegen, output_dir); } + + fn generate_syntax_lib_sources( + &self, + codegen: &mut CodegenContext, + paths: &SyntaxGeneratorPaths, + ) -> Result<()> { + generate_syntax_nodes_mod(self, codegen, &paths.src_dir.join(paths.syntax_nodes_mod))?; + + return Ok(()); + } } diff --git a/crates/codegen/syntax/src/nodes/kinds/mod.rs b/crates/codegen/syntax/src/nodes/kinds/mod.rs new file mode 100644 index 0000000000..34c63d3644 --- /dev/null +++ b/crates/codegen/syntax/src/nodes/kinds/mod.rs @@ -0,0 +1,129 @@ +use std::collections::BTreeSet; + +use codegen_schema::types::{LanguageDefinitionRef, ProductionDefinition}; +use quote::{format_ident, quote}; + +pub fn generate_production_kind(language: &LanguageDefinitionRef) -> String { + let mut kinds = vec![]; + + for production in language.productions.values() { + if production.inlined { + continue; + } + + kinds.push(production.name.as_str()); + } + + kinds.sort(); + + return generate_enum_file("ProductionKind", kinds.into_iter()); +} + +pub fn generate_rule_kind(language: &LanguageDefinitionRef) -> String { + // Use a BTreeSet to deduplicate operator names: + let mut kinds = BTreeSet::new(); + + for production in language.productions.values() { + if production.inlined { + continue; + } + + match &production.definition { + ProductionDefinition::Parser { .. } | ProductionDefinition::TriviaParser { .. } => { + kinds.insert(production.name.as_str()); + } + ProductionDefinition::PrecedenceParser { version_map, .. } => { + kinds.insert(production.name.as_str()); + + match version_map { + codegen_schema::types::VersionMap::Unversioned(unversioned) => { + for expression in &unversioned.operator_expressions { + kinds.insert(expression.name.as_str()); + } + } + codegen_schema::types::VersionMap::Versioned(versioned) => { + for version in versioned.values() { + if let Some(version) = version { + for expression in &version.operator_expressions { + kinds.insert(expression.name.as_str()); + } + } + } + } + }; + } + ProductionDefinition::Scanner { .. } => {} + }; + } + + // BTreeSet iterators are always ordered, so we don't need to sort. + + return generate_enum_file("RuleKind", kinds.into_iter()); +} + +pub fn generate_token_kind(language: &LanguageDefinitionRef) -> String { + let mut kinds = vec![]; + + for production in language.productions.values() { + if production.inlined { + continue; + } + + match production.definition { + ProductionDefinition::Scanner { .. } => { + kinds.push(production.name.as_str()); + } + ProductionDefinition::Parser { .. } + | ProductionDefinition::PrecedenceParser { .. } + | ProductionDefinition::TriviaParser { .. } => {} + }; + } + + kinds.sort(); + + // Insert "SKIPPED" as the first token kind (after sorting): + kinds.insert(0, "SKIPPED"); + + return generate_enum_file("TokenKind", kinds.into_iter()); +} + +fn generate_enum_file<'context, I>(type_name: &str, variants: I) -> String +where + I: Iterator, +{ + let type_name = format_ident!("{type_name}"); + let variants = variants.map(|variant| format_ident!("{variant}")); + + let enum_file = quote! { + #[cfg(feature = "slang_napi_interfaces")] + use napi::bindgen_prelude::*; + + #[derive( + Debug, + Eq, + Ord, + PartialEq, + PartialOrd, + serde::Serialize, + strum_macros::AsRefStr, + strum_macros::Display, + strum_macros::EnumString, + )] + #[cfg_attr( + // If feature is enabled, derive the NAPI version. + // This also derives `Clone` and `Copy` automatically. + feature = "slang_napi_interfaces", + napi(string_enum, namespace = "syntax$nodes") + )] + #[cfg_attr( + // If feature is not enabled, derive `Clone` and `Copy` manually. + not(feature = "slang_napi_interfaces"), + derive(Clone, Copy), + )] + pub enum #type_name { + #(#variants),* + } + }; + + return enum_file.to_string(); +} diff --git a/crates/codegen/syntax/src/nodes/mod.rs b/crates/codegen/syntax/src/nodes/mod.rs new file mode 100644 index 0000000000..ba5c5aa8fb --- /dev/null +++ b/crates/codegen/syntax/src/nodes/mod.rs @@ -0,0 +1,41 @@ +mod kinds; + +use std::path::PathBuf; + +use anyhow::Result; +use codegen_schema::types::LanguageDefinitionRef; +use codegen_utils::context::CodegenContext; + +use crate::nodes::kinds::{generate_production_kind, generate_rule_kind, generate_token_kind}; + +pub fn generate_syntax_nodes_mod( + language: &LanguageDefinitionRef, + codegen: &mut CodegenContext, + syntax_nodes_dir: &PathBuf, +) -> Result<()> { + codegen.write_file( + &syntax_nodes_dir.join("production_kind.rs"), + &generate_production_kind(language), + )?; + + codegen.write_file( + &syntax_nodes_dir.join("rule_kind.rs"), + &generate_rule_kind(language), + )?; + + codegen.write_file( + &syntax_nodes_dir.join("token_kind.rs"), + &generate_token_kind(language), + )?; + + codegen.write_file( + &syntax_nodes_dir.join("mod.rs"), + " + pub mod production_kind; + pub mod rule_kind; + pub mod token_kind; + ", + )?; + + return Ok(()); +} diff --git a/crates/solidity/outputs/cargo/build/build.rs b/crates/solidity/outputs/cargo/build/build.rs index 909a55e238..ece238f6fb 100644 --- a/crates/solidity/outputs/cargo/build/build.rs +++ b/crates/solidity/outputs/cargo/build/build.rs @@ -1,6 +1,6 @@ use anyhow::Result; use codegen_schema::types::LanguageDefinition; -use codegen_syntax::SyntaxGeneratorExtensions; +use codegen_syntax::{SyntaxGeneratorExtensions, SyntaxGeneratorPaths}; use codegen_utils::context::CodegenContext; use solidity_language::SolidityLanguageExtensions; @@ -14,6 +14,14 @@ fn main() -> Result<()> { language.generate_legacy_rust_lib_sources(codegen, &src_dir.join("legacy/generated")); + language.generate_syntax_lib_sources( + codegen, + &SyntaxGeneratorPaths { + src_dir, + syntax_nodes_mod: "syntax/nodes/generated", + }, + )?; + return Ok(()); }); } diff --git a/crates/solidity/outputs/cargo/crate/src/legacy/generated/cst.rs b/crates/solidity/outputs/cargo/crate/src/legacy/generated/cst.rs index 508a9fb2b5..a597d931d5 100644 --- a/crates/solidity/outputs/cargo/crate/src/legacy/generated/cst.rs +++ b/crates/solidity/outputs/cargo/crate/src/legacy/generated/cst.rs @@ -4,11 +4,9 @@ use std::rc::Rc; use serde::Serialize; -use super::{ - cursor::Cursor, - kinds::{RuleKind, TokenKind}, - text_index::TextIndex, -}; +use super::{cursor::Cursor, text_index::TextIndex}; + +use crate::syntax::nodes::{RuleKind, TokenKind}; #[derive(Clone, Debug, PartialEq, Eq, Serialize)] pub struct RuleNode { diff --git a/crates/solidity/outputs/cargo/crate/src/legacy/generated/cursor.rs b/crates/solidity/outputs/cargo/crate/src/legacy/generated/cursor.rs index 77700d57b9..9a98b592c0 100644 --- a/crates/solidity/outputs/cargo/crate/src/legacy/generated/cursor.rs +++ b/crates/solidity/outputs/cargo/crate/src/legacy/generated/cursor.rs @@ -4,10 +4,11 @@ use std::rc::Rc; use super::{ cst::{Node, RuleNode, TokenNode}, - kinds::{RuleKind, TokenKind}, text_index::{TextIndex, TextRange}, }; +use crate::syntax::nodes::{RuleKind, TokenKind}; + #[derive(Clone, Debug, PartialEq, Eq)] struct CursorPathElement { rule_node: Rc, diff --git a/crates/solidity/outputs/cargo/crate/src/legacy/generated/kinds.rs b/crates/solidity/outputs/cargo/crate/src/legacy/generated/kinds.rs deleted file mode 100644 index a2ab8f7bc6..0000000000 --- a/crates/solidity/outputs/cargo/crate/src/legacy/generated/kinds.rs +++ /dev/null @@ -1,640 +0,0 @@ -// This file is generated automatically by infrastructure scripts. Please don't edit by hand. - -use serde::Serialize; -#[derive( - Clone, - Copy, - Debug, - PartialEq, - Eq, - PartialOrd, - Ord, - Serialize, - strum_macros :: EnumString, - strum_macros :: AsRefStr, - strum_macros :: Display, -)] -pub enum TokenKind { - SKIPPED, - AbicoderKeyword, - AbstractKeyword, - AddressKeyword, - Ampersand, - AmpersandAmpersand, - AmpersandEqual, - AnonymousKeyword, - AsKeyword, - AsciiStringLiteral, - AssemblyKeyword, - Asterisk, - AsteriskAsterisk, - AsteriskEqual, - Bang, - BangEqual, - Bar, - BarBar, - BarEqual, - BoolKeyword, - BreakKeyword, - ByteKeyword, - CalldataKeyword, - Caret, - CaretEqual, - CaseKeyword, - CatchKeyword, - CloseBrace, - CloseBracket, - CloseParen, - Colon, - ColonEqual, - Comma, - ConstantKeyword, - ConstructorKeyword, - ContinueKeyword, - ContractKeyword, - DaysKeyword, - DecimalLiteral, - DefaultKeyword, - DeleteKeyword, - DoKeyword, - ElseKeyword, - EmitKeyword, - EndOfLine, - EnumKeyword, - Equal, - EqualEqual, - EqualGreaterThan, - ErrorKeyword, - EtherKeyword, - EventKeyword, - ExperimentalKeyword, - ExternalKeyword, - FallbackKeyword, - FalseKeyword, - FinneyKeyword, - FixedBytesType, - ForKeyword, - FromKeyword, - FunctionKeyword, - GlobalKeyword, - GreaterThan, - GreaterThanEqual, - GreaterThanGreaterThan, - GreaterThanGreaterThanEqual, - GreaterThanGreaterThanGreaterThan, - GreaterThanGreaterThanGreaterThanEqual, - GweiKeyword, - HexLiteral, - HexStringLiteral, - HoursKeyword, - Identifier, - IfKeyword, - ImmutableKeyword, - ImportKeyword, - IndexedKeyword, - InterfaceKeyword, - InternalKeyword, - IsKeyword, - LeaveKeyword, - LessThan, - LessThanEqual, - LessThanLessThan, - LessThanLessThanEqual, - LetKeyword, - LibraryKeyword, - MappingKeyword, - MemoryKeyword, - Minus, - MinusEqual, - MinusGreaterThan, - MinusMinus, - MinutesKeyword, - ModifierKeyword, - MultilineComment, - NewKeyword, - OpenBrace, - OpenBracket, - OpenParen, - OverrideKeyword, - PayableKeyword, - Percent, - PercentEqual, - Period, - Plus, - PlusEqual, - PlusPlus, - PragmaKeyword, - PrivateKeyword, - PublicKeyword, - PureKeyword, - QuestionMark, - ReceiveKeyword, - ReturnKeyword, - ReturnsKeyword, - RevertKeyword, - SecondsKeyword, - Semicolon, - SignedFixedType, - SignedIntegerType, - SingleLineComment, - Slash, - SlashEqual, - SolidityKeyword, - StorageKeyword, - StringKeyword, - StructKeyword, - SwitchKeyword, - SzaboKeyword, - ThrowKeyword, - Tilde, - TrueKeyword, - TryKeyword, - TypeKeyword, - UncheckedKeyword, - UnicodeStringLiteral, - UnsignedFixedType, - UnsignedIntegerType, - UsingKeyword, - VarKeyword, - VersionPragmaValue, - ViewKeyword, - VirtualKeyword, - WeeksKeyword, - WeiKeyword, - WhileKeyword, - Whitespace, - YearsKeyword, - YulDecimalLiteral, - YulHexLiteral, - YulIdentifier, -} -#[derive( - Clone, - Copy, - Debug, - PartialEq, - Eq, - PartialOrd, - Ord, - Serialize, - strum_macros :: EnumString, - strum_macros :: AsRefStr, - strum_macros :: Display, -)] -pub enum RuleKind { - ABICoderPragma, - AddressType, - ArgumentsDeclaration, - ArrayExpression, - ArrayTypeName, - ArrayValuesList, - AsciiStringLiteralsList, - AssemblyFlagsList, - AssemblyStatement, - BinaryExpression, - Block, - BreakStatement, - CatchClause, - CatchClauseError, - CatchClausesList, - ConditionalExpression, - ConstantDefinition, - ConstructorAttributesList, - ConstructorDefinition, - ContinueStatement, - ContractDefinition, - ContractMembersList, - DeconstructionImport, - DeconstructionImportSymbol, - DeconstructionImportSymbolsList, - DeleteStatement, - DoWhileStatement, - EmitStatement, - EndOfFileTrivia, - EnumDefinition, - ErrorDefinition, - ErrorParameter, - ErrorParametersList, - EventDefinition, - EventParameter, - EventParametersList, - ExperimentalPragma, - Expression, - ExpressionStatement, - FallbackFunctionAttributesList, - FallbackFunctionDefinition, - ForStatement, - FunctionAttributesList, - FunctionCallExpression, - FunctionCallOptions, - FunctionDefinition, - FunctionType, - FunctionTypeAttributesList, - HexStringLiteralsList, - IdentifierPath, - IdentifierPathsList, - IdentifiersList, - IfStatement, - ImportDirective, - IndexAccessExpression, - InheritanceSpecifier, - InheritanceType, - InheritanceTypesList, - InterfaceDefinition, - InterfaceMembersList, - LeadingTrivia, - LibraryDefinition, - LibraryMembersList, - MappingKeyType, - MappingType, - MappingValueType, - MemberAccessExpression, - ModifierAttributesList, - ModifierDefinition, - ModifierInvocation, - NamedArgument, - NamedArgumentsDeclaration, - NamedArgumentsList, - NamedImport, - NewExpression, - NumericExpression, - OverrideSpecifier, - Parameter, - ParametersDeclaration, - ParametersList, - PathImport, - PositionalArgumentsList, - PragmaDirective, - ReceiveFunctionAttributesList, - ReceiveFunctionDefinition, - ReturnStatement, - ReturnsDeclaration, - RevertStatement, - SourceUnit, - SourceUnitMembersList, - StateVariableAttributesList, - StateVariableDefinition, - Statement, - StatementsList, - StructDefinition, - StructMember, - StructMembersList, - ThrowStatement, - TrailingTrivia, - TryStatement, - TupleDeconstructionStatement, - TupleExpression, - TupleMember, - TupleMembersList, - TupleValuesList, - TypeExpression, - TypeName, - UnaryPostfixExpression, - UnaryPrefixExpression, - UncheckedBlock, - UnicodeStringLiteralsList, - UnnamedFunctionAttributesList, - UnnamedFunctionDefinition, - UserDefinedValueTypeDefinition, - UsingDirective, - UsingDirectiveDeconstruction, - UsingDirectivePath, - UsingDirectiveSymbol, - UsingDirectiveSymbolsList, - VariableDeclaration, - VariableDeclarationStatement, - VersionPragma, - VersionPragmaBinaryExpression, - VersionPragmaExpression, - VersionPragmaExpressionsList, - VersionPragmaSpecifier, - VersionPragmaUnaryExpression, - WhileStatement, - YulAssignmentStatement, - YulBlock, - YulBreakStatement, - YulContinueStatement, - YulDeclarationStatement, - YulExpression, - YulExpressionsList, - YulForStatement, - YulFunctionCallExpression, - YulFunctionDefinition, - YulIdentifierPath, - YulIdentifierPathsList, - YulIdentifiersList, - YulIfStatement, - YulLeaveStatement, - YulParametersDeclaration, - YulReturnsDeclaration, - YulStatement, - YulStatementsList, - YulSwitchCase, - YulSwitchCasesList, - YulSwitchStatement, -} -#[derive( - Clone, - Copy, - Debug, - PartialEq, - Eq, - PartialOrd, - Ord, - Serialize, - strum_macros :: EnumString, - strum_macros :: AsRefStr, - strum_macros :: Display, -)] -pub enum ProductionKind { - ABICoderPragma, - AbicoderKeyword, - AbstractKeyword, - AddressKeyword, - AddressType, - Ampersand, - AmpersandAmpersand, - AmpersandEqual, - AnonymousKeyword, - ArgumentsDeclaration, - ArrayExpression, - ArrayValuesList, - AsKeyword, - AsciiStringLiteral, - AsciiStringLiteralsList, - AssemblyFlagsList, - AssemblyKeyword, - AssemblyStatement, - Asterisk, - AsteriskAsterisk, - AsteriskEqual, - Bang, - BangEqual, - Bar, - BarBar, - BarEqual, - Block, - BoolKeyword, - BreakKeyword, - BreakStatement, - ByteKeyword, - CalldataKeyword, - Caret, - CaretEqual, - CaseKeyword, - CatchClause, - CatchClauseError, - CatchClausesList, - CatchKeyword, - CloseBrace, - CloseBracket, - CloseParen, - Colon, - ColonEqual, - Comma, - ConstantDefinition, - ConstantKeyword, - ConstructorAttributesList, - ConstructorDefinition, - ConstructorKeyword, - ContinueKeyword, - ContinueStatement, - ContractDefinition, - ContractKeyword, - ContractMembersList, - DaysKeyword, - DecimalLiteral, - DeconstructionImport, - DeconstructionImportSymbol, - DeconstructionImportSymbolsList, - DefaultKeyword, - DeleteKeyword, - DeleteStatement, - DoKeyword, - DoWhileStatement, - ElseKeyword, - EmitKeyword, - EmitStatement, - EndOfFileTrivia, - EndOfLine, - EnumDefinition, - EnumKeyword, - Equal, - EqualEqual, - EqualGreaterThan, - ErrorDefinition, - ErrorKeyword, - ErrorParameter, - ErrorParametersList, - EtherKeyword, - EventDefinition, - EventKeyword, - EventParameter, - EventParametersList, - ExperimentalKeyword, - ExperimentalPragma, - Expression, - ExpressionStatement, - ExternalKeyword, - FallbackFunctionAttributesList, - FallbackFunctionDefinition, - FallbackKeyword, - FalseKeyword, - FinneyKeyword, - FixedBytesType, - ForKeyword, - ForStatement, - FromKeyword, - FunctionAttributesList, - FunctionCallOptions, - FunctionDefinition, - FunctionKeyword, - FunctionType, - FunctionTypeAttributesList, - GlobalKeyword, - GreaterThan, - GreaterThanEqual, - GreaterThanGreaterThan, - GreaterThanGreaterThanEqual, - GreaterThanGreaterThanGreaterThan, - GreaterThanGreaterThanGreaterThanEqual, - GweiKeyword, - HexLiteral, - HexStringLiteral, - HexStringLiteralsList, - HoursKeyword, - Identifier, - IdentifierPath, - IdentifierPathsList, - IdentifiersList, - IfKeyword, - IfStatement, - ImmutableKeyword, - ImportDirective, - ImportKeyword, - IndexedKeyword, - InheritanceSpecifier, - InheritanceType, - InheritanceTypesList, - InterfaceDefinition, - InterfaceKeyword, - InterfaceMembersList, - InternalKeyword, - IsKeyword, - LeadingTrivia, - LeaveKeyword, - LessThan, - LessThanEqual, - LessThanLessThan, - LessThanLessThanEqual, - LetKeyword, - LibraryDefinition, - LibraryKeyword, - LibraryMembersList, - MappingKeyType, - MappingKeyword, - MappingType, - MappingValueType, - MemoryKeyword, - Minus, - MinusEqual, - MinusGreaterThan, - MinusMinus, - MinutesKeyword, - ModifierAttributesList, - ModifierDefinition, - ModifierInvocation, - ModifierKeyword, - MultilineComment, - NamedArgument, - NamedArgumentsDeclaration, - NamedArgumentsList, - NamedImport, - NewExpression, - NewKeyword, - NumericExpression, - OpenBrace, - OpenBracket, - OpenParen, - OverrideKeyword, - OverrideSpecifier, - Parameter, - ParametersDeclaration, - ParametersList, - PathImport, - PayableKeyword, - Percent, - PercentEqual, - Period, - Plus, - PlusEqual, - PlusPlus, - PositionalArgumentsList, - PragmaDirective, - PragmaKeyword, - PrivateKeyword, - PublicKeyword, - PureKeyword, - QuestionMark, - ReceiveFunctionAttributesList, - ReceiveFunctionDefinition, - ReceiveKeyword, - ReturnKeyword, - ReturnStatement, - ReturnsDeclaration, - ReturnsKeyword, - RevertKeyword, - RevertStatement, - SecondsKeyword, - Semicolon, - SignedFixedType, - SignedIntegerType, - SingleLineComment, - Slash, - SlashEqual, - SolidityKeyword, - SourceUnit, - SourceUnitMembersList, - StateVariableAttributesList, - StateVariableDefinition, - Statement, - StatementsList, - StorageKeyword, - StringKeyword, - StructDefinition, - StructKeyword, - StructMember, - StructMembersList, - SwitchKeyword, - SzaboKeyword, - ThrowKeyword, - ThrowStatement, - Tilde, - TrailingTrivia, - TrueKeyword, - TryKeyword, - TryStatement, - TupleDeconstructionStatement, - TupleExpression, - TupleMember, - TupleMembersList, - TupleValuesList, - TypeExpression, - TypeKeyword, - TypeName, - UncheckedBlock, - UncheckedKeyword, - UnicodeStringLiteral, - UnicodeStringLiteralsList, - UnnamedFunctionAttributesList, - UnnamedFunctionDefinition, - UnsignedFixedType, - UnsignedIntegerType, - UserDefinedValueTypeDefinition, - UsingDirective, - UsingDirectiveDeconstruction, - UsingDirectivePath, - UsingDirectiveSymbol, - UsingDirectiveSymbolsList, - UsingKeyword, - VarKeyword, - VariableDeclaration, - VariableDeclarationStatement, - VersionPragma, - VersionPragmaExpression, - VersionPragmaExpressionsList, - VersionPragmaSpecifier, - VersionPragmaValue, - ViewKeyword, - VirtualKeyword, - WeeksKeyword, - WeiKeyword, - WhileKeyword, - WhileStatement, - Whitespace, - YearsKeyword, - YulAssignmentStatement, - YulBlock, - YulBreakStatement, - YulContinueStatement, - YulDecimalLiteral, - YulDeclarationStatement, - YulExpression, - YulExpressionsList, - YulForStatement, - YulFunctionDefinition, - YulHexLiteral, - YulIdentifier, - YulIdentifierPath, - YulIdentifierPathsList, - YulIdentifiersList, - YulIfStatement, - YulLeaveStatement, - YulParametersDeclaration, - YulReturnsDeclaration, - YulStatement, - YulStatementsList, - YulSwitchCase, - YulSwitchCasesList, - YulSwitchStatement, -} diff --git a/crates/solidity/outputs/cargo/crate/src/legacy/generated/language.rs b/crates/solidity/outputs/cargo/crate/src/legacy/generated/language.rs index f616aadd6a..4204402b4a 100644 --- a/crates/solidity/outputs/cargo/crate/src/legacy/generated/language.rs +++ b/crates/solidity/outputs/cargo/crate/src/legacy/generated/language.rs @@ -4,7 +4,10 @@ use semver::Version; #[allow(unused_imports)] -use super::{kinds::*, parse_output::*, parser_function::*, scanner_function::*}; +use super::{parse_output::*, parser_function::*, scanner_function::*}; + +#[allow(unused_imports)] +use crate::syntax::nodes::{ProductionKind, RuleKind, TokenKind}; #[derive(Debug)] pub struct Language { diff --git a/crates/solidity/outputs/cargo/crate/src/legacy/generated/mod.rs b/crates/solidity/outputs/cargo/crate/src/legacy/generated/mod.rs index f90a8dfb22..67a126560b 100644 --- a/crates/solidity/outputs/cargo/crate/src/legacy/generated/mod.rs +++ b/crates/solidity/outputs/cargo/crate/src/legacy/generated/mod.rs @@ -4,7 +4,6 @@ mod scanner_macros; pub mod cst; pub mod cursor; -pub mod kinds; pub mod language; pub mod parse_error; pub mod parse_output; diff --git a/crates/solidity/outputs/cargo/crate/src/legacy/generated/parse_error.rs b/crates/solidity/outputs/cargo/crate/src/legacy/generated/parse_error.rs index 12af5b7550..2cd9e5de59 100644 --- a/crates/solidity/outputs/cargo/crate/src/legacy/generated/parse_error.rs +++ b/crates/solidity/outputs/cargo/crate/src/legacy/generated/parse_error.rs @@ -1,11 +1,12 @@ // This file is generated automatically by infrastructure scripts. Please don't edit by hand. use super::{ - kinds::*, parse_output::ParseError, text_index::{TextIndex, TextRange}, }; +use crate::syntax::nodes::TokenKind; + impl ParseError { #[allow(dead_code)] pub(crate) fn new_at_position( diff --git a/crates/solidity/outputs/cargo/crate/src/legacy/generated/parse_output.rs b/crates/solidity/outputs/cargo/crate/src/legacy/generated/parse_output.rs index 046767ee43..4187957e40 100644 --- a/crates/solidity/outputs/cargo/crate/src/legacy/generated/parse_output.rs +++ b/crates/solidity/outputs/cargo/crate/src/legacy/generated/parse_output.rs @@ -2,7 +2,9 @@ use std::collections::BTreeSet; -use super::{cst, kinds::TokenKind, parse_error::render_error_report, text_index::TextRange}; +use super::{cst, parse_error::render_error_report, text_index::TextRange}; + +use crate::syntax::nodes::TokenKind; #[derive(Debug, PartialEq)] pub struct ParseOutput { diff --git a/crates/solidity/outputs/cargo/crate/src/legacy/generated/parser_function.rs b/crates/solidity/outputs/cargo/crate/src/legacy/generated/parser_function.rs index 12cdac89db..f11c8903a6 100644 --- a/crates/solidity/outputs/cargo/crate/src/legacy/generated/parser_function.rs +++ b/crates/solidity/outputs/cargo/crate/src/legacy/generated/parser_function.rs @@ -2,12 +2,13 @@ use super::{ cst, - kinds::*, parse_output::{ParseError, ParseOutput}, parser_result::*, stream::Stream, }; +use crate::syntax::nodes::TokenKind; + // Return type of the function has to be a type parameter of the trait pub trait ParserFunction where diff --git a/crates/solidity/outputs/cargo/crate/src/legacy/generated/parser_result.rs b/crates/solidity/outputs/cargo/crate/src/legacy/generated/parser_result.rs index ccbdd31645..cd65e18a2e 100644 --- a/crates/solidity/outputs/cargo/crate/src/legacy/generated/parser_result.rs +++ b/crates/solidity/outputs/cargo/crate/src/legacy/generated/parser_result.rs @@ -1,6 +1,8 @@ // This file is generated automatically by infrastructure scripts. Please don't edit by hand. -use super::{cst, kinds::*, stream::Stream}; +use super::{cst, stream::Stream}; + +use crate::syntax::nodes::{RuleKind, TokenKind}; #[derive(PartialEq, Eq, Clone, Debug)] pub struct Match { diff --git a/crates/solidity/outputs/cargo/crate/src/legacy/generated/parsers.rs b/crates/solidity/outputs/cargo/crate/src/legacy/generated/parsers.rs index bee83fc936..26a5c5b496 100644 --- a/crates/solidity/outputs/cargo/crate/src/legacy/generated/parsers.rs +++ b/crates/solidity/outputs/cargo/crate/src/legacy/generated/parsers.rs @@ -1,12 +1,13 @@ // This file is generated automatically by infrastructure scripts. Please don't edit by hand. use super::cst; -use super::kinds::*; use super::language::Language; use super::parser_helpers::*; use super::parser_result::*; use super::stream::*; +use crate::syntax::nodes::{RuleKind, TokenKind}; + impl Language { fn parse_token_with_trivia( &self, diff --git a/crates/solidity/outputs/cargo/crate/src/legacy/generated/scanner_function.rs b/crates/solidity/outputs/cargo/crate/src/legacy/generated/scanner_function.rs index 256d056e40..a7b5e1ac83 100644 --- a/crates/solidity/outputs/cargo/crate/src/legacy/generated/scanner_function.rs +++ b/crates/solidity/outputs/cargo/crate/src/legacy/generated/scanner_function.rs @@ -2,11 +2,12 @@ use super::{ cst, - kinds::*, parse_output::{ParseError, ParseOutput}, stream::Stream, }; +use crate::syntax::nodes::TokenKind; + // Return type of the function has to be a type parameter of the trait pub trait ScannerFunction where diff --git a/crates/solidity/outputs/cargo/crate/src/main.rs b/crates/solidity/outputs/cargo/crate/src/main.rs index 512b2f64fd..9e0567180b 100644 --- a/crates/solidity/outputs/cargo/crate/src/main.rs +++ b/crates/solidity/outputs/cargo/crate/src/main.rs @@ -3,7 +3,7 @@ use std::{fs, path::PathBuf}; use anyhow::{Context, Result}; use clap::{Parser as ClapParser, Subcommand}; use semver::Version; -use slang_solidity::{language::Language, syntax::parser::ProductionKind}; +use slang_solidity::{language::Language, syntax::nodes::ProductionKind}; // Below are dependencies used by the API `lib.rs`, but not the CLI "main.rs". // However, we need to add a fake usage to suppress Cargo warnings about unused dependencies. diff --git a/crates/solidity/outputs/cargo/crate/src/syntax/nodes/generated/mod.rs b/crates/solidity/outputs/cargo/crate/src/syntax/nodes/generated/mod.rs new file mode 100644 index 0000000000..e33333cdaf --- /dev/null +++ b/crates/solidity/outputs/cargo/crate/src/syntax/nodes/generated/mod.rs @@ -0,0 +1,5 @@ +// This file is generated automatically by infrastructure scripts. Please don't edit by hand. + +pub mod production_kind; +pub mod rule_kind; +pub mod token_kind; diff --git a/crates/solidity/outputs/cargo/crate/src/syntax/nodes/generated/production_kind.rs b/crates/solidity/outputs/cargo/crate/src/syntax/nodes/generated/production_kind.rs new file mode 100644 index 0000000000..025a9de2a4 --- /dev/null +++ b/crates/solidity/outputs/cargo/crate/src/syntax/nodes/generated/production_kind.rs @@ -0,0 +1,312 @@ +// This file is generated automatically by infrastructure scripts. Please don't edit by hand. + +#[cfg(feature = "slang_napi_interfaces")] +use napi::bindgen_prelude::*; +#[derive( + Debug, + Eq, + Ord, + PartialEq, + PartialOrd, + serde :: Serialize, + strum_macros :: AsRefStr, + strum_macros :: Display, + strum_macros :: EnumString, +)] +#[cfg_attr( + feature = "slang_napi_interfaces", + napi(string_enum, namespace = "syntax$nodes") +)] +#[cfg_attr(not(feature = "slang_napi_interfaces"), derive(Clone, Copy))] +pub enum ProductionKind { + ABICoderPragma, + AbicoderKeyword, + AbstractKeyword, + AddressKeyword, + AddressType, + Ampersand, + AmpersandAmpersand, + AmpersandEqual, + AnonymousKeyword, + ArgumentsDeclaration, + ArrayExpression, + ArrayValuesList, + AsKeyword, + AsciiStringLiteral, + AsciiStringLiteralsList, + AssemblyFlagsList, + AssemblyKeyword, + AssemblyStatement, + Asterisk, + AsteriskAsterisk, + AsteriskEqual, + Bang, + BangEqual, + Bar, + BarBar, + BarEqual, + Block, + BoolKeyword, + BreakKeyword, + BreakStatement, + ByteKeyword, + CalldataKeyword, + Caret, + CaretEqual, + CaseKeyword, + CatchClause, + CatchClauseError, + CatchClausesList, + CatchKeyword, + CloseBrace, + CloseBracket, + CloseParen, + Colon, + ColonEqual, + Comma, + ConstantDefinition, + ConstantKeyword, + ConstructorAttributesList, + ConstructorDefinition, + ConstructorKeyword, + ContinueKeyword, + ContinueStatement, + ContractDefinition, + ContractKeyword, + ContractMembersList, + DaysKeyword, + DecimalLiteral, + DeconstructionImport, + DeconstructionImportSymbol, + DeconstructionImportSymbolsList, + DefaultKeyword, + DeleteKeyword, + DeleteStatement, + DoKeyword, + DoWhileStatement, + ElseKeyword, + EmitKeyword, + EmitStatement, + EndOfFileTrivia, + EndOfLine, + EnumDefinition, + EnumKeyword, + Equal, + EqualEqual, + EqualGreaterThan, + ErrorDefinition, + ErrorKeyword, + ErrorParameter, + ErrorParametersList, + EtherKeyword, + EventDefinition, + EventKeyword, + EventParameter, + EventParametersList, + ExperimentalKeyword, + ExperimentalPragma, + Expression, + ExpressionStatement, + ExternalKeyword, + FallbackFunctionAttributesList, + FallbackFunctionDefinition, + FallbackKeyword, + FalseKeyword, + FinneyKeyword, + FixedBytesType, + ForKeyword, + ForStatement, + FromKeyword, + FunctionAttributesList, + FunctionCallOptions, + FunctionDefinition, + FunctionKeyword, + FunctionType, + FunctionTypeAttributesList, + GlobalKeyword, + GreaterThan, + GreaterThanEqual, + GreaterThanGreaterThan, + GreaterThanGreaterThanEqual, + GreaterThanGreaterThanGreaterThan, + GreaterThanGreaterThanGreaterThanEqual, + GweiKeyword, + HexLiteral, + HexStringLiteral, + HexStringLiteralsList, + HoursKeyword, + Identifier, + IdentifierPath, + IdentifierPathsList, + IdentifiersList, + IfKeyword, + IfStatement, + ImmutableKeyword, + ImportDirective, + ImportKeyword, + IndexedKeyword, + InheritanceSpecifier, + InheritanceType, + InheritanceTypesList, + InterfaceDefinition, + InterfaceKeyword, + InterfaceMembersList, + InternalKeyword, + IsKeyword, + LeadingTrivia, + LeaveKeyword, + LessThan, + LessThanEqual, + LessThanLessThan, + LessThanLessThanEqual, + LetKeyword, + LibraryDefinition, + LibraryKeyword, + LibraryMembersList, + MappingKeyType, + MappingKeyword, + MappingType, + MappingValueType, + MemoryKeyword, + Minus, + MinusEqual, + MinusGreaterThan, + MinusMinus, + MinutesKeyword, + ModifierAttributesList, + ModifierDefinition, + ModifierInvocation, + ModifierKeyword, + MultilineComment, + NamedArgument, + NamedArgumentsDeclaration, + NamedArgumentsList, + NamedImport, + NewExpression, + NewKeyword, + NumericExpression, + OpenBrace, + OpenBracket, + OpenParen, + OverrideKeyword, + OverrideSpecifier, + Parameter, + ParametersDeclaration, + ParametersList, + PathImport, + PayableKeyword, + Percent, + PercentEqual, + Period, + Plus, + PlusEqual, + PlusPlus, + PositionalArgumentsList, + PragmaDirective, + PragmaKeyword, + PrivateKeyword, + PublicKeyword, + PureKeyword, + QuestionMark, + ReceiveFunctionAttributesList, + ReceiveFunctionDefinition, + ReceiveKeyword, + ReturnKeyword, + ReturnStatement, + ReturnsDeclaration, + ReturnsKeyword, + RevertKeyword, + RevertStatement, + SecondsKeyword, + Semicolon, + SignedFixedType, + SignedIntegerType, + SingleLineComment, + Slash, + SlashEqual, + SolidityKeyword, + SourceUnit, + SourceUnitMembersList, + StateVariableAttributesList, + StateVariableDefinition, + Statement, + StatementsList, + StorageKeyword, + StringKeyword, + StructDefinition, + StructKeyword, + StructMember, + StructMembersList, + SwitchKeyword, + SzaboKeyword, + ThrowKeyword, + ThrowStatement, + Tilde, + TrailingTrivia, + TrueKeyword, + TryKeyword, + TryStatement, + TupleDeconstructionStatement, + TupleExpression, + TupleMember, + TupleMembersList, + TupleValuesList, + TypeExpression, + TypeKeyword, + TypeName, + UncheckedBlock, + UncheckedKeyword, + UnicodeStringLiteral, + UnicodeStringLiteralsList, + UnnamedFunctionAttributesList, + UnnamedFunctionDefinition, + UnsignedFixedType, + UnsignedIntegerType, + UserDefinedValueTypeDefinition, + UsingDirective, + UsingDirectiveDeconstruction, + UsingDirectivePath, + UsingDirectiveSymbol, + UsingDirectiveSymbolsList, + UsingKeyword, + VarKeyword, + VariableDeclaration, + VariableDeclarationStatement, + VersionPragma, + VersionPragmaExpression, + VersionPragmaExpressionsList, + VersionPragmaSpecifier, + VersionPragmaValue, + ViewKeyword, + VirtualKeyword, + WeeksKeyword, + WeiKeyword, + WhileKeyword, + WhileStatement, + Whitespace, + YearsKeyword, + YulAssignmentStatement, + YulBlock, + YulBreakStatement, + YulContinueStatement, + YulDecimalLiteral, + YulDeclarationStatement, + YulExpression, + YulExpressionsList, + YulForStatement, + YulFunctionDefinition, + YulHexLiteral, + YulIdentifier, + YulIdentifierPath, + YulIdentifierPathsList, + YulIdentifiersList, + YulIfStatement, + YulLeaveStatement, + YulParametersDeclaration, + YulReturnsDeclaration, + YulStatement, + YulStatementsList, + YulSwitchCase, + YulSwitchCasesList, + YulSwitchStatement, +} diff --git a/crates/solidity/outputs/cargo/crate/src/syntax/nodes/generated/rule_kind.rs b/crates/solidity/outputs/cargo/crate/src/syntax/nodes/generated/rule_kind.rs new file mode 100644 index 0000000000..6285bc2547 --- /dev/null +++ b/crates/solidity/outputs/cargo/crate/src/syntax/nodes/generated/rule_kind.rs @@ -0,0 +1,172 @@ +// This file is generated automatically by infrastructure scripts. Please don't edit by hand. + +#[cfg(feature = "slang_napi_interfaces")] +use napi::bindgen_prelude::*; +#[derive( + Debug, + Eq, + Ord, + PartialEq, + PartialOrd, + serde :: Serialize, + strum_macros :: AsRefStr, + strum_macros :: Display, + strum_macros :: EnumString, +)] +#[cfg_attr( + feature = "slang_napi_interfaces", + napi(string_enum, namespace = "syntax$nodes") +)] +#[cfg_attr(not(feature = "slang_napi_interfaces"), derive(Clone, Copy))] +pub enum RuleKind { + ABICoderPragma, + AddressType, + ArgumentsDeclaration, + ArrayExpression, + ArrayTypeName, + ArrayValuesList, + AsciiStringLiteralsList, + AssemblyFlagsList, + AssemblyStatement, + BinaryExpression, + Block, + BreakStatement, + CatchClause, + CatchClauseError, + CatchClausesList, + ConditionalExpression, + ConstantDefinition, + ConstructorAttributesList, + ConstructorDefinition, + ContinueStatement, + ContractDefinition, + ContractMembersList, + DeconstructionImport, + DeconstructionImportSymbol, + DeconstructionImportSymbolsList, + DeleteStatement, + DoWhileStatement, + EmitStatement, + EndOfFileTrivia, + EnumDefinition, + ErrorDefinition, + ErrorParameter, + ErrorParametersList, + EventDefinition, + EventParameter, + EventParametersList, + ExperimentalPragma, + Expression, + ExpressionStatement, + FallbackFunctionAttributesList, + FallbackFunctionDefinition, + ForStatement, + FunctionAttributesList, + FunctionCallExpression, + FunctionCallOptions, + FunctionDefinition, + FunctionType, + FunctionTypeAttributesList, + HexStringLiteralsList, + IdentifierPath, + IdentifierPathsList, + IdentifiersList, + IfStatement, + ImportDirective, + IndexAccessExpression, + InheritanceSpecifier, + InheritanceType, + InheritanceTypesList, + InterfaceDefinition, + InterfaceMembersList, + LeadingTrivia, + LibraryDefinition, + LibraryMembersList, + MappingKeyType, + MappingType, + MappingValueType, + MemberAccessExpression, + ModifierAttributesList, + ModifierDefinition, + ModifierInvocation, + NamedArgument, + NamedArgumentsDeclaration, + NamedArgumentsList, + NamedImport, + NewExpression, + NumericExpression, + OverrideSpecifier, + Parameter, + ParametersDeclaration, + ParametersList, + PathImport, + PositionalArgumentsList, + PragmaDirective, + ReceiveFunctionAttributesList, + ReceiveFunctionDefinition, + ReturnStatement, + ReturnsDeclaration, + RevertStatement, + SourceUnit, + SourceUnitMembersList, + StateVariableAttributesList, + StateVariableDefinition, + Statement, + StatementsList, + StructDefinition, + StructMember, + StructMembersList, + ThrowStatement, + TrailingTrivia, + TryStatement, + TupleDeconstructionStatement, + TupleExpression, + TupleMember, + TupleMembersList, + TupleValuesList, + TypeExpression, + TypeName, + UnaryPostfixExpression, + UnaryPrefixExpression, + UncheckedBlock, + UnicodeStringLiteralsList, + UnnamedFunctionAttributesList, + UnnamedFunctionDefinition, + UserDefinedValueTypeDefinition, + UsingDirective, + UsingDirectiveDeconstruction, + UsingDirectivePath, + UsingDirectiveSymbol, + UsingDirectiveSymbolsList, + VariableDeclaration, + VariableDeclarationStatement, + VersionPragma, + VersionPragmaBinaryExpression, + VersionPragmaExpression, + VersionPragmaExpressionsList, + VersionPragmaSpecifier, + VersionPragmaUnaryExpression, + WhileStatement, + YulAssignmentStatement, + YulBlock, + YulBreakStatement, + YulContinueStatement, + YulDeclarationStatement, + YulExpression, + YulExpressionsList, + YulForStatement, + YulFunctionCallExpression, + YulFunctionDefinition, + YulIdentifierPath, + YulIdentifierPathsList, + YulIdentifiersList, + YulIfStatement, + YulLeaveStatement, + YulParametersDeclaration, + YulReturnsDeclaration, + YulStatement, + YulStatementsList, + YulSwitchCase, + YulSwitchCasesList, + YulSwitchStatement, +} diff --git a/crates/solidity/outputs/cargo/crate/src/syntax/nodes/generated/token_kind.rs b/crates/solidity/outputs/cargo/crate/src/syntax/nodes/generated/token_kind.rs new file mode 100644 index 0000000000..3921f586eb --- /dev/null +++ b/crates/solidity/outputs/cargo/crate/src/syntax/nodes/generated/token_kind.rs @@ -0,0 +1,174 @@ +// This file is generated automatically by infrastructure scripts. Please don't edit by hand. + +#[cfg(feature = "slang_napi_interfaces")] +use napi::bindgen_prelude::*; +#[derive( + Debug, + Eq, + Ord, + PartialEq, + PartialOrd, + serde :: Serialize, + strum_macros :: AsRefStr, + strum_macros :: Display, + strum_macros :: EnumString, +)] +#[cfg_attr( + feature = "slang_napi_interfaces", + napi(string_enum, namespace = "syntax$nodes") +)] +#[cfg_attr(not(feature = "slang_napi_interfaces"), derive(Clone, Copy))] +pub enum TokenKind { + SKIPPED, + AbicoderKeyword, + AbstractKeyword, + AddressKeyword, + Ampersand, + AmpersandAmpersand, + AmpersandEqual, + AnonymousKeyword, + AsKeyword, + AsciiStringLiteral, + AssemblyKeyword, + Asterisk, + AsteriskAsterisk, + AsteriskEqual, + Bang, + BangEqual, + Bar, + BarBar, + BarEqual, + BoolKeyword, + BreakKeyword, + ByteKeyword, + CalldataKeyword, + Caret, + CaretEqual, + CaseKeyword, + CatchKeyword, + CloseBrace, + CloseBracket, + CloseParen, + Colon, + ColonEqual, + Comma, + ConstantKeyword, + ConstructorKeyword, + ContinueKeyword, + ContractKeyword, + DaysKeyword, + DecimalLiteral, + DefaultKeyword, + DeleteKeyword, + DoKeyword, + ElseKeyword, + EmitKeyword, + EndOfLine, + EnumKeyword, + Equal, + EqualEqual, + EqualGreaterThan, + ErrorKeyword, + EtherKeyword, + EventKeyword, + ExperimentalKeyword, + ExternalKeyword, + FallbackKeyword, + FalseKeyword, + FinneyKeyword, + FixedBytesType, + ForKeyword, + FromKeyword, + FunctionKeyword, + GlobalKeyword, + GreaterThan, + GreaterThanEqual, + GreaterThanGreaterThan, + GreaterThanGreaterThanEqual, + GreaterThanGreaterThanGreaterThan, + GreaterThanGreaterThanGreaterThanEqual, + GweiKeyword, + HexLiteral, + HexStringLiteral, + HoursKeyword, + Identifier, + IfKeyword, + ImmutableKeyword, + ImportKeyword, + IndexedKeyword, + InterfaceKeyword, + InternalKeyword, + IsKeyword, + LeaveKeyword, + LessThan, + LessThanEqual, + LessThanLessThan, + LessThanLessThanEqual, + LetKeyword, + LibraryKeyword, + MappingKeyword, + MemoryKeyword, + Minus, + MinusEqual, + MinusGreaterThan, + MinusMinus, + MinutesKeyword, + ModifierKeyword, + MultilineComment, + NewKeyword, + OpenBrace, + OpenBracket, + OpenParen, + OverrideKeyword, + PayableKeyword, + Percent, + PercentEqual, + Period, + Plus, + PlusEqual, + PlusPlus, + PragmaKeyword, + PrivateKeyword, + PublicKeyword, + PureKeyword, + QuestionMark, + ReceiveKeyword, + ReturnKeyword, + ReturnsKeyword, + RevertKeyword, + SecondsKeyword, + Semicolon, + SignedFixedType, + SignedIntegerType, + SingleLineComment, + Slash, + SlashEqual, + SolidityKeyword, + StorageKeyword, + StringKeyword, + StructKeyword, + SwitchKeyword, + SzaboKeyword, + ThrowKeyword, + Tilde, + TrueKeyword, + TryKeyword, + TypeKeyword, + UncheckedKeyword, + UnicodeStringLiteral, + UnsignedFixedType, + UnsignedIntegerType, + UsingKeyword, + VarKeyword, + VersionPragmaValue, + ViewKeyword, + VirtualKeyword, + WeeksKeyword, + WeiKeyword, + WhileKeyword, + Whitespace, + YearsKeyword, + YulDecimalLiteral, + YulHexLiteral, + YulIdentifier, +} diff --git a/crates/solidity/outputs/cargo/crate/src/syntax/nodes/mod.rs b/crates/solidity/outputs/cargo/crate/src/syntax/nodes/mod.rs index 456ea8860c..706f6f95b1 100644 --- a/crates/solidity/outputs/cargo/crate/src/syntax/nodes/mod.rs +++ b/crates/solidity/outputs/cargo/crate/src/syntax/nodes/mod.rs @@ -1,7 +1,10 @@ +mod generated; + pub use crate::legacy::generated::{ cst::{Node, RuleNode, TokenNode}, cursor::Cursor, - kinds::{RuleKind, TokenKind}, text_index::{TextIndex, TextRange, TextRangeExtensions}, visitor::{Visitor, VisitorEntryResponse, VisitorExitResponse}, }; + +pub use generated::{production_kind::ProductionKind, rule_kind::RuleKind, token_kind::TokenKind}; diff --git a/crates/solidity/outputs/cargo/crate/src/syntax/parser/mod.rs b/crates/solidity/outputs/cargo/crate/src/syntax/parser/mod.rs index 66eceef422..4d7b57380b 100644 --- a/crates/solidity/outputs/cargo/crate/src/syntax/parser/mod.rs +++ b/crates/solidity/outputs/cargo/crate/src/syntax/parser/mod.rs @@ -1,4 +1 @@ -pub use crate::legacy::generated::{ - kinds::ProductionKind, - parse_output::{ParseError, ParseOutput}, -}; +pub use crate::legacy::generated::parse_output::{ParseError, ParseOutput}; 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 5eb5f929ac..0b4e39aaf8 100644 --- a/crates/solidity/outputs/cargo/tests/src/cst_output/runner.rs +++ b/crates/solidity/outputs/cargo/tests/src/cst_output/runner.rs @@ -5,7 +5,7 @@ use codegen_utils::context::CodegenContext; use semver::Version; use slang_solidity::{ language::{Error, Language}, - syntax::parser::{ParseOutput, ProductionKind}, + syntax::{nodes::ProductionKind, parser::ParseOutput}, }; use solidity_testing_utils::cst_snapshots::ParseOutputTestSnapshotExtensions; diff --git a/crates/solidity/outputs/cargo/tests/src/doc_examples/cursor_api.rs b/crates/solidity/outputs/cargo/tests/src/doc_examples/cursor_api.rs index 48dc4dedc0..e768622bcf 100644 --- a/crates/solidity/outputs/cargo/tests/src/doc_examples/cursor_api.rs +++ b/crates/solidity/outputs/cargo/tests/src/doc_examples/cursor_api.rs @@ -3,10 +3,7 @@ use semver::Version; use slang_solidity::{ language::Language, - syntax::{ - nodes::{RuleKind, TokenKind}, - parser::ProductionKind, - }, + syntax::nodes::{ProductionKind, RuleKind, TokenKind}, }; #[test] diff --git a/crates/solidity/outputs/cargo/tests/src/doc_examples/simple_contract.rs b/crates/solidity/outputs/cargo/tests/src/doc_examples/simple_contract.rs index e4dc30245d..1d9198173c 100644 --- a/crates/solidity/outputs/cargo/tests/src/doc_examples/simple_contract.rs +++ b/crates/solidity/outputs/cargo/tests/src/doc_examples/simple_contract.rs @@ -3,10 +3,7 @@ use semver::Version; use slang_solidity::{ language::Language, - syntax::{ - nodes::{Node, RuleKind, TokenKind}, - parser::ProductionKind, - }, + syntax::nodes::{Node, ProductionKind, RuleKind, TokenKind}, }; #[test] diff --git a/crates/solidity/outputs/cargo/tests/src/doc_examples/visitor_api.rs b/crates/solidity/outputs/cargo/tests/src/doc_examples/visitor_api.rs index ee51bf6961..9ab5e027df 100644 --- a/crates/solidity/outputs/cargo/tests/src/doc_examples/visitor_api.rs +++ b/crates/solidity/outputs/cargo/tests/src/doc_examples/visitor_api.rs @@ -5,9 +5,8 @@ use semver::Version; use slang_solidity::{ language::Language, - syntax::{ - nodes::{Cursor, Node, RuleKind, RuleNode, TokenKind, Visitor, VisitorEntryResponse}, - parser::ProductionKind, + syntax::nodes::{ + Cursor, Node, ProductionKind, RuleKind, RuleNode, TokenKind, Visitor, VisitorEntryResponse, }, }; diff --git a/crates/solidity/outputs/cargo/tests/src/errors/mod.rs b/crates/solidity/outputs/cargo/tests/src/errors/mod.rs index 8f006578b8..a38a20d558 100644 --- a/crates/solidity/outputs/cargo/tests/src/errors/mod.rs +++ b/crates/solidity/outputs/cargo/tests/src/errors/mod.rs @@ -1,5 +1,5 @@ use semver::Version; -use slang_solidity::{language::Language, syntax::parser::ProductionKind}; +use slang_solidity::{language::Language, syntax::nodes::ProductionKind}; #[test] fn unsupported_language_version() { diff --git a/crates/solidity/outputs/npm/crate/Cargo.toml b/crates/solidity/outputs/npm/crate/Cargo.toml index 5802e03833..baf1e97404 100644 --- a/crates/solidity/outputs/npm/crate/Cargo.toml +++ b/crates/solidity/outputs/npm/crate/Cargo.toml @@ -8,6 +8,13 @@ publish = false [lib] crate-type = ["cdylib"] +[features] +default = ["slang_napi_interfaces"] +slang_napi_interfaces = [ + # This feature is used to enable `#[napi]` attributes on Rust API types. + # It is defined here as we import the source files via `#[path] mod` declarations. +] + [dev-dependencies] solidity_npm_build = { workspace = true } diff --git a/crates/solidity/outputs/npm/crate/src/generated/cst_types.rs b/crates/solidity/outputs/npm/crate/src/generated/cst_types.rs index 0d636e0d81..09758f16f7 100644 --- a/crates/solidity/outputs/npm/crate/src/generated/cst_types.rs +++ b/crates/solidity/outputs/npm/crate/src/generated/cst_types.rs @@ -2,7 +2,6 @@ use super::{ cst::{Node, RuleNode as RustRuleNode, TokenNode as RustTokenNode}, - kinds::*, text_index::{TextIndex as RustTextIndex, TextRange as RustTextRange}, }; diff --git a/crates/solidity/outputs/npm/crate/src/legacy/generated/cst.rs b/crates/solidity/outputs/npm/crate/src/legacy/generated/cst.rs index 508a9fb2b5..a597d931d5 100644 --- a/crates/solidity/outputs/npm/crate/src/legacy/generated/cst.rs +++ b/crates/solidity/outputs/npm/crate/src/legacy/generated/cst.rs @@ -4,11 +4,9 @@ use std::rc::Rc; use serde::Serialize; -use super::{ - cursor::Cursor, - kinds::{RuleKind, TokenKind}, - text_index::TextIndex, -}; +use super::{cursor::Cursor, text_index::TextIndex}; + +use crate::syntax::nodes::{RuleKind, TokenKind}; #[derive(Clone, Debug, PartialEq, Eq, Serialize)] pub struct RuleNode { diff --git a/crates/solidity/outputs/npm/crate/src/legacy/generated/cst_ts_wrappers.rs b/crates/solidity/outputs/npm/crate/src/legacy/generated/cst_ts_wrappers.rs index c2fe811520..c119c09b5c 100644 --- a/crates/solidity/outputs/npm/crate/src/legacy/generated/cst_ts_wrappers.rs +++ b/crates/solidity/outputs/npm/crate/src/legacy/generated/cst_ts_wrappers.rs @@ -3,7 +3,6 @@ use super::{ cst::{Node as RustNode, RuleNode as RustRuleNode, TokenNode as RustTokenNode}, cursor_ts_wrappers::Cursor, - kinds::*, text_index::{TextIndex as RustTextIndex, TextRange as RustTextRange}, }; @@ -13,6 +12,8 @@ use napi::bindgen_prelude::*; use napi::JsObject; use napi::NapiValue; +use crate::syntax::nodes::{RuleKind, TokenKind}; + #[napi(object, namespace = "legacy")] #[derive(Copy, Clone)] pub struct TextIndex { diff --git a/crates/solidity/outputs/npm/crate/src/legacy/generated/cursor.rs b/crates/solidity/outputs/npm/crate/src/legacy/generated/cursor.rs index 77700d57b9..9a98b592c0 100644 --- a/crates/solidity/outputs/npm/crate/src/legacy/generated/cursor.rs +++ b/crates/solidity/outputs/npm/crate/src/legacy/generated/cursor.rs @@ -4,10 +4,11 @@ use std::rc::Rc; use super::{ cst::{Node, RuleNode, TokenNode}, - kinds::{RuleKind, TokenKind}, text_index::{TextIndex, TextRange}, }; +use crate::syntax::nodes::{RuleKind, TokenKind}; + #[derive(Clone, Debug, PartialEq, Eq)] struct CursorPathElement { rule_node: Rc, diff --git a/crates/solidity/outputs/npm/crate/src/legacy/generated/cursor_ts_wrappers.rs b/crates/solidity/outputs/npm/crate/src/legacy/generated/cursor_ts_wrappers.rs index 4f4cd6ff1c..8b9fe7c963 100644 --- a/crates/solidity/outputs/npm/crate/src/legacy/generated/cursor_ts_wrappers.rs +++ b/crates/solidity/outputs/npm/crate/src/legacy/generated/cursor_ts_wrappers.rs @@ -3,12 +3,13 @@ use super::{ cst_ts_wrappers::{TextIndex, TextRange, ToJS}, cursor::Cursor as RustCursor, - kinds::*, }; use napi::bindgen_prelude::*; use napi::JsObject; +use crate::syntax::nodes::{RuleKind, TokenKind}; + #[napi(namespace = "legacy")] pub struct Cursor(Box); diff --git a/crates/solidity/outputs/npm/crate/src/legacy/generated/kinds.rs b/crates/solidity/outputs/npm/crate/src/legacy/generated/kinds.rs deleted file mode 100644 index 3fbc5ef073..0000000000 --- a/crates/solidity/outputs/npm/crate/src/legacy/generated/kinds.rs +++ /dev/null @@ -1,633 +0,0 @@ -// This file is generated automatically by infrastructure scripts. Please don't edit by hand. - -use napi::bindgen_prelude::*; -use napi_derive::napi; -use serde::Serialize; -#[napi(string_enum, namespace = "legacy")] -#[derive( - Debug, - PartialEq, - Eq, - Serialize, - strum_macros :: EnumString, - strum_macros :: AsRefStr, - strum_macros :: Display, -)] -pub enum TokenKind { - SKIPPED, - AbicoderKeyword, - AbstractKeyword, - AddressKeyword, - Ampersand, - AmpersandAmpersand, - AmpersandEqual, - AnonymousKeyword, - AsKeyword, - AsciiStringLiteral, - AssemblyKeyword, - Asterisk, - AsteriskAsterisk, - AsteriskEqual, - Bang, - BangEqual, - Bar, - BarBar, - BarEqual, - BoolKeyword, - BreakKeyword, - ByteKeyword, - CalldataKeyword, - Caret, - CaretEqual, - CaseKeyword, - CatchKeyword, - CloseBrace, - CloseBracket, - CloseParen, - Colon, - ColonEqual, - Comma, - ConstantKeyword, - ConstructorKeyword, - ContinueKeyword, - ContractKeyword, - DaysKeyword, - DecimalLiteral, - DefaultKeyword, - DeleteKeyword, - DoKeyword, - ElseKeyword, - EmitKeyword, - EndOfLine, - EnumKeyword, - Equal, - EqualEqual, - EqualGreaterThan, - ErrorKeyword, - EtherKeyword, - EventKeyword, - ExperimentalKeyword, - ExternalKeyword, - FallbackKeyword, - FalseKeyword, - FinneyKeyword, - FixedBytesType, - ForKeyword, - FromKeyword, - FunctionKeyword, - GlobalKeyword, - GreaterThan, - GreaterThanEqual, - GreaterThanGreaterThan, - GreaterThanGreaterThanEqual, - GreaterThanGreaterThanGreaterThan, - GreaterThanGreaterThanGreaterThanEqual, - GweiKeyword, - HexLiteral, - HexStringLiteral, - HoursKeyword, - Identifier, - IfKeyword, - ImmutableKeyword, - ImportKeyword, - IndexedKeyword, - InterfaceKeyword, - InternalKeyword, - IsKeyword, - LeaveKeyword, - LessThan, - LessThanEqual, - LessThanLessThan, - LessThanLessThanEqual, - LetKeyword, - LibraryKeyword, - MappingKeyword, - MemoryKeyword, - Minus, - MinusEqual, - MinusGreaterThan, - MinusMinus, - MinutesKeyword, - ModifierKeyword, - MultilineComment, - NewKeyword, - OpenBrace, - OpenBracket, - OpenParen, - OverrideKeyword, - PayableKeyword, - Percent, - PercentEqual, - Period, - Plus, - PlusEqual, - PlusPlus, - PragmaKeyword, - PrivateKeyword, - PublicKeyword, - PureKeyword, - QuestionMark, - ReceiveKeyword, - ReturnKeyword, - ReturnsKeyword, - RevertKeyword, - SecondsKeyword, - Semicolon, - SignedFixedType, - SignedIntegerType, - SingleLineComment, - Slash, - SlashEqual, - SolidityKeyword, - StorageKeyword, - StringKeyword, - StructKeyword, - SwitchKeyword, - SzaboKeyword, - ThrowKeyword, - Tilde, - TrueKeyword, - TryKeyword, - TypeKeyword, - UncheckedKeyword, - UnicodeStringLiteral, - UnsignedFixedType, - UnsignedIntegerType, - UsingKeyword, - VarKeyword, - VersionPragmaValue, - ViewKeyword, - VirtualKeyword, - WeeksKeyword, - WeiKeyword, - WhileKeyword, - Whitespace, - YearsKeyword, - YulDecimalLiteral, - YulHexLiteral, - YulIdentifier, -} -#[napi(string_enum, namespace = "legacy")] -#[derive( - Debug, - PartialEq, - Eq, - Serialize, - strum_macros :: EnumString, - strum_macros :: AsRefStr, - strum_macros :: Display, -)] -pub enum RuleKind { - ABICoderPragma, - AddressType, - ArgumentsDeclaration, - ArrayExpression, - ArrayTypeName, - ArrayValuesList, - AsciiStringLiteralsList, - AssemblyFlagsList, - AssemblyStatement, - BinaryExpression, - Block, - BreakStatement, - CatchClause, - CatchClauseError, - CatchClausesList, - ConditionalExpression, - ConstantDefinition, - ConstructorAttributesList, - ConstructorDefinition, - ContinueStatement, - ContractDefinition, - ContractMembersList, - DeconstructionImport, - DeconstructionImportSymbol, - DeconstructionImportSymbolsList, - DeleteStatement, - DoWhileStatement, - EmitStatement, - EndOfFileTrivia, - EnumDefinition, - ErrorDefinition, - ErrorParameter, - ErrorParametersList, - EventDefinition, - EventParameter, - EventParametersList, - ExperimentalPragma, - Expression, - ExpressionStatement, - FallbackFunctionAttributesList, - FallbackFunctionDefinition, - ForStatement, - FunctionAttributesList, - FunctionCallExpression, - FunctionCallOptions, - FunctionDefinition, - FunctionType, - FunctionTypeAttributesList, - HexStringLiteralsList, - IdentifierPath, - IdentifierPathsList, - IdentifiersList, - IfStatement, - ImportDirective, - IndexAccessExpression, - InheritanceSpecifier, - InheritanceType, - InheritanceTypesList, - InterfaceDefinition, - InterfaceMembersList, - LeadingTrivia, - LibraryDefinition, - LibraryMembersList, - MappingKeyType, - MappingType, - MappingValueType, - MemberAccessExpression, - ModifierAttributesList, - ModifierDefinition, - ModifierInvocation, - NamedArgument, - NamedArgumentsDeclaration, - NamedArgumentsList, - NamedImport, - NewExpression, - NumericExpression, - OverrideSpecifier, - Parameter, - ParametersDeclaration, - ParametersList, - PathImport, - PositionalArgumentsList, - PragmaDirective, - ReceiveFunctionAttributesList, - ReceiveFunctionDefinition, - ReturnStatement, - ReturnsDeclaration, - RevertStatement, - SourceUnit, - SourceUnitMembersList, - StateVariableAttributesList, - StateVariableDefinition, - Statement, - StatementsList, - StructDefinition, - StructMember, - StructMembersList, - ThrowStatement, - TrailingTrivia, - TryStatement, - TupleDeconstructionStatement, - TupleExpression, - TupleMember, - TupleMembersList, - TupleValuesList, - TypeExpression, - TypeName, - UnaryPostfixExpression, - UnaryPrefixExpression, - UncheckedBlock, - UnicodeStringLiteralsList, - UnnamedFunctionAttributesList, - UnnamedFunctionDefinition, - UserDefinedValueTypeDefinition, - UsingDirective, - UsingDirectiveDeconstruction, - UsingDirectivePath, - UsingDirectiveSymbol, - UsingDirectiveSymbolsList, - VariableDeclaration, - VariableDeclarationStatement, - VersionPragma, - VersionPragmaBinaryExpression, - VersionPragmaExpression, - VersionPragmaExpressionsList, - VersionPragmaSpecifier, - VersionPragmaUnaryExpression, - WhileStatement, - YulAssignmentStatement, - YulBlock, - YulBreakStatement, - YulContinueStatement, - YulDeclarationStatement, - YulExpression, - YulExpressionsList, - YulForStatement, - YulFunctionCallExpression, - YulFunctionDefinition, - YulIdentifierPath, - YulIdentifierPathsList, - YulIdentifiersList, - YulIfStatement, - YulLeaveStatement, - YulParametersDeclaration, - YulReturnsDeclaration, - YulStatement, - YulStatementsList, - YulSwitchCase, - YulSwitchCasesList, - YulSwitchStatement, -} -#[napi(string_enum, namespace = "legacy")] -#[derive( - Debug, - PartialEq, - Eq, - Serialize, - strum_macros :: EnumString, - strum_macros :: AsRefStr, - strum_macros :: Display, -)] -pub enum ProductionKind { - ABICoderPragma, - AbicoderKeyword, - AbstractKeyword, - AddressKeyword, - AddressType, - Ampersand, - AmpersandAmpersand, - AmpersandEqual, - AnonymousKeyword, - ArgumentsDeclaration, - ArrayExpression, - ArrayValuesList, - AsKeyword, - AsciiStringLiteral, - AsciiStringLiteralsList, - AssemblyFlagsList, - AssemblyKeyword, - AssemblyStatement, - Asterisk, - AsteriskAsterisk, - AsteriskEqual, - Bang, - BangEqual, - Bar, - BarBar, - BarEqual, - Block, - BoolKeyword, - BreakKeyword, - BreakStatement, - ByteKeyword, - CalldataKeyword, - Caret, - CaretEqual, - CaseKeyword, - CatchClause, - CatchClauseError, - CatchClausesList, - CatchKeyword, - CloseBrace, - CloseBracket, - CloseParen, - Colon, - ColonEqual, - Comma, - ConstantDefinition, - ConstantKeyword, - ConstructorAttributesList, - ConstructorDefinition, - ConstructorKeyword, - ContinueKeyword, - ContinueStatement, - ContractDefinition, - ContractKeyword, - ContractMembersList, - DaysKeyword, - DecimalLiteral, - DeconstructionImport, - DeconstructionImportSymbol, - DeconstructionImportSymbolsList, - DefaultKeyword, - DeleteKeyword, - DeleteStatement, - DoKeyword, - DoWhileStatement, - ElseKeyword, - EmitKeyword, - EmitStatement, - EndOfFileTrivia, - EndOfLine, - EnumDefinition, - EnumKeyword, - Equal, - EqualEqual, - EqualGreaterThan, - ErrorDefinition, - ErrorKeyword, - ErrorParameter, - ErrorParametersList, - EtherKeyword, - EventDefinition, - EventKeyword, - EventParameter, - EventParametersList, - ExperimentalKeyword, - ExperimentalPragma, - Expression, - ExpressionStatement, - ExternalKeyword, - FallbackFunctionAttributesList, - FallbackFunctionDefinition, - FallbackKeyword, - FalseKeyword, - FinneyKeyword, - FixedBytesType, - ForKeyword, - ForStatement, - FromKeyword, - FunctionAttributesList, - FunctionCallOptions, - FunctionDefinition, - FunctionKeyword, - FunctionType, - FunctionTypeAttributesList, - GlobalKeyword, - GreaterThan, - GreaterThanEqual, - GreaterThanGreaterThan, - GreaterThanGreaterThanEqual, - GreaterThanGreaterThanGreaterThan, - GreaterThanGreaterThanGreaterThanEqual, - GweiKeyword, - HexLiteral, - HexStringLiteral, - HexStringLiteralsList, - HoursKeyword, - Identifier, - IdentifierPath, - IdentifierPathsList, - IdentifiersList, - IfKeyword, - IfStatement, - ImmutableKeyword, - ImportDirective, - ImportKeyword, - IndexedKeyword, - InheritanceSpecifier, - InheritanceType, - InheritanceTypesList, - InterfaceDefinition, - InterfaceKeyword, - InterfaceMembersList, - InternalKeyword, - IsKeyword, - LeadingTrivia, - LeaveKeyword, - LessThan, - LessThanEqual, - LessThanLessThan, - LessThanLessThanEqual, - LetKeyword, - LibraryDefinition, - LibraryKeyword, - LibraryMembersList, - MappingKeyType, - MappingKeyword, - MappingType, - MappingValueType, - MemoryKeyword, - Minus, - MinusEqual, - MinusGreaterThan, - MinusMinus, - MinutesKeyword, - ModifierAttributesList, - ModifierDefinition, - ModifierInvocation, - ModifierKeyword, - MultilineComment, - NamedArgument, - NamedArgumentsDeclaration, - NamedArgumentsList, - NamedImport, - NewExpression, - NewKeyword, - NumericExpression, - OpenBrace, - OpenBracket, - OpenParen, - OverrideKeyword, - OverrideSpecifier, - Parameter, - ParametersDeclaration, - ParametersList, - PathImport, - PayableKeyword, - Percent, - PercentEqual, - Period, - Plus, - PlusEqual, - PlusPlus, - PositionalArgumentsList, - PragmaDirective, - PragmaKeyword, - PrivateKeyword, - PublicKeyword, - PureKeyword, - QuestionMark, - ReceiveFunctionAttributesList, - ReceiveFunctionDefinition, - ReceiveKeyword, - ReturnKeyword, - ReturnStatement, - ReturnsDeclaration, - ReturnsKeyword, - RevertKeyword, - RevertStatement, - SecondsKeyword, - Semicolon, - SignedFixedType, - SignedIntegerType, - SingleLineComment, - Slash, - SlashEqual, - SolidityKeyword, - SourceUnit, - SourceUnitMembersList, - StateVariableAttributesList, - StateVariableDefinition, - Statement, - StatementsList, - StorageKeyword, - StringKeyword, - StructDefinition, - StructKeyword, - StructMember, - StructMembersList, - SwitchKeyword, - SzaboKeyword, - ThrowKeyword, - ThrowStatement, - Tilde, - TrailingTrivia, - TrueKeyword, - TryKeyword, - TryStatement, - TupleDeconstructionStatement, - TupleExpression, - TupleMember, - TupleMembersList, - TupleValuesList, - TypeExpression, - TypeKeyword, - TypeName, - UncheckedBlock, - UncheckedKeyword, - UnicodeStringLiteral, - UnicodeStringLiteralsList, - UnnamedFunctionAttributesList, - UnnamedFunctionDefinition, - UnsignedFixedType, - UnsignedIntegerType, - UserDefinedValueTypeDefinition, - UsingDirective, - UsingDirectiveDeconstruction, - UsingDirectivePath, - UsingDirectiveSymbol, - UsingDirectiveSymbolsList, - UsingKeyword, - VarKeyword, - VariableDeclaration, - VariableDeclarationStatement, - VersionPragma, - VersionPragmaExpression, - VersionPragmaExpressionsList, - VersionPragmaSpecifier, - VersionPragmaValue, - ViewKeyword, - VirtualKeyword, - WeeksKeyword, - WeiKeyword, - WhileKeyword, - WhileStatement, - Whitespace, - YearsKeyword, - YulAssignmentStatement, - YulBlock, - YulBreakStatement, - YulContinueStatement, - YulDecimalLiteral, - YulDeclarationStatement, - YulExpression, - YulExpressionsList, - YulForStatement, - YulFunctionDefinition, - YulHexLiteral, - YulIdentifier, - YulIdentifierPath, - YulIdentifierPathsList, - YulIdentifiersList, - YulIfStatement, - YulLeaveStatement, - YulParametersDeclaration, - YulReturnsDeclaration, - YulStatement, - YulStatementsList, - YulSwitchCase, - YulSwitchCasesList, - YulSwitchStatement, -} diff --git a/crates/solidity/outputs/npm/crate/src/legacy/generated/language.rs b/crates/solidity/outputs/npm/crate/src/legacy/generated/language.rs index 27b1f41b92..9bbf4710d4 100644 --- a/crates/solidity/outputs/npm/crate/src/legacy/generated/language.rs +++ b/crates/solidity/outputs/npm/crate/src/legacy/generated/language.rs @@ -4,7 +4,10 @@ use semver::Version; #[allow(unused_imports)] -use super::{kinds::*, parse_output::*, parser_function::*, scanner_function::*}; +use super::{parse_output::*, parser_function::*, scanner_function::*}; + +#[allow(unused_imports)] +use crate::syntax::nodes::{ProductionKind, RuleKind, TokenKind}; #[napi(namespace = "legacy")] pub struct Language { diff --git a/crates/solidity/outputs/npm/crate/src/legacy/generated/mod.rs b/crates/solidity/outputs/npm/crate/src/legacy/generated/mod.rs index 17fd981d1f..d3715a31f7 100644 --- a/crates/solidity/outputs/npm/crate/src/legacy/generated/mod.rs +++ b/crates/solidity/outputs/npm/crate/src/legacy/generated/mod.rs @@ -6,7 +6,6 @@ pub mod cst; pub mod cst_ts_wrappers; pub mod cursor; pub mod cursor_ts_wrappers; -pub mod kinds; pub mod language; pub mod parse_error; pub mod parse_output; diff --git a/crates/solidity/outputs/npm/crate/src/legacy/generated/parse_error.rs b/crates/solidity/outputs/npm/crate/src/legacy/generated/parse_error.rs index 12af5b7550..2cd9e5de59 100644 --- a/crates/solidity/outputs/npm/crate/src/legacy/generated/parse_error.rs +++ b/crates/solidity/outputs/npm/crate/src/legacy/generated/parse_error.rs @@ -1,11 +1,12 @@ // This file is generated automatically by infrastructure scripts. Please don't edit by hand. use super::{ - kinds::*, parse_output::ParseError, text_index::{TextIndex, TextRange}, }; +use crate::syntax::nodes::TokenKind; + impl ParseError { #[allow(dead_code)] pub(crate) fn new_at_position( diff --git a/crates/solidity/outputs/npm/crate/src/legacy/generated/parse_output.rs b/crates/solidity/outputs/npm/crate/src/legacy/generated/parse_output.rs index e6e3f0c7aa..7a83899427 100644 --- a/crates/solidity/outputs/npm/crate/src/legacy/generated/parse_output.rs +++ b/crates/solidity/outputs/npm/crate/src/legacy/generated/parse_output.rs @@ -2,14 +2,16 @@ use std::collections::BTreeSet; +use napi::bindgen_prelude::*; + use super::{ cst, cst_ts_wrappers::{TextRange, ToJS}, - kinds::TokenKind, parse_error::render_error_report, text_index::TextRange as RustTextRange, }; -use napi::bindgen_prelude::*; + +use crate::syntax::nodes::TokenKind; #[napi(namespace = "legacy")] pub struct ParseOutput { diff --git a/crates/solidity/outputs/npm/crate/src/legacy/generated/parser_function.rs b/crates/solidity/outputs/npm/crate/src/legacy/generated/parser_function.rs index 12cdac89db..f11c8903a6 100644 --- a/crates/solidity/outputs/npm/crate/src/legacy/generated/parser_function.rs +++ b/crates/solidity/outputs/npm/crate/src/legacy/generated/parser_function.rs @@ -2,12 +2,13 @@ use super::{ cst, - kinds::*, parse_output::{ParseError, ParseOutput}, parser_result::*, stream::Stream, }; +use crate::syntax::nodes::TokenKind; + // Return type of the function has to be a type parameter of the trait pub trait ParserFunction where diff --git a/crates/solidity/outputs/npm/crate/src/legacy/generated/parser_result.rs b/crates/solidity/outputs/npm/crate/src/legacy/generated/parser_result.rs index ccbdd31645..cd65e18a2e 100644 --- a/crates/solidity/outputs/npm/crate/src/legacy/generated/parser_result.rs +++ b/crates/solidity/outputs/npm/crate/src/legacy/generated/parser_result.rs @@ -1,6 +1,8 @@ // This file is generated automatically by infrastructure scripts. Please don't edit by hand. -use super::{cst, kinds::*, stream::Stream}; +use super::{cst, stream::Stream}; + +use crate::syntax::nodes::{RuleKind, TokenKind}; #[derive(PartialEq, Eq, Clone, Debug)] pub struct Match { diff --git a/crates/solidity/outputs/npm/crate/src/legacy/generated/parsers.rs b/crates/solidity/outputs/npm/crate/src/legacy/generated/parsers.rs index bee83fc936..26a5c5b496 100644 --- a/crates/solidity/outputs/npm/crate/src/legacy/generated/parsers.rs +++ b/crates/solidity/outputs/npm/crate/src/legacy/generated/parsers.rs @@ -1,12 +1,13 @@ // This file is generated automatically by infrastructure scripts. Please don't edit by hand. use super::cst; -use super::kinds::*; use super::language::Language; use super::parser_helpers::*; use super::parser_result::*; use super::stream::*; +use crate::syntax::nodes::{RuleKind, TokenKind}; + impl Language { fn parse_token_with_trivia( &self, diff --git a/crates/solidity/outputs/npm/crate/src/legacy/generated/scanner_function.rs b/crates/solidity/outputs/npm/crate/src/legacy/generated/scanner_function.rs index 256d056e40..a7b5e1ac83 100644 --- a/crates/solidity/outputs/npm/crate/src/legacy/generated/scanner_function.rs +++ b/crates/solidity/outputs/npm/crate/src/legacy/generated/scanner_function.rs @@ -2,11 +2,12 @@ use super::{ cst, - kinds::*, parse_output::{ParseError, ParseOutput}, stream::Stream, }; +use crate::syntax::nodes::TokenKind; + // Return type of the function has to be a type parameter of the trait pub trait ScannerFunction where diff --git a/crates/solidity/outputs/npm/crate/src/lib.rs b/crates/solidity/outputs/npm/crate/src/lib.rs index a0a2edd3a0..cfe7c2dec4 100644 --- a/crates/solidity/outputs/npm/crate/src/lib.rs +++ b/crates/solidity/outputs/npm/crate/src/lib.rs @@ -1,5 +1,7 @@ mod legacy; +pub mod syntax; + // Make sure codegen runs before building for tests. #[cfg(test)] use solidity_npm_build as _; diff --git a/crates/solidity/outputs/npm/crate/src/syntax/mod.rs b/crates/solidity/outputs/npm/crate/src/syntax/mod.rs new file mode 100644 index 0000000000..69e3fea510 --- /dev/null +++ b/crates/solidity/outputs/npm/crate/src/syntax/mod.rs @@ -0,0 +1 @@ +pub mod nodes; diff --git a/crates/solidity/outputs/npm/crate/src/syntax/nodes/mod.rs b/crates/solidity/outputs/npm/crate/src/syntax/nodes/mod.rs new file mode 100644 index 0000000000..9669a40c75 --- /dev/null +++ b/crates/solidity/outputs/npm/crate/src/syntax/nodes/mod.rs @@ -0,0 +1,4 @@ +#[path = "../../../../../cargo/crate/src/syntax/nodes/generated/mod.rs"] +mod generated; + +pub use generated::{production_kind::ProductionKind, rule_kind::RuleKind, token_kind::TokenKind}; diff --git a/crates/solidity/outputs/npm/package/generated/index.d.ts b/crates/solidity/outputs/npm/package/generated/index.d.ts index 05a7f64576..2a2db64acc 100644 --- a/crates/solidity/outputs/npm/package/generated/index.d.ts +++ b/crates/solidity/outputs/npm/package/generated/index.d.ts @@ -22,18 +22,76 @@ export namespace legacy { Rule = 0, Token = 1, } - export enum TokenKind { - SKIPPED = "SKIPPED", + export class RuleNode { + get type(): NodeType.Rule; + get kind(): RuleKind; + get textLength(): TextIndex; + get children(): Array; + } + export class TokenNode { + get type(): NodeType.Token; + get kind(): TokenKind; + get textLength(): TextIndex; + get text(): string; + } + export class Cursor { + get reset(): void; + get complete(): void; + clone(): Cursor; + spawn(): Cursor; + get isCompleted(): boolean; + get node(): RuleNode | TokenNode; + get textOffset(): TextIndex; + get textRange(): TextRange; + get pathRuleNodes(): Array; + goToNext(): boolean; + goToNextNonDescendent(): boolean; + goToPrevious(): boolean; + goToParent(): boolean; + goToFirstChild(): boolean; + goToLastChild(): boolean; + goToNthChild(childNumber: number): boolean; + goToNextSibling(): boolean; + goToPreviousSibling(): boolean; + findTokenWithKind(kinds: Array): TokenNode | null; + findRuleWithKind(kinds: Array): RuleNode | null; + } + export class Language { + constructor(version: string); + get version(): string; + static supportedVersions(): Array; + parse(productionKind: ProductionKind, input: string): ParseOutput; + } + export class ParseOutput { + get parseTree(): RuleNode | TokenNode | null; + get errors(): Array; + get isValid(): boolean; + } + export class ParseError { + get textRange(): TextRange; + toErrorReport(sourceId: string, source: string, withColour: boolean): string; + } +} +export namespace syntax$nodes { + export enum ProductionKind { + ABICoderPragma = "ABICoderPragma", AbicoderKeyword = "AbicoderKeyword", AbstractKeyword = "AbstractKeyword", AddressKeyword = "AddressKeyword", + AddressType = "AddressType", Ampersand = "Ampersand", AmpersandAmpersand = "AmpersandAmpersand", AmpersandEqual = "AmpersandEqual", AnonymousKeyword = "AnonymousKeyword", + ArgumentsDeclaration = "ArgumentsDeclaration", + ArrayExpression = "ArrayExpression", + ArrayValuesList = "ArrayValuesList", AsKeyword = "AsKeyword", AsciiStringLiteral = "AsciiStringLiteral", + AsciiStringLiteralsList = "AsciiStringLiteralsList", + AssemblyFlagsList = "AssemblyFlagsList", AssemblyKeyword = "AssemblyKeyword", + AssemblyStatement = "AssemblyStatement", Asterisk = "Asterisk", AsteriskAsterisk = "AsteriskAsterisk", AsteriskEqual = "AsteriskEqual", @@ -42,13 +100,18 @@ export namespace legacy { Bar = "Bar", BarBar = "BarBar", BarEqual = "BarEqual", + Block = "Block", BoolKeyword = "BoolKeyword", BreakKeyword = "BreakKeyword", + BreakStatement = "BreakStatement", ByteKeyword = "ByteKeyword", CalldataKeyword = "CalldataKeyword", Caret = "Caret", CaretEqual = "CaretEqual", CaseKeyword = "CaseKeyword", + CatchClause = "CatchClause", + CatchClauseError = "CatchClauseError", + CatchClausesList = "CatchClausesList", CatchKeyword = "CatchKeyword", CloseBrace = "CloseBrace", CloseBracket = "CloseBracket", @@ -56,34 +119,65 @@ export namespace legacy { Colon = "Colon", ColonEqual = "ColonEqual", Comma = "Comma", + ConstantDefinition = "ConstantDefinition", ConstantKeyword = "ConstantKeyword", + ConstructorAttributesList = "ConstructorAttributesList", + ConstructorDefinition = "ConstructorDefinition", ConstructorKeyword = "ConstructorKeyword", ContinueKeyword = "ContinueKeyword", + ContinueStatement = "ContinueStatement", + ContractDefinition = "ContractDefinition", ContractKeyword = "ContractKeyword", + ContractMembersList = "ContractMembersList", DaysKeyword = "DaysKeyword", DecimalLiteral = "DecimalLiteral", + DeconstructionImport = "DeconstructionImport", + DeconstructionImportSymbol = "DeconstructionImportSymbol", + DeconstructionImportSymbolsList = "DeconstructionImportSymbolsList", DefaultKeyword = "DefaultKeyword", DeleteKeyword = "DeleteKeyword", + DeleteStatement = "DeleteStatement", DoKeyword = "DoKeyword", + DoWhileStatement = "DoWhileStatement", ElseKeyword = "ElseKeyword", EmitKeyword = "EmitKeyword", + EmitStatement = "EmitStatement", + EndOfFileTrivia = "EndOfFileTrivia", EndOfLine = "EndOfLine", + EnumDefinition = "EnumDefinition", EnumKeyword = "EnumKeyword", Equal = "Equal", EqualEqual = "EqualEqual", EqualGreaterThan = "EqualGreaterThan", + ErrorDefinition = "ErrorDefinition", ErrorKeyword = "ErrorKeyword", + ErrorParameter = "ErrorParameter", + ErrorParametersList = "ErrorParametersList", EtherKeyword = "EtherKeyword", + EventDefinition = "EventDefinition", EventKeyword = "EventKeyword", + EventParameter = "EventParameter", + EventParametersList = "EventParametersList", ExperimentalKeyword = "ExperimentalKeyword", + ExperimentalPragma = "ExperimentalPragma", + Expression = "Expression", + ExpressionStatement = "ExpressionStatement", ExternalKeyword = "ExternalKeyword", + FallbackFunctionAttributesList = "FallbackFunctionAttributesList", + FallbackFunctionDefinition = "FallbackFunctionDefinition", FallbackKeyword = "FallbackKeyword", FalseKeyword = "FalseKeyword", FinneyKeyword = "FinneyKeyword", FixedBytesType = "FixedBytesType", ForKeyword = "ForKeyword", + ForStatement = "ForStatement", FromKeyword = "FromKeyword", + FunctionAttributesList = "FunctionAttributesList", + FunctionCallOptions = "FunctionCallOptions", + FunctionDefinition = "FunctionDefinition", FunctionKeyword = "FunctionKeyword", + FunctionType = "FunctionType", + FunctionTypeAttributesList = "FunctionTypeAttributesList", GlobalKeyword = "GlobalKeyword", GreaterThan = "GreaterThan", GreaterThanEqual = "GreaterThanEqual", @@ -94,36 +188,67 @@ export namespace legacy { GweiKeyword = "GweiKeyword", HexLiteral = "HexLiteral", HexStringLiteral = "HexStringLiteral", + HexStringLiteralsList = "HexStringLiteralsList", HoursKeyword = "HoursKeyword", Identifier = "Identifier", + IdentifierPath = "IdentifierPath", + IdentifierPathsList = "IdentifierPathsList", + IdentifiersList = "IdentifiersList", IfKeyword = "IfKeyword", + IfStatement = "IfStatement", ImmutableKeyword = "ImmutableKeyword", + ImportDirective = "ImportDirective", ImportKeyword = "ImportKeyword", IndexedKeyword = "IndexedKeyword", + InheritanceSpecifier = "InheritanceSpecifier", + InheritanceType = "InheritanceType", + InheritanceTypesList = "InheritanceTypesList", + InterfaceDefinition = "InterfaceDefinition", InterfaceKeyword = "InterfaceKeyword", + InterfaceMembersList = "InterfaceMembersList", InternalKeyword = "InternalKeyword", IsKeyword = "IsKeyword", + LeadingTrivia = "LeadingTrivia", LeaveKeyword = "LeaveKeyword", LessThan = "LessThan", LessThanEqual = "LessThanEqual", LessThanLessThan = "LessThanLessThan", LessThanLessThanEqual = "LessThanLessThanEqual", LetKeyword = "LetKeyword", + LibraryDefinition = "LibraryDefinition", LibraryKeyword = "LibraryKeyword", + LibraryMembersList = "LibraryMembersList", + MappingKeyType = "MappingKeyType", MappingKeyword = "MappingKeyword", + MappingType = "MappingType", + MappingValueType = "MappingValueType", MemoryKeyword = "MemoryKeyword", Minus = "Minus", MinusEqual = "MinusEqual", MinusGreaterThan = "MinusGreaterThan", MinusMinus = "MinusMinus", MinutesKeyword = "MinutesKeyword", + ModifierAttributesList = "ModifierAttributesList", + ModifierDefinition = "ModifierDefinition", + ModifierInvocation = "ModifierInvocation", ModifierKeyword = "ModifierKeyword", MultilineComment = "MultilineComment", + NamedArgument = "NamedArgument", + NamedArgumentsDeclaration = "NamedArgumentsDeclaration", + NamedArgumentsList = "NamedArgumentsList", + NamedImport = "NamedImport", + NewExpression = "NewExpression", NewKeyword = "NewKeyword", + NumericExpression = "NumericExpression", OpenBrace = "OpenBrace", OpenBracket = "OpenBracket", OpenParen = "OpenParen", OverrideKeyword = "OverrideKeyword", + OverrideSpecifier = "OverrideSpecifier", + Parameter = "Parameter", + ParametersDeclaration = "ParametersDeclaration", + ParametersList = "ParametersList", + PathImport = "PathImport", PayableKeyword = "PayableKeyword", Percent = "Percent", PercentEqual = "PercentEqual", @@ -131,15 +256,22 @@ export namespace legacy { Plus = "Plus", PlusEqual = "PlusEqual", PlusPlus = "PlusPlus", + PositionalArgumentsList = "PositionalArgumentsList", + PragmaDirective = "PragmaDirective", PragmaKeyword = "PragmaKeyword", PrivateKeyword = "PrivateKeyword", PublicKeyword = "PublicKeyword", PureKeyword = "PureKeyword", QuestionMark = "QuestionMark", + ReceiveFunctionAttributesList = "ReceiveFunctionAttributesList", + ReceiveFunctionDefinition = "ReceiveFunctionDefinition", ReceiveKeyword = "ReceiveKeyword", ReturnKeyword = "ReturnKeyword", + ReturnStatement = "ReturnStatement", + ReturnsDeclaration = "ReturnsDeclaration", ReturnsKeyword = "ReturnsKeyword", RevertKeyword = "RevertKeyword", + RevertStatement = "RevertStatement", SecondsKeyword = "SecondsKeyword", Semicolon = "Semicolon", SignedFixedType = "SignedFixedType", @@ -148,33 +280,90 @@ export namespace legacy { Slash = "Slash", SlashEqual = "SlashEqual", SolidityKeyword = "SolidityKeyword", + SourceUnit = "SourceUnit", + SourceUnitMembersList = "SourceUnitMembersList", + StateVariableAttributesList = "StateVariableAttributesList", + StateVariableDefinition = "StateVariableDefinition", + Statement = "Statement", + StatementsList = "StatementsList", StorageKeyword = "StorageKeyword", StringKeyword = "StringKeyword", + StructDefinition = "StructDefinition", StructKeyword = "StructKeyword", + StructMember = "StructMember", + StructMembersList = "StructMembersList", SwitchKeyword = "SwitchKeyword", SzaboKeyword = "SzaboKeyword", ThrowKeyword = "ThrowKeyword", + ThrowStatement = "ThrowStatement", Tilde = "Tilde", + TrailingTrivia = "TrailingTrivia", TrueKeyword = "TrueKeyword", TryKeyword = "TryKeyword", + TryStatement = "TryStatement", + TupleDeconstructionStatement = "TupleDeconstructionStatement", + TupleExpression = "TupleExpression", + TupleMember = "TupleMember", + TupleMembersList = "TupleMembersList", + TupleValuesList = "TupleValuesList", + TypeExpression = "TypeExpression", TypeKeyword = "TypeKeyword", + TypeName = "TypeName", + UncheckedBlock = "UncheckedBlock", UncheckedKeyword = "UncheckedKeyword", UnicodeStringLiteral = "UnicodeStringLiteral", + UnicodeStringLiteralsList = "UnicodeStringLiteralsList", + UnnamedFunctionAttributesList = "UnnamedFunctionAttributesList", + UnnamedFunctionDefinition = "UnnamedFunctionDefinition", UnsignedFixedType = "UnsignedFixedType", UnsignedIntegerType = "UnsignedIntegerType", + UserDefinedValueTypeDefinition = "UserDefinedValueTypeDefinition", + UsingDirective = "UsingDirective", + UsingDirectiveDeconstruction = "UsingDirectiveDeconstruction", + UsingDirectivePath = "UsingDirectivePath", + UsingDirectiveSymbol = "UsingDirectiveSymbol", + UsingDirectiveSymbolsList = "UsingDirectiveSymbolsList", UsingKeyword = "UsingKeyword", VarKeyword = "VarKeyword", + VariableDeclaration = "VariableDeclaration", + VariableDeclarationStatement = "VariableDeclarationStatement", + VersionPragma = "VersionPragma", + VersionPragmaExpression = "VersionPragmaExpression", + VersionPragmaExpressionsList = "VersionPragmaExpressionsList", + VersionPragmaSpecifier = "VersionPragmaSpecifier", VersionPragmaValue = "VersionPragmaValue", ViewKeyword = "ViewKeyword", VirtualKeyword = "VirtualKeyword", WeeksKeyword = "WeeksKeyword", WeiKeyword = "WeiKeyword", WhileKeyword = "WhileKeyword", + WhileStatement = "WhileStatement", Whitespace = "Whitespace", YearsKeyword = "YearsKeyword", + YulAssignmentStatement = "YulAssignmentStatement", + YulBlock = "YulBlock", + YulBreakStatement = "YulBreakStatement", + YulContinueStatement = "YulContinueStatement", YulDecimalLiteral = "YulDecimalLiteral", + YulDeclarationStatement = "YulDeclarationStatement", + YulExpression = "YulExpression", + YulExpressionsList = "YulExpressionsList", + YulForStatement = "YulForStatement", + YulFunctionDefinition = "YulFunctionDefinition", YulHexLiteral = "YulHexLiteral", YulIdentifier = "YulIdentifier", + YulIdentifierPath = "YulIdentifierPath", + YulIdentifierPathsList = "YulIdentifierPathsList", + YulIdentifiersList = "YulIdentifiersList", + YulIfStatement = "YulIfStatement", + YulLeaveStatement = "YulLeaveStatement", + YulParametersDeclaration = "YulParametersDeclaration", + YulReturnsDeclaration = "YulReturnsDeclaration", + YulStatement = "YulStatement", + YulStatementsList = "YulStatementsList", + YulSwitchCase = "YulSwitchCase", + YulSwitchCasesList = "YulSwitchCasesList", + YulSwitchStatement = "YulSwitchStatement", } export enum RuleKind { ABICoderPragma = "ABICoderPragma", @@ -328,25 +517,18 @@ export namespace legacy { YulSwitchCasesList = "YulSwitchCasesList", YulSwitchStatement = "YulSwitchStatement", } - export enum ProductionKind { - ABICoderPragma = "ABICoderPragma", + export enum TokenKind { + SKIPPED = "SKIPPED", AbicoderKeyword = "AbicoderKeyword", AbstractKeyword = "AbstractKeyword", AddressKeyword = "AddressKeyword", - AddressType = "AddressType", Ampersand = "Ampersand", AmpersandAmpersand = "AmpersandAmpersand", AmpersandEqual = "AmpersandEqual", AnonymousKeyword = "AnonymousKeyword", - ArgumentsDeclaration = "ArgumentsDeclaration", - ArrayExpression = "ArrayExpression", - ArrayValuesList = "ArrayValuesList", AsKeyword = "AsKeyword", AsciiStringLiteral = "AsciiStringLiteral", - AsciiStringLiteralsList = "AsciiStringLiteralsList", - AssemblyFlagsList = "AssemblyFlagsList", AssemblyKeyword = "AssemblyKeyword", - AssemblyStatement = "AssemblyStatement", Asterisk = "Asterisk", AsteriskAsterisk = "AsteriskAsterisk", AsteriskEqual = "AsteriskEqual", @@ -355,18 +537,13 @@ export namespace legacy { Bar = "Bar", BarBar = "BarBar", BarEqual = "BarEqual", - Block = "Block", BoolKeyword = "BoolKeyword", BreakKeyword = "BreakKeyword", - BreakStatement = "BreakStatement", ByteKeyword = "ByteKeyword", CalldataKeyword = "CalldataKeyword", Caret = "Caret", CaretEqual = "CaretEqual", CaseKeyword = "CaseKeyword", - CatchClause = "CatchClause", - CatchClauseError = "CatchClauseError", - CatchClausesList = "CatchClausesList", CatchKeyword = "CatchKeyword", CloseBrace = "CloseBrace", CloseBracket = "CloseBracket", @@ -374,65 +551,34 @@ export namespace legacy { Colon = "Colon", ColonEqual = "ColonEqual", Comma = "Comma", - ConstantDefinition = "ConstantDefinition", ConstantKeyword = "ConstantKeyword", - ConstructorAttributesList = "ConstructorAttributesList", - ConstructorDefinition = "ConstructorDefinition", ConstructorKeyword = "ConstructorKeyword", ContinueKeyword = "ContinueKeyword", - ContinueStatement = "ContinueStatement", - ContractDefinition = "ContractDefinition", ContractKeyword = "ContractKeyword", - ContractMembersList = "ContractMembersList", DaysKeyword = "DaysKeyword", DecimalLiteral = "DecimalLiteral", - DeconstructionImport = "DeconstructionImport", - DeconstructionImportSymbol = "DeconstructionImportSymbol", - DeconstructionImportSymbolsList = "DeconstructionImportSymbolsList", DefaultKeyword = "DefaultKeyword", DeleteKeyword = "DeleteKeyword", - DeleteStatement = "DeleteStatement", DoKeyword = "DoKeyword", - DoWhileStatement = "DoWhileStatement", ElseKeyword = "ElseKeyword", EmitKeyword = "EmitKeyword", - EmitStatement = "EmitStatement", - EndOfFileTrivia = "EndOfFileTrivia", EndOfLine = "EndOfLine", - EnumDefinition = "EnumDefinition", EnumKeyword = "EnumKeyword", Equal = "Equal", EqualEqual = "EqualEqual", EqualGreaterThan = "EqualGreaterThan", - ErrorDefinition = "ErrorDefinition", ErrorKeyword = "ErrorKeyword", - ErrorParameter = "ErrorParameter", - ErrorParametersList = "ErrorParametersList", EtherKeyword = "EtherKeyword", - EventDefinition = "EventDefinition", EventKeyword = "EventKeyword", - EventParameter = "EventParameter", - EventParametersList = "EventParametersList", ExperimentalKeyword = "ExperimentalKeyword", - ExperimentalPragma = "ExperimentalPragma", - Expression = "Expression", - ExpressionStatement = "ExpressionStatement", ExternalKeyword = "ExternalKeyword", - FallbackFunctionAttributesList = "FallbackFunctionAttributesList", - FallbackFunctionDefinition = "FallbackFunctionDefinition", FallbackKeyword = "FallbackKeyword", FalseKeyword = "FalseKeyword", FinneyKeyword = "FinneyKeyword", FixedBytesType = "FixedBytesType", ForKeyword = "ForKeyword", - ForStatement = "ForStatement", FromKeyword = "FromKeyword", - FunctionAttributesList = "FunctionAttributesList", - FunctionCallOptions = "FunctionCallOptions", - FunctionDefinition = "FunctionDefinition", FunctionKeyword = "FunctionKeyword", - FunctionType = "FunctionType", - FunctionTypeAttributesList = "FunctionTypeAttributesList", GlobalKeyword = "GlobalKeyword", GreaterThan = "GreaterThan", GreaterThanEqual = "GreaterThanEqual", @@ -443,67 +589,36 @@ export namespace legacy { GweiKeyword = "GweiKeyword", HexLiteral = "HexLiteral", HexStringLiteral = "HexStringLiteral", - HexStringLiteralsList = "HexStringLiteralsList", HoursKeyword = "HoursKeyword", Identifier = "Identifier", - IdentifierPath = "IdentifierPath", - IdentifierPathsList = "IdentifierPathsList", - IdentifiersList = "IdentifiersList", IfKeyword = "IfKeyword", - IfStatement = "IfStatement", ImmutableKeyword = "ImmutableKeyword", - ImportDirective = "ImportDirective", ImportKeyword = "ImportKeyword", IndexedKeyword = "IndexedKeyword", - InheritanceSpecifier = "InheritanceSpecifier", - InheritanceType = "InheritanceType", - InheritanceTypesList = "InheritanceTypesList", - InterfaceDefinition = "InterfaceDefinition", InterfaceKeyword = "InterfaceKeyword", - InterfaceMembersList = "InterfaceMembersList", InternalKeyword = "InternalKeyword", IsKeyword = "IsKeyword", - LeadingTrivia = "LeadingTrivia", LeaveKeyword = "LeaveKeyword", LessThan = "LessThan", LessThanEqual = "LessThanEqual", LessThanLessThan = "LessThanLessThan", LessThanLessThanEqual = "LessThanLessThanEqual", LetKeyword = "LetKeyword", - LibraryDefinition = "LibraryDefinition", LibraryKeyword = "LibraryKeyword", - LibraryMembersList = "LibraryMembersList", - MappingKeyType = "MappingKeyType", MappingKeyword = "MappingKeyword", - MappingType = "MappingType", - MappingValueType = "MappingValueType", MemoryKeyword = "MemoryKeyword", Minus = "Minus", MinusEqual = "MinusEqual", MinusGreaterThan = "MinusGreaterThan", MinusMinus = "MinusMinus", MinutesKeyword = "MinutesKeyword", - ModifierAttributesList = "ModifierAttributesList", - ModifierDefinition = "ModifierDefinition", - ModifierInvocation = "ModifierInvocation", ModifierKeyword = "ModifierKeyword", MultilineComment = "MultilineComment", - NamedArgument = "NamedArgument", - NamedArgumentsDeclaration = "NamedArgumentsDeclaration", - NamedArgumentsList = "NamedArgumentsList", - NamedImport = "NamedImport", - NewExpression = "NewExpression", NewKeyword = "NewKeyword", - NumericExpression = "NumericExpression", OpenBrace = "OpenBrace", OpenBracket = "OpenBracket", OpenParen = "OpenParen", OverrideKeyword = "OverrideKeyword", - OverrideSpecifier = "OverrideSpecifier", - Parameter = "Parameter", - ParametersDeclaration = "ParametersDeclaration", - ParametersList = "ParametersList", - PathImport = "PathImport", PayableKeyword = "PayableKeyword", Percent = "Percent", PercentEqual = "PercentEqual", @@ -511,22 +626,15 @@ export namespace legacy { Plus = "Plus", PlusEqual = "PlusEqual", PlusPlus = "PlusPlus", - PositionalArgumentsList = "PositionalArgumentsList", - PragmaDirective = "PragmaDirective", PragmaKeyword = "PragmaKeyword", PrivateKeyword = "PrivateKeyword", PublicKeyword = "PublicKeyword", PureKeyword = "PureKeyword", QuestionMark = "QuestionMark", - ReceiveFunctionAttributesList = "ReceiveFunctionAttributesList", - ReceiveFunctionDefinition = "ReceiveFunctionDefinition", ReceiveKeyword = "ReceiveKeyword", ReturnKeyword = "ReturnKeyword", - ReturnStatement = "ReturnStatement", - ReturnsDeclaration = "ReturnsDeclaration", ReturnsKeyword = "ReturnsKeyword", RevertKeyword = "RevertKeyword", - RevertStatement = "RevertStatement", SecondsKeyword = "SecondsKeyword", Semicolon = "Semicolon", SignedFixedType = "SignedFixedType", @@ -535,138 +643,32 @@ export namespace legacy { Slash = "Slash", SlashEqual = "SlashEqual", SolidityKeyword = "SolidityKeyword", - SourceUnit = "SourceUnit", - SourceUnitMembersList = "SourceUnitMembersList", - StateVariableAttributesList = "StateVariableAttributesList", - StateVariableDefinition = "StateVariableDefinition", - Statement = "Statement", - StatementsList = "StatementsList", StorageKeyword = "StorageKeyword", StringKeyword = "StringKeyword", - StructDefinition = "StructDefinition", StructKeyword = "StructKeyword", - StructMember = "StructMember", - StructMembersList = "StructMembersList", SwitchKeyword = "SwitchKeyword", SzaboKeyword = "SzaboKeyword", ThrowKeyword = "ThrowKeyword", - ThrowStatement = "ThrowStatement", Tilde = "Tilde", - TrailingTrivia = "TrailingTrivia", TrueKeyword = "TrueKeyword", TryKeyword = "TryKeyword", - TryStatement = "TryStatement", - TupleDeconstructionStatement = "TupleDeconstructionStatement", - TupleExpression = "TupleExpression", - TupleMember = "TupleMember", - TupleMembersList = "TupleMembersList", - TupleValuesList = "TupleValuesList", - TypeExpression = "TypeExpression", TypeKeyword = "TypeKeyword", - TypeName = "TypeName", - UncheckedBlock = "UncheckedBlock", UncheckedKeyword = "UncheckedKeyword", UnicodeStringLiteral = "UnicodeStringLiteral", - UnicodeStringLiteralsList = "UnicodeStringLiteralsList", - UnnamedFunctionAttributesList = "UnnamedFunctionAttributesList", - UnnamedFunctionDefinition = "UnnamedFunctionDefinition", UnsignedFixedType = "UnsignedFixedType", UnsignedIntegerType = "UnsignedIntegerType", - UserDefinedValueTypeDefinition = "UserDefinedValueTypeDefinition", - UsingDirective = "UsingDirective", - UsingDirectiveDeconstruction = "UsingDirectiveDeconstruction", - UsingDirectivePath = "UsingDirectivePath", - UsingDirectiveSymbol = "UsingDirectiveSymbol", - UsingDirectiveSymbolsList = "UsingDirectiveSymbolsList", UsingKeyword = "UsingKeyword", VarKeyword = "VarKeyword", - VariableDeclaration = "VariableDeclaration", - VariableDeclarationStatement = "VariableDeclarationStatement", - VersionPragma = "VersionPragma", - VersionPragmaExpression = "VersionPragmaExpression", - VersionPragmaExpressionsList = "VersionPragmaExpressionsList", - VersionPragmaSpecifier = "VersionPragmaSpecifier", VersionPragmaValue = "VersionPragmaValue", ViewKeyword = "ViewKeyword", VirtualKeyword = "VirtualKeyword", WeeksKeyword = "WeeksKeyword", WeiKeyword = "WeiKeyword", WhileKeyword = "WhileKeyword", - WhileStatement = "WhileStatement", Whitespace = "Whitespace", YearsKeyword = "YearsKeyword", - YulAssignmentStatement = "YulAssignmentStatement", - YulBlock = "YulBlock", - YulBreakStatement = "YulBreakStatement", - YulContinueStatement = "YulContinueStatement", YulDecimalLiteral = "YulDecimalLiteral", - YulDeclarationStatement = "YulDeclarationStatement", - YulExpression = "YulExpression", - YulExpressionsList = "YulExpressionsList", - YulForStatement = "YulForStatement", - YulFunctionDefinition = "YulFunctionDefinition", YulHexLiteral = "YulHexLiteral", YulIdentifier = "YulIdentifier", - YulIdentifierPath = "YulIdentifierPath", - YulIdentifierPathsList = "YulIdentifierPathsList", - YulIdentifiersList = "YulIdentifiersList", - YulIfStatement = "YulIfStatement", - YulLeaveStatement = "YulLeaveStatement", - YulParametersDeclaration = "YulParametersDeclaration", - YulReturnsDeclaration = "YulReturnsDeclaration", - YulStatement = "YulStatement", - YulStatementsList = "YulStatementsList", - YulSwitchCase = "YulSwitchCase", - YulSwitchCasesList = "YulSwitchCasesList", - YulSwitchStatement = "YulSwitchStatement", - } - export class RuleNode { - get type(): NodeType.Rule; - get kind(): RuleKind; - get textLength(): TextIndex; - get children(): Array; - } - export class TokenNode { - get type(): NodeType.Token; - get kind(): TokenKind; - get textLength(): TextIndex; - get text(): string; - } - export class Cursor { - get reset(): void; - get complete(): void; - clone(): Cursor; - spawn(): Cursor; - get isCompleted(): boolean; - get node(): RuleNode | TokenNode; - get textOffset(): TextIndex; - get textRange(): TextRange; - get pathRuleNodes(): Array; - goToNext(): boolean; - goToNextNonDescendent(): boolean; - goToPrevious(): boolean; - goToParent(): boolean; - goToFirstChild(): boolean; - goToLastChild(): boolean; - goToNthChild(childNumber: number): boolean; - goToNextSibling(): boolean; - goToPreviousSibling(): boolean; - findTokenWithKind(kinds: Array): TokenNode | null; - findRuleWithKind(kinds: Array): RuleNode | null; - } - export class Language { - constructor(version: string); - get version(): string; - static supportedVersions(): Array; - parse(productionKind: ProductionKind, input: string): ParseOutput; - } - export class ParseOutput { - get parseTree(): RuleNode | TokenNode | null; - get errors(): Array; - get isValid(): boolean; - } - export class ParseError { - get textRange(): TextRange; - toErrorReport(sourceId: string, source: string, withColour: boolean): string; } } diff --git a/crates/solidity/outputs/npm/package/generated/index.js b/crates/solidity/outputs/npm/package/generated/index.js index 58fe65d1d2..8270224409 100644 --- a/crates/solidity/outputs/npm/package/generated/index.js +++ b/crates/solidity/outputs/npm/package/generated/index.js @@ -239,6 +239,7 @@ if (!nativeBinding) { throw new Error(`Failed to load native binding`); } -const { legacy } = nativeBinding; +const { legacy, syntax$nodes } = nativeBinding; module.exports.legacy = legacy; +module.exports.syntax$nodes = syntax$nodes; diff --git a/crates/solidity/outputs/npm/package/syntax/nodes/index.d.ts b/crates/solidity/outputs/npm/package/syntax/nodes/index.d.ts index 27f20f51f9..c34836e2e7 100644 --- a/crates/solidity/outputs/npm/package/syntax/nodes/index.d.ts +++ b/crates/solidity/outputs/npm/package/syntax/nodes/index.d.ts @@ -1,14 +1,13 @@ import * as generated from "../../generated"; +// generated.legacy + export const Cursor: typeof generated.legacy.Cursor; export type Cursor = generated.legacy.Cursor; export const NodeType: typeof generated.legacy.NodeType; export type NodeType = generated.legacy.NodeType; -export const RuleKind: typeof generated.legacy.RuleKind; -export type RuleKind = generated.legacy.RuleKind; - export const RuleNode: typeof generated.legacy.RuleNode; export type RuleNode = generated.legacy.RuleNode; @@ -16,8 +15,16 @@ export type TextIndex = generated.legacy.TextIndex; export type TextRange = generated.legacy.TextRange; -export const TokenKind: typeof generated.legacy.TokenKind; -export type TokenKind = generated.legacy.TokenKind; - export const TokenNode: typeof generated.legacy.TokenNode; export type TokenNode = generated.legacy.TokenNode; + +// generated.syntax$nodes + +export const ProductionKind: typeof generated.syntax$nodes.ProductionKind; +export type ProductionKind = generated.syntax$nodes.ProductionKind; + +export const RuleKind: typeof generated.syntax$nodes.RuleKind; +export type RuleKind = generated.syntax$nodes.RuleKind; + +export const TokenKind: typeof generated.syntax$nodes.TokenKind; +export type TokenKind = generated.syntax$nodes.TokenKind; diff --git a/crates/solidity/outputs/npm/package/syntax/nodes/index.js b/crates/solidity/outputs/npm/package/syntax/nodes/index.js index 5206dfb115..b5ebe1533d 100644 --- a/crates/solidity/outputs/npm/package/syntax/nodes/index.js +++ b/crates/solidity/outputs/npm/package/syntax/nodes/index.js @@ -2,9 +2,15 @@ const generated = require("../../generated"); +// generated.legacy + module.exports.Cursor = generated.legacy.Cursor; module.exports.NodeType = generated.legacy.NodeType; -module.exports.RuleKind = generated.legacy.RuleKind; module.exports.RuleNode = generated.legacy.RuleNode; -module.exports.TokenKind = generated.legacy.TokenKind; module.exports.TokenNode = generated.legacy.TokenNode; + +// generated.syntax$nodes + +module.exports.ProductionKind = generated.syntax$nodes.ProductionKind; +module.exports.RuleKind = generated.syntax$nodes.RuleKind; +module.exports.TokenKind = generated.syntax$nodes.TokenKind; diff --git a/crates/solidity/outputs/npm/package/syntax/parser/index.d.ts b/crates/solidity/outputs/npm/package/syntax/parser/index.d.ts index 076c341b9b..7cc771225b 100644 --- a/crates/solidity/outputs/npm/package/syntax/parser/index.d.ts +++ b/crates/solidity/outputs/npm/package/syntax/parser/index.d.ts @@ -5,6 +5,3 @@ export type ParseError = generated.legacy.ParseError; export const ParseOutput: typeof generated.legacy.ParseOutput; export type ParseOutput = generated.legacy.ParseOutput; - -export const ProductionKind: typeof generated.legacy.ProductionKind; -export type ProductionKind = generated.legacy.ProductionKind; diff --git a/crates/solidity/outputs/npm/package/syntax/parser/index.js b/crates/solidity/outputs/npm/package/syntax/parser/index.js index a295a890cd..7d0441be9c 100644 --- a/crates/solidity/outputs/npm/package/syntax/parser/index.js +++ b/crates/solidity/outputs/npm/package/syntax/parser/index.js @@ -4,4 +4,3 @@ const generated = require("../../generated"); module.exports.ParseError = generated.legacy.ParseError; module.exports.ParseOutput = generated.legacy.ParseOutput; -module.exports.ProductionKind = generated.legacy.ProductionKind; diff --git a/crates/solidity/outputs/npm/tests/src/cst-output.ts b/crates/solidity/outputs/npm/tests/src/cst-output.ts index 0be1649b71..d8fd0a565f 100644 --- a/crates/solidity/outputs/npm/tests/src/cst-output.ts +++ b/crates/solidity/outputs/npm/tests/src/cst-output.ts @@ -1,7 +1,13 @@ import test from "ava"; import { Language } from "@nomicfoundation/slang/language"; -import { NodeType, RuleKind, RuleNode, TokenKind, TokenNode } from "@nomicfoundation/slang/syntax/nodes"; -import { ProductionKind } from "@nomicfoundation/slang/syntax/parser"; +import { + ProductionKind, + NodeType, + RuleKind, + RuleNode, + TokenKind, + TokenNode, +} from "@nomicfoundation/slang/syntax/nodes"; test("parse token", (t) => { const source = "5_286_981"; diff --git a/crates/solidity/outputs/npm/tests/src/doc-examples/simple-contract.ts b/crates/solidity/outputs/npm/tests/src/doc-examples/simple-contract.ts index c85f250ecf..4b7e5ce523 100644 --- a/crates/solidity/outputs/npm/tests/src/doc-examples/simple-contract.ts +++ b/crates/solidity/outputs/npm/tests/src/doc-examples/simple-contract.ts @@ -1,7 +1,6 @@ import test from "ava"; import { Language } from "@nomicfoundation/slang/language"; -import { RuleKind, RuleNode, TokenKind, TokenNode } from "@nomicfoundation/slang/syntax/nodes"; -import { ProductionKind } from "@nomicfoundation/slang/syntax/parser"; +import { ProductionKind, RuleKind, RuleNode, TokenKind, TokenNode } from "@nomicfoundation/slang/syntax/nodes"; test("simple contract", (t) => { const language = new Language("0.8.0"); diff --git a/crates/solidity/outputs/npm/tests/src/errors.ts b/crates/solidity/outputs/npm/tests/src/errors.ts index edbf40b098..08611409ad 100644 --- a/crates/solidity/outputs/npm/tests/src/errors.ts +++ b/crates/solidity/outputs/npm/tests/src/errors.ts @@ -1,6 +1,6 @@ import test from "ava"; import { Language } from "@nomicfoundation/slang/language"; -import { ProductionKind } from "@nomicfoundation/slang/syntax/parser"; +import { ProductionKind } from "@nomicfoundation/slang/syntax/nodes"; test("render error reports", (t) => { const source = "int256 constant"; diff --git a/crates/solidity/outputs/npm/tests/src/public-api.ts b/crates/solidity/outputs/npm/tests/src/public-api.ts index 6adde37197..4b0ea69f6d 100644 --- a/crates/solidity/outputs/npm/tests/src/public-api.ts +++ b/crates/solidity/outputs/npm/tests/src/public-api.ts @@ -1,14 +1,15 @@ import test from "ava"; import * as slang from "@nomicfoundation/slang"; -import { RuleKind } from "@nomicfoundation/slang/syntax/nodes"; -import { ProductionKind } from "@nomicfoundation/slang/syntax/parser"; +import { ProductionKind, RuleKind, TokenKind } from "@nomicfoundation/slang/syntax/nodes"; test("use namespace imports of the API", (t) => { - t.is(typeof slang.syntax.nodes.RuleKind, "object"); - t.is(typeof slang.syntax.parser.ProductionKind, "object"); + t.deepEqual(slang.syntax.nodes.ProductionKind.SourceUnit, "SourceUnit"); + t.deepEqual(slang.syntax.nodes.RuleKind.ContractDefinition, "ContractDefinition"); + t.deepEqual(slang.syntax.nodes.TokenKind.IfKeyword, "IfKeyword"); }); test("use nested imports of the API", (t) => { - t.is(typeof RuleKind, "object"); - t.is(typeof ProductionKind, "object"); + t.deepEqual(ProductionKind.SourceUnit, "SourceUnit"); + t.deepEqual(RuleKind.ContractDefinition, "ContractDefinition"); + t.deepEqual(TokenKind.IfKeyword, "IfKeyword"); }); diff --git a/crates/solidity/testing/smoke/src/main.rs b/crates/solidity/testing/smoke/src/main.rs index e0b3162b68..1a64f0e459 100644 --- a/crates/solidity/testing/smoke/src/main.rs +++ b/crates/solidity/testing/smoke/src/main.rs @@ -7,7 +7,7 @@ use anyhow::Result; use codegen_schema::types::LanguageDefinition; use rayon::prelude::{IntoParallelRefIterator, ParallelIterator}; use semver::Version; -use slang_solidity::{language::Language, syntax::parser::ProductionKind}; +use slang_solidity::{language::Language, syntax::nodes::ProductionKind}; use solidity_language::SolidityLanguageExtensions; use solidity_testing_utils::version_pragmas::extract_version_pragmas; diff --git a/crates/solidity/testing/utils/src/node_extensions/tests.rs b/crates/solidity/testing/utils/src/node_extensions/tests.rs index 591a558a5e..d6824270d9 100644 --- a/crates/solidity/testing/utils/src/node_extensions/tests.rs +++ b/crates/solidity/testing/utils/src/node_extensions/tests.rs @@ -1,6 +1,6 @@ use anyhow::Result; use semver::Version; -use slang_solidity::{language::Language, syntax::parser::ProductionKind}; +use slang_solidity::{language::Language, syntax::nodes::ProductionKind}; use crate::node_extensions::NodeExtensions; diff --git a/crates/solidity/testing/utils/src/version_pragmas/mod.rs b/crates/solidity/testing/utils/src/version_pragmas/mod.rs index 287d3dac17..0659007d0e 100644 --- a/crates/solidity/testing/utils/src/version_pragmas/mod.rs +++ b/crates/solidity/testing/utils/src/version_pragmas/mod.rs @@ -7,10 +7,7 @@ use anyhow::{bail, ensure, Context, Result}; use semver::{Comparator, Op, Version}; use slang_solidity::{ language::Language, - syntax::{ - nodes::{Node, RuleKind, TokenKind}, - parser::ProductionKind, - }, + syntax::nodes::{Node, ProductionKind, RuleKind, TokenKind}, }; use crate::node_extensions::NodeExtensions;