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 ESMTPS id 685D35D4 for ; Sat, 28 Jul 2018 20:17:48 +0000 (UTC) X-IronPort-AV: E=Sophos;i="5.51,415,1526335200"; d="scan'208,217";a="340602262" Received: from sympa.inria.fr ([193.51.193.213]) by mail2-relais-roc.national.inria.fr with ESMTP; 28 Jul 2018 22:17:46 +0200 Received: by sympa.inria.fr (Postfix, from userid 20132) id 6C679824C0; Sat, 28 Jul 2018 22:17:46 +0200 (CEST) Received: from mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by sympa.inria.fr (Postfix) with ESMTPS id AEE4D824A0 for ; Sat, 28 Jul 2018 22:17:41 +0200 (CEST) Authentication-Results: mail2-smtp-roc.national.inria.fr; spf=None smtp.pra=kennethadammiller@gmail.com; spf=Pass smtp.mailfrom=kennethadammiller@gmail.com; spf=None smtp.helo=postmaster@mail-lf1-f54.google.com IronPort-PHdr: =?us-ascii?q?9a23=3AGLdlQRaKBCVuGSGUIJVs1oT/LSx+4OfEezUN459i?= =?us-ascii?q?sYplN5qZoMiybnLW6fgltlLVR4KTs6sC17KI9fi4EUU7or+5+EgYd5JNUxJXwe?= =?us-ascii?q?43pCcHRPC/NEvgMfTxZDY7FskRHHVs/nW8LFQHUJ2mPw6arXK99yMdFQviPgRp?= =?us-ascii?q?OOv1BpTSj8Oq3Oyu5pHfeQpFiCa8bL9oMBm6sRjau9ULj4dlNqs/0AbCrGFSe+?= =?us-ascii?q?RRy2NoJFaTkAj568yt4pNt8Dletuw4+cJYXqr0Y6o3TbpDDDQ7KG81/9HktQPC?= =?us-ascii?q?TQSU+HQRVHgdnwdSDAjE6BH6WYrxsjf/u+Fg1iSWIdH6QLYpUjmk8qxlSgLniD?= =?us-ascii?q?0fOjE2/mHYiMx+gqxYrhy8uRJw35XZb5uJOPdkZK7RYc8WSGhHU81MVyJBGIS8?= =?us-ascii?q?b44XAuQEI+lYqY/9qEUSrRu+GAKhGP7gxSVNhnTr2qM60uAhEQXY0ww6AtkDt3?= =?us-ascii?q?fUo8vzNKcUT++10KnIwi/eYPxM3Df97YnIchQlof6SR7J9asXRyUw1GAPEilWc?= =?us-ascii?q?s5DqPzSQ1ukUtWWQ8uluVfq3hmI5tw18piKjy8Qsh4XTm44Yy1LJ+T95zYs6I9?= =?us-ascii?q?CzVVR1bsS+EJRKsiGXL4t2Td0mQ2FvoCs6z6cJuZ+/fCQTzJQnyQPTZ+WJc4WI?= =?us-ascii?q?7R/vTumRITB/hHJqfLKwmQy+/lSnyu35TsW00VBKoTRZktTUqHwByxje5tKER/?= =?us-ascii?q?Z95EutxDeC2gLJ5uxELk04ja/bJIQgwr40mJoTq0PDHirulUX1kqCWcEMk9fa0?= =?us-ascii?q?6+TneLrpu4WTN4pxigH/NqQuntKwAf4jPwgBWmiU4+W81Ln58ULlR7VKi+U6kr?= =?us-ascii?q?PFv5DCOcQbuqm5DhdJ3Yk57ha/Cy6q0NAZnXkcMFJIYwmHjojsO1HWOv/0F/a/?= =?us-ascii?q?g1K2kDdq3f/KJLPhAo+eZkTExanie7dV+kdaxAcji8pCtLxODbRUA//1XELttJ?= =?us-ascii?q?TxAhY8eym1x+LqEp0p1Y4YX2+TAqaVOabXsFuM6/gHLOyFZYtTszH4fat2r8Xy?= =?us-ascii?q?hGM0zAdONZKi2oEaPSjhT6ZWZn6BaH+pue8vVGIDvw4wVuvv0QTQXjtaZnL0VK?= =?us-ascii?q?U5tGhiVNCWSLzbT4Xou4SvmT+hF8QPNG9DA1GIV3zvctfcAqpeWGepOsZk1wc8?= =?us-ascii?q?e/2hRosmj0z8sQb7z/9jILOR9HBE853k09dx6qvYkhRgrTE=3D?= X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: =?us-ascii?q?A0BnBwDOzlxbhjanVdFcHgEGDIMgUoE+K?= =?us-ascii?q?IN+gR2CUJBUgg2IT2iHBIcQC4RsAoJ7GQcBBDQUAQIBAQIBAQEBARMBAQEICws?= =?us-ascii?q?IGw4jDII1IoJgAQICASMdARsdAQMBCwYDAgs3AgIiAREBBQEcGYMggWcBAw0Ij?= =?us-ascii?q?nCQAjyLCYERBQEXgnUFg00KGSYNV4JLAgYSiHAXggCDJn6Hf4JVAogfhTmMOAm?= =?us-ascii?q?PN44JkigPIYE3gXMzGiNQMYI4ghkag06Kch8wjzMBAQ?= X-IPAS-Result: =?us-ascii?q?A0BnBwDOzlxbhjanVdFcHgEGDIMgUoE+KIN+gR2CUJBUgg2?= =?us-ascii?q?IT2iHBIcQC4RsAoJ7GQcBBDQUAQIBAQIBAQEBARMBAQEICwsIGw4jDII1IoJgA?= =?us-ascii?q?QICASMdARsdAQMBCwYDAgs3AgIiAREBBQEcGYMggWcBAw0IjnCQAjyLCYERBQE?= =?us-ascii?q?XgnUFg00KGSYNV4JLAgYSiHAXggCDJn6Hf4JVAogfhTmMOAmPN44JkigPIYE3g?= =?us-ascii?q?XMzGiNQMYI4ghkag06Kch8wjzMBAQ?= X-IronPort-AV: E=Sophos;i="5.51,415,1526335200"; d="scan'208,217";a="340602246" Received: from mail-lf1-f54.google.com ([209.85.167.54]) by mail2-smtp-roc.national.inria.fr with ESMTP/TLS/AES128-GCM-SHA256; 28 Jul 2018 22:17:37 +0200 Received: by mail-lf1-f54.google.com with SMTP id f18-v6so5686504lfc.2 for ; Sat, 28 Jul 2018 13:17:37 -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=EDrB4Bzyo21QqrqqyY0FjMKPx3uAh6QWNFpp/2uEw/Y=; b=BwR2VBHdRjWku46Og7n7+fCSKTksP/ELi3cZOUq80ffTRcq5JIMrOw2os9VBWVKC/U jp2HE13puJXU3w82/SBHUIqxbi90t3AdifDK69x5rHdkNLX4IdWrhfFjpo3dkeoqlpCc XqOFSouujNeTb3R93tKwLzgpjPiavbMRpsKEAWxCT5rRIj+LDXCLlqhw6cZNu+/sdHj1 WaRm4U7Q7O1LPD1Atte6EF/MrCDVz+2eXgHD5QENU+EljK0J89oX5jjU+eTNE/zdieX3 qpuyFIfK4AR0HhZ0ZA4UUH5dMCltfyZjuthqyHGLJjITUVj1XDFAJg0TLNtJIGdax5nF Zcfg== 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=EDrB4Bzyo21QqrqqyY0FjMKPx3uAh6QWNFpp/2uEw/Y=; b=WSjhrTl1MdnppvBpTPgumZ+GAw3OUaqMC/TEInkHHQ2Jnqx1xjNZ6jv+R7/gp+dI1T vOzESZFCrp/3xt9lzum7wXWbmHtVoqujyBTAfEq/bUmI2qPG5p+7IA7fd4tScL2HHPwL Ab9eoeCA+5VNNpGbJcCMfOSlSQ97ummKz+hRXSfQwx1I6E8m0d9/VGSpaxuaaM7qIlb0 IqcqGJ0jsmkHpuB1rdaJ9BDrihKS4aUBSNNjChfnof5XL/SkeZx8ZYMMKcWmfFDncqPr 8k6E6f+gAzffAuMjuyMigKDAzWQEGSFAlIbZ7ziGnAMknom/HU+ioS3MZJ5koWvPTax0 kyMg== X-Gm-Message-State: AOUpUlGTlL/BXuFyRm/6fezJ22jjkwYj2yWzcqLaGO5BQApdBnbkOIwM N6hEd/FRkQbVicnjZJ6aOyJ6R2P3azChHOm+nEvD20sx X-Google-Smtp-Source: AAOMgpcOIDj958y4EuTeqUoRd5FvXPLjfAAkmQ3LWWRnJe6pqjvvNNztt0MLZ2A3GbNWoWYUXbYzRLZyGZewChjyHp4= X-Received: by 2002:a19:cf95:: with SMTP id f143-v6mr7070859lfg.101.1532809056093; Sat, 28 Jul 2018 13:17:36 -0700 (PDT) MIME-Version: 1.0 References: <14267431532800443@iva1-3d0d937e850f.qloud-c.yandex.net> In-Reply-To: <14267431532800443@iva1-3d0d937e850f.qloud-c.yandex.net> From: Kenneth Adam Miller Date: Sat, 28 Jul 2018 13:16:44 -0700 Message-ID: To: vkni@yandex.ru Cc: caml users Content-Type: multipart/alternative; boundary="0000000000004c0a33057214eb48" Subject: Re: [Caml-list] cmdliner difficulties Reply-To: Kenneth Adam Miller X-Loop: caml-list@inria.fr X-Sequence: 17014 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: --0000000000004c0a33057214eb48 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable 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 t= oo > light (otherwise they become optparse-applicative, which is too specific = to > study it =3D> everyone uses cookbook). > --=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= --0000000000004c0a33057214eb48 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
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 deadli= ne pressure, and I think it would not be looked up on well if I had somethi= ng 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 whe= n you could have been working on the minimum viable product!! Unhappy!!&quo= t; So I'm not disregarding the input I've got, but I think that I c= an achieve a less robust working version with the same set of features in a= simpler fashion.

