Skip to main content

Crate tree_sitter_perl_c

Crate tree_sitter_perl_c 

Source
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§

PerlParser
Reusable Perl parser for hot parse loops.

Enums§

ParsePerlError
Typed errors produced by Perl parse helpers in this crate.

Functions§

create_parser
Creates a tree_sitter::Parser configured for Perl, silently ignoring language-set errors.
get_scanner_config
Returns the scanner backend identifier for this crate.
language
Returns the tree-sitter Language for 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 path and parses it as Perl source.
try_create_parser
Creates a tree_sitter::Parser configured 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 path and parses it as Perl source.