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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
//! S-Expression Parser Library
//!
//! A high-performance, zero-copy S-expression parser optimized for compiler use cases.
//! This library provides fast parsing with minimal memory allocations through borrowed
//! string slices and various performance optimizations.
//!
//! # Features
//!
//! - **Zero-copy parsing**: Uses borrowed string slices to avoid unnecessary allocations
//! - **Fast-path optimizations**: Optimized number parsing and single-character symbols
//! - **Production error handling**: Proper error types instead of panics
//! - **Memory efficient**: Pre-allocated vectors and optimized tokenization
//! - **Compiler-friendly**: Designed for use in language compilers and interpreters
//!
//! # Quick Start
//!
//! ```rust
//! use sexpression::{Expression, read, ParseError};
//!
//! fn main() -> Result<(), ParseError> {
//! let source = "(define (factorial n) (if (= n 0) 1 (* n (factorial (- n 1)))))";
//! let expr = read(source)?;
//! println!("Parsed: {:?}", expr);
//! Ok(())
//! }
//! ```
//!
//! # API Overview
//!
//! ## Core Types
//!
//! - [`Expression`]: Zero-copy S-expression representation
//! - [`OwnedExpression`]: Owned version for independent storage
//! - [`ParseError`]: Comprehensive error types
//!
//! ## Main Functions
//!
//! - [`read`]: Primary parsing function with error handling
//! - [`read_unchecked`]: Convenience function that panics on error
//!
//! # Performance
//!
//! The parser is optimized for:
//!
//! - **Memory efficiency**: Zero-copy parsing with borrowed slices
//! - **Speed**: Fast-path checks and pre-allocated vectors
//! - **Compiler workloads**: Designed for parsing large amounts of code
//!
//! # Examples
//!
//! ## Basic Parsing
//!
//! ```rust
//! use sexpression::{read, Expression};
//!
//! let result = read("(define x 42)");
//! match result {
//! Ok(expr) => println!("Success: {:?}", expr),
//! Err(e) => eprintln!("Error: {}", e),
//! }
//! ```
//!
//! ## Error Handling
//!
//! ```rust
//! use sexpression::{read, ParseError};
//!
//! let result = read("(unclosed");
//! assert!(matches!(result, Err(ParseError::MissingClosingParen)));
//! ```
//!
//! ## Converting to Owned
//!
//! ```rust
//! use sexpression::{Expression, OwnedExpression};
//!
//! let borrowed = Expression::Symbol("hello");
//! let owned = borrowed.to_owned();
//! assert_eq!(owned, OwnedExpression::Symbol("hello".to_string()));
//! ```
// Re-export main types and functions for easy access
pub use crate;