From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by c5ff346549e7 (Postfix) with ESMTP id 377A65D4 for ; Sun, 29 Jul 2018 07:00:18 +0000 (UTC) X-IronPort-AV: E=Sophos;i="5.51,417,1526335200"; d="scan'208,217";a="340627151" Received: from sympa.inria.fr ([193.51.193.213]) by mail2-relais-roc.national.inria.fr with ESMTP; 29 Jul 2018 09:00:14 +0200 Received: by sympa.inria.fr (Postfix, from userid 20132) id 22806824BF; Sun, 29 Jul 2018 09:00:14 +0200 (CEST) Received: from mail3-relais-sop.national.inria.fr (mail3-relais-sop.national.inria.fr [192.134.164.104]) by sympa.inria.fr (Postfix) with ESMTPS id 7372282486 for ; Sun, 29 Jul 2018 09:00:07 +0200 (CEST) Authentication-Results: mail3-smtp-sop.national.inria.fr; spf=None smtp.pra=vietlq85@gmail.com; spf=Pass smtp.mailfrom=vietlq85@gmail.com; spf=None smtp.helo=postmaster@mail-ua0-f181.google.com IronPort-PHdr: =?us-ascii?q?9a23=3AY+yI8BXf72Sd98RgVRXoXh56L9TV8LGtZVwlr6E/?= =?us-ascii?q?grcLSJyIuqrYbBGPt8tkgFKBZ4jH8fUM07OQ7/i+HzRYqb+681k6OKRWUBEEjc?= =?us-ascii?q?hE1ycBO+WiTXPBEfjxciYhF95DXlI2t1uyMExSBdqsLwaK+i764jEdAAjwOhRo?= =?us-ascii?q?LerpBIHSk9631+ev8JHPfglEnjWwba9zIRmssQndqtQdjJd/JKo21hbHuGZDdf?= =?us-ascii?q?5MxWNvK1KTnhL86dm18ZV+7SleuO8v+tBZX6nicKs2UbJXDDI9M2Ao/8LrrgXM?= =?us-ascii?q?TRGO5nQHTGoblAdDDhXf4xH7WpfxtTb6tvZ41SKHM8D6Uaw4VDK/5KpwVhTmlD?= =?us-ascii?q?kIOCI48GHPi8x/kqRboA66pxdix4LYeZyZOOZicq/Ye94VQndPXttKVyxZHIyz?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1lEtDntSjtmiqnB7hPye6ODZ0wt7/Vhz3/fpYkjXnB06?= =?us-ascii?q?Ylgh8tRc4dbWA=3D?= X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: =?us-ascii?q?A0DPCABBZV1bhrXZVdFcHAEBAQQBAQoBA?= =?us-ascii?q?YMggRF/FRODfmI7glCQVIINAoJWhVqPGQsjhEkCgnsZBwEENBQBAgEBAgEBAQE?= =?us-ascii?q?BEwEBAQgLCwgbDiMMgjUkgl0BAQEBAgEjHQEbEgsBAwELBgMCCw0NHQICIQEBE?= =?us-ascii?q?QEFAQoSBhMICoMOAYFmAQMNCA+PJZACPIsJgREFAReCdQWDTQoZJgMKV1CBewI?= =?us-ascii?q?GEohwgheDJn6CVjoLAoIOglSCVQKBJQEBhRwIgVSRRioBBgIBgTMEhGCGFIMMg?= =?us-ascii?q?g2LfIpQU4I8hEkPIYEQJ4FzcFAxbIFMCYIQGoNOgT6JFT4wj10BAQ?= X-IPAS-Result: =?us-ascii?q?A0DPCABBZV1bhrXZVdFcHAEBAQQBAQoBAYMggRF/FRODfmI?= =?us-ascii?q?7glCQVIINAoJWhVqPGQsjhEkCgnsZBwEENBQBAgEBAgEBAQEBEwEBAQgLCwgbD?= =?us-ascii?q?iMMgjUkgl0BAQEBAgEjHQEbEgsBAwELBgMCCw0NHQICIQEBEQEFAQoSBhMICoM?= =?us-ascii?q?OAYFmAQMNCA+PJZACPIsJgREFAReCdQWDTQoZJgMKV1CBewIGEohwgheDJn6CV?= =?us-ascii?q?joLAoIOglSCVQKBJQEBhRwIgVSRRioBBgIBgTMEhGCGFIMMgg2LfIpQU4I8hEk?= =?us-ascii?q?PIYEQJ4FzcFAxbIFMCYIQGoNOgT6JFT4wj10BAQ?= X-IronPort-AV: E=Sophos;i="5.51,417,1526335200"; d="scan'208,217";a="274349524" Received: from mail-ua0-f181.google.com ([209.85.217.181]) by mail3-smtp-sop.national.inria.fr with ESMTP/TLS/AES128-GCM-SHA256; 29 Jul 2018 09:00:05 +0200 Received: by mail-ua0-f181.google.com with SMTP id u11-v6so1205765uan.13 for ; Sun, 29 Jul 2018 00:00:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=RYdb7k7shCjNj8bdkAJnoCN8VSjmjPlGKPsDOczO1KA=; b=FHDOJu5jn0mH9tJXJRugA3UJaawKgc19Mpe77UxmaBuGgnRbRg9tiUJZPWBY9PmHNZ 8Dd/xoKCjLpDcsJoh4F4avl1t8XqDuNh4b6ntGmeKwMn5uwu9sCp3L7PtD+UlW++SBEQ pDltgXtBwNoGxW2eywtx3/rOW3qlRcgzR2A15A48EPlrjBAcKtPTf2ahygk46DoJwyZT 5ERT/7COZBJNZN0Ovvam+VBS/1Eft45g4zl3MLWSN9OQNz8WaFebtTjMKSc14eE2vrYb AMJwJa5/NAKZMTChQ+W6d276xQDVuhagAbbgGiGvz3RCHujfoIj1xBZfdfXTFfZWd0op D6ow== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=RYdb7k7shCjNj8bdkAJnoCN8VSjmjPlGKPsDOczO1KA=; b=YaZ9MHQB0hhwhdfN2tUEU+iO6dckAbM9vJc/dewHyeHu/0X4isy27O9+icUt8AyItm eiDL2cdz5O5YRawaNWDxV2ho2ZDXOdGA8E3dSlOuGwRtdc1Ik1SgRoTuSGYlndPIGH4i K2GBYEukMvucV0uTqcGZnZipWSigye/4ZmGzzptMEXfT33y5cxf1E245HgfwLCJQyhi4 FR45Ec6HDSbTG0IRFXpkzkfd8U6eIE1DnGw3Pnq7Hb7CGwNIcPsRxd+/v870T5UwVMWW u9nEOepx5jJvhsugkIPM72vXaFdfVM9KE/LUvceBQw2UvFa9ehXwgxzq84ju+V26u3SJ rQ3Q== X-Gm-Message-State: AOUpUlGJxrA8BjtKmBik5WcHO/q7VHMkru3CFVIKjxWKJW/xeYz/bBmy hqNA35Yz2QTNCz0R05HT6/0zM79+46s6Ex+wMuQ= X-Google-Smtp-Source: AAOMgpdXiHqjNggAp9DH1h4anvzWcQIYkpXSTQU1EkK9gzCb6x8UxpOw8JvVFMtwQ/UMDQR1srZIX49FM2+TxqtFWaE= X-Received: by 2002:ab0:1e07:: with SMTP id m7-v6mr9010433uak.146.1532847604059; Sun, 29 Jul 2018 00:00:04 -0700 (PDT) MIME-Version: 1.0 References: <14267431532800443@iva1-3d0d937e850f.qloud-c.yandex.net> In-Reply-To: From: Viet Le Date: Sun, 29 Jul 2018 07:59:52 +0100 Message-ID: To: Gabriel Scherer Cc: Kenneth Adam Miller , Martin DeMello , caml users , vkni@yandex.ru Content-Type: multipart/alternative; boundary="000000000000ef55d405721de437" Subject: Re: [Caml-list] cmdliner difficulties Reply-To: Viet Le X-Loop: caml-list@inria.fr X-Sequence: 17018 Errors-to: caml-list-owner@inria.fr Precedence: list Precedence: bulk Sender: caml-list-request@inria.fr X-no-archive: yes List-Id: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: --000000000000ef55d405721de437 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable You can wrap docopt C++ and use it: https://github.com/docopt Watch their short video (Python) for inspiration. Best cmd line parser ever On Sun, 29 Jul 2018 at 07:26, Gabriel Scherer wrote: > Just in case, Menhir has "demos", small examples of lexer+parser pairs > and an environment setup (example caller code, build script...). The > simplest demo is "calc" > > https://gitlab.inria.fr/fpottier/menhir/tree/master/demos/calc > > a syntax for arithmetic expressions such as "(1 + 3) * 5 + 2". > > It should be fairly easy to get a syntax for set operators by > replacing "*" with "Intersection" and "+" with "Union" in the Lexer, > and integer literals by feature names. > On Sun, Jul 29, 2018 at 2:27 AM Martin DeMello > wrote: > > > > 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 =3D > >> | Intersection > >> | Difference > >> | Union > >> [@@deriving sexp] > >> > >> let list_setops =3D [ > >> "Intersection", Intersection; > >> "Difference", Difference; > >> "Union", Union; > >> ] > >> let setops_doc =3D List.(to_string ~f:fst (list_setops)) > >> let setops =3D > >> let doc =3D "." in > >> Cmdliner.Arg.( > >> value & opt_all (some (pair ~sep:'=3D' 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=3DUnion (Feature1, Feature2) --setop Green=3DIntersection = (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 =3D > >> | 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 =D0=90=D0=BD=D0=B4=D1=80=D0=B5=D0=B9 = =D0=91=D0=B5=D1=80=D0=B3=D0=BC=D0=B0=D0=BD 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 =3D> 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 --=20 Kind regards, Viet --=20 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= --000000000000ef55d405721de437 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
You can wrap docopt C++ and use it:

