problem combining partially overlapping parsers with Alternative
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 35/100
Research direction
Start by compiling and running the supplied Haskell program, then inspect Options.Applicative.Internal and the Alternative behavior for the two parser orderings. Done means both orderings handle ./foo a, ./foo --bar a b, and ./foo b --bar a without an incorrect Missing: --bar ARG failure.
Written by the indexing model from the issue text.
Description
The test program below prints this --help
Usage: foo ([--bar ARG] [string] | [string])
And "./foo --bar a b" works. However:
joey@darkstar:~>./foo a
Missing: --bar ARG
Seems that in bar <|> foo, the bar parser can fail in a way that makes it never try the
foo parser, which would succeed if it were tried.
If it's changed to foo <|> bar, the example above works, as does "./foo --bar a b" , so that version of the program works ok. Except, "./foo b --bar a" does not work; normally the bar
parser would accept that, but now the foo parser fails in a way that makes the bar parser not work.
import Options.Applicative
import Options.Applicative.Internal
data Foo = Foo [String] | Bar String String
deriving (Show)
parser :: Parser Foo
parser = bar <|> foo
where
foo = Foo <$> many (argument str ( metavar ""))
bar = Bar <$> strOption (long "bar") <*> argument str (metavar "dir")
main = print =<< execParser opts
where
opts = info (parser <**> helper)
( fullDesc
<> progDesc "testcase"
<> header "testcase"
)
- Dominant language
- Haskell
- Stars
- 957
- Forks
- 124
- PR merge metrics
- No merged PRs in 30d
Getting set up
This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from pcapriotti/optparse-applicative
-
Difficulty 1/5 Under an hour Newbie friendliness 75/100
-
Difficulty 4/5 3-5 days Newbie friendliness 42/100
pcapriotti/optparse-applicative#524 · 2 comments ·
-
Allow replacing commands with metavar when using parserOptionGroupPossibly taken @tbidne claimed this 86 days ago. Open
Difficulty 4/5 3-5 days Newbie friendliness 48/100
pcapriotti/optparse-applicative#523 · 1 comment · 1 reaction ·
-
Nushell CompletionsOpen
Difficulty 4/5 3-5 days Newbie friendliness 48/100
-
Difficulty 4/5 3-5 days Newbie friendliness 48/100
pcapriotti/optparse-applicative#513 · 4 comments ·
All issues in pcapriotti/optparse-applicative
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
IntersectMBO/cardano-ledger#6276 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
OpenZeppelin/canton-contracts#92 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
hasura/graphql-engine#10954 ·
Maintainers usually reply within 1 day