Extension:NaturalLanguageList

This is a syntax proposal for a parser function to make natural language lists (e.g. 1, 2, 3, ... n-1 and n).

Code

 * NaturalLanguageList.php
 * NaturalLanguageList.body.php
 * NaturalLanguageList.i18n.php

Live!
Since this extension is not implemented anywhere else than my place, you can currently see it in action here:


 * http://dev.sviip.dk/List_tests

Options
Each parameter containing data in the format of 'variable=value' will be considered an option, so for several options, separate them by a pipe. In addition, it is regardless of the position in the list of items where the options come. First, last or in the middle, the construct of 'variable=value' will be assumed to be an option, if it matches one of the following understood variables:


 * duplicates (boolean)
 * (Default: true) Whether the list should include duplicates, if true duplicates will be included, per default they won't.


 * blanks (boolean)
 * (Default: false) Whether the list should include blank elements, if true blank elements will be included, per default they won't.


 * separator (string)
 * outputseparator (string)
 * (Default: empty) The output's separation character(s), if not set, it will default to the 1, 2, 3, ... n-1 and n format.  If set, however, the ' and ' feature will not be available, and all elements will be separated the same way.  So if you set it to a comma, it will simply be the same but the two last elements separated by a comma rather than an ' and '.


 * lastseparator (string)
 * (Default: empty) Allows to set a specific separator for the last two elements, if not set, it will default to the language's setting for ' and '.


 * itemcover (string)
 * (Default: empty) Allows to create string surrounding each item. Must contain $1 to refer to the item.  When used with fieldsperitem, $2, $3, etc. may also appear.


 * fieldsperitem (integer)
 * itemsperitem (integer)
 * (Default: 1) Allows to create more inputs per a single field in the end result, combining several fields into one.  The amount it is set to is the size of the pairs of fields.  It requires itemcover to be set.  Though, it is not required for itemcover to contain more than $1.

#ignore:
This parameter indicates that this item and all items henceforth are to be ignored by the parser. Useful for automatic lists.

In which case the result would be 1, 3 and 5.

#data:
Basically the opposite of #ignore:, but can also be used to ignore the parser to read certain items that would otherwise be thought of as parameters, etc.

Similar to the regular function, but instead takes raw input, rather than input separated by pipes. This would usually be the case for templates or other functions that spews out data in other formats, since pipes cannot be separated from list output.

The first element is always the separator key. The following parameter are thus the raw data or a parameter as listed above in the options section.

Which would become 1, 2, 3, 4 and 5.