From c5118b9dafb1b861961953089bbeb8601de1d2af Mon Sep 17 00:00:00 2001 From: Noratrieb <48135649+Noratrieb@users.noreply.github.com> Date: Sun, 20 Apr 2025 15:56:05 +0200 Subject: [PATCH] wip --- cargo_tests/a/Cargo.lock | 7 +++ cargo_tests/a/Cargo.toml | 9 ++++ cargo_tests/a/src/main.rs | 3 ++ tstest/Cargo.lock | 90 +++++++++++++++++++++++++++++++++++++++ tstest/Cargo.toml | 12 ++++++ tstest/src/main.rs | 25 +++++++++++ 6 files changed, 146 insertions(+) create mode 100644 cargo_tests/a/Cargo.lock create mode 100644 cargo_tests/a/Cargo.toml create mode 100644 cargo_tests/a/src/main.rs create mode 100644 tstest/Cargo.lock create mode 100644 tstest/Cargo.toml create mode 100644 tstest/src/main.rs diff --git a/cargo_tests/a/Cargo.lock b/cargo_tests/a/Cargo.lock new file mode 100644 index 0000000..3676b09 --- /dev/null +++ b/cargo_tests/a/Cargo.lock @@ -0,0 +1,7 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "a" +version = "0.1.0" diff --git a/cargo_tests/a/Cargo.toml b/cargo_tests/a/Cargo.toml new file mode 100644 index 0000000..bc55c82 --- /dev/null +++ b/cargo_tests/a/Cargo.toml @@ -0,0 +1,9 @@ +[package] +name = "a" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +[workspace] \ No newline at end of file diff --git a/cargo_tests/a/src/main.rs b/cargo_tests/a/src/main.rs new file mode 100644 index 0000000..e035c6b --- /dev/null +++ b/cargo_tests/a/src/main.rs @@ -0,0 +1,3 @@ +pub struct A {} + +fn main() {} \ No newline at end of file diff --git a/tstest/Cargo.lock b/tstest/Cargo.lock new file mode 100644 index 0000000..2fab71c --- /dev/null +++ b/tstest/Cargo.lock @@ -0,0 +1,90 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "aho-corasick" +version = "1.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b2969dcb958b36655471fc61f7e416fa76033bdd4bfed0678d8fee1e2d07a1f0" +dependencies = [ + "memchr", +] + +[[package]] +name = "cc" +version = "1.0.83" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f1174fb0b6ec23863f8b971027804a42614e347eafb0a95bf0b12cdae21fc4d0" +dependencies = [ + "libc", +] + +[[package]] +name = "libc" +version = "0.2.151" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "302d7ab3130588088d277783b1e2d2e10c9e9e4a16dd9050e6ec93fb3e7048f4" + +[[package]] +name = "memchr" +version = "2.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "523dc4f511e55ab87b694dc30d0f820d60906ef06413f93d4d7a1385599cc149" + +[[package]] +name = "regex" +version = "1.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "380b951a9c5e80ddfd6136919eef32310721aa4aacd4889a8d39124b026ab343" +dependencies = [ + "aho-corasick", + "memchr", + "regex-automata", + "regex-syntax", +] + +[[package]] +name = "regex-automata" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5f804c7828047e88b2d32e2d7fe5a105da8ee3264f01902f796c8e067dc2483f" +dependencies = [ + "aho-corasick", + "memchr", + "regex-syntax", +] + +[[package]] +name = "regex-syntax" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c08c74e62047bb2de4ff487b251e4a92e24f48745648451635cec7d591162d9f" + +[[package]] +name = "tree-sitter" +version = "0.20.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e747b1f9b7b931ed39a548c1fae149101497de3c1fc8d9e18c62c1a66c683d3d" +dependencies = [ + "cc", + "regex", +] + +[[package]] +name = "tree-sitter-rust" +version = "0.20.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b0832309b0b2b6d33760ce5c0e818cb47e1d72b468516bfe4134408926fa7594" +dependencies = [ + "cc", + "tree-sitter", +] + +[[package]] +name = "tstest" +version = "0.1.0" +dependencies = [ + "tree-sitter", + "tree-sitter-rust", +] diff --git a/tstest/Cargo.toml b/tstest/Cargo.toml new file mode 100644 index 0000000..d39c9e3 --- /dev/null +++ b/tstest/Cargo.toml @@ -0,0 +1,12 @@ +[workspace] + +[package] +name = "tstest" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +tree-sitter = "0.20.10" +tree-sitter-rust = "0.20.4" diff --git a/tstest/src/main.rs b/tstest/src/main.rs new file mode 100644 index 0000000..5103a4b --- /dev/null +++ b/tstest/src/main.rs @@ -0,0 +1,25 @@ +use tree_sitter::{Node, Parser, Tree}; + +fn main() { + let mut parser = Parser::new(); + parser.set_language(tree_sitter_rust::language()).unwrap(); + let src = "/// hello\nstruct A (pub(crate) u8,u8);"; + let result = parser.parse(src, None).unwrap(); + + print_node(src, 0, result.root_node()); + + println!("{}", result.root_node().to_sexp()); +} + +fn print_node(src: &str, ind: usize, node: Node<'_>) { + println!( + "{}{} `{}`", + " ".repeat(ind), + node.kind(), + src[node.byte_range()].replace("\n", "\\n") + ); + + for i in 0..node.child_count() { + print_node(src, ind + 1, node.child(i).unwrap()) + } +}