Skip to content
This repository has been archived by the owner on Apr 26, 2021. It is now read-only.

Ambiguous fallbacks not resolved across groups #22

Closed
felixSchl opened this issue Apr 29, 2016 · 0 comments
Closed

Ambiguous fallbacks not resolved across groups #22

felixSchl opened this issue Apr 29, 2016 · 0 comments
Labels

Comments

@felixSchl
Copy link
Owner

felixSchl commented Apr 29, 2016

Failing test case

r"""
Usage: foo
  or: foo (--input=FILE)
Options: --input [env: INPUT]
"""

$ INPUT=bar prog
{"--input": "bar"}

Fails with: Unexpected output: - empty - (incorrectly matches first usage branch, rather than second)

This is because fallback scores are only kept for one group parse and then discarded, they must somehow be propagated until they reach a terminal group parse.

This should be a fairly easy fix in

genParser x@(D.Group optional bs repeated) canSkip = do
vs <- concat <$>
let mod = if optional then P.try >>> P.option mempty else \p -> p
parser = if repeated then goR else singleton <$> go
in mod parser
return $ score 0 vs
where
goR :: Parser (List (List ValueMapping))
goR = do
{score, result} <- unScoredResult
<$> genBranchesParser bs
false
optsFirst
-- always allow skipping for non-free groups.
(not (D.isFree x) || canSkip)
if (length (snd result) == 0)
then return $ singleton (snd result)
else do
xs <- goR <|> pure Nil
return $ (snd result) : xs
go :: Parser (List ValueMapping)
go = if length bs == 0
then return mempty
else do
snd <<< _.result <<< unScoredResult
<$> genBranchesParser bs
false
optsFirst
-- always allow skipping for
-- non-free groups.
(not (D.isFree x) || canSkip)
.

goR must somehow fold <> and go must return the full result ({ score, result }).

@felixSchl felixSchl added the bug label Apr 29, 2016
@felixSchl felixSchl changed the title Ambigous fallbacks not resolved across groups Ambiguous fallbacks not resolved across groups Apr 29, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

1 participant