မေႃႇၵျူး:template utilities/doc
Appearance
This is the documentation page for မေႃႇၵျူး:template utilities
This module provides functions for finding and parsing template invocations found in wikitext, though it can also be used for other purposes.
find_bracket(str, brackets, p_start)- Finds a substring with balanced brackets. This means that, if one reads the string from left to right, counting +1 for a left bracket and -1 for a right bracket, the ending right bracket is the first right bracket where the count reaches 0. This function is similar to Lua search pattern
'%b', but accepts multi-character tokens as brackets.str: the string to be searchedbrackets: the left and right brackets to be searched for, given as a hash table with the left brackets being keys and the right being values. They are interpreted as Lua patterns:
{
['{{'] = '}}',
['%[%['] = ']]',
}
p_start: where instrto start the search- Return value: If it finds a match, returns indices of where this bracket starts and ends, and the whole bracket substring (including the brackets); otherwise returns
nil.
gfind_bracket(str, brackets)- Iterates through all top-level
bracketsfound instr.- The parameters are the same as in
find_bracket(). - Return value: Returns an iterator function. It yields indices of where this bracket starts and ends, and the whole bracket substring.
- The parameters are the same as in
find_ignoring_brackets(str, brackets, pat, init, ...)- Searches
strusingstring.find(), but ignore all text insidebrackets.pat, init, ...: the same parameters forstring.find()- Other parameters are the same as in
find_bracket(). - Return value: Returns the result of
string.find().
gsplit_ignoring_brackets- Splits
strinto substrings at boundaries that match the patternsepand are not in anybrackets, and iterates through them.sep: the pattern matching the boundaries. If it matches the empty string, s will be split into individual characters.- Other parameters are the same as in
find_bracket(). - Return value: Returns an iterator function. It yields each section substring.
parse_temp(str)- Parses
stras a template invocation and returns the result table.str: the string of a template invocation- Return value: If success, returns a table containing the template name as a string
['title']and the parameters as a table['args']; otherwise, returnsnil.
iter_num(t)- Iterates through all extant numbered parameters of a template. Named parameters are ignored. Nonexistent numbered parameters are skipped.
t: a table containing the template name as a string['title']and the parameters as a table['args']- Return value: Returns an iterator function. It yields the index and values of all number-indexed non-nil content of the table in order.
glue_temp(t)- Serializes a template information table to template invocation wikitext. The inverse operation of
parse_temp(str).t: the same as initer_num(t)- Return value: Returns a string of template invocation wikitext. Raises errors when it fails.