bracket-parser 0.1.0

A Rust library that detects if positions in text are inside or outside brackets
Documentation
  • Coverage
  • 90%
    9 out of 10 items documented0 out of 6 items with examples
  • Size
  • Source code size: 79.24 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 848.29 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 31s Average build duration of successful builds.
  • all releases: 31s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • berecik/bracket-parser
    0 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • berecik

Bracket Parser

Crates.io Documentation License: MIT

A Rust library that uses tree-sitter to parse text and determine whether positions in the text are inside or outside brackets.

Features

  • Detects positions inside or outside brackets (parentheses, square brackets, curly braces)
  • Handles nested brackets correctly
  • Simple API for checking the state at the end of a string or at any position
  • Built on the robust tree-sitter parsing library
  • Zero false positives - properly handles all edge cases

Installation

Add the following to your Cargo.toml:

[dependencies]
bracket-parser = "0.1.0"

Usage

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);
    }
}

How It Works

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.

Development

Code Quality

This project includes a script to check code quality. Run it before submitting changes:

./check_quality.sh

The script performs the following checks:

  • Code formatting with cargo fmt
  • Linting with cargo clippy
  • Running tests with cargo test
  • Documentation generation with cargo doc
  • Dependency checks with cargo outdated
  • Security vulnerability scanning with cargo audit (if installed)

To install additional tools:

# Install cargo-outdated
cargo install cargo-outdated

# Install cargo-audit
cargo install cargo-audit

License

MIT