1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
//! Perl AST library -- typed syntax tree for Perl source code.
//!
//! This crate defines the Abstract Syntax Tree used by `perl-parser-core` and
//! downstream analysis tools. Every parsed Perl construct is represented as a
//! [`Node`] carrying a [`NodeKind`] discriminant and a [`SourceLocation`]
//! (byte-offset span).
//!
//! # Modules
//!
//! - [`ast`] -- The primary AST used by the current recursive-descent parser.
//! - [`v2`] -- Experimental second-generation AST with full position tracking
//! for incremental parsing.
//!
//! # Quick start
//!
//! ```rust
//! use perl_ast::{Node, NodeKind, SourceLocation};
//!
//! // Build a small AST by hand
//! let loc = SourceLocation { start: 0, end: 2 };
//! let num = Node::new(NodeKind::Number { value: "42".to_string() }, loc);
//!
//! assert_eq!(num.kind.kind_name(), "Number");
//! assert_eq!(num.location.start, 0);
//! assert_eq!(num.location.end, 2);
//! ```
//!
//! In practice the AST is produced by the parser (requires `perl-parser-core`):
//!
//! ```rust,ignore
//! use perl_parser_core::Parser;
//! use perl_ast::NodeKind;
//!
//! let mut parser = Parser::new("my $x = 42;");
//! let ast = parser.parse().expect("should parse");
//! assert!(matches!(ast.kind, NodeKind::Program { .. }));
//! ```
//!
//! # Traversal
//!
//! [`Node`] exposes `to_sexp()` for a tree-sitter-compatible S-expression and
//! `count_nodes()` for a quick size metric. For deeper inspection, match on
//! [`NodeKind`] variants and recurse into child nodes.
/// Incremental parsing AST types extracted into a dedicated microcrate.
pub use perl_ast_v2 as v2;
/// Primary AST node -- the building block of every syntax tree.
pub use ;
/// Byte-offset span indicating where a node appears in source text.
pub use SourceLocation;