Features
- Parses
.larkgrammar files with full Lark compatibility - Import Resolution: Automatically resolves
%importstatements for common Lark modules - Generates efficient LALR(1) parsers in TypeScript
- Alternative Ordering: Respects the order of alternatives in grammar rules (first match wins)
- Automatic AST Flattening: Rules prefixed with
?are automatically inlined when they have one child - Token Filtering: Automatically removes literal tokens and operators from the AST
- Zero runtime dependencies
Supported Grammar Features
- Rules and terminals
- EBNF operators (
?,*,+) - Rule modifiers (
?,_,!) - Aliases for alternatives
- String and regex literals
- Priorities
- Ignored patterns
- Import statements (
%import common.CNAME, etc.)
Installation
Usage
Command Line
Global Installation
Import Resolution
The parser generator supports automatic import resolution for Lark’s standardcommon module:
Supported Common Module Terminals
| Terminal | Pattern | Description |
|---|---|---|
CNAME | /[a-zA-Z_][a-zA-Z0-9_]*/ | C-style identifiers |
DECIMAL | /[+-]?([0-9]+\.[0-9]*|\.[0-9]+)/ | Decimal numbers |
ESCAPED_STRING | /"(?:[^"\\]|\\.)* "/ | Quoted strings with escapes |
SIGNED_INT | /[+-]?[0-9]+/ | Signed integers |
NUMBER | /[0-9]+/ | Unsigned integers |
WORD | /[a-zA-Z]+/ | Word tokens |
WS | /[ \t\f\r\n]+/ | Whitespace |
WS_INLINE | /[ \t\f]+/ | Inline whitespace |
grammars/common.lark.
Project Structure
Key Features
Alternative Ordering
The parser correctly implements alternative precedence following Lark’s behavior. When multiple alternatives could match, the first alternative listed wins.["1", "2"]→string_array(notinteger_array)[1, 2]→integer_array(notdecimal_array)[1.5, 2.7]→decimal_array
Automatic AST Processing
The generated parser automatically handles:- Inline Rule Flattening: Rules with
?prefix are flattened when they have one child - Token Filtering: Literal tokens are removed from the final AST
- Alias Handling: Rules with aliases create appropriately named nodes
- Empty Production Handling: Zero-length productions are handled correctly
Lark Grammar Syntax
Rules
Terminals
EBNF Operators
| Operator | Meaning |
|---|---|
? | Optional (zero or one) |
* | Zero or more |
+ | One or more |
Rule Modifiers
| Prefix | Effect |
|---|---|
? | Inline rule (expand in parent) |
_ | Anonymous rule (hide from tree) |
! | Keep all tokens |
Aliases
Priorities
Ignored Patterns
Using Generated Parsers
Feature Support
✅ Fully Supported
- Rules and terminals
- EBNF operators (
?,*,+) - Groups and alternatives
- Rule modifiers (
?,_,!) - String literals and regex
- Terminal priorities
- Rule aliases
%ignoredirective- Basic imports
⚠️ Partially Supported
- Simple character ranges (
"a".."z") - Module imports (limited to predefined modules)
❌ Not Supported
- Template rules
- Advanced repetition (
item ~ 3,item ~ 2..5) %declare,%override,%extenddirectives- Multiple parsing algorithms (only LALR)
- Ambiguity handling
Testing
Development
Limitations
- Import resolution currently supports only the
commonmodule - No support for template rules (parameterized rules)
- No support for custom lexer callbacks
- Some advanced Lark features may not be fully implemented