Swiftlet - Text parsing library
Swiftlet is a high-performance text-parsing library for Rust, inspired by Python’s Lark.
It accepts a context-free grammar (CFG) as input and generates an efficient parser capable of analyzing and validating any text that conforms to the specified grammar. The parser constructs a well-structured Abstract Syntax Tree (AST), enabling further semantic analysis, transformation, or code generation.
Designed with Rust’s performance, and safety in mind, Swiftlet aims to provide a robust, extensible, and developer-friendly framework for building custom parsers, interpreters, and compilers with minimal boilerplate.
Features
- Earley parser, capable to parse any context free grammar (CFG).
- Use cache, to further optimize parsing.
- Canonical LR (CLR) parser is less powerful than an Earley parser, but it is fast and memory-efficient.
- EBNF base grammar
- Builds a parse-tree (AST) based on the grammar.
- Display each step of parser, when debug set true.
- Line and column tracking.
Example
use *;
use Arc;
Output
AST:
start
sub
add
sub
expr 10
-
2
+
5
-
2
Total: 11
For more examples, please check examples folder.
Grammar reference
Click here