caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Martin DeMello <martindemello@gmail.com>
To: Kenneth Adam Miller <kennethadammiller@gmail.com>
Cc: vkni@yandex.ru, caml users <caml-list@inria.fr>
Subject: Re: [Caml-list] cmdliner difficulties
Date: Sat, 28 Jul 2018 18:26:40 -0600	[thread overview]
Message-ID: <CAFrFfuHB=QNbLh-Ozs0NL8ZoZmK3LqguQqnD=-SHSsyzLr1cig@mail.gmail.com> (raw)
In-Reply-To: <CAK7rcp9zFOaPKNNCo1DP-88ao_p3NOdM=uKxpDdJMEzKoxQKPQ@mail.gmail.com>

[-- Attachment #1: Type: text/plain, Size: 4016 bytes --]

How about "lexing" them into a list of operation tokens, then using the
shunting-yard algorithm to parse them into an expression tree? that would
allow arbitrary recursive expressions and still be relatively
straightforward to process.

martin

On Sat, Jul 28, 2018 at 2:16 PM, Kenneth Adam Miller <
kennethadammiller@gmail.com> wrote:

> I understand other people have written those things before, and that it's
> probably not so challenging to someone else, and I'm not saying I can't or
> wouldn't write it, but I'm under deadline pressure, and I think it would
> not be looked up on well if I had something with anywhere near so many
> features or as much work to deliver since if they even exist. Since I have
> to demonstrate this, the first question they are going to ask is "you spent
> more than X minutes working on this when you could have been working on the
> minimum viable product!! Unhappy!!" So I'm not disregarding the input I've
> got, but I think that I can achieve a less robust working version with the
> same set of features in a simpler fashion.
>
> So, instead I think can get something very near to a full grammar, while
> still allowing the fundamental operations I want. Here's what I've got:
>
>
> type setop =
>   | Intersection
>   | Difference
>   | Union
> [@@deriving sexp]
>
> let list_setops = [
>     "Intersection", Intersection;
>     "Difference", Difference;
>     "Union", Union;
> ]
> let setops_doc = List.(to_string ~f:fst (list_setops))
> let setops =
>   let doc = "." in
>   Cmdliner.Arg.(
>     value & opt_all (some (pair ~sep:'=' string & pair (enum
> (list_setops)) & pair string string)) []
>     & info ["setop"] ~docv:setops_doc ~doc
>   )
>
>
> Instead of having an recursive variant instance in the type setop place to
> allow the grammar to be recursive, I will fold over the setops, and add
> each one to a map. For example, I might have:
>
> --setop Red=Union (Feature1, Feature2) --setop Green=Intersection (Red,
> Feature3)
>
> So that, as I fold, I will add colors to the feature set. Then, for
> whatever nested operations otherwise would have been required, I can just
> manually unfold them on the command line.
>
> I guess I've solved my problem, but I was hoping to get a recursive
> parsing capability on the command line that would have supporting a type
> declaration more like the following:
>
> type setop =
>   | Result of setop
>   | Intersection of string * string
>   | Difference of string * string
>   | Union of string * string
>
> The problem with this is, 1) the constructors are non-uniform so that
> there isn't a clean way to specify to the Cmdliner.Arg.value function what
> the converter should be 2) The list type of their resulting pairwise
> sub-command specifications to the command line (the "enum list_setops"
> part) becomes much harder to specify since those also need to be
> constructible in the string - type pairs for the list_setops argument to
> enum.
>
> I suppose my thinking about how to deal with this would be to write a
> custom conv to convert the command line input, but to do so it would have
> to be recursive, and the Cmdliner.Arg.enum would have to support both
> non-uniform constructors and an argument conv to be able to do this
> correctly.
>
> Does anybody have a better way to capture what I'm looking to do?
>
> On Sat, Jul 28, 2018 at 10:54 AM Андрей Бергман <vkni@yandex.ru> wrote:
>
>> Probably a parser combinator with a small language would be a better tool
>> for that. Parser generators look too heavy, and comman-line parsers are too
>> light (otherwise they become optparse-applicative, which is too specific to
>> study it => everyone uses cookbook).
>>
>

-- 
Caml-list mailing list.  Subscription management and archives:
https://sympa.inria.fr/sympa/arc/caml-list
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs

[-- Attachment #2: Type: text/html, Size: 4736 bytes --]

  reply	other threads:[~2018-07-29  0:26 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-07-27 18:10 Kenneth Adam Miller
2018-07-27 19:34 ` Gabriel Scherer
2018-07-28 17:54 ` Андрей Бергман
2018-07-28 20:16   ` Kenneth Adam Miller
2018-07-29  0:26     ` Martin DeMello [this message]
2018-07-29  6:33       ` Gabriel Scherer
2018-07-29  6:59         ` Viet Le

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAFrFfuHB=QNbLh-Ozs0NL8ZoZmK3LqguQqnD=-SHSsyzLr1cig@mail.gmail.com' \
    --to=martindemello@gmail.com \
    --cc=caml-list@inria.fr \
    --cc=kennethadammiller@gmail.com \
    --cc=vkni@yandex.ru \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).