Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

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

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);
```