Jump to content

Module:Sandbox/AbstractWikipedia/TemplateParser/doc

From Meta, a Wikimedia project coordination wiki

This is the documentation page for Module:Sandbox/AbstractWikipedia/TemplateParser

This module is part of user:AGutman-WMF's prototype implementation of Abstract Wikipedia's template language in Scribunto.

This module specifically implements a template-language parser. Its parse function returns three return values, described below.

An structured representation of the template elements

[edit]

This is a list of tables, each table representing a single element of the template (either a slot or a textual element). The order of the list corresponds to the order of the elements in the table. The table have the following fields:

  • type :
For textual elements this can be punctuation, spacing or text.
For slots, this can be one of function, lexeme (for L-ids), item (for Q-ids), interpolation (for identifiers which are assumed to interpolate an argument), text (quoted strings within slots), number (an integer number) or undefined (yielding later an error).
  • text: for all above types, except function and interpolation, this field contains the content of the slot or the textual element (unquoted if it is text within a slot).
  • function: used only in the function type, this field represent the name of the function.
  • args: used only in the function type, this is a (possibly-empty) list of the arguments to the function, which are themselves tables of the type discussed here. Given that an argument to a function may be a function itself, this yields a tree representation of the function arguments.
  • arg: used only in the interpolation type, this field represent the name of the interpolated argument.
  • role: For slots with a dependency label, this contains the grammatical role indicated by the label (i.e. the label without any additional indexes or source indication.
  • index: for debugging purposes, this gives the sequential number of the element within the template (only for top-level elements). These indexes are referred to by the relations table (described below).

Relations table

[edit]

The relations table is a list of tables indicating a relation to be applied on the slots of the template. The order is immaterial. Each table in the list has the following three fields:

  • role: the name of the relation to be applied.
  • target: the index of the target slot (i.e. the slot where the label is given).
  • source: the index of the source slot (by default the root slot, unless another source label is given).

Root of the template

[edit]

The last return value is the index of the slot marked as `root`. If none is given (which is only allowed if dependency labels are not used at all), this will be the index of the first slot (or in the absence of slots, this will be the index of the last element).