Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/gsingh93/regex-parser
A recursive descent parser for basic regular expressions in Rust
https://github.com/gsingh93/regex-parser
Last synced: 8 days ago
JSON representation
A recursive descent parser for basic regular expressions in Rust
- Host: GitHub
- URL: https://github.com/gsingh93/regex-parser
- Owner: gsingh93
- Created: 2015-03-11T18:57:57.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2015-03-19T23:02:57.000Z (over 9 years ago)
- Last Synced: 2024-10-31T11:39:37.585Z (15 days ago)
- Language: Rust
- Size: 145 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Regex Parser
This is a recursive descent parser written in Rust for regular expresssions. Given a regular expression as input, it outputs an AST. It follows this very simple LL(1) grammar:```
::= '|'
|::= { }
::= { '*' }
::=
| '(' ')'
```## Usage
```
let mut p = RegExParser::new("((a|b*)|a*)|aab".to_string());
let res = Ok(Or(
Box::new(Sequence(vec![Box::new(Or(
Box::new(Sequence(
vec![Box::new(Or(Box::new(Sequence(vec![Box::new(Terminal('a'))])),
Box::new(Sequence(
vec![Box::new(Repetition(Box::new(Terminal('b'))))]))))])),
Box::new(Sequence(vec![Box::new(Repetition(Box::new(Terminal('a'))))]))))])),
Box::new(Sequence(vec![Box::new(Terminal('a')), Box::new(Terminal('a')),
Box::new(Terminal('b'))]))));
assert_eq!(p.parse(), res);
```