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

Add function sepBy1Cont #103

Open
lamg opened this issue Sep 24, 2023 · 0 comments
Open

Add function sepBy1Cont #103

lamg opened this issue Sep 24, 2023 · 0 comments

Comments

@lamg
Copy link

lamg commented Sep 24, 2023

I found a case where it might be useful to add a parser combinator which returns two things:

  • a value built with what is meant to recognize
  • a parser or a value useful for continuing parsing after that string

This can happen when you have a clause in SQL like SELECT column0, … column_N (FROM | ORDER BY), where you might have a function for parsing the column list, and then different functions for parsing what comes after FROM or ORDER BY.

I explain that situation with more detail here

sepBy1Cont could be used the following way

type Either<'a, 'b> =
    | Left of 'a
    | Right of 'b

let sepCont =
    parse {
        do! symbol S.Comma
        return Left ()
    }
    <|> parse {
        do! keyword K.From
        return Right From
    }
    <|> parse {
        do! keyword K.Order
        do! keyword K.By
        return Right OrderBy
    }

let! xs, next = sepBy1Cont identifier sepCont
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

1 participant