| Crates.io | bracket-parser |
| lib.rs | bracket-parser |
| version | 0.1.0 |
| created_at | 2025-06-11 02:09:57.998179+00 |
| updated_at | 2025-06-11 02:09:57.998179+00 |
| description | A Rust library that detects if positions in text are inside or outside brackets |
| homepage | |
| repository | https://github.com/berecik/bracket-parser |
| max_upload_size | |
| id | 1708007 |
| size | 79,759 |
A Rust library that uses tree-sitter to parse text and determine whether positions in the text are inside or outside brackets.
Add the following to your Cargo.toml:
[dependencies]
bracket-parser = "0.1.0"
use bracket_parser::{BracketParser, BracketState};
fn main() {
// Create a new parser instance
let mut parser = BracketParser::new().expect("Failed to initialize parser");
// Check if the cursor would be inside brackets at the end of this string
let code = "function call(param";
let state = parser.get_final_state(code);
match state {
BracketState::Inside => println!("Cursor is inside brackets"),
BracketState::Outside => println!("Cursor is outside brackets"),
}
// Get the state at each character position
let states = parser.get_all_states("a(b)c");
for (i, (ch, state)) in "a(b)c".chars().zip(states.iter()).enumerate() {
println!("Character '{}' at position {} is {:?}", ch, i, state);
}
}
The library uses tree-sitter to parse the input text into a syntax tree that recognizes bracketed expressions. It then traverses the tree to determine if a given position is inside or outside brackets.
This project includes a script to check code quality. Run it before submitting changes:
./check_quality.sh
The script performs the following checks:
cargo fmtcargo clippycargo testcargo doccargo outdatedcargo audit (if installed)To install additional tools:
# Install cargo-outdated
cargo install cargo-outdated
# Install cargo-audit
cargo install cargo-audit
MIT