ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
* Parsing [key=value, key2=value2, ...] with Lua
@ 2012-09-27 16:42 Sietse Brouwer
  0 siblings, 0 replies; only message in thread
From: Sietse Brouwer @ 2012-09-27 16:42 UTC (permalink / raw)
  To: mailing list for ConTeXt users

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
___________________________________________________________________________________


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2012-09-27 16:42 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-09-27 16:42 Parsing [key=value, key2=value2, ...] with Lua Sietse Brouwer

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).