perl-token
Core token type definitions for the Perl parser ecosystem.
Overview
perl-token is a Tier 1 leaf crate that defines the shared token types used
across the lexer, tokenizer, and parser crates. It has zero external
dependencies (only std::sync::Arc).
Stability Contract
perl-token is a tiny stable leaf crate and should stay dependency-free at runtime.
Public Token/TokenKind source compatibility is intentionally conservative and should
only change with explicit, reviewed intent.
- TokenKind variants: 132
- Conformance update rule: adding a
TokenKindvariant must also update metadata, this crate's docs, and the conformance guard tests.
Public API
Token-- a token withkind: TokenKind,text: Arc<str>,start: usize,end: usizeTokenRef<'src>-- borrowed token view withkind,text: &'src str,start,endfor allocation-sensitive pathsTokenKind-- enum classifying every Perl token: keywords, operators, delimiters, literals, sigils, and special tokens
Usage
use ;
let tok = new;
assert_eq!;
let borrowed = new;
let owned = borrowed.to_owned_token;
assert_eq!;
Borrowed view from owned tokens:
use ;
let tok = new;
let borrowed = tok.as_ref_token;
assert_eq!;
Benchmark scorecard
Run the token allocation scorecard benchmark:
The benchmark group includes:
token/borrowed_construction(noArcallocation)token/owned_construction(Arc<str>allocation path)token/borrowed_to_owned_conversion(explicit conversion cost)
Workspace Role
Foundational crate consumed by perl-lexer, perl-tokenizer, perl-parser-core,
and downstream parser/LSP crates. Part of the
tree-sitter-perl-rs workspace.
License
MIT OR Apache-2.0