Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Able to create own parser with other types? #10

Open
pocket7878 opened this issue Mar 7, 2017 · 1 comment
Open

Able to create own parser with other types? #10

pocket7878 opened this issue Mar 7, 2017 · 1 comment

Comments

@pocket7878
Copy link

Hi! I love this library.
I want to use this to parse byte sequence [UInt8]. How can I extend?
I tried to extends like:

extension Parsec
where StreamType.Iterator.Element == UInt8, Result ==  Token {
    internal static func satisfy(
        _ predicate: @escaping (UInt8) -> Bool
        ) -> GenericParser<StreamType, UserState, Result> {
        
        return tokenPrimitive(
            tokenDescription: { String(reflecting: $0) },
            nextPosition: { position, elem in
                
                var pos = position
                pos.updatePosition(elem)
                
                return pos
                
        },
            match: { elem in
                
                predicate(elem) ? Token.seq([elem]) : nil
        })
    }
    
    static func oneOf(_ list: [UInt8]) -> GenericParser<StreamType, UserState, Result> {
    }
}

But I got an error with pos.updatePosition ..

@davedufresne
Copy link
Owner

Hi,

This is a feature I want to add when I'll have more time. Feel free to give it a try. One of the things that have to be done is to make updatePosition() more general. For now it only supports the Character type. It could be changed to support more types. Another possible solution would be to pass a custom function for each types that should be supported.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants