combining parsers with overlapping flags

オープン
#85 コメント 5 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
5/5
見積もり時間
1週間以上
初心者へのやさしさ
25/100
issue の種類
機能追加
明瞭さ
おおむね明確
活発さ
停滞
技術スタック
haskell
領域
cli

調査の方向性

Start by tracing the parser representation around OptP, MultP, AltP, and BindP, then examine how OptName values are collected during parser combination. Compare the requested behavior with the uu-options delimiter approach and determine how overlapping flags should be reported or renamed. Done means combined parsers provide useful help for conflicts without requiring prefixes when no conflict exists.

索引モデルが issue の本文から書いたものです。

説明

enhancement

Could optparse-applicative provide more help when combining parsers that have the same flag names. For example:

mapOptName  :: (OptName -> OptName) -> Parser a -> Parser a
mapOptName f (OptP x) = OptP (mapOption x)
  where
    mapOption :: Option a -> Option a
    mapOption (Option r p) = Option (mapReader r) p

    mapReader :: OptReader a -> OptReader a
    mapReader (OptReader n x y) = OptReader (map f n) x y
    mapReader (FlagReader n a) = FlagReader (map f n) a
    mapReader x = x
mapOptName f (MultP x y) = MultP (mapOptName f x) (mapOptName f y)
mapOptName f (AltP x y) = AltP (mapOptName f x) (mapOptName f y)
mapOptName f (BindP x y) = BindP (mapOptName f x) (mapOptName f . y)
mapOptName f x = x

addPrefix p (OptShort c) = OptLong (p ++ "-" ++ [c])
addPrefix p (OptLong c) = OptLong (p ++ "-" ++ c)

Lets me write something like:

step :: Parser Step
step = ...

steps :: Parser (Step, Step)
steps = (,) <$> mapOptName (addPrefix "step1") step
   <*> mapOptName (addPrefix "step2") step

steps accepts arguments like --step1-x --step2-x if step accepts -x. Ideally the prefix could be left out when there is no conflict, but I think BindP gets in the way of defining a renameOptNames :: ([OptName] -> [OptName]) -> Parser a -> Parser a that sees all OptName at once.

uu-options supports +blah -blah delimiters. See section 5.2 of their techreport

主要言語
Haskell
スター
957
フォーク
124
PR マージ指標
30日以内にマージされた PR はありません

環境構築

このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

pcapriotti/optparse-applicative のほかの issue

pcapriotti/optparse-applicative の issue をすべて見る

似ている issue

Haskell の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。