Module fusion.core.parsers.source
Compile FusionScript AST to Lua code
Functions
parser:new () | Initialize a parser state |
parser:transform (node) | Transform a node using the registered handler. |
parser:l (line) | Add indent to a line of text. |
parser:transform_expression_list (node) | Convert an expression_list field to a transformed list of expressions. |
parser:transform_variable_list (node) | Convert a variable_list to a transformed list of variable names. |
parser:transform_class_function (node) | Convert a function field in a class to a lambda table assignment. |
parser.compile (in_values, output_stream) | Convert an iterator returning FusionScript chunks to Lua code. |
parser.read_file (file) | Read FusionScript code from a file and return output. |
parser.load_file (file) | Load FusionScript code from a file and return a function to run the code. |
parser.do_file (file) | Load and run FusionScript code from a file |
parser.search_for (module_name) | Find a module in the package path and return relevant information. |
parser.inject_loader () | Inject parser.search_for into the require() searchers list. |
Functions
- parser:new ()
- Initialize a parser state
- parser:transform (node)
-
Transform a node using the registered handler.
Parameters:
- node table
- parser:l (line)
-
Add indent to a line of text.
Parameters:
- line string
- parser:transform_expression_list (node)
-
Convert an expression_list field to a transformed list of expressions.
Parameters:
- node table
- parser:transform_variable_list (node)
-
Convert a variable_list to a transformed list of variable names.
Parameters:
- node table
- parser:transform_class_function (node)
-
Convert a function field in a class to a lambda table assignment.
Parameters:
- node table
- parser.compile (in_values, output_stream)
-
Convert an iterator returning FusionScript chunks to Lua code.
Do not use this function directly to compile code.
Parameters:
- in_values table Table of values to compile
- output_stream function Repeatedly called with generated code
- parser.read_file (file)
-
Read FusionScript code from a file and return output.
Parameters:
- file string File to read input from
Returns:
-
string
Lua code
- parser.load_file (file)
-
Load FusionScript code from a file and return a function to run the code.
Parameters:
- file string
Returns:
-
function
Loaded FusionScript code
- parser.do_file (file)
-
Load and run FusionScript code from a file
Parameters:
- file string
- parser.search_for (module_name)
-
Find a module in the package path and return relevant information.
Returns
nil
and an error message if not found. Do not use this function by itself; useparser.inject_loader()
.Parameters:
- module_name string
Returns:
- function Closure to return loaded module
- string Path to loaded file
- parser.inject_loader ()
-
Inject parser.search_for into the
require()
searchers list.Returns:
-
boolean
False if loader already found
Usage:
parser.inject_loader(); print(require("test_module")) -- Attempts to load a FusionScript
test_module
package