A Lua parser and AST builder written in Python.
It's both a development library and a command line tool.
The package can be installed through `pip`:
$ python3.6 -m pip install luaparser
It will install the shell command 'luaparser'.
These are the command-line flags:
Usage: luaparser [options] filename
CLI Options:
--version Show program's version number and exit
-h, --help Show this help message and exit
-s, --source Source passed in a string
-x, --xml Set output format to xml
-o, --output Write output to file
Each node contains the following data:
Minimal exemple:
will display:
Chunk: {} 1 key
body: {} 1 key
Block: {} 1 key
body: [] 2 items
0: {} 1 key
LocalFunction: {} 3 keys
name: {} 1 key
Name: {} 1 key
id: "sayHello"
args: [] 0 item
body: [] 1 item
0: {} 1 key
Call: {} 2 keys
func: {} 1 key
Name: {} 1 key
id: "print"
args: [] 1 item
0: {} 1 key
String: {} 1 key
s: "hello world !"
1: {} 1 key
Call: {} 2 keys
func: {} 1 key
Name: {} 1 key
id: "sayHello"
args: [] 0 item
You can run through the list of all the nodes in the tree using ast.walk(tree):
Alternatively, you can use a node visitor:
Warning
Experimental feature
Will render:
Given:
Will output:
{
"Chunk": {
"body": {
"Block": {
"body": [
{
"LocalFunction": {
"name": {
"Name": {
"id": "log"
}
},
"args": [
{
"Name": {
"id": "msg"
}
}
],
"body": {
"Block": {
"body": [
{
"Call": {
"func": {
"Name": {
"id": "print"
}
},
"args": [
{
"Name": {
"id": "msg"
}
}
]
}
}
]
}
}
}
},
{
"Call": {
"func": {
"Name": {
"id": "log"
}
},
"args": [
{
"String": {
"s": "hello world !"
}
}
]
}
}
]
}
}
}
}
Documentation can be built with Sphinx:
$ cd doc
$ pip install -r requirements.txt
$ make html