oneparse/
lib.rs

1#![allow(unused)]
2
3use std::{error::Error, fmt::Display};
4
5#[cfg(test)]
6mod tests;
7
8pub mod lexer;
9pub mod parser;
10pub mod position;
11
12/// lexes the `text` with the provided `Lexable` type
13pub fn lex<T: lexer::Lexable>(
14    text: String,
15) -> Result<Vec<position::Located<T>>, position::Located<T::Error>> {
16    lexer::Lexer::new(text).lex::<T>()
17}
18
19/// lexes and then parses the `text` with the provided `Lexable`, `Parsable` and `Error` types
20pub fn parse<T: lexer::Lexable, P: parser::Parsable<T>, E: Error>(
21    text: String,
22) -> Result<position::Located<P>, position::Located<E>>
23where
24    P::Error: Display + Into<E>,
25    T::Error: Display + Into<E>,
26{
27    let tokens = lex::<T>(text).map_err(|err| err.map(|err| err.into()))?;
28    let mut parser = parser::Parser::new(tokens);
29    P::parse(&mut parser).map_err(|err| err.map(|err| err.into()))
30}