From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.comp.tex.context/78448 Path: news.gmane.org!not-for-mail From: Sietse Brouwer Newsgroups: gmane.comp.tex.context Subject: Parsing [key=value, key2=value2, ...] with Lua Date: Thu, 27 Sep 2012 18:42:24 +0200 Message-ID: Reply-To: mailing list for ConTeXt users NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Trace: ger.gmane.org 1348764175 11450 80.91.229.3 (27 Sep 2012 16:42:55 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 27 Sep 2012 16:42:55 +0000 (UTC) To: mailing list for ConTeXt users Original-X-From: ntg-context-bounces@ntg.nl Thu Sep 27 18:43:01 2012 Return-path: Envelope-to: gctc-ntg-context-518@m.gmane.org Original-Received: from balder.ntg.nl ([195.12.62.10]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1THHAy-0003WD-Rs for gctc-ntg-context-518@m.gmane.org; Thu, 27 Sep 2012 18:43:00 +0200 Original-Received: from localhost (localhost [127.0.0.1]) by balder.ntg.nl (Postfix) with ESMTP id 5A0BE101F0; Thu, 27 Sep 2012 18:42:55 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at balder.ntg.nl Original-Received: from balder.ntg.nl ([127.0.0.1]) by localhost (balder.ntg.nl [127.0.0.1]) (amavisd-new, port 10024) with LMTP id I4kvJolitzZD; Thu, 27 Sep 2012 18:42:53 +0200 (CEST) Original-Received: from balder.ntg.nl (localhost [IPv6:::1]) by balder.ntg.nl (Postfix) with ESMTP id 45D84101E7; Thu, 27 Sep 2012 18:42:53 +0200 (CEST) Original-Received: from localhost (localhost [127.0.0.1]) by balder.ntg.nl (Postfix) with ESMTP id DEAD5101E7 for ; Thu, 27 Sep 2012 18:42:51 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at balder.ntg.nl Original-Received: from balder.ntg.nl ([127.0.0.1]) by localhost (balder.ntg.nl [127.0.0.1]) (amavisd-new, port 10024) with LMTP id ADz5UB7jcjdj for ; Thu, 27 Sep 2012 18:42:47 +0200 (CEST) Original-Received: from filter5-til.mf.surf.net (filter5-til.mf.surf.net [194.171.167.221]) by balder.ntg.nl (Postfix) with ESMTP id 19FF4101E5 for ; Thu, 27 Sep 2012 18:42:47 +0200 (CEST) Original-Received: from mail-ie0-f169.google.com (mail-ie0-f169.google.com [209.85.223.169]) by filter5-til.mf.surf.net (8.14.3/8.14.3/Debian-9.4) with ESMTP id q8RGdvT1014075 for ; Thu, 27 Sep 2012 18:39:57 +0200 Original-Received: by ied10 with SMTP id 10so6236342ied.14 for ; Thu, 27 Sep 2012 09:42:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:from:date:message-id:subject:to:content-type; bh=/9M5bnvyYrXjDL9cAexpl+FAvu930cATIwdUnMDSYbs=; b=YhGhj+4LVucXVummzMeFa9yCbJz8YqFXfOd7/morCeUetE6eFPsy1YoJ/mAsZjsQNs qnVubuHvJzr2UgVrC2d0yLTmeKuytUfUQXz7cZKRNNkfk92f0CWTi7K0/0LlkOk99nVM NfqQAcasDSUh4q4juANKue3nqyHDkiJIkbzAM5856bn/8ZfPRnF7tUHQRlV/mt11RINg rO1AhY0mElmkZv2rBIcz4sxMfoc+yG4tAUKDMpeqNg+BYD/n+OL7jeWMnn1vt2//HgfR WgfwBSu3YibQ9u53wE19ezwvI30mcGXAWZUTbUPiTVs2gaZDd80xvWboa/ZCW1hvHF4i D3Lw== Original-Received: by 10.50.160.195 with SMTP id xm3mr4100577igb.12.1348764165141; Thu, 27 Sep 2012 09:42:45 -0700 (PDT) Original-Received: by 10.64.31.67 with HTTP; Thu, 27 Sep 2012 09:42:24 -0700 (PDT) X-Bayes-Prob: 0.0001 (Score 0, tokens from: @@RPTN) X-CanIt-Geo: ip=209.85.223.169; country=US; region=CA; city=Mountain View; postalcode=94043; latitude=37.4192; longitude=-122.0574; metrocode=807; areacode=650; http://maps.google.com/maps?q=37.4192,-122.0574&z=6 X-CanItPRO-Stream: uu:ntg-context@ntg.nl (inherits from uu:default, base:default) X-Canit-Stats-ID: 0WI4gDV64 - feda7f97934b - 20120927 (trained as not-spam) X-Scanned-By: CanIt (www . roaringpenguin . com) on 194.171.167.221 X-BeenThere: ntg-context@ntg.nl X-Mailman-Version: 2.1.14 Precedence: list List-Id: mailing list for ConTeXt users List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ntg-context-bounces@ntg.nl Original-Sender: ntg-context-bounces@ntg.nl Xref: news.gmane.org gmane.comp.tex.context:78448 Archived-At: Hi all, I've found a helper function that does this: utilities.parsers.settings_to_hash('ape=1, note=2, mice=3') --> { ["ape"] = 1, ["note"] = 2, ["mice"] = 3 } This makes me very happy. This function and its friends are stored under utilities.parsers, and defined in util-prs.lua; I've listed them below. Perhaps they'll be useful to somebody else, too. I should probably add this info to http://wiki.contextgarden.net/Commands_with_KeyVal_arguments, but dinner first. Cheers, Sietse First some examples of what the most important functions: utilities.parsers.settings_to_hash('ape=1, note=2, mice=3') --> { ["ape"] = 1, ["note"] = 2, ["mice"] = 3 } -- settings_to_hash takes an option 'strict', -- I assume that has to do with space-trimming. utilities.parsers.settings_to_array('ape, note=2, mice, ape') --> { "ape", "note=2", "mice", "ape" } utilities.parsers.settings_to_array('ape, note=2, mice, ape') --> { ["ape"]=true, ["note=2"]=true, ["mice"]=true,} Complete list of functions (and one table) in utilities.parsers: T.add_settings_to_array T.arguments_to_table T.array_to_string T.getparameters T.hash_to_string T.listitem T.make_settings_to_hash_pattern T.patterns : table: 0x9a67680 T.patterns.settings_to_array : userdata: 0x9a6c904 T.patterns.settings_to_hash_a : userdata: 0x9a6a694 T.patterns.settings_to_hash_b : userdata: 0x9a6ad6c T.patterns.settings_to_hash_c : userdata: 0x9a6b424 T.settings_to_array T.settings_to_hash T.settings_to_hash_strict T.settings_to_hash_tolerant T.settings_to_set T.simple_hash_to_string T.splitthousands ___________________________________________________________________________________ If your question is of interest to others as well, please add an entry to the Wiki! maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context webpage : http://www.pragma-ade.nl / http://tex.aanhet.net archive : http://foundry.supelec.fr/projects/contextrev/ wiki : http://contextgarden.net ___________________________________________________________________________________