Skip to content

Parsing big Data blobs where all related bytes aren't sequential #23

Answered by ryanbooker
ryanbooker asked this question in Q&A
Discussion options

You must be logged in to vote

I found the following higher order parser useful for this big messy data blob. Parsing it linearly and then sorting out what's what was a huge pain, but being able to logically group things by repeatedly parsing out just the relevant bits seems to work quite well.

public extension Parser {
    /// Returns a parser that runs a parser without consuming the input.
    ///
    /// - Returns: A parser that runs the parser without consuming the input.
    @inlinable
    func nonConsuming() -> Parsers.NonConsuming<Self> {
        .init(self)
    }
}

public extension Parsers {
    /// A parser that runs a parser without consuming the input.
    struct NonConsuming<P>: Parser
    where P: Parser {

Replies: 3 comments 3 replies

Comment options

You must be logged in to vote
3 replies
@ryanbooker
Comment options

@stephencelis
Comment options

@ryanbooker
Comment options

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 ryanbooker
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