Overview
10/13/25About 1 min
The RCParsing library provides a rich set of rule types and token patterns to construct your grammar. Rules define the hierarchical structure of your parser, while tokens serve as the fundamental units for matching input and producing intermediate values. Below, we introduce the available rule types and token patterns to help you build powerful parsers.
Rule Types
Rules define the structure of your grammar and produce AST nodes. Learn about the different types of rules and how to use them:
- Sequence: Match child rules in order.
- Choice: Match one of several possible rules.
- Optional: Match a rule optionally without failing.
- Repeat: Match a rule multiple times within a range.
- SeparatedRepeat: Match a rule multiple times with separators.
- Lookahead: Ensure a rule does match/does not match ahead in the input.
Token Pattern Types
Tokens are the building blocks of parsing, consuming input and producing intermediate values. Explore the various token patterns:
Combination Primitives
- Sequence: Match child tokens in order.
- Choice: Match one of several possible tokens.
- Optional: Match a token optionally.
- Repeat: Match a token multiple times.
- SeparatedRepeat: Match a token multiple times with separators.
- Between: Match a sequence and propagate the middle token's value.
- First: Match a sequence and propagate the first token's value.
- Second: Match a sequence and propagate the second token's value.
- Map: Transform a token's intermediate value.
- Return: Return a fixed value for a token.
- CaptureText: Capture the matched text as the intermediate value.
- SkipWhitespaces: Skip whitespace before matching a token.
- Lookahead: Ensure a token does match/does not match ahead.
Matching Primitives
- EOF: Match the end of input.
- Empty: Always match nothing.
- Fail: Always fails.
- Literal: Match a specific string.
- LiteralChar: Match a specific character.
- LiteralChoice: Match one of several strings.
- Keyword: Match a string not followed by specific characters.
- KeywordChoice: Match one of several keywords.
- Number: Match and parse numeric values.
- Regex: Match a regular expression.
- EscapedText: Match text with escape sequences.
- TextUntil: Match text until specific sequences.
- Character: Match a single character based on a predicate.
- RepeatCharacters: Match multiple characters based on a predicate.
- Identifier: Match identifiers like variable names.
- Whitespaces: Match whitespace characters.
- Spaces: Match spaces and tabs.
- Newline: Match newline sequences.
- Custom Tokens: Create custom token patterns.