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 searched
  • brackets: 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 in str to 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 brackets found in str.
  • 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.
find_ignoring_brackets(str, brackets, pat, init, ...)
Searches str using string.find(), but ignore all text inside brackets.
  • pat, init, ...: the same parameters for string.find()
  • Other parameters are the same as in find_bracket().
  • Return value: Returns the result of string.find().
gsplit_ignoring_brackets
Splits str into substrings at boundaries that match the pattern sep and are not in any brackets, 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 str as 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, returns nil.
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 in iter_num(t)
  • Return value: Returns a string of template invocation wikitext. Raises errors when it fails.


"https://si.wiktionary.org/w/index.php?title=Module:template_utilities/documentation&oldid=165699" වෙතින් සම්ප්‍රවේශනය කෙරිණි