Skip to content

Commit

Permalink
Lua parser
Browse files Browse the repository at this point in the history
  • Loading branch information
AsynchronousAI committed Oct 28, 2023
1 parent 6be184e commit 956f5c2
Showing 1 changed file with 21 additions and 31 deletions.
52 changes: 21 additions & 31 deletions src/rbxpy.py
Original file line number Diff line number Diff line change
Expand Up @@ -2255,7 +2255,12 @@ def usage():
{TAB}\033[1m-clrtxt\033[0m modify system shell for a better experience
{TAB}\033[1m-o\033[0m output file
{TAB}\033[1m-c\033[0m ignore pyright errors
{TAB}\033[1m-u\033[0m open this""")
{TAB}\033[1m-u\033[0m open this
\033[1mInputs:\033[0m
{TAB}\033[1m-j\033[0m input is a jupyter notebook
{TAB}\033[1m-py\033[0m input is python file (default)
{TAB}\033[1m-lua\033[0m input is lua file to convert to python""")
sys.exit()

def version():
Expand Down Expand Up @@ -2391,40 +2396,25 @@ def check():
else:
print(lua_code)
else:
command = "luac -l "+input_filename

try:
res = subprocess.check_output(command, shell=True, stderr=subprocess.STDOUT)
except subprocess.CalledProcessError as e:
sys.exit(1)
res = (res.decode("utf-8"))

# Parse
commands = {}
from luaparser import ast as luast
except:
error("luaparser not installed, please install it with 'pip install luaparser'")
if (input_filename == "NONE"):
usage()
if (not Path(input_filename).is_file()):
error(
"The given filename ('{}') is not a file.".format(input_filename))

lines = res.split("\n")
lines.pop(0)
lines.pop(0)
lines.pop(0)
for line in lines:
data = line.split("\t")
if len(data) < 4:
continue
num, cmd, args = data[1], data[3], data[4]
if len(data) > 5:
data = data[5]
else:
data = "NONE"

commands[num] = {"cmd": cmd, "args": args, "data": data}
res = "\n".join(lines)
with open(input_filename, "r") as file:
content = file.read()

print(commands)
if not content:
error("The input file is empty.")

lua_code = luast.parse(content)
print(luast.to_pretty_str(lua_code))

# If luac.out is found then remove it
if Path("luac.out").is_file():
os.remove("luac.out")

return 0

Expand Down

0 comments on commit 956f5c2

Please sign in to comment.