chasa
Parser combinators for the YuLang workspace.
TL;DR
use *;
// Parse "let x" and extract the identifier
let mut input = "let x";
let name = parse_ok_once.unwrap;
assert_eq!;
Key combinators:
tag("...")– match an exact stringws1/ws– match whitespace (one-or-more / zero-or-more)any– match any single characterright(q)– parse both, return right resultmany()– repeat zero or more timessep(s)– parse separated list
Most combinators are available as methods (via ParserOnce / ParserMut / Parser), and the
prelude imports those traits so you can write p.right(q) / p.many() / p.sep(...).
Showcase
This crate supports both combinator style and imperative style via In.
Example 1: S-expressions (combinator style)
use *;
let mut input = "(a (b c) d)";
let out = parse_ok_once.unwrap;
assert_eq!;
Example 2: key = value (imperative style)
use *;
let mut input = "port = 8080";
assert_eq!;
let mut input = "name = \"alice\"";
assert_eq!;
Quick API tour
Entry points:
parse_once(&mut input, parser)– run aParserOncewith a freshMergerparse_ok_once(&mut input, parser)– run aParserOnceand returnResult<T, Error>
Building blocks:
- Items:
any,item(c),one_of("abc"),none_of("xyz") - Tags:
tag("keyword") - Whitespace:
ws,ws1 - Sequencing:
then,right,left,between - Choice:
or,choice - Repetition:
many,many1,many_map - Separated lists:
sep,sep1,sep_map,sep_reduce - Lookahead:
lookahead,not - Control:
cut,maybe,label
Where to look next
prelude: start here for importsparser: combinators and traitsinput: input abstractions and streaming inputsparse: helpers likeparse_ok_once