Module SU.ast

AST utilities.

Functions for working with SILE's Abstract Syntax Trees.

Functions

debug(tree, level) Output developer friendly debugging view of an AST.
findInTree(tree, command) Find a command node in a SILE AST tree, looking only at the first level.
removeFromTree(tree, command) Find and extract (remove) a command node in a SILE AST tree, looking only at the first level.
createCommand(command, options, content, position) Create a command from a simple content tree.
createStructuredCommand(command, options, content, position) Create a command from a structured content tree.
subContent(content) Extract the sub-content tree from a (command) node, that is the child nodes of the (command) node.
trimSubContent(content) Content tree trimming: remove leading and trailing spaces, but from a content tree i.e.
processAsStructure(content) Process the AST walking through content nodes as a "structure": Text nodes are ignored (e.g.
walkContent(content, action) Call action on each content AST node, recursively, including content itself.
stripContentPos(table) Strip position, line and column recursively from a content tree.
contentToString(content) Flatten content trees into just the string components (allows passing objects with complex structures to functions that need plain strings)
hasContent(content) Check whether a content AST tree is empty.


Functions

debug(tree, level)
Output developer friendly debugging view of an AST.

Parameters:

  • tree table Abstract Syntax Tree.
  • level integer Starting level to review.
findInTree(tree, command)
Find a command node in a SILE AST tree, looking only at the first level. (We're not reimplementing XPath here.)

Parameters:

Returns:

    table or nil AST command node
removeFromTree(tree, command)
Find and extract (remove) a command node in a SILE AST tree, looking only at the first level.

Parameters:

Returns:

    table or nil AST command node
createCommand(command, options, content, position)
Create a command from a simple content tree. It encapsulates the content in a command node.

Parameters:

  • command string command name
  • options table command options
  • content table child AST tree
  • position table position in source (or parent AST command node)

Returns:

    table AST command node
createStructuredCommand(command, options, content, position)
Create a command from a structured content tree. The content is normally a table of an already prepared content list.

Parameters:

  • command string command name
  • options table command options
  • content table child AST tree
  • position table position in source (or parent AST command node)

Returns:

    table AST command node
subContent(content)
Extract the sub-content tree from a (command) node, that is the child nodes of the (command) node.

Parameters:

Returns:

    table AST tree
trimSubContent(content)
Content tree trimming: remove leading and trailing spaces, but from a content tree i.e. possibly containing several elements.

Parameters:

Returns:

    table AST tree
processAsStructure(content)
Process the AST walking through content nodes as a "structure": Text nodes are ignored (e.g. usually just spaces due to indentation) Command options are enriched with their "true" node position, so we can later refer to it (as with an XPath pos()).

Parameters:

walkContent(content, action)
Call action on each content AST node, recursively, including content itself. Not called on leaves, i.e. strings.

Parameters:

  • content table AST tree
  • action function A function to call on each node
stripContentPos(table)
Strip position, line and column recursively from a content tree. This can be used to remove position details where we do not want them, e.g. in table of contents entries (referring to the original content, regardless where it was exactly, for the purpose of checking whether the table of contents changed.)

Parameters:

  • table content AST tree

Returns:

    table AST tree
contentToString(content)
Flatten content trees into just the string components (allows passing objects with complex structures to functions that need plain strings)

Parameters:

Returns:

    string A string representation of content
hasContent(content)
Check whether a content AST tree is empty.

Parameters:

Returns:

    boolean true if content is not empty
generated by LDoc 1.5.0 Last updated 1980-01-01 00:00:00