Module jls.util.ast

Abstract Syntax Tree (AST) utility module.

This module allows to parse Lua into AST, manipulate AST and to generate Lua from AST.

The AST is represented using Lua table.

The types are: assignment, binary, block, break, call, declaration, for, function, goto, identifier, if, label, literal, lookup, repeat, return, table, unary, vararg, while

The operators are: +, -, *, /, //, ^, %, &, ~, |, >>, <<, .., <, <=, >, >=, ==, ~=, and, or, -, not, #, ~

The table fields are: adjustToOne, arguments, attribute, body, bodyFalse, bodyTrue, callee, condition, declaration, expression, fields, kind, label, left, member, method, name, names, object, operator, parameters, right, statements, targets, type, value, values

Functions

ast.parse (lua[, verbose]) Returns the AST representing the specified Lua code.
ast.parseExpression (lua[, verbose]) Returns the AST representing the specified Lua expression.
ast.traverse (tree, callback[, context]) Walks through the specified AST calling the callback function for each node.
ast.generate (tree) Returns the Lua code representing the specified AST.


Functions

ast.parse (lua[, verbose])
Returns the AST representing the specified Lua code.

Parameters:

  • lua string the Lua code to parse.
  • verbose boolean whether or not to include extra information such as the line number. (optional)

Returns:

    table the AST representing the Lua.
ast.parseExpression (lua[, verbose])
Returns the AST representing the specified Lua expression.

Parameters:

  • lua string the Lua expression to parse.
  • verbose boolean whether or not to include extra information such as the line number. (optional)

Returns:

    table the AST representing the Lua.
ast.traverse (tree, callback[, context])
Walks through the specified AST calling the callback function for each node. The function is called with the AST node, if the return value is a table then it will replace the current AST node.

Parameters:

  • tree table the AST to walk through.
  • callback function the callback function, will be called with the node and the context.
  • context an optional context to pass to the callback function. (optional)

Returns:

    table the AST.
ast.generate (tree)
Returns the Lua code representing the specified AST.

Parameters:

Returns:

    string the Lua code representing the AST.
generated by LDoc 1.4.6