jetcrab\parser/mod.rs
1//! # JavaScript Parser Module
2//!
3//! Provides JavaScript source code parsing capabilities, converting text input
4//! into an Abstract Syntax Tree (AST) representation for further processing.
5//!
6//! ## Overview
7//!
8//! The parser module implements a recursive descent parser that handles:
9//!
10//! - **Expressions**: Arithmetic, logical, assignment, and function calls
11//! - **Statements**: Control flow, declarations, and blocks
12//! - **Literals**: Objects, arrays, functions, and primitive values
13//! - **Recovery**: Error recovery and partial parsing
14//!
15//! ## Features
16//!
17//! - **ECMAScript 2020+ Support**: Modern JavaScript syntax
18//! - **Error Recovery**: Continues parsing after syntax errors
19//! - **Position Tracking**: Accurate source location information
20//! - **Modular Design**: Separate parsers for different constructs
21//!
22//! ## Usage
23//!
24//! ```rust
25//! use jetcrab::parser::{parse, parse_with_recovery};
26//!
27//! // Parse with error handling
28//! let ast = parse("let x = 42;")?;
29//!
30//! // Parse with recovery for invalid code
31//! let (ast, errors) = parse_with_recovery("let x = ;");
32//! ```
33
34pub mod core;
35pub mod error;
36pub mod expressions;
37pub mod literals;
38pub mod recovery;
39pub mod statements;
40pub mod utils;
41
42pub use core::Parser;
43pub use error::ParserError;
44
45pub fn parse(source: &str) -> Result<crate::ast::Node, ParserError> {
46 let mut parser = Parser::new(source);
47 parser.parse()
48}
49
50pub fn parse_with_recovery(source: &str) -> (Option<crate::ast::Node>, Vec<ParserError>) {
51 let mut parser = Parser::new(source);
52 parser.parse_with_recovery()
53}