Wat= ch their short video (Python) for inspiration. Best cmd line parser ever

On Sun, 29 Jul 2018= at 07:26, Gabriel Scherer <gabriel.scherer@gmail.com> wrote:
Just in case, Menhir has "demos", small examples of lexer+= parser pairs
and an environment setup (example caller code, build script...). The
simplest demo is "calc"

=C2=A0 https://gitlab.inria.fr/fpottie= r/menhir/tree/master/demos/calc

a syntax for arithmetic expressions such as "(1 + 3) * 5 + 2".

It should be fairly easy to get a syntax for set operators by
replacing "*" with "Intersection" and "+" wit= h "Union" in the Lexer,
and integer literals by feature names.
On Sun, Jul 29, 2018 at 2:27 AM Martin DeMello <martindemello@gmail.com> wrote:=
>
> How about "lexing" them into a list of operation tokens, the= n using the shunting-yard algorithm to parse them into an expression tree? = that would allow arbitrary recursive expressions and still be relatively st= raightforward 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 th= at it's probably not so challenging to someone else, and I'm not sa= ying I can't or wouldn't write it, but I'm under deadline press= ure, 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 eve= n exist. Since I have to demonstrate this, the first question they are goin= g to ask is "you spent more than X minutes working on this when you co= uld have been working on the minimum viable product!! Unhappy!!" So I&= #39;m not disregarding the input I've got, but I think that I can achie= ve 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&= #39;ve got:
>>
>>
>> type setop =3D
>>=C2=A0 =C2=A0| Intersection
>>=C2=A0 =C2=A0| Difference
>>=C2=A0 =C2=A0| Union
>> [@@deriving sexp]
>>
>> let list_setops =3D [
>>=C2=A0 =C2=A0 =C2=A0"Intersection", Intersection;
>>=C2=A0 =C2=A0 =C2=A0"Difference", Difference;
>>=C2=A0 =C2=A0 =C2=A0"Union", Union;
>> ]
>> let setops_doc =3D List.(to_string ~f:fst (list_setops))
>> let setops =3D
>>=C2=A0 =C2=A0let doc =3D "." in
>>=C2=A0 =C2=A0Cmdliner.Arg.(
>>=C2=A0 =C2=A0 =C2=A0value & opt_all (some (pair ~sep:'=3D&#= 39; string & pair (enum (list_setops)) & pair string string)) []
>>=C2=A0 =C2=A0 =C2=A0& info ["setop"] ~docv:setops_doc= ~doc
>>=C2=A0 =C2=A0)
>>
>>
>> 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, an= d add each one to a map. For example, I might have:
>>
>> --setop Red=3DUnion (Feature1, Feature2) --setop Green=3DIntersect= ion (Red, Feature3)
>>
>> So that, as I fold, I will add colors to the feature set. Then, fo= r 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 recu= rsive parsing capability on the command line that would have supporting a t= ype declaration more like the following:
>>
>> type setop =3D
>>=C2=A0 =C2=A0| Result of setop
>>=C2=A0 =C2=A0| Intersection of string * string
>>=C2=A0 =C2=A0| Difference of string * string
>>=C2=A0 =C2=A0| Union of string * string
>>
>> The problem with this is, 1) the constructors are non-uniform so t= hat there isn't a clean way to specify to the Cmdliner.Arg.value functi= on what the converter should be 2) The list type of their resulting pairwis= e sub-command specifications to the command line (the "enum list_setop= s" part) becomes much harder to specify since those also need to be co= nstructible 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 writ= e a custom conv to convert the command line input, but to do so it would ha= ve to be recursive, and the Cmdliner.Arg.enum would have to support both no= n-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 =D0=90=D0=BD=D0=B4=D1=80=D0=B5=D0= =B9 =D0=91=D0=B5=D1=80=D0=B3=D0=BC=D0=B0=D0=BD <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 par= sers are too light (otherwise they become optparse-applicative, which is to= o specific to study it =3D> everyone uses cookbook).
>
>

--
Caml-list mailing list.=C2=A0 Subscription management and archives:
https://sympa.inria.fr/sympa/arc/caml-list
Beginner's list: http://groups.yahoo.com/group/ocam= l_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs
--
Kind regards,
Viet=
--000000000000ef55d405721de437--