From cddedb0142805ebd72e74f8bce3ceb2b4dcb04aa Mon Sep 17 00:00:00 2001 From: OmarTawfik <15987992+OmarTawfik@users.noreply.github.com> Date: Sun, 18 Aug 2024 17:10:15 -0700 Subject: [PATCH] separate `slang_solidity_cli` into a separate crate and update documentation everywhere. --- .changeset/rare-shrimps-lick.md | 5 + Cargo.lock | 11 +- Cargo.toml | 2 + crates/codegen/runtime/cargo/Cargo.toml | 4 +- .../cargo/src/runtime/cli/commands/mod.rs | 17 - .../cargo/src/runtime/cli/commands/parse.rs | 85 ++-- .../runtime/cargo/src/runtime/cli/mod.rs | 55 ++- .../cargo/src/runtime/diagnostic/mod.rs | 5 +- .../codegen/runtime/cargo/src/runtime/mod.rs | 14 +- .../cli/src/commands/publish/cargo/mod.rs | 1 + crates/metaslang/bindings/README.md | 16 +- crates/metaslang/cst/README.md | 7 +- crates/metaslang/graph_builder/Cargo.toml | 2 +- crates/metaslang/graph_builder/README.md | 19 +- crates/metaslang/graph_builder/src/lib.rs | 5 +- crates/metaslang/graph_builder/tests/main.rs | 15 - .../outputs/cargo/slang_solidity/Cargo.toml | 9 +- .../src/generated/cli/commands/mod.rs | 17 - .../src/generated/cli/commands/parse.rs | 85 ++-- .../slang_solidity/src/generated/cli/mod.rs | 55 ++- .../src/generated/diagnostic/mod.rs | 5 +- .../cargo/slang_solidity/src/generated/mod.rs | 14 +- .../outputs/cargo/slang_solidity/src/lib.rs | 9 - .../outputs/cargo/slang_solidity/src/main.rs | 37 -- .../cargo/slang_solidity_cli/CHANGELOG.md | 368 ++++++++++++++++++ .../cargo/slang_solidity_cli/Cargo.toml | 37 ++ .../outputs/cargo/slang_solidity_cli/LICENSE | 21 + .../cargo/slang_solidity_cli/README.md | 21 + .../cargo/slang_solidity_cli/src/main.rs | 3 + .../outputs/cargo/slang_testlang/Cargo.toml | 4 +- .../src/generated/cli/commands/mod.rs | 17 - .../src/generated/cli/commands/parse.rs | 85 ++-- .../slang_testlang/src/generated/cli/mod.rs | 55 ++- .../src/generated/diagnostic/mod.rs | 5 +- .../cargo/slang_testlang/src/generated/mod.rs | 14 +- .../user-guide/rust-crate/installation.md | 6 +- 36 files changed, 734 insertions(+), 396 deletions(-) create mode 100644 .changeset/rare-shrimps-lick.md delete mode 100644 crates/solidity/outputs/cargo/slang_solidity/src/main.rs create mode 100644 crates/solidity/outputs/cargo/slang_solidity_cli/CHANGELOG.md create mode 100644 crates/solidity/outputs/cargo/slang_solidity_cli/Cargo.toml create mode 100644 crates/solidity/outputs/cargo/slang_solidity_cli/LICENSE create mode 100644 crates/solidity/outputs/cargo/slang_solidity_cli/README.md create mode 100644 crates/solidity/outputs/cargo/slang_solidity_cli/src/main.rs diff --git a/.changeset/rare-shrimps-lick.md b/.changeset/rare-shrimps-lick.md new file mode 100644 index 0000000000..e890271f65 --- /dev/null +++ b/.changeset/rare-shrimps-lick.md @@ -0,0 +1,5 @@ +--- +"@nomicfoundation/slang": minor +--- + +Move the Rust CLI into a separate `slang_solidity_cli` crate. diff --git a/Cargo.lock b/Cargo.lock index 6cdafd9d6b..dba5c504b7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -720,9 +720,9 @@ dependencies = [ [[package]] name = "env_filter" -version = "0.1.0" +version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a009aa4810eb158359dda09d0c87378e4bbb89b5a801f016885a4707ba24f7ea" +checksum = "4f2c92ceda6ceec50f43169f9ee8424fe2db276791afde7b2cd8bc084cb376ab" dependencies = [ "log", "regex", @@ -2227,6 +2227,13 @@ dependencies = [ "wit-bindgen", ] +[[package]] +name = "slang_solidity_cli" +version = "0.16.0" +dependencies = [ + "slang_solidity", +] + [[package]] name = "slang_solidity_node_addon" version = "0.16.0" diff --git a/Cargo.toml b/Cargo.toml index 6ee36b1469..8ac0dff046 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -27,6 +27,7 @@ members = [ "crates/metaslang/graph_builder", "crates/solidity/inputs/language", + "crates/solidity/outputs/cargo/slang_solidity_cli", "crates/solidity/outputs/cargo/slang_solidity_node_addon", "crates/solidity/outputs/cargo/slang_solidity", "crates/solidity/outputs/cargo/tests", @@ -68,6 +69,7 @@ metaslang_graph_builder = { path = "crates/metaslang/graph_builder", version = " metaslang_cst = { path = "crates/metaslang/cst", version = "0.16.0" } slang_solidity = { path = "crates/solidity/outputs/cargo/slang_solidity", version = "0.16.0" } +slang_solidity_cli = { path = "crates/solidity/outputs/cargo/slang_solidity_cli", version = "0.16.0" } slang_solidity_node_addon = { path = "crates/solidity/outputs/cargo/slang_solidity_node_addon", version = "0.16.0" } solidity_cargo_tests = { path = "crates/solidity/outputs/cargo/tests", version = "0.16.0" } solidity_language = { path = "crates/solidity/inputs/language", version = "0.16.0" } diff --git a/crates/codegen/runtime/cargo/Cargo.toml b/crates/codegen/runtime/cargo/Cargo.toml index ea531b5e78..1306f3a357 100644 --- a/crates/codegen/runtime/cargo/Cargo.toml +++ b/crates/codegen/runtime/cargo/Cargo.toml @@ -9,9 +9,9 @@ description = "Cargo runtime copied over by codegen" # __RUST_PRODUCT_CRATE_FEATURES__ (keep in sync) [features] -default = ["cli"] -cli = ["dep:ariadne", "dep:clap", "dep:serde_json"] +default = [] __experimental_bindings_api = ["dep:metaslang_bindings"] +__private_cli_execution = ["dep:ariadne", "dep:clap", "dep:serde_json"] __private_testing_utils = ["dep:ariadne"] __private_wit_bindings = ["dep:paste", "dep:wit-bindgen"] diff --git a/crates/codegen/runtime/cargo/src/runtime/cli/commands/mod.rs b/crates/codegen/runtime/cargo/src/runtime/cli/commands/mod.rs index a0247eeffe..ea868482d6 100644 --- a/crates/codegen/runtime/cargo/src/runtime/cli/commands/mod.rs +++ b/crates/codegen/runtime/cargo/src/runtime/cli/commands/mod.rs @@ -1,18 +1 @@ -use thiserror::Error; - pub mod parse; - -#[derive(Debug, Error)] -pub enum CommandError { - #[error("File not found: {0:?}")] - FileNotFound(String), - - #[error(transparent)] - Io(#[from] std::io::Error), - - #[error(transparent)] - LanguageError(#[from] crate::language::Error), - - #[error("Parsing failed: {0}")] - ParseFailed(String), -} diff --git a/crates/codegen/runtime/cargo/src/runtime/cli/commands/parse.rs b/crates/codegen/runtime/cargo/src/runtime/cli/commands/parse.rs index 496d3dbe55..6b2b2beef3 100644 --- a/crates/codegen/runtime/cargo/src/runtime/cli/commands/parse.rs +++ b/crates/codegen/runtime/cargo/src/runtime/cli/commands/parse.rs @@ -1,52 +1,59 @@ use std::fs; use std::path::PathBuf; +use clap::Parser; use semver::Version; -use super::CommandError; use crate::diagnostic; use crate::language::Language; -use crate::parse_output::ParseOutput; -pub fn execute(file_path_string: &str, version: Version, json: bool) -> Result<(), CommandError> { - parse_source_file(file_path_string, version, |output| { +#[derive(Parser, Debug)] +pub struct ParseCommand { + /// File path to the source file to parse + file_path: PathBuf, + + /// The language version to use for parsing + #[arg(short, long)] + version: Version, + + /// Print the concrete syntax tree as JSON + #[clap(long)] + json: bool, +} + +impl ParseCommand { + pub fn execute(self) { + let Self { + file_path, + version, + json, + } = self; + + let file_path = file_path + .canonicalize() + .unwrap_or_else(|_| panic!("File not found: {file_path:?}")); + + let input = fs::read_to_string(&file_path).unwrap(); + let language = Language::new(version).unwrap(); + let parse_output = language.parse(Language::ROOT_KIND, &input); + + if !parse_output.is_valid() { + const COLOR: bool = true; + + let report = parse_output + .errors() + .iter() + .map(|error| diagnostic::render(error, file_path.to_str().unwrap(), &input, COLOR)) + .collect::>() + .join("\n"); + + panic!("Parse failed:\n{report}"); + } + if json { - let root_node = output.tree(); - let json = serde_json::to_string_pretty(&root_node).expect("JSON serialization failed"); + let json = serde_json::to_string_pretty(&parse_output.tree()).unwrap(); + println!("{json}"); } - }) - .map(|_| ()) -} - -pub(crate) fn parse_source_file( - file_path_string: &str, - version: Version, - run_before_checking: F, -) -> Result -where - F: FnOnce(&ParseOutput), -{ - let file_path = PathBuf::from(&file_path_string) - .canonicalize() - .map_err(|_| CommandError::FileNotFound(file_path_string.to_string()))?; - - let input = fs::read_to_string(file_path)?; - let language = Language::new(version)?; - let parse_output = language.parse(Language::ROOT_KIND, &input); - - run_before_checking(&parse_output); - - if parse_output.is_valid() { - Ok(parse_output) - } else { - const COLOR: bool = true; - let report = parse_output - .errors() - .iter() - .map(|error| diagnostic::render(error, file_path_string, &input, COLOR)) - .collect::>() - .join("\n"); - Err(CommandError::ParseFailed(report)) } } diff --git a/crates/codegen/runtime/cargo/src/runtime/cli/mod.rs b/crates/codegen/runtime/cargo/src/runtime/cli/mod.rs index 211631f9cd..e084a76484 100644 --- a/crates/codegen/runtime/cargo/src/runtime/cli/mod.rs +++ b/crates/codegen/runtime/cargo/src/runtime/cli/mod.rs @@ -1,42 +1,31 @@ -use std::process::ExitCode; +mod commands; -use clap::Subcommand; -use semver::Version; +use clap::{Parser, Subcommand}; -pub mod commands; +use crate::cli::commands::parse::ParseCommand; + +#[derive(Parser, Debug)] +#[command(next_line_help = true)] +#[command(author, about)] +struct Cli { + #[command(subcommand)] + command: Commands, +} #[derive(Subcommand, Debug)] -pub enum Commands { +enum Commands { /// Parses a source file, and outputs any syntax errors, or a JSON concrete syntax tree - Parse { - /// File path to the source file to parse - file_path: String, - - /// The language version to use for parsing - #[arg(short, long)] - version: Version, + Parse(ParseCommand), +} - /// Print the concrete syntax tree as JSON - #[clap(long)] - json: bool, - }, +pub fn execute() { + match Cli::parse().command { + Commands::Parse(command) => command.execute(), + }; } -impl Commands { - pub fn execute(self) -> ExitCode { - let command_result = match self { - Commands::Parse { - file_path, - version, - json, - } => commands::parse::execute(&file_path, version, json), - }; - match command_result { - Ok(()) => ExitCode::SUCCESS, - Err(error) => { - eprintln!("{error}"); - ExitCode::FAILURE - } - } - } +#[test] +fn verify_clap_cli() { + // Catches problems earlier in the development cycle: + ::command().debug_assert(); } diff --git a/crates/codegen/runtime/cargo/src/runtime/diagnostic/mod.rs b/crates/codegen/runtime/cargo/src/runtime/diagnostic/mod.rs index ce50452bbc..b3ad490af4 100644 --- a/crates/codegen/runtime/cargo/src/runtime/diagnostic/mod.rs +++ b/crates/codegen/runtime/cargo/src/runtime/diagnostic/mod.rs @@ -22,7 +22,10 @@ pub trait Diagnostic { fn message(&self) -> String; } -#[cfg(any(feature = "cli", feature = "__private_testing_utils"))] +#[cfg(any( + feature = "__private_cli_execution", + feature = "__private_testing_utils" +))] pub fn render(error: &D, source_id: &str, source: &str, with_color: bool) -> String { use ariadne::{Color, Config, Label, Report, ReportKind, Source}; diff --git a/crates/codegen/runtime/cargo/src/runtime/mod.rs b/crates/codegen/runtime/cargo/src/runtime/mod.rs index c9fb9361e0..14f45a02b3 100644 --- a/crates/codegen/runtime/cargo/src/runtime/mod.rs +++ b/crates/codegen/runtime/cargo/src/runtime/mod.rs @@ -8,14 +8,14 @@ pub mod parse_output; pub mod query; pub mod text_index; -#[cfg(feature = "__private_wit_bindings")] -pub mod wit; +#[cfg(feature = "__experimental_bindings_api")] +pub mod bindings; + +#[cfg(feature = "__private_cli_execution")] +pub mod cli; #[cfg(feature = "__private_napi_interfaces")] pub mod napi_interface; -#[cfg(feature = "cli")] -pub mod cli; - -#[cfg(feature = "__experimental_bindings_api")] -pub mod bindings; +#[cfg(feature = "__private_wit_bindings")] +pub mod wit; diff --git a/crates/infra/cli/src/commands/publish/cargo/mod.rs b/crates/infra/cli/src/commands/publish/cargo/mod.rs index 3db271c7ea..bc03976af5 100644 --- a/crates/infra/cli/src/commands/publish/cargo/mod.rs +++ b/crates/infra/cli/src/commands/publish/cargo/mod.rs @@ -17,6 +17,7 @@ const USER_FACING_CRATES: &[&str] = &[ "metaslang_graph_builder", "metaslang_bindings", "slang_solidity", + "slang_solidity_cli", ]; #[derive(Clone, Debug, Parser)] diff --git a/crates/metaslang/bindings/README.md b/crates/metaslang/bindings/README.md index c1fabdc3e6..c290b0065f 100644 --- a/crates/metaslang/bindings/README.md +++ b/crates/metaslang/bindings/README.md @@ -1,12 +1,3 @@ - - -# metaslang_bindings - -The `metaslang_bindings` library allows computing language semantic bindings -by building stack graphs (see crate `stack-graphs`) from graphs constructed -using the `metaslang_graph_builder` library from source code parsed by parsers -generated by `metaslang`. - # metaslang_bindings @@ -16,6 +7,13 @@ generated by `metaslang`. ## Solidity compiler tooling by [@NomicFoundation](https://github.com/NomicFoundation) +A modular set of compiler APIs empowering the next generation of Solidity code analysis and developer tooling. +Written in Rust and distributed in multiple languages. + +- [Announcement Post](https://medium.com/nomic-foundation-blog/slang-rethnet-2ad465fd7880) +- [How to write your own Solidity linter using Slang, in 25 lines of code!](https://blog.nomic.foundation/how-to-write-your-own-solidity-linter-using-slang-356e7565ad1b/) +- [User Guide](https://nomicfoundation.github.io/slang/latest/user-guide/rust-crate/) + > ❗ This project is still in alpha, and is under active development. > If you are planning on using it, please [reach out to us on Telegram](https://t.me/+pxApdT-Ssn5hMTFh) so we can help you get started. diff --git a/crates/metaslang/cst/README.md b/crates/metaslang/cst/README.md index d14f40e729..700a274f42 100644 --- a/crates/metaslang/cst/README.md +++ b/crates/metaslang/cst/README.md @@ -7,7 +7,12 @@ ## Solidity compiler tooling by [@NomicFoundation](https://github.com/NomicFoundation) -This crate provides support for parse trees used in the Solidity compiler tooling. +A modular set of compiler APIs empowering the next generation of Solidity code analysis and developer tooling. +Written in Rust and distributed in multiple languages. + +- [Announcement Post](https://medium.com/nomic-foundation-blog/slang-rethnet-2ad465fd7880) +- [How to write your own Solidity linter using Slang, in 25 lines of code!](https://blog.nomic.foundation/how-to-write-your-own-solidity-linter-using-slang-356e7565ad1b/) +- [User Guide](https://nomicfoundation.github.io/slang/latest/user-guide/rust-crate/) > ❗ This project is still in alpha, and is under active development. > If you are planning on using it, please [reach out to us on Telegram](https://t.me/+pxApdT-Ssn5hMTFh) so we can help you get started. diff --git a/crates/metaslang/graph_builder/Cargo.toml b/crates/metaslang/graph_builder/Cargo.toml index 489c8434d6..0626da23a6 100644 --- a/crates/metaslang/graph_builder/Cargo.toml +++ b/crates/metaslang/graph_builder/Cargo.toml @@ -27,12 +27,12 @@ regex = { workspace = true } serde = { workspace = true } serde_json = { workspace = true } smallvec = { workspace = true } -string-interner = { workspace = true } thiserror = { workspace = true } [dev-dependencies] env_logger = { workspace = true } indoc = { workspace = true } +string-interner = { workspace = true } strum = { workspace = true } strum_macros = { workspace = true } diff --git a/crates/metaslang/graph_builder/README.md b/crates/metaslang/graph_builder/README.md index c2de9cba66..ab243861b1 100644 --- a/crates/metaslang/graph_builder/README.md +++ b/crates/metaslang/graph_builder/README.md @@ -1,14 +1,3 @@ - - -# metaslang_graph_builder - -Based on `tree-sitter-graph` [![DOI](https://zenodo.org/badge/368886913.svg)](https://zenodo.org/badge/latestdoi/368886913) - -The `metaslang_graph_builder` library defines a DSL for constructing arbitrary graph -structures from source code that has been parsed using parsers generated using `metaslang`. - -This library is currently not intended to be - # metaslang_graph_builder @@ -18,8 +7,12 @@ This library is currently not intended to be ## Solidity compiler tooling by [@NomicFoundation](https://github.com/NomicFoundation) -This crate defines a DSL for constructing arbitrary graph -structures from source code that has been parsed using parsers generated using `metaslang`. +A modular set of compiler APIs empowering the next generation of Solidity code analysis and developer tooling. +Written in Rust and distributed in multiple languages. + +- [Announcement Post](https://medium.com/nomic-foundation-blog/slang-rethnet-2ad465fd7880) +- [How to write your own Solidity linter using Slang, in 25 lines of code!](https://blog.nomic.foundation/how-to-write-your-own-solidity-linter-using-slang-356e7565ad1b/) +- [User Guide](https://nomicfoundation.github.io/slang/latest/user-guide/rust-crate/) > ❗ This project is still in alpha, and is under active development. > If you are planning on using it, please [reach out to us on Telegram](https://t.me/+pxApdT-Ssn5hMTFh) so we can help you get started. diff --git a/crates/metaslang/graph_builder/src/lib.rs b/crates/metaslang/graph_builder/src/lib.rs index be20122de3..1284315473 100644 --- a/crates/metaslang/graph_builder/src/lib.rs +++ b/crates/metaslang/graph_builder/src/lib.rs @@ -79,11 +79,8 @@ #![allow(clippy::single_char_pattern)] #![allow(clippy::unused_unit)] -use string_interner as _; -#[cfg(feature = "cli")] -use {anyhow as _, clap as _, env_logger as _, tree_sitter_config as _, tree_sitter_loader as _}; #[cfg(test)] -use {env_logger as _, indoc as _, strum as _, strum_macros as _}; +use {env_logger as _, indoc as _, string_interner as _, strum as _, strum_macros as _}; #[cfg(doc)] pub mod reference; diff --git a/crates/metaslang/graph_builder/tests/main.rs b/crates/metaslang/graph_builder/tests/main.rs index 13d6d9cd20..f465d31614 100644 --- a/crates/metaslang/graph_builder/tests/main.rs +++ b/crates/metaslang/graph_builder/tests/main.rs @@ -4,21 +4,6 @@ // Licensed under either of Apache License, Version 2.0, or MIT license, at your option. // Please see the LICENSE-APACHE or LICENSE-MIT files in this distribution for license details. // ------------------------------------------------------------------------------------------------ -#![allow(clippy::needless_raw_string_hashes)] -#![allow(clippy::redundant_pattern_matching)] -#![allow(clippy::similar_names)] -#![allow(clippy::too_many_lines)] -#![allow(clippy::uninlined_format_args)] -#![allow(clippy::unnecessary_mut_passed)] -#![allow(clippy::useless_conversion)] -#![allow(clippy::manual_string_new)] - -#[cfg(feature = "cli")] -use {anyhow as _, clap as _, colored as _, tree_sitter_config as _, tree_sitter_loader as _}; -use { - log as _, regex as _, serde as _, serde_json as _, smallvec as _, string_interner as _, - thiserror as _, -}; mod functions; mod graph; diff --git a/crates/solidity/outputs/cargo/slang_solidity/Cargo.toml b/crates/solidity/outputs/cargo/slang_solidity/Cargo.toml index 898b75b199..628106a451 100644 --- a/crates/solidity/outputs/cargo/slang_solidity/Cargo.toml +++ b/crates/solidity/outputs/cargo/slang_solidity/Cargo.toml @@ -26,16 +26,11 @@ categories = [ "text-editors", ] -[[bin]] -name = "slang_solidity" -path = "src/main.rs" -required-features = ["cli"] - # __RUST_PRODUCT_CRATE_FEATURES__ (keep in sync) [features] -default = ["cli"] -cli = ["dep:ariadne", "dep:clap", "dep:serde_json"] +default = [] __experimental_bindings_api = ["dep:metaslang_bindings"] +__private_cli_execution = ["dep:ariadne", "dep:clap", "dep:serde_json"] __private_testing_utils = ["dep:ariadne"] __private_wit_bindings = ["dep:paste", "dep:wit-bindgen"] diff --git a/crates/solidity/outputs/cargo/slang_solidity/src/generated/cli/commands/mod.rs b/crates/solidity/outputs/cargo/slang_solidity/src/generated/cli/commands/mod.rs index 656f75d638..60ba962444 100644 --- a/crates/solidity/outputs/cargo/slang_solidity/src/generated/cli/commands/mod.rs +++ b/crates/solidity/outputs/cargo/slang_solidity/src/generated/cli/commands/mod.rs @@ -1,20 +1,3 @@ // This file is generated automatically by infrastructure scripts. Please don't edit by hand. -use thiserror::Error; - pub mod parse; - -#[derive(Debug, Error)] -pub enum CommandError { - #[error("File not found: {0:?}")] - FileNotFound(String), - - #[error(transparent)] - Io(#[from] std::io::Error), - - #[error(transparent)] - LanguageError(#[from] crate::language::Error), - - #[error("Parsing failed: {0}")] - ParseFailed(String), -} diff --git a/crates/solidity/outputs/cargo/slang_solidity/src/generated/cli/commands/parse.rs b/crates/solidity/outputs/cargo/slang_solidity/src/generated/cli/commands/parse.rs index c2ed11a906..d174ba0839 100644 --- a/crates/solidity/outputs/cargo/slang_solidity/src/generated/cli/commands/parse.rs +++ b/crates/solidity/outputs/cargo/slang_solidity/src/generated/cli/commands/parse.rs @@ -3,52 +3,59 @@ use std::fs; use std::path::PathBuf; +use clap::Parser; use semver::Version; -use super::CommandError; use crate::diagnostic; use crate::language::Language; -use crate::parse_output::ParseOutput; -pub fn execute(file_path_string: &str, version: Version, json: bool) -> Result<(), CommandError> { - parse_source_file(file_path_string, version, |output| { +#[derive(Parser, Debug)] +pub struct ParseCommand { + /// File path to the source file to parse + file_path: PathBuf, + + /// The language version to use for parsing + #[arg(short, long)] + version: Version, + + /// Print the concrete syntax tree as JSON + #[clap(long)] + json: bool, +} + +impl ParseCommand { + pub fn execute(self) { + let Self { + file_path, + version, + json, + } = self; + + let file_path = file_path + .canonicalize() + .unwrap_or_else(|_| panic!("File not found: {file_path:?}")); + + let input = fs::read_to_string(&file_path).unwrap(); + let language = Language::new(version).unwrap(); + let parse_output = language.parse(Language::ROOT_KIND, &input); + + if !parse_output.is_valid() { + const COLOR: bool = true; + + let report = parse_output + .errors() + .iter() + .map(|error| diagnostic::render(error, file_path.to_str().unwrap(), &input, COLOR)) + .collect::>() + .join("\n"); + + panic!("Parse failed:\n{report}"); + } + if json { - let root_node = output.tree(); - let json = serde_json::to_string_pretty(&root_node).expect("JSON serialization failed"); + let json = serde_json::to_string_pretty(&parse_output.tree()).unwrap(); + println!("{json}"); } - }) - .map(|_| ()) -} - -pub(crate) fn parse_source_file( - file_path_string: &str, - version: Version, - run_before_checking: F, -) -> Result -where - F: FnOnce(&ParseOutput), -{ - let file_path = PathBuf::from(&file_path_string) - .canonicalize() - .map_err(|_| CommandError::FileNotFound(file_path_string.to_string()))?; - - let input = fs::read_to_string(file_path)?; - let language = Language::new(version)?; - let parse_output = language.parse(Language::ROOT_KIND, &input); - - run_before_checking(&parse_output); - - if parse_output.is_valid() { - Ok(parse_output) - } else { - const COLOR: bool = true; - let report = parse_output - .errors() - .iter() - .map(|error| diagnostic::render(error, file_path_string, &input, COLOR)) - .collect::>() - .join("\n"); - Err(CommandError::ParseFailed(report)) } } diff --git a/crates/solidity/outputs/cargo/slang_solidity/src/generated/cli/mod.rs b/crates/solidity/outputs/cargo/slang_solidity/src/generated/cli/mod.rs index 805afe8975..4d7994dd92 100644 --- a/crates/solidity/outputs/cargo/slang_solidity/src/generated/cli/mod.rs +++ b/crates/solidity/outputs/cargo/slang_solidity/src/generated/cli/mod.rs @@ -1,44 +1,33 @@ // This file is generated automatically by infrastructure scripts. Please don't edit by hand. -use std::process::ExitCode; +mod commands; -use clap::Subcommand; -use semver::Version; +use clap::{Parser, Subcommand}; -pub mod commands; +use crate::cli::commands::parse::ParseCommand; + +#[derive(Parser, Debug)] +#[command(next_line_help = true)] +#[command(author, about)] +struct Cli { + #[command(subcommand)] + command: Commands, +} #[derive(Subcommand, Debug)] -pub enum Commands { +enum Commands { /// Parses a source file, and outputs any syntax errors, or a JSON concrete syntax tree - Parse { - /// File path to the source file to parse - file_path: String, - - /// The language version to use for parsing - #[arg(short, long)] - version: Version, + Parse(ParseCommand), +} - /// Print the concrete syntax tree as JSON - #[clap(long)] - json: bool, - }, +pub fn execute() { + match Cli::parse().command { + Commands::Parse(command) => command.execute(), + }; } -impl Commands { - pub fn execute(self) -> ExitCode { - let command_result = match self { - Commands::Parse { - file_path, - version, - json, - } => commands::parse::execute(&file_path, version, json), - }; - match command_result { - Ok(()) => ExitCode::SUCCESS, - Err(error) => { - eprintln!("{error}"); - ExitCode::FAILURE - } - } - } +#[test] +fn verify_clap_cli() { + // Catches problems earlier in the development cycle: + ::command().debug_assert(); } diff --git a/crates/solidity/outputs/cargo/slang_solidity/src/generated/diagnostic/mod.rs b/crates/solidity/outputs/cargo/slang_solidity/src/generated/diagnostic/mod.rs index e1f3835a03..c90559f846 100644 --- a/crates/solidity/outputs/cargo/slang_solidity/src/generated/diagnostic/mod.rs +++ b/crates/solidity/outputs/cargo/slang_solidity/src/generated/diagnostic/mod.rs @@ -24,7 +24,10 @@ pub trait Diagnostic { fn message(&self) -> String; } -#[cfg(any(feature = "cli", feature = "__private_testing_utils"))] +#[cfg(any( + feature = "__private_cli_execution", + feature = "__private_testing_utils" +))] pub fn render(error: &D, source_id: &str, source: &str, with_color: bool) -> String { use ariadne::{Color, Config, Label, Report, ReportKind, Source}; diff --git a/crates/solidity/outputs/cargo/slang_solidity/src/generated/mod.rs b/crates/solidity/outputs/cargo/slang_solidity/src/generated/mod.rs index 9b7ed34dcc..db90e0f2cb 100644 --- a/crates/solidity/outputs/cargo/slang_solidity/src/generated/mod.rs +++ b/crates/solidity/outputs/cargo/slang_solidity/src/generated/mod.rs @@ -10,14 +10,14 @@ pub mod parse_output; pub mod query; pub mod text_index; -#[cfg(feature = "__private_wit_bindings")] -pub mod wit; +#[cfg(feature = "__experimental_bindings_api")] +pub mod bindings; + +#[cfg(feature = "__private_cli_execution")] +pub mod cli; #[cfg(feature = "__private_napi_interfaces")] pub mod napi_interface; -#[cfg(feature = "cli")] -pub mod cli; - -#[cfg(feature = "__experimental_bindings_api")] -pub mod bindings; +#[cfg(feature = "__private_wit_bindings")] +pub mod wit; diff --git a/crates/solidity/outputs/cargo/slang_solidity/src/lib.rs b/crates/solidity/outputs/cargo/slang_solidity/src/lib.rs index ff73e70f3d..086cd6d549 100644 --- a/crates/solidity/outputs/cargo/slang_solidity/src/lib.rs +++ b/crates/solidity/outputs/cargo/slang_solidity/src/lib.rs @@ -1,12 +1,3 @@ mod generated; pub use generated::*; - -// Below are dependencies used by the CLI "main.rs", but not the API `lib.rs`. -// However, we need to add a fake usage to suppress Cargo warnings about unused dependencies. -// This is a known issue, and we should remove this hack once there is a better solution from Cargo. -// https://github.com/rust-lang/cargo/issues/1982 -#[cfg(feature = "cli")] -mod supress_cli_dependencies { - use {ariadne as _, clap as _, serde_json as _}; -} diff --git a/crates/solidity/outputs/cargo/slang_solidity/src/main.rs b/crates/solidity/outputs/cargo/slang_solidity/src/main.rs deleted file mode 100644 index a2bf2e4d5f..0000000000 --- a/crates/solidity/outputs/cargo/slang_solidity/src/main.rs +++ /dev/null @@ -1,37 +0,0 @@ -use std::process::ExitCode; - -use clap::Parser as ClapParser; -use slang_solidity::cli::Commands; - -// 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. -// This is a known issue, and we should remove this hack once there is a better solution from Cargo. -// https://github.com/rust-lang/cargo/issues/1982 -mod supress_api_dependencies { - #[cfg(feature = "__experimental_bindings_api")] - use metaslang_bindings as _; - use { - ariadne as _, metaslang_cst as _, semver as _, serde as _, serde_json as _, strum as _, - strum_macros as _, thiserror as _, - }; - #[cfg(feature = "__private_wit_bindings")] - use {paste as _, wit_bindgen as _}; -} - -#[derive(ClapParser, Debug)] -#[command(next_line_help = true)] -#[command(author, about)] -struct Cli { - #[command(subcommand)] - command: Commands, -} - -fn main() -> ExitCode { - Cli::parse().command.execute() -} - -#[test] -fn verify_clap_cli() { - // Catches problems earlier in the development cycle: - ::command().debug_assert(); -} diff --git a/crates/solidity/outputs/cargo/slang_solidity_cli/CHANGELOG.md b/crates/solidity/outputs/cargo/slang_solidity_cli/CHANGELOG.md new file mode 100644 index 0000000000..e0bf4672ae --- /dev/null +++ b/crates/solidity/outputs/cargo/slang_solidity_cli/CHANGELOG.md @@ -0,0 +1,368 @@ +# changelog + +## 0.16.0 + +### Minor Changes + +- [#1030](https://github.com/NomicFoundation/slang/pull/1030) [`7e467ce`](https://github.com/NomicFoundation/slang/commit/7e467ce199cb07acb443da9f542fbcc74f2a5321) Thanks [@ggiraldez](https://github.com/ggiraldez)! - Tree Query Language: queries now ignore trivia nodes. + +- [#1030](https://github.com/NomicFoundation/slang/pull/1030) [`7e467ce`](https://github.com/NomicFoundation/slang/commit/7e467ce199cb07acb443da9f542fbcc74f2a5321) Thanks [@ggiraldez](https://github.com/ggiraldez)! - Tree Query Language: remove the ellipsis query `...` operator making it implicit, add an adjacency operator `.`. + +### Patch Changes + +- [#1015](https://github.com/NomicFoundation/slang/pull/1015) [`369ee30`](https://github.com/NomicFoundation/slang/commit/369ee309325ef57c7cd6f29e2f7adc4f9ec09c88) Thanks [@OmarTawfik](https://github.com/OmarTawfik)! - upgrade to rust `1.79.0`. + +- [#1052](https://github.com/NomicFoundation/slang/pull/1052) [`54c9067`](https://github.com/NomicFoundation/slang/commit/54c9067aa6c587ff93cac6575726a9068a9bb758) Thanks [@ggiraldez](https://github.com/ggiraldez)! - Tree Query Language: Compute row and column information for query parser errors. + +- [#1048](https://github.com/NomicFoundation/slang/pull/1048) [`c408caa`](https://github.com/NomicFoundation/slang/commit/c408caae1826095cc2f2c01caf9be58ab5ff8eee) Thanks [@OmarTawfik](https://github.com/OmarTawfik)! - support Yul multiple variables declaration + +- [#1047](https://github.com/NomicFoundation/slang/pull/1047) [`2b32045`](https://github.com/NomicFoundation/slang/commit/2b3204549af27ea3782da2a9a2de470db13a7402) Thanks [@OmarTawfik](https://github.com/OmarTawfik)! - inline `MemberAccess` enum into the parent `MemberAccessExpression` + +- [#1062](https://github.com/NomicFoundation/slang/pull/1062) [`6b05496`](https://github.com/NomicFoundation/slang/commit/6b05496cbd19b5a7f65033fb223c1bcd3d448738) Thanks [@OmarTawfik](https://github.com/OmarTawfik)! - fix stack assignments operator `=:`. + +- [#1052](https://github.com/NomicFoundation/slang/pull/1052) [`54c9067`](https://github.com/NomicFoundation/slang/commit/54c9067aa6c587ff93cac6575726a9068a9bb758) Thanks [@ggiraldez](https://github.com/ggiraldez)! - Tree Query Language: Improve reporting when an error occurs attempting to parse edge labels or node kinds. + +- [#1037](https://github.com/NomicFoundation/slang/pull/1037) [`2a74f91`](https://github.com/NomicFoundation/slang/commit/2a74f91ed8e67fc3d315afd49f593dfef52f0e4d) Thanks [@OmarTawfik](https://github.com/OmarTawfik)! - fix `ExponentiationExpression` associativity before `0.8.0` + +## 0.15.1 + +### Patch Changes + +- [#1012](https://github.com/NomicFoundation/slang/pull/1012) [`9ca51b4`](https://github.com/NomicFoundation/slang/commit/9ca51b431e6d9e52b537683bf618d8852103936b) Thanks [@OmarTawfik](https://github.com/OmarTawfik)! - expose `QueryMatch` to public API + +## 0.15.0 + +### Minor Changes + +- [#975](https://github.com/NomicFoundation/slang/pull/975) [`46b1dde`](https://github.com/NomicFoundation/slang/commit/46b1dde2e39903cff6398d5da3a4d1a1820f0095) Thanks [@OmarTawfik](https://github.com/OmarTawfik)! - rename `QueryResult` to `QueryMatch`, and its `bindings` to `captures`. + +- [#971](https://github.com/NomicFoundation/slang/pull/971) [`be943b7`](https://github.com/NomicFoundation/slang/commit/be943b7349e4c4b7589d93cf670bc8453125b229) Thanks [@Xanewok](https://github.com/Xanewok)! - Rename `RuleKind` to `NonterminalKind`, `TokenKind` to `TerminalKind`, and `NodeLabel` to `EdgeLabel`. + +- [#963](https://github.com/NomicFoundation/slang/pull/963) [`a5593f9`](https://github.com/NomicFoundation/slang/commit/a5593f981b1df133449264c995c91ac738981474) Thanks [@Xanewok](https://github.com/Xanewok)! - Introduce a `Diagnostic` API for compiler errors, warnings etc. + +### Patch Changes + +- [#996](https://github.com/NomicFoundation/slang/pull/996) [`cdc153d`](https://github.com/NomicFoundation/slang/commit/cdc153dbb149c277f6f0d00ed95bbac1e5bec8f1) Thanks [@OmarTawfik](https://github.com/OmarTawfik)! - add support for version `0.8.26`. + +- [#983](https://github.com/NomicFoundation/slang/pull/983) [`ea31417`](https://github.com/NomicFoundation/slang/commit/ea3141741ef3e491b2125f0d24d5db58c2f5d600) Thanks [@ggiraldez](https://github.com/ggiraldez)! - Expose the language root non-terminal kind at `Language.rootKind()`. + +- [#965](https://github.com/NomicFoundation/slang/pull/965) [`61b6b06`](https://github.com/NomicFoundation/slang/commit/61b6b06deaa1db86a21c5fed675cd665ed2c42a4) Thanks [@OmarTawfik](https://github.com/OmarTawfik)! - refactor CST building and querying utilities into a separate `metaslang_cst` crate. + +- [#997](https://github.com/NomicFoundation/slang/pull/997) [`84ad856`](https://github.com/NomicFoundation/slang/commit/84ad856b344e7c17376b38c420a7952556dc4ff5) Thanks [@OmarTawfik](https://github.com/OmarTawfik)! - Support stack assignments in Yul before `0.5.0`. + +## 0.14.2 + +### Patch Changes + +- [#948](https://github.com/NomicFoundation/slang/pull/948) [`ce88cb7`](https://github.com/NomicFoundation/slang/commit/ce88cb7a6fd945b59ccc967cfd20f423dadc36fc) Thanks [@Xanewok](https://github.com/Xanewok)! - Restrict the grammar to correctly only allow an identifier in Yul variable declaration + +- [#945](https://github.com/NomicFoundation/slang/pull/945) [`e8f80d8`](https://github.com/NomicFoundation/slang/commit/e8f80d867b4b9d02413f42a8ece2630a43bc7494) Thanks [@Xanewok](https://github.com/Xanewok)! - Support `.address` built-in access in Yul paths + +## 0.14.1 + +### Patch Changes + +- [#943](https://github.com/NomicFoundation/slang/pull/943) [`a561fb1`](https://github.com/NomicFoundation/slang/commit/a561fb161eb7c18c838c85f71d132764d1d04050) Thanks [@Xanewok](https://github.com/Xanewok)! - Support Solidity 0.8.25 + +## 0.14.0 + +### Minor Changes + +- [#753](https://github.com/NomicFoundation/slang/pull/753) [`b35c763`](https://github.com/NomicFoundation/slang/commit/b35c7630ab7240304e67a43734700cf359acde0b) Thanks [@AntonyBlakey](https://github.com/AntonyBlakey)! - Add tree query implementation as `Query::parse` and `Cursor::query` + +- [#755](https://github.com/NomicFoundation/slang/pull/755) [`8c260fc`](https://github.com/NomicFoundation/slang/commit/8c260fcb7e3111191cd33dd527817fb51119eac4) Thanks [@OmarTawfik](https://github.com/OmarTawfik)! - support parsing NatSpec comments + +- [#908](https://github.com/NomicFoundation/slang/pull/908) [`ab3688b`](https://github.com/NomicFoundation/slang/commit/ab3688bb99a60862c506566ac6122cd9c1155c57) Thanks [@Xanewok](https://github.com/Xanewok)! - Changed the cst.NodeType in TS to use more descriptive string values rather than 0/1 integers + +- [#886](https://github.com/NomicFoundation/slang/pull/886) [`0125717`](https://github.com/NomicFoundation/slang/commit/0125717fb0b48a5342a8452f18080db13e68fb6b) Thanks [@Xanewok](https://github.com/Xanewok)! - Add `TokenKind::is_trivia` + +- [#887](https://github.com/NomicFoundation/slang/pull/887) [`dff1201`](https://github.com/NomicFoundation/slang/commit/dff12011c549d68b20ecd54251af764643fb72db) Thanks [@Xanewok](https://github.com/Xanewok)! - Add support for constant function modifier removed in 0.5.0 + +- [#885](https://github.com/NomicFoundation/slang/pull/885) [`a9bd8da`](https://github.com/NomicFoundation/slang/commit/a9bd8da018469739832f71e38437caa83087baf0) Thanks [@Xanewok](https://github.com/Xanewok)! - Flatten the trivia syntax nodes into sibling tokens + +- [#908](https://github.com/NomicFoundation/slang/pull/908) [`ab3688b`](https://github.com/NomicFoundation/slang/commit/ab3688bb99a60862c506566ac6122cd9c1155c57) Thanks [@Xanewok](https://github.com/Xanewok)! - Add RuleNode/TokenNode::toJSON() in the TypeScript API + +### Patch Changes + +- [#801](https://github.com/NomicFoundation/slang/pull/801) [`ecbba49`](https://github.com/NomicFoundation/slang/commit/ecbba49c7ac25e37b8d317fb60fab7340c0628a5) Thanks [@OmarTawfik](https://github.com/OmarTawfik)! - unreserve pragma keywords in all versions + +- [#869](https://github.com/NomicFoundation/slang/pull/869) [`951b58d`](https://github.com/NomicFoundation/slang/commit/951b58ddb3eaea600ddf44427a82649761c6b651) Thanks [@OmarTawfik](https://github.com/OmarTawfik)! - support dots in yul identifiers from `0.5.8` till `0.7.0` + +- [#890](https://github.com/NomicFoundation/slang/pull/890) [`1ff8599`](https://github.com/NomicFoundation/slang/commit/1ff85993f25d92b38d0a500baa6ee48669a1b62a) Thanks [@Xanewok](https://github.com/Xanewok)! - Mark `override` as being a valid attribute only after 0.6.0 + +- [#800](https://github.com/NomicFoundation/slang/pull/800) [`d1827ff`](https://github.com/NomicFoundation/slang/commit/d1827ff7e1010493ff5487532a5ee0c77d355aa2) Thanks [@OmarTawfik](https://github.com/OmarTawfik)! - support unicode characters in string literals up to `0.7.0` + +- [#797](https://github.com/NomicFoundation/slang/pull/797) [`86f36d7`](https://github.com/NomicFoundation/slang/commit/86f36d71e60a44261ec114339e931dd3d24cd4a4) Thanks [@OmarTawfik](https://github.com/OmarTawfik)! - fix source locations for unicode characters in error reports + +- [#854](https://github.com/NomicFoundation/slang/pull/854) [`4b8970b`](https://github.com/NomicFoundation/slang/commit/4b8970b47ef7a2d1d51339cf5020a3e0f168b9aa) Thanks [@OmarTawfik](https://github.com/OmarTawfik)! - parse line breaks without newlines + +- [#844](https://github.com/NomicFoundation/slang/pull/844) [`f62de9e`](https://github.com/NomicFoundation/slang/commit/f62de9ea3fc2049ee11e5dbeff3dc51eb1ca984e) Thanks [@OmarTawfik](https://github.com/OmarTawfik)! - fix parsing empty `/**/` comments + +- [#799](https://github.com/NomicFoundation/slang/pull/799) [`303dda9`](https://github.com/NomicFoundation/slang/commit/303dda95c08b20450d03116765c210ece64a0864) Thanks [@OmarTawfik](https://github.com/OmarTawfik)! - prevent parsing multiple literals under `StringExpression` before `0.5.14` + +- [#847](https://github.com/NomicFoundation/slang/pull/847) [`6b6f260`](https://github.com/NomicFoundation/slang/commit/6b6f2603e3ba07c0a7dede0f96082369dc1df940) Thanks [@OmarTawfik](https://github.com/OmarTawfik)! - prioritize parsing `MultiLineComment` over `MultiLineNatSpecComment` + +- [#796](https://github.com/NomicFoundation/slang/pull/796) [`59e1e53`](https://github.com/NomicFoundation/slang/commit/59e1e53e7efa52355c273d7cef1a3974de13d88d) Thanks [@OmarTawfik](https://github.com/OmarTawfik)! - add `public` and `internal` to `UnnamedFunctionAttribute` till `0.5.0` + +- [#756](https://github.com/NomicFoundation/slang/pull/756) [`e839817`](https://github.com/NomicFoundation/slang/commit/e8398173f62d48596669628afc7c8b3572a15291) Thanks [@OmarTawfik](https://github.com/OmarTawfik)! - fix parsing `payable` primary expressions + +- [#851](https://github.com/NomicFoundation/slang/pull/851) [`67dfde8`](https://github.com/NomicFoundation/slang/commit/67dfde81a6d00101a9ed133104f15da5d46662b6) Thanks [@OmarTawfik](https://github.com/OmarTawfik)! - fix selection order of prefix/postfix AST fields + +- [#857](https://github.com/NomicFoundation/slang/pull/857) [`f677d5e`](https://github.com/NomicFoundation/slang/commit/f677d5eff40c4bfcf1db2fc4e63cdf37457fe467) Thanks [@OmarTawfik](https://github.com/OmarTawfik)! - rename `FieldName` to `NodeLabel` + +- [#852](https://github.com/NomicFoundation/slang/pull/852) [`ca79eca`](https://github.com/NomicFoundation/slang/commit/ca79ecaa522e531420b42ffba67da192c1e5fdb2) Thanks [@OmarTawfik](https://github.com/OmarTawfik)! - allow parsing `ColonEqual` as two separate tokens before `0.5.5` + +- [#889](https://github.com/NomicFoundation/slang/pull/889) [`ce5050f`](https://github.com/NomicFoundation/slang/commit/ce5050f95195fdd018a38a0351d8525f7d62073a) Thanks [@Xanewok](https://github.com/Xanewok)! - Support `delete` as an expression rather than a statement + +- [#923](https://github.com/NomicFoundation/slang/pull/923) [`bb30fc1`](https://github.com/NomicFoundation/slang/commit/bb30fc1e28a0fe806f8954a0d2779d903f3f4da7) Thanks [@Xanewok](https://github.com/Xanewok)! - Support arbitrary ASCII escape sequences in string literals until 0.4.25 + +- [#887](https://github.com/NomicFoundation/slang/pull/887) [`dff1201`](https://github.com/NomicFoundation/slang/commit/dff12011c549d68b20ecd54251af764643fb72db) Thanks [@Xanewok](https://github.com/Xanewok)! - Support view and pure function modifiers only from 0.4.16 + +- [#800](https://github.com/NomicFoundation/slang/pull/800) [`d1827ff`](https://github.com/NomicFoundation/slang/commit/d1827ff7e1010493ff5487532a5ee0c77d355aa2) Thanks [@OmarTawfik](https://github.com/OmarTawfik)! - rename `AsciiStringLiteral` to `StringLiteral` + +- [#838](https://github.com/NomicFoundation/slang/pull/838) [`ad98d1c`](https://github.com/NomicFoundation/slang/commit/ad98d1c7d9f9f7cb12b4b6184c04c9b680e6d70a) Thanks [@OmarTawfik](https://github.com/OmarTawfik)! - upgrade to rust `1.76.0` + +- [#849](https://github.com/NomicFoundation/slang/pull/849) [`5c42e0e`](https://github.com/NomicFoundation/slang/commit/5c42e0ef5f3afe0355614967cb6d2daa31518ccf) Thanks [@OmarTawfik](https://github.com/OmarTawfik)! - add `override` and `virtual` to `ConstructorAttribute` + +- [#862](https://github.com/NomicFoundation/slang/pull/862) [`5e37ea0`](https://github.com/NomicFoundation/slang/commit/5e37ea0c40e929e0888b6297fa6dd92952d9cd73) Thanks [@Xanewok](https://github.com/Xanewok)! - allow call options as a post-fix expression + +- [#786](https://github.com/NomicFoundation/slang/pull/786) [`0bfa6b7`](https://github.com/NomicFoundation/slang/commit/0bfa6b7397cd25aca713b30628c6d06e761b416a) Thanks [@OmarTawfik](https://github.com/OmarTawfik)! - support Yul label statements before `0.5.0` + +- [#839](https://github.com/NomicFoundation/slang/pull/839) [`2d698eb`](https://github.com/NomicFoundation/slang/commit/2d698ebe469110b85f539d6e0c75b503cd4ce57e) Thanks [@OmarTawfik](https://github.com/OmarTawfik)! - support string literals in version pragmas + +- [#891](https://github.com/NomicFoundation/slang/pull/891) [`70c9d7d`](https://github.com/NomicFoundation/slang/commit/70c9d7deebddb0f22114b7b05ddc85da6dcceaaf) Thanks [@Xanewok](https://github.com/Xanewok)! - Fix parsing `.member` member access expression + +- [#842](https://github.com/NomicFoundation/slang/pull/842) [`2069126`](https://github.com/NomicFoundation/slang/commit/20691263fb6967195bee30fba92abdfb06daa6fa) Thanks [@OmarTawfik](https://github.com/OmarTawfik)! - add `private` to `UnnamedFunctionAttribute` till `0.5.0` + +- [#840](https://github.com/NomicFoundation/slang/pull/840) [`7fb0d20`](https://github.com/NomicFoundation/slang/commit/7fb0d20655024daf71c872a6ef95aa30277a1366) Thanks [@OmarTawfik](https://github.com/OmarTawfik)! - allow `var` in `TupleDeconstructionStatement` before `0.5.0` + +## 0.13.1 + +### Patch Changes + +- [#748](https://github.com/NomicFoundation/slang/pull/748) [`c289cbf7`](https://github.com/NomicFoundation/slang/commit/c289cbf7e22118881818b82d0ffc5933a424a7aa) Thanks [@OmarTawfik](https://github.com/OmarTawfik)! - Properly parse EVM built-ins up till Paris/Solidity 0.8.18 + +## 0.13.0 + +### Minor Changes + +- [#710](https://github.com/NomicFoundation/slang/pull/710) [`2025b6cb`](https://github.com/NomicFoundation/slang/commit/2025b6cb23dc320b413b482ed1fe8455229b7d84) Thanks [@Xanewok](https://github.com/Xanewok)! - CST children nodes are now named + +- [#723](https://github.com/NomicFoundation/slang/pull/723) [`b3dc6bcd`](https://github.com/NomicFoundation/slang/commit/b3dc6bcdc1834d266a87d483927894617bf8e817) Thanks [@Xanewok](https://github.com/Xanewok)! - Properly parse unreserved keywords in an identifier position, i.e. `from`, `emit`, `global` etc. + +- [#728](https://github.com/NomicFoundation/slang/pull/728) [`662a672c`](https://github.com/NomicFoundation/slang/commit/662a672cd661b9f1bf4c18587acf68111fd1f2e8) Thanks [@Xanewok](https://github.com/Xanewok)! - Remove Language#scan API; use the parser API instead + +- [#719](https://github.com/NomicFoundation/slang/pull/719) [`1ad6bb37`](https://github.com/NomicFoundation/slang/commit/1ad6bb37337aa28d9344380c5c9eb1945e908271) Thanks [@OmarTawfik](https://github.com/OmarTawfik)! - introduce strong types for all Solidity non terminals in the TypeScript API. + +### Patch Changes + +- [#719](https://github.com/NomicFoundation/slang/pull/719) [`1ad6bb37`](https://github.com/NomicFoundation/slang/commit/1ad6bb37337aa28d9344380c5c9eb1945e908271) Thanks [@OmarTawfik](https://github.com/OmarTawfik)! - unify Rust/TypeScript node helpers: `*_with_kind()`, `*_with_kinds()`, `*_is_kind()`), ... + +- [#731](https://github.com/NomicFoundation/slang/pull/731) [`3deaea2e`](https://github.com/NomicFoundation/slang/commit/3deaea2eb82ce33dbccc54d1a79b9cf5657385ac) Thanks [@OmarTawfik](https://github.com/OmarTawfik)! - add `RuleNode.unparse()` to the TypeScript API + +## 0.12.0 + +### Minor Changes + +- [#699](https://github.com/NomicFoundation/slang/pull/699) [`ddfebfe9`](https://github.com/NomicFoundation/slang/commit/ddfebfe988345136007431f8ea2efac19fd7e887) Thanks [@Xanewok](https://github.com/Xanewok)! - Remove `ProductionKind` in favor of `RuleKind` + +- [#699](https://github.com/NomicFoundation/slang/pull/699) [`ddfebfe9`](https://github.com/NomicFoundation/slang/commit/ddfebfe988345136007431f8ea2efac19fd7e887) Thanks [@Xanewok](https://github.com/Xanewok)! - Allow parsing individual precedence expressions, like `ShiftExpression` + +- [#665](https://github.com/NomicFoundation/slang/pull/665) [`4b5f8b46`](https://github.com/NomicFoundation/slang/commit/4b5f8b467d4cbab72cf27a539bb5ca8c71090dd6) Thanks [@Xanewok](https://github.com/Xanewok)! - Remove the CST Visitor API in favor of the Cursor API + +- [#666](https://github.com/NomicFoundation/slang/pull/666) [`0434b68c`](https://github.com/NomicFoundation/slang/commit/0434b68c9ef9cd1d1dcc07d7ed50e6d63645319b) Thanks [@Xanewok](https://github.com/Xanewok)! - Add `Node::unparse()` that allows to reconstruct the source code from the CST node + +- [#675](https://github.com/NomicFoundation/slang/pull/675) [`daea4b7f`](https://github.com/NomicFoundation/slang/commit/daea4b7f954ff1e918b9191aff40ee95c10a4db2) Thanks [@OmarTawfik](https://github.com/OmarTawfik)! - rename `Cursor`'s `pathRuleNodes()` to `ancestors()` in the NodeJS API. + +- [#676](https://github.com/NomicFoundation/slang/pull/676) [`b496d361`](https://github.com/NomicFoundation/slang/commit/b496d36120700347bcbcc25b948eb46814fd5412) Thanks [@OmarTawfik](https://github.com/OmarTawfik)! - Fix NAPI `cursor` types and expose `cursor.depth`. + +### Patch Changes + +- [#685](https://github.com/NomicFoundation/slang/pull/685) [`b5fca94a`](https://github.com/NomicFoundation/slang/commit/b5fca94af917a2f0418c224b3101885c02e5cb9c) Thanks [@Xanewok](https://github.com/Xanewok)! - `bytes` is now properly recognized as a reserved word + +- [#660](https://github.com/NomicFoundation/slang/pull/660) [`97028991`](https://github.com/NomicFoundation/slang/commit/9702899164f0540a49f2e0f7f19d82fbd04b1d1b) Thanks [@Xanewok](https://github.com/Xanewok)! - Drop List suffix from collection grammar rule names + +## 0.11.0 + +### Minor Changes + +- [#625](https://github.com/NomicFoundation/slang/pull/625) [`7bb650b`](https://github.com/NomicFoundation/slang/commit/7bb650b12ae793a318dc5b7839fb93915c88828e) Thanks [@Xanewok](https://github.com/Xanewok)! - The CST Cursor now implements the Iterator trait as part of the Rust API + +- [#647](https://github.com/NomicFoundation/slang/pull/647) [`b1dced3`](https://github.com/NomicFoundation/slang/commit/b1dced355ce83f3bd858c02837d67665f7ef281d) Thanks [@OmarTawfik](https://github.com/OmarTawfik)! - Require specifying an initial offset when creating a CST cursor. + +### Patch Changes + +- [#648](https://github.com/NomicFoundation/slang/pull/648) [`2327bf5`](https://github.com/NomicFoundation/slang/commit/2327bf5d8c40d85edd0cc80fe9e36d367a1a3336) Thanks [@OmarTawfik](https://github.com/OmarTawfik)! - Support Solidity v0.8.22. + +- [#623](https://github.com/NomicFoundation/slang/pull/623) [`80114a8`](https://github.com/NomicFoundation/slang/commit/80114a833dc8249447c382bf457215b1a4d9e5ae) Thanks [@AntonyBlakey](https://github.com/AntonyBlakey)! - Correct the types in the TS api by adding the correct namespaces to type references + +## 0.10.1 + +### Patch Changes + +- [#615](https://github.com/NomicFoundation/slang/pull/615) [`06cbbe8`](https://github.com/NomicFoundation/slang/commit/06cbbe88bc68928ad44046a96c31ad6e53fbf76c) Thanks [@AntonyBlakey](https://github.com/AntonyBlakey)! - `cursor` method is now exposed in Typescript API + +## 0.10.0 + +### Minor Changes + +- [#595](https://github.com/NomicFoundation/slang/pull/595) [`1a258c4`](https://github.com/NomicFoundation/slang/commit/1a258c49432eac06dac7055bc427e68af1fa3875) Thanks [@Xanewok](https://github.com/Xanewok)! - Attempt error recovery when parsing incomplete lists + +- [#564](https://github.com/NomicFoundation/slang/pull/564) [`e326a06`](https://github.com/NomicFoundation/slang/commit/e326a064da559c974fbb7a199090e9e5a313abb8) Thanks [@AntonyBlakey](https://github.com/AntonyBlakey)! - Parsing operators with missing operands should no longer panic + +- [#564](https://github.com/NomicFoundation/slang/pull/564) [`e326a06`](https://github.com/NomicFoundation/slang/commit/e326a064da559c974fbb7a199090e9e5a313abb8) Thanks [@AntonyBlakey](https://github.com/AntonyBlakey)! - Inline parse rules are no longer exposed to the API. + +- [#564](https://github.com/NomicFoundation/slang/pull/564) [`e326a06`](https://github.com/NomicFoundation/slang/commit/e326a064da559c974fbb7a199090e9e5a313abb8) Thanks [@AntonyBlakey](https://github.com/AntonyBlakey)! - Scanners are no longer available as methods - use next_token instead + +- [#564](https://github.com/NomicFoundation/slang/pull/564) [`e326a06`](https://github.com/NomicFoundation/slang/commit/e326a064da559c974fbb7a199090e9e5a313abb8) Thanks [@AntonyBlakey](https://github.com/AntonyBlakey)! - Scanners are now grouped into contexts to deal with contextual scanning + +### Patch Changes + +- [#601](https://github.com/NomicFoundation/slang/pull/601) [`cbd2a79`](https://github.com/NomicFoundation/slang/commit/cbd2a79658849c0029bb6a5ccc0b086564c28fe0) Thanks [@Xanewok](https://github.com/Xanewok)! - Attempt parser error recovery between bracket delimiters + +- [#599](https://github.com/NomicFoundation/slang/pull/599) [`4bbad48`](https://github.com/NomicFoundation/slang/commit/4bbad48d45ae7bde8a22198b33f790b7c792b319) Thanks [@Xanewok](https://github.com/Xanewok)! - Use correct versions for the `revert` and `global` keywords + +- [#561](https://github.com/NomicFoundation/slang/pull/561) [`cb6a138`](https://github.com/NomicFoundation/slang/commit/cb6a1384cb6f04926def3e4c1fe7a0b12a67143c) Thanks [@Xanewok](https://github.com/Xanewok)! - Add preliminary documentation for the `solidity_language` Rust package + +- [#603](https://github.com/NomicFoundation/slang/pull/603) [`be59a10`](https://github.com/NomicFoundation/slang/commit/be59a10c937542f0413a34fd84d84ec4d4400f6d) Thanks [@OmarTawfik](https://github.com/OmarTawfik)! - upgrade to rust 1.72.0 + +## 0.9.0 + +### Minor Changes + +- [#540](https://github.com/NomicFoundation/slang/pull/540) [`0d04f95`](https://github.com/NomicFoundation/slang/commit/0d04f959bf1f5831c912d5109de3d933cfaa6266) Thanks [@AntonyBlakey](https://github.com/AntonyBlakey)! - Add a Rust Cursor API and refactor the Rust Visitor API to run on top of it. + +- [#540](https://github.com/NomicFoundation/slang/pull/540) [`0d04f95`](https://github.com/NomicFoundation/slang/commit/0d04f959bf1f5831c912d5109de3d933cfaa6266) Thanks [@AntonyBlakey](https://github.com/AntonyBlakey)! - Move Visitor et al to node:: namespace, which is where Cursor is. + +- [#540](https://github.com/NomicFoundation/slang/pull/540) [`0d04f95`](https://github.com/NomicFoundation/slang/commit/0d04f959bf1f5831c912d5109de3d933cfaa6266) Thanks [@AntonyBlakey](https://github.com/AntonyBlakey)! - Rename `range` functions that return a TextRange to `text_range` + +### Patch Changes + +- [#543](https://github.com/NomicFoundation/slang/pull/543) [`7a34599`](https://github.com/NomicFoundation/slang/commit/7a34599f6b237b03a0f8ba92755cae6107589e37) Thanks [@OmarTawfik](https://github.com/OmarTawfik)! - Move `syntax::parser::ProductionKind` to `syntax::nodes` namespace. + +- [#540](https://github.com/NomicFoundation/slang/pull/540) [`0d04f95`](https://github.com/NomicFoundation/slang/commit/0d04f959bf1f5831c912d5109de3d933cfaa6266) Thanks [@AntonyBlakey](https://github.com/AntonyBlakey)! - Add TokenNode.text to the TS API. + +- [#540](https://github.com/NomicFoundation/slang/pull/540) [`0d04f95`](https://github.com/NomicFoundation/slang/commit/0d04f959bf1f5831c912d5109de3d933cfaa6266) Thanks [@AntonyBlakey](https://github.com/AntonyBlakey)! - Add first pass of Typescript binding to the Cursor API, but no TS Visitor yet. + +- [#545](https://github.com/NomicFoundation/slang/pull/545) [`e73658a`](https://github.com/NomicFoundation/slang/commit/e73658ae4e777e78a01e213f213e2a5dc13e5cba) Thanks [@OmarTawfik](https://github.com/OmarTawfik)! - render EBNF grammar on top of each `ProductionKind`, `RuleKind`, and `TokenKind`. + +- [#558](https://github.com/NomicFoundation/slang/pull/558) [`95bbc50`](https://github.com/NomicFoundation/slang/commit/95bbc5025fbf63b8d4e07f7652a70a7f66363db6) Thanks [@OmarTawfik](https://github.com/OmarTawfik)! - Correct versioning for `SourceUnitMember` and `ContractMember` children. + +## 0.8.0 + +### Minor Changes + +- [#513](https://github.com/NomicFoundation/slang/pull/513) [`7e01250`](https://github.com/NomicFoundation/slang/commit/7e012501c04e639b54cd150e3736683ee2c2606f) Thanks [@AntonyBlakey](https://github.com/AntonyBlakey)! - Typescript API now has TextIndex and TextRange types that are returned from the appropriate methods rather than tuples. + +### Patch Changes + +- [#527](https://github.com/NomicFoundation/slang/pull/527) [`7ccca87`](https://github.com/NomicFoundation/slang/commit/7ccca87beaa9cb96ad294d1af8a02f115481b71a) Thanks [@AntonyBlakey](https://github.com/AntonyBlakey)! - Fix pratt parser behavior in the face of error correction +- [#531](https://github.com/NomicFoundation/slang/pull/531) [`e3450be4`](https://github.com/NomicFoundation/slang/commit/e3450be4722845bcfce7a9ec3b3046ba6eb6961d) Thanks [@alcuadrado](https://github.com/alcuadrado)! - Make ESM named imports work in Node.js. + +## 0.7.0 + +### Minor Changes + +- [#502](https://github.com/NomicFoundation/slang/pull/502) [`c383238`](https://github.com/NomicFoundation/slang/commit/c383238c1f51157b37ec63bc99e63fb85c1bc224) Thanks [@AntonyBlakey](https://github.com/AntonyBlakey)! - Added error recovery i.e. a CST is _always_ produced, even if there are errors. The erroneous/skipped text is in the CST as a `TokenKind::SKIPPED` token. + +- [#501](https://github.com/NomicFoundation/slang/pull/501) [`cb221fe`](https://github.com/NomicFoundation/slang/commit/cb221fed784e8a2eb59f17907412149c7b415ed8) Thanks [@OmarTawfik](https://github.com/OmarTawfik)! - generate typescript string enums for CST kinds + +- [#517](https://github.com/NomicFoundation/slang/pull/517) [`8bd5446`](https://github.com/NomicFoundation/slang/commit/8bd544695a6dd4880a00d0cecf8d13ad79b238d3) Thanks [@OmarTawfik](https://github.com/OmarTawfik)! - extract inlined and sub-expressions in language grammar + +- [#518](https://github.com/NomicFoundation/slang/pull/518) [`b3b562b`](https://github.com/NomicFoundation/slang/commit/b3b562be6365fab25b97e54746a7500b9e7bd595) Thanks [@OmarTawfik](https://github.com/OmarTawfik)! - fill in missing CST node names + +- [#515](https://github.com/NomicFoundation/slang/pull/515) [`f24e873`](https://github.com/NomicFoundation/slang/commit/f24e873a93cbcef53aad1fa5eed1ea9ab1af1c04) Thanks [@OmarTawfik](https://github.com/OmarTawfik)! - switch over the NPM package to use CommonJS modules instead of ES modules. + +- [#498](https://github.com/NomicFoundation/slang/pull/498) [`44f1ff7`](https://github.com/NomicFoundation/slang/commit/44f1ff70100d6e2f8afe54c7ff87e24a8479e4b9) Thanks [@OmarTawfik](https://github.com/OmarTawfik)! - flatten unnamed CST nodes into parent nodes + +- [#502](https://github.com/NomicFoundation/slang/pull/502) [`c383238`](https://github.com/NomicFoundation/slang/commit/c383238c1f51157b37ec63bc99e63fb85c1bc224) Thanks [@AntonyBlakey](https://github.com/AntonyBlakey)! - Use the Rowan model for the CST i.e. TokenNodes contain the string content, and RuleNodes contain only the combined _length_ of their children's text. + +- [#499](https://github.com/NomicFoundation/slang/pull/499) [`1582d60`](https://github.com/NomicFoundation/slang/commit/1582d60c7ef81a785db0b9e3cb4d074d9cb6d442) Thanks [@OmarTawfik](https://github.com/OmarTawfik)! - preserve correct ranges on empty rule nodes + +- [#500](https://github.com/NomicFoundation/slang/pull/500) [`73ddac9`](https://github.com/NomicFoundation/slang/commit/73ddac9ca972f80aa9a0321de7f94c47b505d7a6) Thanks [@OmarTawfik](https://github.com/OmarTawfik)! - inlining CST nodes that offer no additional syntactic information + +- [#512](https://github.com/NomicFoundation/slang/pull/512) [`72dc3d3`](https://github.com/NomicFoundation/slang/commit/72dc3d3d90bc6a02d36836cc1fed17f5be5de2fb) Thanks [@AntonyBlakey](https://github.com/AntonyBlakey)! - Expression productions now correctly wrap the recursive 'calls' in a rule node + +## 0.6.0 + +### Minor Changes + +- [#490](https://github.com/NomicFoundation/slang/pull/490) [`ea8e7e7`](https://github.com/NomicFoundation/slang/commit/ea8e7e771fef7fd9195bcc3004b08fc132c8990d) Thanks [@OmarTawfik](https://github.com/OmarTawfik)! - provide API to list supported language versions + +- [#489](https://github.com/NomicFoundation/slang/pull/489) [`15c34a7`](https://github.com/NomicFoundation/slang/commit/15c34a7bb0268bf26eaa6535dd637f73349596c8) Thanks [@OmarTawfik](https://github.com/OmarTawfik)! - replace panics with JS exceptions in npm package + +### Patch Changes + +- [#488](https://github.com/NomicFoundation/slang/pull/488) [`d7f171c`](https://github.com/NomicFoundation/slang/commit/d7f171cf1e2da375a7ededd034a62fc6b723d44d) Thanks [@DaniPopes](https://github.com/DaniPopes)! - introduce a `cli` Cargo feature to compile the CLI binary + +## 0.5.0 + +### Minor Changes + +- [#475](https://github.com/NomicFoundation/slang/pull/475) [`0cdfe86`](https://github.com/NomicFoundation/slang/commit/0cdfe86037bfe2f1f8be66a69e8e7d7bdbf06364) Thanks [@OmarTawfik](https://github.com/OmarTawfik)! - match TypeScript and Rust API namespaces + +- [#477](https://github.com/NomicFoundation/slang/pull/477) [`13c85a2`](https://github.com/NomicFoundation/slang/commit/13c85a2a3e4e97894d9f24a3e2886a08ffe6e569) Thanks [@OmarTawfik](https://github.com/OmarTawfik)! - move expression operators into separate nodes + +- [#481](https://github.com/NomicFoundation/slang/pull/481) [`0269f2b`](https://github.com/NomicFoundation/slang/commit/0269f2b9de3f6711055119e1f40c3f036fe3a81f) Thanks [@OmarTawfik](https://github.com/OmarTawfik)! - fix grammar versions of individual keywords + +- [#473](https://github.com/NomicFoundation/slang/pull/473) [`11d8cb0`](https://github.com/NomicFoundation/slang/commit/11d8cb0658e01f16b7afd808f31d1da88e967679) Thanks [@OmarTawfik](https://github.com/OmarTawfik)! - upgrade to rust 1.69.0 + +## 0.4.0 + +### Minor Changes + +- [#458](https://github.com/NomicFoundation/slang/pull/458) [`c0fc7e9`](https://github.com/NomicFoundation/slang/commit/c0fc7e95b87eb1ddca4f9e0003136fcbe74f5798) Thanks [@AntonyBlakey](https://github.com/AntonyBlakey)! - Record both character and byte offsets for input positions + +- [#463](https://github.com/NomicFoundation/slang/pull/463) [`0958d6b`](https://github.com/NomicFoundation/slang/commit/0958d6baadba3295df9307e421ddd0a41ef3aaa0) Thanks [@OmarTawfik](https://github.com/OmarTawfik)! - use `number` and getters in npm public API + +## 0.3.0 + +### Minor Changes + +- [#457](https://github.com/NomicFoundation/slang/pull/457) [`b7aae2a`](https://github.com/NomicFoundation/slang/commit/b7aae2ad891f940ee764365ac12c75fd1cb47687) Thanks [@OmarTawfik](https://github.com/OmarTawfik)! - minor grammar fixes + +- [#453](https://github.com/NomicFoundation/slang/pull/453) [`0f2f9ab`](https://github.com/NomicFoundation/slang/commit/0f2f9abec3f2525640d25bf1f288b769917fbc61) Thanks [@OmarTawfik](https://github.com/OmarTawfik)! - move Rust's `syntax::Parser::Language` API to root module + +- [#454](https://github.com/NomicFoundation/slang/pull/454) [`85dec01`](https://github.com/NomicFoundation/slang/commit/85dec0196eafa337065233de03c30d36211b03cf) Thanks [@OmarTawfik](https://github.com/OmarTawfik)! - moving to Rust version 1.65.0 + +- [#456](https://github.com/NomicFoundation/slang/pull/456) [`c6d1041`](https://github.com/NomicFoundation/slang/commit/c6d10417da440f15e1c074b7d8b5d13d38e95519) Thanks [@OmarTawfik](https://github.com/OmarTawfik)! - expose `ParseError` API + +- [#451](https://github.com/NomicFoundation/slang/pull/451) [`78f633c`](https://github.com/NomicFoundation/slang/commit/78f633cb5977d358b4bcc468151359a4301089b2) Thanks [@OmarTawfik](https://github.com/OmarTawfik)! - rename `VisitorExitResponse::StepIn` to `VisitorExitResponse::Continue` + +## 0.2.1 + +### Patch Changes + +- [#444](https://github.com/NomicFoundation/slang/pull/444) [`a858e2c`](https://github.com/NomicFoundation/slang/commit/a858e2c842db3b2183821fb92ed26af6b433e823) Thanks [@AntonyBlakey](https://github.com/AntonyBlakey)! - Fix HexLiteral cannot have NumberUnit + +## 0.2.0 + +### Minor Changes + +- [#435](https://github.com/NomicFoundation/slang/pull/435) [`2a5b193`](https://github.com/NomicFoundation/slang/commit/2a5b1930b20024359fbaf06b6e9748585d7423ff) Thanks [@OmarTawfik](https://github.com/OmarTawfik)! - support user defined operators + +### Patch Changes + +- [#416](https://github.com/NomicFoundation/slang/pull/416) [`fb977a5`](https://github.com/NomicFoundation/slang/commit/fb977a52b152a1ce8d8ce92db4bb00fcfb5881c1) Thanks [@OmarTawfik](https://github.com/OmarTawfik)! - fix primary expressions parser order + +- [#434](https://github.com/NomicFoundation/slang/pull/434) [`beb3708`](https://github.com/NomicFoundation/slang/commit/beb3708218ec797614ba283a13f1854d5f3c7239) Thanks [@OmarTawfik](https://github.com/OmarTawfik)! - fix UnicodeStringLiteral versioning + +- [#430](https://github.com/NomicFoundation/slang/pull/430) [`8b7492e`](https://github.com/NomicFoundation/slang/commit/8b7492e65ec7261176e444dca2563a82603b43b0) Thanks [@OmarTawfik](https://github.com/OmarTawfik)! - update READMEs with links to packages and user guides. + +- [#425](https://github.com/NomicFoundation/slang/pull/425) [`9b49b3d`](https://github.com/NomicFoundation/slang/commit/9b49b3d827536e707d78a6bc349fc82698237b75) Thanks [@OmarTawfik](https://github.com/OmarTawfik)! - add user guides to rust crate and npm packages. + +- [#432](https://github.com/NomicFoundation/slang/pull/432) [`1d1a8bb`](https://github.com/NomicFoundation/slang/commit/1d1a8bb5503c510a470bb99a18632c3e51a587ec) Thanks [@OmarTawfik](https://github.com/OmarTawfik)! - fix FunctionCallOptions versioning + +- [#427](https://github.com/NomicFoundation/slang/pull/427) [`1103916`](https://github.com/NomicFoundation/slang/commit/11039163ac3a3b66a74fa85683bde1c380a519f4) Thanks [@AntonyBlakey](https://github.com/AntonyBlakey)! - fix VariableDeclarationStatement versioning + +## 0.1.1 + +### Patch Changes + +- [#412](https://github.com/NomicFoundation/slang/pull/412) [`9cac1a04`](https://github.com/NomicFoundation/slang/commit/9cac1a04670fa870c15cee1bd20e0e78c1d213db) Thanks [@OmarTawfik](https://github.com/OmarTawfik)! - publish npm packages + +## 0.1.0 + +### Minor Changes + +- [#396](https://github.com/NomicFoundation/slang/pull/396) [`621b338`](https://github.com/NomicFoundation/slang/commit/621b33838c74415c46ab157205068008e05c5b9b) Thanks [@OmarTawfik](https://github.com/OmarTawfik)! - Initial release. diff --git a/crates/solidity/outputs/cargo/slang_solidity_cli/Cargo.toml b/crates/solidity/outputs/cargo/slang_solidity_cli/Cargo.toml new file mode 100644 index 0000000000..33ab77e6db --- /dev/null +++ b/crates/solidity/outputs/cargo/slang_solidity_cli/Cargo.toml @@ -0,0 +1,37 @@ +[package] +version.workspace = true +rust-version.workspace = true +edition.workspace = true +publish = true + +name = "slang_solidity_cli" +description = "This crate contains the 'slang_solidity' CLI/cargo binary. Please see the 'slang_solidity' crate for more information." +homepage = "https://nomicfoundation.github.io/slang/" +repository = "https://github.com/NomicFoundation/slang/" +authors = [ + "Nomic Foundation ", + "Antony Blakey ", + "Igor Matuszewski ", + "Omar Tawfik ", +] + +readme = "README.md" +license = "MIT" +keywords = ["code-analysis", "parser", "sol", "solidity", "yul"] +categories = [ + "compilers", + "development-tools", + "parsing", + "parser-implementations", + "text-editors", +] + +[[bin]] +name = "slang_solidity" +path = "src/main.rs" + +[dependencies] +slang_solidity = { workspace = true, features = ["__private_cli_execution"] } + +[lints] +workspace = true diff --git a/crates/solidity/outputs/cargo/slang_solidity_cli/LICENSE b/crates/solidity/outputs/cargo/slang_solidity_cli/LICENSE new file mode 100644 index 0000000000..84f9adf0ae --- /dev/null +++ b/crates/solidity/outputs/cargo/slang_solidity_cli/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2022 Nomic Foundation + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/crates/solidity/outputs/cargo/slang_solidity_cli/README.md b/crates/solidity/outputs/cargo/slang_solidity_cli/README.md new file mode 100644 index 0000000000..36b4fe6a90 --- /dev/null +++ b/crates/solidity/outputs/cargo/slang_solidity_cli/README.md @@ -0,0 +1,21 @@ +# slang_solidity_cli + + + +[![release](https://img.shields.io/github/v/tag/NomicFoundation/slang?label=GitHub%20Release&logo=github&sort=semver&logoColor=white)](https://github.com/NomicFoundation/slang/releases) +[![crate](https://img.shields.io/crates/v/slang_solidity_cli?label=Rust%20Crate&logo=rust&logoColor=white)](https://crates.io/crates/slang_solidity_cli) + +## Solidity compiler tooling by [@NomicFoundation](https://github.com/NomicFoundation) + +A modular set of compiler APIs empowering the next generation of Solidity code analysis and developer tooling. +Written in Rust and distributed in multiple languages. + +- [Announcement Post](https://medium.com/nomic-foundation-blog/slang-rethnet-2ad465fd7880) +- [How to write your own Solidity linter using Slang, in 25 lines of code!](https://blog.nomic.foundation/how-to-write-your-own-solidity-linter-using-slang-356e7565ad1b/) +- [User Guide](https://nomicfoundation.github.io/slang/latest/user-guide/rust-crate/) + +> ❗ This project is still in alpha, and is under active development. +> If you are planning on using it, please [reach out to us on Telegram](https://t.me/+pxApdT-Ssn5hMTFh) so we can help you get started. + +- [Slang Telegram Group](https://t.me/+pxApdT-Ssn5hMTFh) +- [We are hiring!](https://nomic.foundation/jobs) diff --git a/crates/solidity/outputs/cargo/slang_solidity_cli/src/main.rs b/crates/solidity/outputs/cargo/slang_solidity_cli/src/main.rs new file mode 100644 index 0000000000..d9a8bec513 --- /dev/null +++ b/crates/solidity/outputs/cargo/slang_solidity_cli/src/main.rs @@ -0,0 +1,3 @@ +fn main() { + slang_solidity::cli::execute(); +} diff --git a/crates/testlang/outputs/cargo/slang_testlang/Cargo.toml b/crates/testlang/outputs/cargo/slang_testlang/Cargo.toml index 9968bcb29e..54fcb2aa7c 100644 --- a/crates/testlang/outputs/cargo/slang_testlang/Cargo.toml +++ b/crates/testlang/outputs/cargo/slang_testlang/Cargo.toml @@ -8,9 +8,9 @@ name = "slang_testlang" # __RUST_PRODUCT_CRATE_FEATURES__ (keep in sync) [features] -default = ["cli"] -cli = ["dep:ariadne", "dep:clap", "dep:serde_json"] +default = [] __experimental_bindings_api = ["dep:metaslang_bindings"] +__private_cli_execution = ["dep:ariadne", "dep:clap", "dep:serde_json"] __private_testing_utils = ["dep:ariadne"] __private_wit_bindings = ["dep:paste", "dep:wit-bindgen"] diff --git a/crates/testlang/outputs/cargo/slang_testlang/src/generated/cli/commands/mod.rs b/crates/testlang/outputs/cargo/slang_testlang/src/generated/cli/commands/mod.rs index 656f75d638..60ba962444 100644 --- a/crates/testlang/outputs/cargo/slang_testlang/src/generated/cli/commands/mod.rs +++ b/crates/testlang/outputs/cargo/slang_testlang/src/generated/cli/commands/mod.rs @@ -1,20 +1,3 @@ // This file is generated automatically by infrastructure scripts. Please don't edit by hand. -use thiserror::Error; - pub mod parse; - -#[derive(Debug, Error)] -pub enum CommandError { - #[error("File not found: {0:?}")] - FileNotFound(String), - - #[error(transparent)] - Io(#[from] std::io::Error), - - #[error(transparent)] - LanguageError(#[from] crate::language::Error), - - #[error("Parsing failed: {0}")] - ParseFailed(String), -} diff --git a/crates/testlang/outputs/cargo/slang_testlang/src/generated/cli/commands/parse.rs b/crates/testlang/outputs/cargo/slang_testlang/src/generated/cli/commands/parse.rs index c2ed11a906..d174ba0839 100644 --- a/crates/testlang/outputs/cargo/slang_testlang/src/generated/cli/commands/parse.rs +++ b/crates/testlang/outputs/cargo/slang_testlang/src/generated/cli/commands/parse.rs @@ -3,52 +3,59 @@ use std::fs; use std::path::PathBuf; +use clap::Parser; use semver::Version; -use super::CommandError; use crate::diagnostic; use crate::language::Language; -use crate::parse_output::ParseOutput; -pub fn execute(file_path_string: &str, version: Version, json: bool) -> Result<(), CommandError> { - parse_source_file(file_path_string, version, |output| { +#[derive(Parser, Debug)] +pub struct ParseCommand { + /// File path to the source file to parse + file_path: PathBuf, + + /// The language version to use for parsing + #[arg(short, long)] + version: Version, + + /// Print the concrete syntax tree as JSON + #[clap(long)] + json: bool, +} + +impl ParseCommand { + pub fn execute(self) { + let Self { + file_path, + version, + json, + } = self; + + let file_path = file_path + .canonicalize() + .unwrap_or_else(|_| panic!("File not found: {file_path:?}")); + + let input = fs::read_to_string(&file_path).unwrap(); + let language = Language::new(version).unwrap(); + let parse_output = language.parse(Language::ROOT_KIND, &input); + + if !parse_output.is_valid() { + const COLOR: bool = true; + + let report = parse_output + .errors() + .iter() + .map(|error| diagnostic::render(error, file_path.to_str().unwrap(), &input, COLOR)) + .collect::>() + .join("\n"); + + panic!("Parse failed:\n{report}"); + } + if json { - let root_node = output.tree(); - let json = serde_json::to_string_pretty(&root_node).expect("JSON serialization failed"); + let json = serde_json::to_string_pretty(&parse_output.tree()).unwrap(); + println!("{json}"); } - }) - .map(|_| ()) -} - -pub(crate) fn parse_source_file( - file_path_string: &str, - version: Version, - run_before_checking: F, -) -> Result -where - F: FnOnce(&ParseOutput), -{ - let file_path = PathBuf::from(&file_path_string) - .canonicalize() - .map_err(|_| CommandError::FileNotFound(file_path_string.to_string()))?; - - let input = fs::read_to_string(file_path)?; - let language = Language::new(version)?; - let parse_output = language.parse(Language::ROOT_KIND, &input); - - run_before_checking(&parse_output); - - if parse_output.is_valid() { - Ok(parse_output) - } else { - const COLOR: bool = true; - let report = parse_output - .errors() - .iter() - .map(|error| diagnostic::render(error, file_path_string, &input, COLOR)) - .collect::>() - .join("\n"); - Err(CommandError::ParseFailed(report)) } } diff --git a/crates/testlang/outputs/cargo/slang_testlang/src/generated/cli/mod.rs b/crates/testlang/outputs/cargo/slang_testlang/src/generated/cli/mod.rs index 805afe8975..4d7994dd92 100644 --- a/crates/testlang/outputs/cargo/slang_testlang/src/generated/cli/mod.rs +++ b/crates/testlang/outputs/cargo/slang_testlang/src/generated/cli/mod.rs @@ -1,44 +1,33 @@ // This file is generated automatically by infrastructure scripts. Please don't edit by hand. -use std::process::ExitCode; +mod commands; -use clap::Subcommand; -use semver::Version; +use clap::{Parser, Subcommand}; -pub mod commands; +use crate::cli::commands::parse::ParseCommand; + +#[derive(Parser, Debug)] +#[command(next_line_help = true)] +#[command(author, about)] +struct Cli { + #[command(subcommand)] + command: Commands, +} #[derive(Subcommand, Debug)] -pub enum Commands { +enum Commands { /// Parses a source file, and outputs any syntax errors, or a JSON concrete syntax tree - Parse { - /// File path to the source file to parse - file_path: String, - - /// The language version to use for parsing - #[arg(short, long)] - version: Version, + Parse(ParseCommand), +} - /// Print the concrete syntax tree as JSON - #[clap(long)] - json: bool, - }, +pub fn execute() { + match Cli::parse().command { + Commands::Parse(command) => command.execute(), + }; } -impl Commands { - pub fn execute(self) -> ExitCode { - let command_result = match self { - Commands::Parse { - file_path, - version, - json, - } => commands::parse::execute(&file_path, version, json), - }; - match command_result { - Ok(()) => ExitCode::SUCCESS, - Err(error) => { - eprintln!("{error}"); - ExitCode::FAILURE - } - } - } +#[test] +fn verify_clap_cli() { + // Catches problems earlier in the development cycle: + ::command().debug_assert(); } diff --git a/crates/testlang/outputs/cargo/slang_testlang/src/generated/diagnostic/mod.rs b/crates/testlang/outputs/cargo/slang_testlang/src/generated/diagnostic/mod.rs index e1f3835a03..c90559f846 100644 --- a/crates/testlang/outputs/cargo/slang_testlang/src/generated/diagnostic/mod.rs +++ b/crates/testlang/outputs/cargo/slang_testlang/src/generated/diagnostic/mod.rs @@ -24,7 +24,10 @@ pub trait Diagnostic { fn message(&self) -> String; } -#[cfg(any(feature = "cli", feature = "__private_testing_utils"))] +#[cfg(any( + feature = "__private_cli_execution", + feature = "__private_testing_utils" +))] pub fn render(error: &D, source_id: &str, source: &str, with_color: bool) -> String { use ariadne::{Color, Config, Label, Report, ReportKind, Source}; diff --git a/crates/testlang/outputs/cargo/slang_testlang/src/generated/mod.rs b/crates/testlang/outputs/cargo/slang_testlang/src/generated/mod.rs index 9b7ed34dcc..db90e0f2cb 100644 --- a/crates/testlang/outputs/cargo/slang_testlang/src/generated/mod.rs +++ b/crates/testlang/outputs/cargo/slang_testlang/src/generated/mod.rs @@ -10,14 +10,14 @@ pub mod parse_output; pub mod query; pub mod text_index; -#[cfg(feature = "__private_wit_bindings")] -pub mod wit; +#[cfg(feature = "__experimental_bindings_api")] +pub mod bindings; + +#[cfg(feature = "__private_cli_execution")] +pub mod cli; #[cfg(feature = "__private_napi_interfaces")] pub mod napi_interface; -#[cfg(feature = "cli")] -pub mod cli; - -#[cfg(feature = "__experimental_bindings_api")] -pub mod bindings; +#[cfg(feature = "__private_wit_bindings")] +pub mod wit; diff --git a/documentation/public/user-guide/rust-crate/installation.md b/documentation/public/user-guide/rust-crate/installation.md index cf4932be67..2adf831d8a 100644 --- a/documentation/public/user-guide/rust-crate/installation.md +++ b/documentation/public/user-guide/rust-crate/installation.md @@ -3,13 +3,13 @@ The Rust package is published to crates.io as [`slang_solidity`](https://crates.io/crates/slang_solidity) ([docs](https://docs.rs/slang_solidity/latest/slang_solidity/)). It can be used both as a regular Rust dependency and as a standalone CLI (installable with Cargo). -You can install `slang` CLI as a cargo binary using: +You can install the CLI as a cargo binary using: ```bash -cargo install "slang_solidity" +cargo install "slang_solidity_cli" ``` -Or you can add its API as a dependency to your project: +Or you can add the API as a dependency to your project: ```bash cargo add "slang_solidity"