Expand description
Tree-sitter Perl grammar binding (C FFI).
This crate is the conventional C/tree-sitter reference implementation for
Perl, maintained alongside the native v3 Rust parser (perl-parser) for
compatibility testing and comparison. It vendors a snapshot of the upstream
tree-sitter-perl C grammar (parser.c + scanner.c) under c-src/ and
exposes it via a hand-written FFI declaration — no bindgen or libclang
dependency is required to build.
§Relation to tree-sitter-perl-rs
tree-sitter-perl-rs is a thin facade over the native v3 Rust parser and
is the recommended choice for new Rust projects. This crate (tree-sitter-perl-c)
should be preferred when:
- Compatibility testing — comparing parse output against the upstream C reference grammar.
- Non-Rust tree-sitter tooling — the C grammar snapshot can be used as a build dependency for language bindings in other languages.
- Baseline benchmarking — measuring parse throughput of the C grammar against the native v3 parser.
§Build requirements
Only a C compiler is required (e.g., cc/gcc/clang on Linux/macOS,
MSVC or MinGW on Windows). No libclang or bindgen toolchain is needed.
§Quick start
use tree_sitter_perl_c::parse_perl_code;
let tree = parse_perl_code("my $x = 42;").unwrap();
assert!(!tree.root_node().has_error());
println!("{}", tree.root_node().to_sexp());Structs§
- Perl
Parser - Reusable Perl parser for hot parse loops.
Enums§
- Parse
Perl Error - Typed errors produced by Perl parse helpers in this crate.
Functions§
- create_
parser - Creates a
tree_sitter::Parserconfigured for Perl, silently ignoring language-set errors. - get_
scanner_ config - Returns the scanner backend identifier for this crate.
- language
- Returns the tree-sitter
Languagefor Perl (C grammar). - parse_
perl_ bytes - Parses Perl source bytes and returns the resulting
tree_sitter::Tree. - parse_
perl_ bytes_ with_ parser - Parses Perl source bytes using a caller-provided configured
tree_sitter::Parser. - parse_
perl_ code - Parses a Perl source string and returns the resulting
tree_sitter::Tree. - parse_
perl_ code_ with_ parser - Parses a Perl source string using a caller-provided configured
tree_sitter::Parser. - parse_
perl_ file - Reads a file from
pathand parses it as Perl source. - try_
create_ parser - Creates a
tree_sitter::Parserconfigured for Perl. - try_
parse_ perl_ bytes - Parses Perl source bytes and returns the resulting
tree_sitter::Tree. - try_
parse_ perl_ bytes_ with_ parser - Parses Perl source bytes using a caller-provided configured
tree_sitter::Parser. - try_
parse_ perl_ code - Parses a Perl source string and returns the resulting
tree_sitter::Tree. - try_
parse_ perl_ code_ with_ parser - Parses a Perl source string using a caller-provided configured
tree_sitter::Parser. - try_
parse_ perl_ file - Reads a file from
pathand parses it as Perl source.