Expand description
Core parser engine for Perl source code.
perl-parser-core is the foundational crate that wires together the lexer,
AST, error recovery, and position mapping into a single Parser entry
point. Higher-level crates – semantic analysis, workspace indexing, and the
LSP server – all build on top of this crate.
§Key types
| Type | Role |
|---|---|
Parser | Recursive-descent parser; call Parser::parse to get an AST |
Node / NodeKind | AST node and its discriminant (re-exported from perl-ast) |
ParseError | Syntax error collected during parsing |
ParseOutput | AST + diagnostics bundle for IDE workflows |
Token / TokenKind | Lexer tokens consumed by the parser |
SourceLocation | Byte-offset span for every node |
§Quick start
use perl_parser_core::{Parser, Node, NodeKind};
let mut parser = Parser::new("my $x = 42;");
let ast = parser.parse().expect("should parse");
// The root is always a Program node
assert!(matches!(ast.kind, NodeKind::Program { .. }));
// Non-fatal errors are collected, not returned as Err
assert!(parser.errors().is_empty());For IDE workflows that need error-tolerant parsing, use
Parser::parse_with_recovery:
use perl_parser_core::Parser;
let mut parser = Parser::new("if (");
let output = parser.parse_with_recovery();
// Always returns an AST (possibly with ERROR nodes)
assert!(!output.diagnostics.is_empty());Re-exports§
pub use engine::ast;pub use engine::parser_context;pub use engine::error;pub use engine::parser;pub use engine::position;pub use engine::parser::Parser;pub use tokens::token_stream;pub use perl_builtins as builtins;pub use engine::ast_v2;pub use engine::pragma_tracker;pub use engine::quote_parser;pub use perl_edit as edit;pub use perl_heredoc as heredoc_collector;pub use builtins::builtin_signatures_phf;
Modules§
- builtin_
signatures - Builtin function signature lookup tables. Comprehensive built-in function signatures for Perl scripting.
- engine
- Parser engine components and supporting utilities. Parser engine components and supporting utilities.
- error_
classifier - Error classification and recovery strategies for parse failures. Error types and result aliases used by the parser engine. Error classification and diagnostic generation for parsed Perl code. Error classification and diagnostic generation for Perl parsing workflows
- error_
recovery - Error recovery helpers and strategies. Error types and result aliases used by the parser engine. Error recovery strategies and traits for the Perl parser. Error recovery for the Perl parser
- line_
index - Line indexing and position mapping utilities.
- token_
wrapper - Lightweight token wrapper for AST integration. Token wrapper utilities for preserving original lexemes and trivia. Token wrapper with enhanced position tracking
- tokens
- Token stream and trivia utilities for the parser. Token stream and trivia utilities for parser workflows.
- trivia
- Trivia (whitespace and comments) representation. Trivia tokens (whitespace/comments) used for formatting and diagnostics. Trivia (comments and whitespace) handling for the Perl parser
- trivia_
parser - Trivia-preserving parser and formatting utilities. Trivia parser helpers for preserving formatting context. Trivia-preserving parser implementation
- util
- Parser utilities and helpers. Utility functions for the Perl parser
Structs§
- Budget
Tracker - Parse error, budget, and output types. Error types and result aliases used by the parser engine. Tracks budget consumption during parsing.
- Node
- Core AST types re-exported for convenience. Re-exported AST node types used during Parse/Index/Analyze stages. Core AST node representing any Perl language construct within parsing workflows.
- Node
With Trivia - Trivia types attached to AST nodes for formatting preservation. A node with attached trivia
- Parse
Budget - Parse error, budget, and output types. Error types and result aliases used by the parser engine. Budget limits for parser operations to prevent runaway parsing.
- Parse
Output - Parse error, budget, and output types. Error types and result aliases used by the parser engine. Structured output from parsing, combining AST with all diagnostics.
- Position
Mapper - Line ending detection for mixed-EOL source files. Centralized position mapper using rope for efficiency.
- Token
- Individual token, its classification, and the streaming iterator. Token stream types used during the Parse stage of the workflow. Token produced by the lexer and consumed by the parser.
- Token
Stream - Individual token, its classification, and the streaming iterator. Token stream types used during the Parse stage of the workflow. Token stream that wraps perl-lexer
- Trivia
Preserving Parser - Trivia-preserving parser and source formatting helper. Parser that preserves trivia
- Trivia
Token - Trivia types attached to AST nodes for formatting preservation. A trivia token with position information
Enums§
- Line
Ending - Line ending detection for mixed-EOL source files. Line ending style detected in a document
- Missing
Kind - Index into the diagnostics array in
ParseOutput(fromast_v2). Kinds of missing syntax elements for error recovery. - Node
Kind - Core AST types re-exported for convenience. Re-exported AST node types used during Parse/Index/Analyze stages. Comprehensive enumeration of all Perl language constructs supported by the parser.
- Parse
Error - Parse error, budget, and output types. Error types and result aliases used by the parser engine. Comprehensive error types that can occur during Perl parsing workflows
- Recovery
Result - Result of an error recovery attempt. Result of a recovery operation.
- Token
Kind - Individual token, its classification, and the streaming iterator. Token stream types used during the Parse stage of the workflow. Token classification for Perl parsing.
- Trivia
- Trivia types attached to AST nodes for formatting preservation. Trivia represents non-semantic tokens like comments and whitespace
Functions§
- format_
with_ trivia - Trivia-preserving parser and source formatting helper. Format an AST with trivia back to source code
Type Aliases§
- Diagnostic
Id - Index into the diagnostics array in
ParseOutput(fromast_v2). Index into the diagnostics array inParseOutput. - Parse
Result - Parse error, budget, and output types. Error types and result aliases used by the parser engine. Result type for parser operations in the Perl parsing workflow pipeline
- Source
Location - Core AST types re-exported for convenience.
Re-exported AST node types used during Parse/Index/Analyze stages.
Type alias for backward compatibility with
SourceLocation.