Skip to content

How to read everything until a parser succeeds #1878

@PNys

Description

@PNys

Hi there,

I have been stuck with this issues for a few days now and I can't seem to figure it out on my own:

So basically the title, I want to ready everything until a parser succeeds. So essentially the terminated combinator. Here is a snippet:

let parser = make_parser(); // placeholder for brevity
let (input, text) = terminated(read_all, parser).parse(input)?;

My issues is the first argument of terminated read_all. I seem to have tried everything, but nothing works, either it stop too early and throws an error because the terminating parser is invalid or it just reads all the way through to the end and throws an error because it is eof.

The annoying part it seems is, that the text I am trying to read basically contains all types of characters and it can even contain parts of what the terminator parses. Is there a way to make terminated check the terminator before reading every character or a complete alternative to achieve this?

I think just realized the text could even exactly contain the terminator, but I need the very last one, is there a way to parse from the end of the input?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions