Module Refactor

Refactoring module

Tables

Stmt AST Stmt
Expr AST Expr

Fields

refactor Global refactoring state

Class RefactorState

RefactorState:run_command (name, args) Run a builtin refactoring command
RefactorState:transform (callback) Run a custom refactoring transformation

Class MatchCtxt

MatchCtxt:parse_stmts (pat) Parse statements and add them to this MatchCtxt
MatchCtxt:parse_expr (pat) Parse an expressiong and add it to this MatchCtxt
MatchCtxt:fold_with (needle, crate, callback) Find matches of pattern within crate and rewrite using callback
MatchCtxt:get_expr (Expression) Get matched binding for an expression variable
MatchCtxt:get_stmt (Statement) Get matched binding for a statement variable
MatchCtxt:try_match (pat, target) Attempt to match target against pat, updating bindings if matched.
MatchCtxt:subst (replacement) Substitute the currently matched AST node with a new AST node

Class TransformCtxt

TransformCtxt:replace_stmts_with (needle, callback) Replace matching statements using given callback
TransformCtxt:replace_expr_with (needle, callback) Replace matching expressions using given callback
TransformCtxt:match () Create a new, empty MatchCtxt
TransformCtxt:get_ast (node) Retrieve a Lua version of an AST node


Tables

Stmt
AST Stmt

Fields:

  • type "Stmt"
  • kind string StmtKind of this statement

    StmtKind::Local only:

  • ty AstNode Type of local (optional)
  • init AstNode Initializer of local (optional)
  • pat AstNode Name of local

    StmtKind::Item only:

  • item AstNode Item node

    StmtKind::Semi and StmtKind::Expr only:

  • expr AstNode Expression in this statement
Expr
AST Expr

Fields:

  • type "Expr"
  • kind string ExprKind of this expression

    ExprKind::Lit only:

  • value Literal value of this expression

Fields

refactor
Global refactoring state
  • refactor RefactorState object

Class RefactorState

Refactoring context
RefactorState:run_command (name, args)
Run a builtin refactoring command

Parameters:

RefactorState:transform (callback)
Run a custom refactoring transformation

Parameters:

  • callback function(TransformCtxt,AstNode) Transformation function called with a fresh TransformCtxt and the crate to be transformed.

Class MatchCtxt

A match context
MatchCtxt:parse_stmts (pat)
Parse statements and add them to this MatchCtxt

Parameters:

Returns:

    AstNode The parsed statements
MatchCtxt:parse_expr (pat)
Parse an expressiong and add it to this MatchCtxt

Parameters:

Returns:

    AstNode The parsed expression
MatchCtxt:fold_with (needle, crate, callback)
Find matches of pattern within crate and rewrite using callback

Parameters:

  • needle AstNode Pattern to search for
  • crate AstNode Crate to fold over
  • callback function(AstNode,MatchCtxt) Function called for each match. Takes the matching node and a new MatchCtxt for that match.
MatchCtxt:get_expr (Expression)
Get matched binding for an expression variable

Parameters:

  • Expression string variable pattern

Returns:

    AstNode Expression matched by this binding
MatchCtxt:get_stmt (Statement)
Get matched binding for a statement variable

Parameters:

  • Statement string variable pattern

Returns:

    AstNode Statement matched by this binding
MatchCtxt:try_match (pat, target)
Attempt to match target against pat, updating bindings if matched.

Parameters:

  • pat AstNode AST (potentially with variable bindings) to match with
  • target AstNode AST to match against

Returns:

    bool true if match was successful
MatchCtxt:subst (replacement)
Substitute the currently matched AST node with a new AST node

Parameters:

  • replacement AstNode New AST node to replace the currently matched AST. May include variable bindings if these bindings were matched by the search pattern.

Returns:

    AstNode New AST node with variable bindings replaced by their matched values

Class TransformCtxt

Transformation context
TransformCtxt:replace_stmts_with (needle, callback)
Replace matching statements using given callback

Parameters:

  • needle string Statements pattern to search for, may include variable bindings
  • callback function(AstNode,MatchCtxt) Function called for each match. Takes the matching node and a new MatchCtxt for that match. See MatchCtxt:fold_with
TransformCtxt:replace_expr_with (needle, callback)
Replace matching expressions using given callback

Parameters:

  • needle string Expression pattern to search for, may include variable bindings
  • callback function(AstNode,MatchCtxt) Function called for each match. Takes the matching node and a new MatchCtxt for that match. See MatchCtxt:fold_with
TransformCtxt:match ()
Create a new, empty MatchCtxt

Returns:

    MatchCtxt New match context
TransformCtxt:get_ast (node)
Retrieve a Lua version of an AST node

Parameters:

Returns:

    Struct representation of this AST node. Valid return types are Stmt, and Expr.
generated by LDoc 1.4.6 Last updated 2019-02-21 10:38:12