Expand description
Parsanol - Highly Optimized Rust PEG Parser Library
This is a generic PEG parser library that can be used for any language. It provides:
- Core PEG parsing with packrat memoization
- Arena allocation for zero-copy AST construction
- Parser DSL for idiomatic grammar definition
- Rich error reporting with tree-structured errors
- Transformation system for converting parse trees to typed structs
- Infix expression parsing with precedence handling
- Developer tools (debug tracing, visualization)
- Optional Ruby FFI bindings
- Optional WASM bindings
§Quick Start
use parsanol::portable::{Grammar, PortableParser, AstArena};
// Define grammar via JSON
let grammar_json = r#"{
"atoms": [
{ "Str": { "pattern": "hello" } }
],
"root": 0
}"#;
let grammar: Grammar = serde_json::from_str(grammar_json).unwrap();
let input = "hello";
let mut arena = AstArena::for_input(input.len());
let mut parser = PortableParser::new(&grammar, input, &mut arena);
let ast = parser.parse().unwrap();§Using the Parser DSL
use parsanol::portable::parser_dsl::*;
let grammar = GrammarBuilder::new()
.rule("greeting", str("hello").then(str("world")))
.build();§Feature Flags
ruby- Enable Ruby FFI bindings via magnuswasm- Enable WebAssembly bindingslogging- Enable debug logging using thelogcrateparallel- Enable parallel parsing with rayoncompare-nom- Include nom parser for benchmarking comparisonscompare-winnow- Include winnow parser for benchmarking comparisons
Re-exports§
pub use portable::debug::GrammarVisualizer;pub use portable::debug::ParseTrace;pub use portable::debug::SourceFormatter;pub use portable::debug::TreePrinter;pub use portable::error::ErrorBuilder;pub use portable::error::RichError;pub use portable::error::Span;pub use portable::incremental::DirtyRegion;pub use portable::incremental::DirtyRegionTracker;pub use portable::incremental::Edit;pub use portable::incremental::IncrementalParser;pub use portable::incremental::IncrementalResult;pub use portable::infix::infix;pub use portable::infix::Assoc;pub use portable::infix::InfixBuilder;pub use portable::infix::Operator;pub use portable::infix::PrecedenceClimber;pub use portable::parser_dsl::any;pub use portable::parser_dsl::choice;pub use portable::parser_dsl::dynamic;pub use portable::parser_dsl::re;pub use portable::parser_dsl::ref_;pub use portable::parser_dsl::seq;pub use portable::parser_dsl::str;pub use portable::parser_dsl::Alternative2;pub use portable::parser_dsl::Alternative3;pub use portable::parser_dsl::Alternative4;pub use portable::parser_dsl::Alternative5;pub use portable::parser_dsl::GrammarBuilder;pub use portable::parser_dsl::Parslet;pub use portable::parser_dsl::ParsletExt;pub use portable::parser_dsl::Sequence2;pub use portable::parser_dsl::Sequence3;pub use portable::parser_dsl::Sequence4;pub use portable::parser_dsl::Sequence5;pub use portable::streaming::ChunkConfig;pub use portable::streaming::ChunkSource;pub use portable::streaming::StreamingError;pub use portable::streaming::StreamingParser;pub use portable::streaming::StreamingResult;pub use portable::transform::ast_to_value;pub use portable::transform::Transform;pub use portable::transform::Value;pub use portable::AstArena;pub use portable::AstNode;pub use portable::Grammar;pub use portable::ParseError;pub use portable::PortableParser;
Modules§
- derive
- Derive macro support for parsanol
- ffi
- FFI (Foreign Function Interface) module for Parsanol
- portable
- Portable core module for Parsanol
- prelude
- Prelude module for convenient imports
Macros§
- all
- Alias for
parsanol_all!- create a sequence of any length - grammar
- Macro for building grammars declaratively
- oneof
- Alias for
parsanol_oneof!- create a choice of any length - parsanol_
all - Create a sequence of parslets with dynamic boxing (ergonomic macro)
- parsanol_
oneof - Create a choice/alternative of parslets with dynamic boxing (ergonomic macro)
- pattern
- Declarative pattern matching macro for transforms
- precedence
- Declarative macro for defining infix expression grammars.