API Reference
Complete reference for all Parsanol functions and types.
Basic Parsers
str(pattern: &str) -> Atom
Matches a literal string exactly.
re(pattern: &str) -> Atom
Matches a regular expression pattern.
any() -> Atom
Matches any single character.
eof() -> Atom
Matches end of input.
cut() -> Atom
Commits to the current parsing branch, preventing backtracking. Use after a decision point to improve error messages.
Character Classes
Pre-defined character classes with O(1) lookup using pre-computed tables.
digit()
[0-9] or \d
non_digit()
\D
alpha()
[a-zA-Z]
lower()
[a-z]
upper()
[A-Z]
alnum()
[a-zA-Z0-9]
word()
[a-zA-Z0-9_] or \w
non_word()
\W
space()
[ \t\n\r\f\v] or \s
non_space()
\S
hex_digit()
[0-9a-fA-F]
blank()
[ \t]
Combinators
.then(other: Atom) -> Atom
Sequences two parsers. Both must succeed in order.
.or(other: Atom) -> Atom
Ordered choice: tries the first parser, falls back to the second if it fails.
seq(atoms: Vec<Atom>) -> Atom
Sequence of multiple atoms. All must succeed in order.
choice(atoms: Vec<Atom>) -> Atom
Ordered choice among multiple alternatives. Tries each in order until one succeeds.
Repetition
.repeat(min: usize, max: Option<usize>) -> Atom
Repeats the parser between min and max times.
.many() -> Atom
Zero or more repetitions. Equivalent to .repeat(0, None).
.many1() -> Atom
One or more repetitions. Equivalent to .repeat(1, None).
.optional() -> Atom
Makes the parser optional (zero or one). Equivalent to .repeat(0, Some(1)).
Lookahead
.lookahead() -> Atom
Positive lookahead: succeeds if the pattern matches, but doesn't consume input.
.not_ahead() -> Atom
Negative lookahead: succeeds if the pattern does NOT match, doesn't consume input.
Modifiers
.label(name: &str) -> Atom
Names the capture for later access in transforms. Key feature for structured output.
.ignore() -> Atom
Excludes the result from the output AST. Useful for whitespace and delimiters.
Grammar Definition
ref_(name: &str) -> Atom
References a named rule in the grammar. Essential for recursive structures.
grammar! { ... }
Macro for defining grammars with named rules. Clean syntax for complex parsers.
Infix Expressions
InfixBuilder
Builder for parsing infix expressions with operator precedence and associativity.
Transform System
Transform::new()
Transform raw parse trees into structured data using pattern matching.
Derive Macros
#[derive(FromAst)]
Automatically derive AST-to-struct conversion for type-safe parsing.
Visitor Pattern
trait Visitor
Walk the AST without transforming it. Useful for analysis, validation, and code generation.
Streaming Builder
trait StreamingBuilder
Build custom output structures during parsing without intermediate AST. Zero-allocation for maximum performance.