Skip to main content

java_lang/
lib.rs

1//! Java AST Parser — a syn-style API for Java 25.
2//!
3//! This crate provides a complete Java Abstract Syntax Tree parser that closely
4//! follows the Java Language Specification (JLS) SE 25. The API design is inspired
5//! by Rust's [`syn`] crate.
6//!
7//! # Quick Start
8//!
9//! ```
10//! use java_lang::ast::CompilationUnit;
11//! use java_lang::parse_str;
12//!
13//! let unit: CompilationUnit = parse_str(
14//!     "package com.example;\n\npublic class Hello {\n    public static void main(String[] args) {\n        System.out.println(\"Hello, World!\");\n    }\n}\n"
15//! ).unwrap();
16//!
17//! // Access parsed elements
18//! if let Some(pkg) = &unit.package {
19//!     println!("Package: {:?}", pkg.name);
20//! }
21//! for item in &unit.type_decls {
22//!     println!("Type: {:?}", item);
23//! }
24//! ```
25//!
26//! # Design Principles
27//!
28//! - **Syn-style API**: Uses `Parse` trait and `ParseStream` similar to [`syn`].
29//! - **Complete coverage**: Supports Java 25 features including records, sealed classes,
30//!   pattern matching, switch expressions, text blocks, and unnamed variables.
31//! - **Span tracking**: Every AST node carries span information for error reporting.
32//! - **Zero-copy identifiers**: Uses `Ident` with interning for efficient comparison.
33
34mod error;
35mod ident;
36mod lexer;
37mod span;
38mod token;
39#[macro_use]
40mod parse;
41mod parser;
42
43pub mod ast;
44
45pub use error::{Error, Result};
46pub use ident::Ident;
47pub use parse::{Parse, ParseStream, parse, parse_file, parse_str};
48pub use span::Span;
49pub use token::{Token, TokenKind};
50
51// Re-export the top-level AST types for convenience
52pub use ast::compilation_unit::CompilationUnit;
53pub use ast::{Comment, CommentKind};