problem combining partially overlapping parsers with Alternative

Aperta
#333 4 commenti 1 reazione 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
35/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Ferma
Stack tecnologico
haskell
Ambito
cli

Direzione di ricerca

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.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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"
                )
Lingua principale
Haskell
Stelle
957
Fork
124
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di pcapriotti/optparse-applicative

Tutte le issue di pcapriotti/optparse-applicative

Issue simili

Altre issue su Haskell

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.