Skip to main content

Crate perl_parser_core

Crate perl_parser_core 

Source
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

TypeRole
ParserRecursive-descent parser; call Parser::parse to get an AST
Node / NodeKindAST node and its discriminant (re-exported from perl-ast)
ParseErrorSyntax error collected during parsing
ParseOutputAST + diagnostics bundle for IDE workflows
Token / TokenKindLexer tokens consumed by the parser
SourceLocationByte-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::quote_parser;
pub use engine::error;
pub use engine::parser;
pub use engine::position;
pub use syntax::edit;
pub use syntax::heredoc as heredoc_collector;
pub use syntax::path_normalize;
pub use syntax::path_security;
pub use syntax::percentile;
pub use syntax::qualified_name;
pub use syntax::source_file;
pub use syntax::text_line;
pub use engine::parser::Parser;
pub use error::classifier as error_classifier;
pub use error::recovery as error_recovery;
pub use error_recovery::RecoveryResult;
pub use error::classifier::RecoverySalvageMetrics;
pub use error::classifier::classify_recovery_salvage;
pub use error::BudgetTracker;
pub use error::ParseBudget;
pub use error::ParseError;
pub use error::ParseOutput;
pub use error::ParseResult;
pub use error::RecoverySalvageClass;
pub use error::RecoverySalvageProfile;
pub use tokens::token_stream;
pub use tokens::trivia;
pub use tokens::trivia_parser;
pub use token_stream::TokenStream;
pub use trivia::NodeWithTrivia;
pub use trivia::Trivia;
pub use trivia::TriviaToken;
pub use trivia_parser::TriviaPreservingParser;
pub use trivia_parser::format_with_trivia;
pub use engine::ast_v2;
pub use engine::pragma_tracker;

Modules§

builtin_signatures
Builtin function signature lookup tables. Comprehensive built-in function signatures for Perl scripting.
builtin_signatures_phf
Perfect hash function (PHF) based builtin signature lookup. Consolidated built-in function signatures for Perl using perfect hash
builtins
Builtin function signatures and metadata. Builtin function signatures and metadata for Perl.
engine
Parser engine components and supporting utilities. Parser engine components and supporting utilities.
line_index
Line indexing and position mapping utilities.
syntax
Syntax-level types absorbed from Wave D satellite crates. Syntax-level types and utilities absorbed from Wave D satellite crates.
token_wrapper
Lightweight token wrapper for AST integration. Token wrapper utilities for preserving original lexemes. Token wrapper with enhanced position tracking
tokens
Token stream and trivia utilities for the parser. Token stream and trivia utilities for parser workflows.
util
Parser utilities and helpers. Tokenization utilities shared by parser-facing entry points.

Structs§

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.
PositionMapper
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 produced by the lexer and consumed by the parser.

Enums§

LineEnding
Line ending detection for mixed-EOL source files. Line ending style detected in a document
MissingKind
Index into the diagnostics array in ParseOutput (from ast_v2). Kinds of missing syntax elements for error recovery.
NodeKind
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.
TokenKind
Individual token, its classification, and the streaming iterator. Token classification for Perl parsing.

Type Aliases§

DiagnosticId
Index into the diagnostics array in ParseOutput (from ast_v2). Index into the diagnostics array in ParseOutput.
SourceLocation
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.