Skip to content

Ensure complete parsing without SOI and EOI #827

Closed Answered by teiesti
teiesti asked this question in Q&A
Discussion options

You must be logged in to vote

Thanks for the answer. Unfortunately, the rules are overlapping. To solve the issue, I went the long way and implemented my own custom "parser extension".

use pest::{
    error::{Error, ErrorVariant},
    iterators::Pairs,
    Parser, Position, RuleType,
};

pub trait CompleteParser<R: RuleType>: Parser<R> {
    fn parse_complete(rule: R, input: &str) -> Result<Pairs<'_, R>, Error<R>> {
        Self::parse(rule, input).and_then(|pairs| {
            if pairs.as_str() == input {
                Ok(pairs)
            } else {
                Err(Error::new_from_pos(
                    ErrorVariant::CustomError {
                        message: String::from("expected EOI"),

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by tomtau
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants