Compare commits

..

No commits in common. "4e813a7efd60ef0cb6dbece852e1fb43e8e7461c" and "5141cdadd99d6106c855b58d2e6e6576f56a6041" have entirely different histories.

6 changed files with 6 additions and 35 deletions

View File

@ -1,6 +1,6 @@
use std::marker::PhantomData; use std::marker::PhantomData;
use crate::{representation::Representation, ParseResult, Parser}; use crate::{ParseResult, Parser};
pub struct AnnotatedParser<P, I, O, E> pub struct AnnotatedParser<P, I, O, E>
where where
@ -8,7 +8,6 @@ where
{ {
inner: P, inner: P,
name: Option<String>, name: Option<String>,
repr: Option<Representation>,
phantom: PhantomData<(I, O, E)>, phantom: PhantomData<(I, O, E)>,
} }
@ -33,7 +32,6 @@ where
Self { Self {
inner, inner,
name: None, name: None,
repr: None,
phantom: PhantomData, phantom: PhantomData,
} }
} }
@ -44,11 +42,4 @@ where
..self ..self
} }
} }
pub fn with_repr(self, repr: Representation) -> Self {
Self {
repr: Some(repr),
..self
}
}
} }

View File

@ -5,7 +5,6 @@ mod combinators;
mod map; mod map;
mod parser; mod parser;
mod primitives; mod primitives;
mod representation;
mod sequence; mod sequence;
#[cfg(test)] #[cfg(test)]

View File

@ -28,12 +28,6 @@ pub trait ParserExtension<I, O, E>: Parser<I, O, E> {
fn then_ignore<O2, P: Parser<I, O2, E>>(self, next: P) -> impl Parser<I, O, E>; fn then_ignore<O2, P: Parser<I, O2, E>>(self, next: P) -> impl Parser<I, O, E>;
fn ignore_then<O2, P: Parser<I, O2, E>>(self, next: P) -> impl Parser<I, O2, E>; fn ignore_then<O2, P: Parser<I, O2, E>>(self, next: P) -> impl Parser<I, O2, E>;
fn surrounded_by<O2>(self, surrounding: impl Parser<I, O2, E>) -> impl Parser<I, O, E>; fn surrounded_by<O2>(self, surrounding: impl Parser<I, O2, E>) -> impl Parser<I, O, E>;
fn to_anno(self) -> AnnotatedParser<Self, I, O, E>
where
Self: Sized,
{
AnnotatedParser::new(self)
}
fn to_named(self, name: &str) -> AnnotatedParser<Self, I, O, E> fn to_named(self, name: &str) -> AnnotatedParser<Self, I, O, E>
where where
Self: Sized, Self: Sized,

View File

@ -1,11 +1,10 @@
use crate::{representation::Representation, ParseResult, Parser, ParserExtension}; use crate::{ParseResult, Parser};
pub fn literal<'a>(expected: &'static str) -> impl Parser<&'a str, &'a str, ()> { pub fn literal(expected: &'static str) -> impl Fn(&str) -> ParseResult<&str, &str, ()> {
let p = move |input: &'a str| match input.get(0..expected.len()) { move |input| match input.get(0..expected.len()) {
Some(next) if next == expected => Ok((next, &input[expected.len()..])), Some(next) if next == expected => Ok((next, &input[expected.len()..])),
_ => Err(((), input)), _ => Err(((), input)),
}; }
p.to_anno().with_repr(Representation::new())
} }
pub fn literal_char<'a>(expected: char) -> impl Parser<&'a str, char, ()> { pub fn literal_char<'a>(expected: char) -> impl Parser<&'a str, char, ()> {

View File

@ -1,12 +0,0 @@
#[derive(Debug)]
pub struct Representation {}
impl Representation {
pub fn show(&self) {
println!("Not done");
}
pub fn new() -> Self {
Self {}
}
}

View File

@ -4,7 +4,7 @@ use super::*;
#[test] #[test]
fn parsing() { fn parsing() {
let (parsed, rest) = literal("a").parse("a yolo").unwrap(); let (parsed, rest) = literal("a")("a yolo").unwrap();
assert_eq!(parsed, "a"); assert_eq!(parsed, "a");
assert_eq!(rest, " yolo"); assert_eq!(rest, " yolo");
} }