Crate nom_tracable
source ·Expand description
nom-tracable
is an extension of nom to trace parser.
Examples
The following example show a quick example.
use nom::character::complete::*;
use nom::IResult;
use nom_locate::LocatedSpan;
use nom_tracable::{tracable_parser, TracableInfo};
// Input type must implement trait Tracable
// nom_locate::LocatedSpan<T, TracableInfo> implements it.
type Span<'a> = LocatedSpan<&'a str, TracableInfo>;
// Apply tracable_parser by custom attribute
#[tracable_parser]
pub fn term(s: Span) -> IResult<Span, String> {
let (s, x) = char('1')(s)?;
Ok((s, x.to_string()))
}
#[test]
fn test() {
// Configure trace setting
let info = TracableInfo::new().forward(true).backward(true);
let ret = term(LocatedSpan::new_extra("1", info));
assert_eq!("\"1\"", format!("{:?}", ret.unwrap().1));
}
Structs
- Struct to have trace configuration.
Traits
- Trait to indicate the type can display as fragment.
- Trait to indicate
TracableInfo
is provided. - Trait to indicate the type has information for tracing.
Functions
- Show cumulative histogram of parser call count.
- Show histogram of parser call count.
Attribute Macros
- Custom attribute to enable trace