Compare commits
No commits in common. "4818b23c3b3f9c4de7db213e99d9769366674331" and "9ed860383ed6d19d4620e078b31f584a00c871ac" have entirely different histories.
4818b23c3b
...
9ed860383e
@ -8,7 +8,7 @@ where
|
||||
{
|
||||
inner: P,
|
||||
name: Option<String>,
|
||||
repr: Representation,
|
||||
repr: Option<Representation>,
|
||||
phantom: PhantomData<(I, O, E)>,
|
||||
}
|
||||
|
||||
@ -23,10 +23,6 @@ where
|
||||
fn name(&self) -> Option<String> {
|
||||
self.name.clone()
|
||||
}
|
||||
|
||||
fn representation(&self) -> Representation {
|
||||
self.repr.clone()
|
||||
}
|
||||
}
|
||||
|
||||
impl<P, I, O, E> AnnotatedParser<P, I, O, E>
|
||||
@ -37,7 +33,7 @@ where
|
||||
Self {
|
||||
inner,
|
||||
name: None,
|
||||
repr: Representation::new(),
|
||||
repr: None,
|
||||
phantom: PhantomData,
|
||||
}
|
||||
}
|
||||
@ -50,6 +46,9 @@ where
|
||||
}
|
||||
|
||||
pub fn with_repr(self, repr: Representation) -> Self {
|
||||
Self { repr, ..self }
|
||||
Self {
|
||||
repr: Some(repr),
|
||||
..self
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
use crate::{annotated::AnnotatedParser, map, representation::Representation, seq2, surrounded_by};
|
||||
use crate::{annotated::AnnotatedParser, map, seq2, surrounded_by};
|
||||
|
||||
pub type ParseResult<I, O, E> = Result<(O, I), (E, I)>;
|
||||
|
||||
@ -7,9 +7,6 @@ pub trait Parser<I, O, E> {
|
||||
fn name(&self) -> Option<String> {
|
||||
None
|
||||
}
|
||||
fn representation(&self) -> Representation {
|
||||
Representation::new()
|
||||
}
|
||||
}
|
||||
|
||||
impl<I, O, E, F> Parser<I, O, E> for F
|
||||
|
@ -1,25 +1,18 @@
|
||||
use crate::{
|
||||
representation::{Representation, EBNF},
|
||||
ParseResult, Parser, ParserExtension,
|
||||
};
|
||||
use crate::{representation::Representation, ParseResult, Parser, ParserExtension};
|
||||
|
||||
pub fn literal<'a>(expected: &'static str) -> impl Parser<&'a str, &'a str, ()> {
|
||||
let p = move |input: &'a str| match input.get(0..expected.len()) {
|
||||
Some(next) if next == expected => Ok((next, &input[expected.len()..])),
|
||||
_ => Err(((), input)),
|
||||
};
|
||||
let production = EBNF::StringTerminal(expected.into());
|
||||
p.to_anno()
|
||||
.with_repr(Representation::new().with_production(production))
|
||||
p.to_anno().with_repr(Representation::new())
|
||||
}
|
||||
|
||||
pub fn literal_char<'a>(expected: char) -> impl Parser<&'a str, char, ()> {
|
||||
(move |input: &'a str| match input.chars().next() {
|
||||
move |input: &'a str| match input.chars().next() {
|
||||
Some(ch) if ch == expected => Ok((expected, &input[ch.len_utf8()..])),
|
||||
_ => Err(((), input)),
|
||||
})
|
||||
.to_anno()
|
||||
.with_repr(Representation::new().with_production(EBNF::CharTerminal(expected)))
|
||||
}
|
||||
}
|
||||
|
||||
pub fn one_of<'a>(items: &'static str) -> impl Parser<&'a str, char, ()> {
|
||||
@ -71,8 +64,5 @@ mod tests {
|
||||
fn literals() {
|
||||
let parser = literal_char('f');
|
||||
assert_eq!(Ok(('f', "unky")), parser.parse("funky"));
|
||||
|
||||
let repr = parser.representation();
|
||||
assert!(matches!(repr.production(), EBNF::CharTerminal('f')));
|
||||
}
|
||||
}
|
||||
|
@ -2,7 +2,7 @@ use std::fmt;
|
||||
|
||||
use crate::util::intersperse_option;
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
#[derive(Debug)]
|
||||
pub struct Representation {
|
||||
production_output: EBNF,
|
||||
}
|
||||
@ -12,25 +12,18 @@ impl Representation {
|
||||
self.production_output.to_string()
|
||||
}
|
||||
|
||||
pub fn production(&self) -> EBNF {
|
||||
self.production_output.clone()
|
||||
}
|
||||
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
production_output: EBNF::None,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn with_production(self, production_output: EBNF) -> Self {
|
||||
Self {
|
||||
production_output,
|
||||
..self
|
||||
}
|
||||
pub fn with_production(production_output: EBNF) -> Self {
|
||||
Self { production_output }
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
#[derive(Debug)]
|
||||
pub enum EBNF {
|
||||
None,
|
||||
Nonterminal(String),
|
||||
|
Loading…
Reference in New Issue
Block a user