So, instead I think can get something very ne= ar to a full grammar, while still allowing the fundamental operations I wan= t. Here's what I've got:


type setop =3D<= /div>
=C2=A0 | Intersection
=C2=A0 | Difference
=C2= =A0 | Union
[@@deriving sexp]

let list_s= etops =3D [
=C2=A0 =C2=A0 "Intersection", Intersection;=
=C2=A0 =C2=A0 "Difference", Difference;
=C2= =A0 =C2=A0 "Union", Union;
]
let setops_doc = =3D List.(to_string ~f:fst (list_setops))
let setops =3D
=C2=A0 let doc =3D "." in
=C2=A0 Cmdliner.Arg.(<= /div>
=C2=A0 =C2=A0 value & opt_all (some (pair ~sep:'=3D' = string & pair (enum (list_setops)) & pair string string)) []
<= div>=C2=A0 =C2=A0 & info ["setop"] ~docv:setops_doc ~doc
=C2=A0 )


Instead of having an recursive= variant instance in the type setop place to allow the grammar to be recurs= ive, 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 color= s to the feature set. Then, for whatever nested operations otherwise would = have been required, I can just manually unfold them on the command line.=C2= =A0

I guess I've solved my problem, but I was hoping to get a re= cursive parsing capability on the command line that would have supporting a= type declaration more like the following:

type setop =3D
=
=C2=A0 | Result of setop
=C2=A0 | Intersection of string * s= tring
=C2=A0 | Difference of string * string
=C2=A0 | U= nion of string * string

The problem with this is, 1) the constructor= s are non-uniform so that there isn't a clean way to specify to the Cmd= liner.Arg.value function what the converter should be 2) The list type of t= heir resulting pairwise sub-command specifications to the command line (the= "enum list_setops" part) becomes much harder to specify since th= ose also need to be constructible in the string - type pairs for the list_s= etops argument to enum.=C2=A0

I suppose my t= hinking about how to deal with this would be to write a custom conv to conv= ert 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.

<= div>Does anybody have a better way to capture what I'm looking to do?= =C2=A0

On Sat, J= ul 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@y= andex.ru> wrote:
Probably a = parser combinator with a small language would be a better tool for that. Pa= rser generators look too heavy, and comman-line parsers are too light (othe= rwise they become optparse-applicative, which is too specific to study it = =3D> everyone uses cookbook).
--0000000000004c0a33057214eb48--