From 19d6ba695a25c5aa12140ddbba26c4f96d907caa Mon Sep 17 00:00:00 2001 From: Antony Blakey Date: Sat, 28 Dec 2024 02:39:18 +1100 Subject: [PATCH] Add cli tool to dump solidity grammar definition as json --- Cargo.lock | 8 ++++++ Cargo.toml | 2 ++ .../outputs/cargo/grammar_export/Cargo.toml | 28 +++++++++++++++++++ .../outputs/cargo/grammar_export/src/main.rs | 6 ++++ 4 files changed, 44 insertions(+) create mode 100644 crates/solidity/outputs/cargo/grammar_export/Cargo.toml create mode 100644 crates/solidity/outputs/cargo/grammar_export/src/main.rs diff --git a/Cargo.lock b/Cargo.lock index a5a2c96c1c..b9ec1d0adf 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2375,6 +2375,14 @@ dependencies = [ "slang_solidity", ] +[[package]] +name = "slang_solidity_grammar_export" +version = "0.18.3" +dependencies = [ + "serde_json", + "solidity_language", +] + [[package]] name = "slang_testlang" version = "0.18.3" diff --git a/Cargo.toml b/Cargo.toml index 9de5256933..25fb4a5881 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -29,6 +29,7 @@ members = [ "crates/solidity/inputs/language", "crates/solidity/outputs/cargo/cli", "crates/solidity/outputs/cargo/crate", + "crates/solidity/outputs/cargo/grammar_export", "crates/solidity/outputs/cargo/tests", "crates/solidity/outputs/cargo/wasm", "crates/solidity/outputs/npm/package", @@ -70,6 +71,7 @@ metaslang_cst = { path = "crates/metaslang/cst", version = "0.18.3" } slang_solidity = { path = "crates/solidity/outputs/cargo/crate", version = "0.18.3" } slang_solidity_cli = { path = "crates/solidity/outputs/cargo/cli", version = "0.18.3" } +slang_solidity_grammar_export = { path = "crates/solidity/outputs/cargo/slang_solidity_grammar_export", version = "0.18.3" } solidity_cargo_tests = { path = "crates/solidity/outputs/cargo/tests", version = "0.18.3" } solidity_cargo_wasm = { path = "crates/solidity/outputs/cargo/wasm", version = "0.18.3" } solidity_language = { path = "crates/solidity/inputs/language", version = "0.18.3" } diff --git a/crates/solidity/outputs/cargo/grammar_export/Cargo.toml b/crates/solidity/outputs/cargo/grammar_export/Cargo.toml new file mode 100644 index 0000000000..b8a17443c0 --- /dev/null +++ b/crates/solidity/outputs/cargo/grammar_export/Cargo.toml @@ -0,0 +1,28 @@ +[package] +version.workspace = true +rust-version.workspace = true +edition.workspace = true +# __SLANG_CARGO_PUBLISH_TEMPORARILY_DISABLED__ (keep in sync) +# publish = true + +name = "slang_solidity_grammar_export" +description = "" +homepage = "https://nomicfoundation.github.io/slang/" +repository = "https://github.com/NomicFoundation/slang/" +authors = [ + "Nomic Foundation ", + "Antony Blakey ", + "Igor Matuszewski ", + "Omar Tawfik ", +] + +[[bin]] +name = "slang_solidity_grammar_export" +path = "src/main.rs" + +[dependencies] +serde_json = { workspace = true } +solidity_language = { workspace = true } + +[lints] +workspace = true diff --git a/crates/solidity/outputs/cargo/grammar_export/src/main.rs b/crates/solidity/outputs/cargo/grammar_export/src/main.rs new file mode 100644 index 0000000000..2a2bc49f43 --- /dev/null +++ b/crates/solidity/outputs/cargo/grammar_export/src/main.rs @@ -0,0 +1,6 @@ +fn main() { + println!( + "{}", + serde_json::to_string(&solidity_language::SolidityDefinition::create().sections).unwrap() + ); +}