pub struct RuleBuilder { /* private fields */ }Expand description
Builder for parser rules
Implementations§
Source§impl RuleBuilder
impl RuleBuilder
pub fn new(name: &str) -> Self
Sourcepub fn parse(&self, rule_name: &str) -> Combinator
pub fn parse(&self, rule_name: &str) -> Combinator
Reference another rule by name
Sourcepub fn lit(&self, s: &str) -> Combinator
pub fn lit(&self, s: &str) -> Combinator
Match a literal string exactly (e.g., “if”, “===”, “+”)
Sourcepub fn char(&self, c: char) -> Combinator
pub fn char(&self, c: char) -> Combinator
Match a single specific character
Sourcepub fn digit(&self) -> Combinator
pub fn digit(&self) -> Combinator
Match any decimal digit (0-9)
Sourcepub fn hex_digit(&self) -> Combinator
pub fn hex_digit(&self) -> Combinator
Match any hexadecimal digit (0-9, a-f, A-F)
Sourcepub fn alpha(&self) -> Combinator
pub fn alpha(&self) -> Combinator
Match any alphabetic character (a-z, A-Z)
Sourcepub fn alpha_num(&self) -> Combinator
pub fn alpha_num(&self) -> Combinator
Match any alphanumeric character (a-z, A-Z, 0-9)
Sourcepub fn ws(&self) -> Combinator
pub fn ws(&self) -> Combinator
Match any whitespace character (space, tab, newline, etc.)
Sourcepub fn ident_start(&self) -> Combinator
pub fn ident_start(&self) -> Combinator
Match identifier start character (a-z, A-Z, _, $)
Sourcepub fn ident_cont(&self) -> Combinator
pub fn ident_cont(&self) -> Combinator
Match identifier continue character (a-z, A-Z, 0-9, _, $)
Sourcepub fn any_char(&self) -> Combinator
pub fn any_char(&self) -> Combinator
Match any single character
Sourcepub fn range(&self, from: char, to: char) -> Combinator
pub fn range(&self, from: char, to: char) -> Combinator
Match a character in the given range (inclusive)
Sourcepub fn not_followed_by(&self, inner: Combinator) -> Combinator
pub fn not_followed_by(&self, inner: Combinator) -> Combinator
Negative lookahead: succeed if inner does NOT match, consume nothing
Sourcepub fn followed_by(&self, inner: Combinator) -> Combinator
pub fn followed_by(&self, inner: Combinator) -> Combinator
Positive lookahead: succeed if inner matches, consume nothing
Sourcepub fn capture(&self, inner: Combinator) -> Combinator
pub fn capture(&self, inner: Combinator) -> Combinator
Capture the matched text as a string token
Sourcepub fn memoize(&self, id: usize, inner: Combinator) -> Combinator
pub fn memoize(&self, id: usize, inner: Combinator) -> Combinator
Memoize the result of parsing to avoid exponential backtracking.
When a memoized combinator is tried at a position, the result is cached. If the same combinator is tried again at the same position (due to backtracking), the cached result is returned instead of re-parsing.
Use this for rules that:
- Appear in multiple Choice alternatives
- Contain recursion
- Are frequently backtracked
The id parameter must be unique across all memoization points.
Sourcepub fn sequence<T: IntoCombinatorsVec>(&self, items: T) -> Combinator
pub fn sequence<T: IntoCombinatorsVec>(&self, items: T) -> Combinator
Sequence of combinators
Sourcepub fn choice<T: IntoCombinatorsVec>(&self, items: T) -> Combinator
pub fn choice<T: IntoCombinatorsVec>(&self, items: T) -> Combinator
Ordered choice (first match wins, auto-backtrack)
Sourcepub fn zero_or_more(&self, inner: Combinator) -> Combinator
pub fn zero_or_more(&self, inner: Combinator) -> Combinator
Zero or more
Sourcepub fn one_or_more(&self, inner: Combinator) -> Combinator
pub fn one_or_more(&self, inner: Combinator) -> Combinator
One or more
Sourcepub fn optional(&self, inner: Combinator) -> Combinator
pub fn optional(&self, inner: Combinator) -> Combinator
Optional (zero or one)
Sourcepub fn skip(&self, inner: Combinator) -> Combinator
pub fn skip(&self, inner: Combinator) -> Combinator
Parse but discard result
Sourcepub fn separated_by(
&self,
item: Combinator,
separator: Combinator,
) -> Combinator
pub fn separated_by( &self, item: Combinator, separator: Combinator, ) -> Combinator
Separated list: item (sep item)*
Sourcepub fn separated_by_trailing(
&self,
item: Combinator,
separator: Combinator,
) -> Combinator
pub fn separated_by_trailing( &self, item: Combinator, separator: Combinator, ) -> Combinator
Separated list with optional trailing separator
Sourcepub fn pratt<F>(&self, operand: Combinator, f: F) -> Combinator
pub fn pratt<F>(&self, operand: Combinator, f: F) -> Combinator
Pratt expression parsing