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 0561B5D4 for ; Sun, 29 Jul 2018 06:25:16 +0000 (UTC) X-IronPort-AV: E=Sophos;i="5.51,417,1526335200"; d="scan'208";a="340619965" Received: from sympa.inria.fr ([193.51.193.213]) by mail2-relais-roc.national.inria.fr with ESMTP; 29 Jul 2018 08:25:14 +0200 Received: by sympa.inria.fr (Postfix, from userid 20132) id 6EAB6824BF; Sun, 29 Jul 2018 08:25:14 +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 253E782486 for ; Sun, 29 Jul 2018 08:25:08 +0200 (CEST) Authentication-Results: mail2-smtp-roc.national.inria.fr; spf=None smtp.pra=gabriel.scherer@gmail.com; spf=Pass smtp.mailfrom=gabriel.scherer@gmail.com; spf=None smtp.helo=postmaster@mail-lj1-f172.google.com IronPort-PHdr: =?us-ascii?q?9a23=3A8ZbyHhGgy3N6kKs9OksjAp1GYnF86YWxBRYc798d?= =?us-ascii?q?s5kLTJ7zpMmwAkXT6L1XgUPTWs2DsrQY07SQ6/iocFdDyK7JiGoFfp1IWk1Nou?= =?us-ascii?q?QttCtkPvS4D1bmJuXhdS0wEZcKflZk+3amLRodQ56mNBXdrXKo8DEdBAj0OxZr?= =?us-ascii?q?KeTpAI7SiNm82/yv95HJbAhEmDuwbaluIBmqsA7cqtQYjYx+J6gr1xDHuGFIe+?= =?us-ascii?q?NYxWNpIVKcgRPx7dqu8ZBg7ipdpesv+9ZPXqvmcas4S6dYDCk9PGAu+MLrrxjD?= =?us-ascii?q?QhCR6XYaT24bjwBHAwnB7BH9Q5fxri73vfdz1SWGIcH7S60/VC+85Kl3VhDnlC?= =?us-ascii?q?YHNyY48G7JjMxwkLlbqw+lqxBm3oLYfJ2ZOP94c6jAf90VWHBBU95eWCxPAIyy?= =?us-ascii?q?b4UBAekcM+hGs4bzqEADrQenBQS2GO/j1iNEi33w0KYn0+ohCwbG3Ak4EtwPqn?= =?us-ascii?q?vbt8/1NKYMXuCx0aLG0CnMb/NI1jfn9ofIaA0qrPaDXb1qasXR00gvGB3BjlmK?= =?us-ascii?q?sozqIzOV2foXs2eF9eptTu2vi2s9pAFwpjij3Nsjio7Mho8MzF3P6Ct3wIEwJd?= =?us-ascii?q?KiSU57Z8apEJpWtyGANot5WNkuQ29yuCs817YIuoa7cTAUxJg7wxPTcf+KfoiS?= =?us-ascii?q?7h79SOqcIi10iG9ndb6hgRu57FKuxffmVsau1VZHtipFncfItnAKzxHT79KISv?= =?us-ascii?q?p5/ku43TaP1R3f5vhKIUwpl6fXNYQtwrE3lpoUvkTDGjH5lF/qg6+Rc0Uo4umo?= =?us-ascii?q?6+L5bbX6vpKQKZN4hwXkPqktmsGzG/o0PhQNUmSB5Oix1qPv8VX8QLpQj/02lq?= =?us-ascii?q?fZsIrdJcQevqO5DBVa3Z056xa+ETim1M4UnWIbI1JFZh2HlZbmO0vVLfD3CPew?= =?us-ascii?q?mVWskDNxy//aOb3hB43BLmLfn7f5YbZ990lcxRIvwt9F4pJUDqgNIPbyWk/qqN?= =?us-ascii?q?zVFQQ5Mgyxw+b/EtpxzIIeWWSVAq+YKqzeq1GI5vh8a9WLMaocoir8LbAJ6tvj?= =?us-ascii?q?iXs+0QsYdLO13J0bZXW1GvBhC0qcaHvoxNwGFDFZkBA5SbnFgVeYUDNXL025X6?= =?us-ascii?q?8m6ytzXI2vB53CS4Trm7eB0T22BLVZY2lHDhaHFnK+JNbMYOsFdC/HepwpqTcD?= =?us-ascii?q?T7X0DtZ5jUj/5j+/8KJuK6/vwgNdsJvi0NZv4OiKzEM98DV1C4KW1GTfFjgozF?= =?us-ascii?q?NNfCc/2eVEmWI40k2KiPEqjPlRFNgV7PRMAF9jaMzsitdiAtW3YTrvO9eETFH8?= =?us-ascii?q?HIejCDA1C9YzmpoAOhknXdqliR/H0myhBLpHz7E=3D?= X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: =?us-ascii?q?A0DqAwB3XV1bhqzQVdFbHgEGDIMggRF/F?= =?us-ascii?q?RODfmKDC5BUgg2XSwsjhEUCAgKCexkHAQQ0FAECAQECAQEBAQETAQEBCAsLCBs?= =?us-ascii?q?OIwxCEAGBYiQBgl0BAgMjHQEbHQEDDAYDAgsNAgImAgIhAQERAQUBHAYTgyABg?= =?us-ascii?q?WYBAxUPjn+QAjyLCYERBQEXgnUFg00KGSYNV4JLAgEFEnmHd4FYP4MmfoJWgii?= =?us-ascii?q?DAYJVAogfkUYrBwKBdYQihhSDDI4JilBThwUPIYE3gXMzGiNQMYI4ghkag06BP?= =?us-ascii?q?okWPTCHSIgVAQE?= X-IPAS-Result: =?us-ascii?q?A0DqAwB3XV1bhqzQVdFbHgEGDIMggRF/FRODfmKDC5BUgg2?= =?us-ascii?q?XSwsjhEUCAgKCexkHAQQ0FAECAQECAQEBAQETAQEBCAsLCBsOIwxCEAGBYiQBg?= =?us-ascii?q?l0BAgMjHQEbHQEDDAYDAgsNAgImAgIhAQERAQUBHAYTgyABgWYBAxUPjn+QAjy?= =?us-ascii?q?LCYERBQEXgnUFg00KGSYNV4JLAgEFEnmHd4FYP4MmfoJWgiiDAYJVAogfkUYrB?= =?us-ascii?q?wKBdYQihhSDDI4JilBThwUPIYE3gXMzGiNQMYI4ghkag06BPokWPTCHSIgVAQE?= X-IronPort-AV: E=Sophos;i="5.51,417,1526335200"; d="scan'208";a="340619930" Received: from mail-lj1-f172.google.com ([209.85.208.172]) by mail2-smtp-roc.national.inria.fr with ESMTP/TLS/AES128-GCM-SHA256; 29 Jul 2018 08:25:07 +0200 Received: by mail-lj1-f172.google.com with SMTP id j19-v6so7738146ljc.7 for ; Sat, 28 Jul 2018 23:25:07 -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:content-transfer-encoding; bh=n2kB2/mS9pBuVZtNm3biNo/88gzKyel59cDswpamDXk=; b=ihs32pMcGfsOYJ3dhLqc8pt4/QmW12roM2/uQZ4t3I/kUN1AiPO08C3GJ/QVwFedM4 GO3F+0wIyHWsEfp9xcnotbnTl9E4x+BmN7sEo5JV2095lBdffg/ZUkYXz/CuFThsaEcT p9B0r8MF3sOk0O1R5NqwFJT5knd1+a2GKBTyyf/MnJZz69TIMW3IvK9qlJa2h7o5Yw4M D5J6rU+00gxc35c94d5Kfg6WtzwTdVf8E5R8K91l3i3m9RNGAvmGX90/ROvV/EEnORDZ G8ahXRezbXct8x2vvdkst/xHa3DQ6IIGzoEAjUDdZN6+5LR1GoPZKF/0dU14HmIKLIDu CXbQ== 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:content-transfer-encoding; bh=n2kB2/mS9pBuVZtNm3biNo/88gzKyel59cDswpamDXk=; b=OaToV9Ri/yPnghC8m6AMZ8gbOZg4llj7H/bRF1RtGzc4U1z6/AGVGgn3YRv+eAtJgI BhqwfFQDanKI3VGFCVBnn5r06boCRKNqjDZwGLzh3PpDYUOipEH7kRacn2Nj8i6FFxTs EjjPFx3Ricou5LOL52VG11KX7NYzuFEElR4pSHaCQz9R3f0mHkkAFaXOQha9k3i9zRKa SgQzheMzlcVUABF7Ktt1g3SzhedJFCOjfEAXdWoP88dcjVWCQVUBo+heyVZ7xC3gG0ph 1iiCgaJkdHvqeC0Bq1Vlwrl4ULEuH0W6NcwRuaXw1JuRUQ3OKJF+6u4iu0fhSzoAmwgK 9hDA== X-Gm-Message-State: AOUpUlEFaWkfQbUFfuyk3H5W7/S+sDlf5GTFfF+yBuouOHlAIKVfHgWc 3C1BEZ8gosRptzO6BUQ/P5jSePe9Nr6ZcvYPsrA= X-Google-Smtp-Source: AAOMgpflzgf/ocxEPtga6s169TsSgpSHBy0m9E5ZNRbZrauYWVobRGbEUAmwJ+UqbSmPLJf0YnBEXycLe0GZOTI/zIw= X-Received: by 2002:a2e:9883:: with SMTP id b3-v6mr9011415ljj.80.1532845506509; Sat, 28 Jul 2018 23:25:06 -0700 (PDT) MIME-Version: 1.0 References: <14267431532800443@iva1-3d0d937e850f.qloud-c.yandex.net> In-Reply-To: From: Gabriel Scherer Date: Sun, 29 Jul 2018 08:33:08 +0200 Message-ID: To: Martin DeMello Cc: Kenneth Adam Miller , vkni@yandex.ru, caml users Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Subject: Re: [Caml-list] cmdliner difficulties Reply-To: Gabriel Scherer X-Loop: caml-list@inria.fr X-Sequence: 17017 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: 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 wr= ote: > > How about "lexing" them into a list of operation tokens, then using the s= hunting-yard algorithm to parse them into an expression tree? that would al= low arbitrary recursive expressions and still be relatively straightforward= to process. > > martin > > On Sat, Jul 28, 2018 at 2:16 PM, Kenneth Adam Miller 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 o= r 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 feat= ures or as much work to deliver since if they even exist. Since I have to d= emonstrate this, the first question they are going to ask is "you spent mor= e than X minutes working on this when you could have been working on the mi= nimum viable product!! Unhappy!!" So I'm not disregarding the input I've go= t, but I think that I can achieve a less robust working version with the sa= me 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_set= ops)) & 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 (R= ed, Feature3) >> >> So that, as I fold, I will add colors to the feature set. Then, for what= ever nested operations otherwise would have been required, I can just manua= lly unfold them on the command line. >> >> I guess I've solved my problem, but I was hoping to get a recursive pars= ing capability on the command line that would have supporting a type declar= ation 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 th= ere isn't a clean way to specify to the Cmdliner.Arg.value function what th= e converter should be 2) The list type of their resulting pairwise sub-comm= and specifications to the command line (the "enum list_setops" part) become= s much harder to specify since those also need to be constructible in the s= tring - type pairs for the list_setops argument to enum. >> >> I suppose my thinking about how to deal with this would be to write a cu= stom 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-unif= orm 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 to= ol for that. Parser generators look too heavy, and comman-line parsers are = too light (otherwise they become optparse-applicative, which is too specifi= c 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=