Crate lua_parser

Source
Expand description
let source = " <lua source code> ";

let block = match lua_parser::parse_str(&source) {
    Ok(block) => block,
    Err(err) => {
        println!("{}", err);
        return;
    }
};

println!("AST:\n{:#?}", block);

Structs§

AttName
pair of variable name and attribute.
Block
block of statements. return statement must be optionally placed at the end of the block.
ExprBinaryData
Internal data for binary operation
ExprBool
lua boolean literal value
ExprFunction
unnamed function
ExprFunctionCall
function call. prefix(args) or prefix:method(args).
ExprIdent
just identifier
ExprNil
ExprNumeric
lua numeric literal value
ExprString
lua string literal value
ExprTable
table constructor, a list of fields
ExprTableIndex
table[index], table.index
ExprUnaryData
Internal data for unary operation
ExprVariadic
...
FunctionCallArguments
FunctionName
function name. a sequence of identifiers separated by dots, and an optional colon followed by an identifier. e.g. a.b.c:d
InvalidToken
ParameterList
parameter list for named & anonymous function definition
Parser
struct that holds parser data, DFA tables
ReturnStatement
return statement
Span
range of a token in the source code
SpannedString
string with span information.
StmtAssignment
l0, l1, l2 = r0, r1, r2. variadic ... can be used in both l and r
StmtBreak
break statement
StmtDo
do - end statements block
StmtElseIf
else-if fragment for if statements
StmtFor
for statement with start, end, step.
StmtForGeneric
for statement with generic expressions.
StmtFunctionDefinition
function definition statement.
StmtFunctionDefinitionLocal
local function definition statement.
StmtGoto
Goto statement
StmtIf
if statement
StmtLabel
label definition
StmtLocalDeclaration
local variable declaration.
StmtNone
StmtRepeat
repeat statement
StmtWhile
while statement
TableFieldKeyValue
table field constructor [key] = value
TableFieldNameValue
table field constructor name = value
TableFieldValue
table field constructor value
Token
Token classification and metadata.
Tokenizer
lazy tokenize iterator.

Enums§

Attrib
local variable attribute. either const or close.
ChunkOrExpressions
for interpreter to handle both chunk and expression
ExprBinary
binary operation. lhs OP rhs
ExprUnary
unary operation. OP x
Expression
lua value & expression
IntOrFloat
Lua’s numeric representation, can be either integer or float.
ParseError
error when tokenizing & parsing lua source code
Statement
lua statement
TableField
table field
TokenizeError

Functions§

parse_bytes
parse lua source code to AST
parse_str
parse lua source code to AST

Type Aliases§

Context
type alias for Context
FloatType
type alias for lua float type.
IntType
type alias for lua integer type.
InvalidTerminalError
type alias for InvalidTerminalError
StmtFunctionCall
function call statement.