gramex
grammer expressions, a common language for advance parsers.
gramex is a library and a simple language for building parsers, tokenizers and other forms of grammer based transformers.
it simplify parsing by transforming a simple yet expressive grammer declerations into efficient reusable matcher functions.
features
- type agnostic matching: parse
str, byte slices[u8], or custom token streams. - zero cost abstractions: grammers compile down to highly optimized, near metal matcher functions.
- rich grammar syntax: native support for
repetitions, alternations|, intersections&, ranges.., lookahead peeks~, and negations!. - powerful capturing & mapping: extract sections, nested or enumerated, and map them into custom types.
- extensible throught code: just drop your custom matcher inside
{}block. - term based grammer defenition thought
gramex, or inlined expression matching throughmatches] andtry_match - batteries included: comes with various built-in helpers and standard patterns.
quick guide
// quick matching can be done using `matches` macro
// matches agianst items by literals, path or blocks
assert!;
let pat = "abc";
assert!;
assert!;
// patterns are separated by whitespace
assert!;
// `?`: optional, `*`: +0 repetition, `+`: +1 repetition
// `[count]`: exact repetition, `[min..max]`: ranged repetition
assert!;
// `!`: matches one item if pattern doesnt match
// `~`: matches a pattern without advancing
assert!;
// `_`: matches any, `..` range match
assert!;
// `|`: match any of the pattern
// `&`: match if all patterns matches
assert!;
assert!;
// `cond -> expr` matches `expr` if `cond` matches
assert!;
// capture are done using `(name = pattern)`
assert!;