Last active
December 30, 2021 12:50
-
-
Save naclsn/b85467b379d676481e6a4483ee2ef5a0 to your computer and use it in GitHub Desktop.
Parses PICO-8's peculiar Lua into an AST, stores the result as a JSON file. See https://github.com/boolangery/py-lua-parser as for the AST itself.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env pwsh | |
# .SYNOPSIS | |
# Parses a .p8 file into an AST, stores the result as JSON. | |
param ([Parameter(Mandatory)][string]$InputP8, [Parameter(Mandatory)][string]$OutputJSON) | |
$FileInfo = Get-Item $InputP8 | |
$OLDPWD = $PWD | |
Set-Location $FileInfo.Directory | |
$TempFile = "_tmp$(Get-Random).txt" | |
"pico-8 cartridge`n`n__lua__`nprinth([=[`n#include $($FileInfo.Name)`n]=],'$TempFile',true)" > $TempFile | |
pico8 -root_path "$PWD" -x $TempFile > $null | |
python3 -m pip install luaparser > $null | |
python3 -m luaparser $TempFile -o "$OLDPWD/$OutputJSON" | |
Remove-Item $TempFile | |
Set-Location $OLDPWD |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env sh | |
# .SYNOPSIS | |
# Parses a .p8 file into an AST, stores the result as JSON. | |
INPUT_P8="$1" | |
OUTPUT_JSON="$2" | |
cd $(dirname "$INPUT_P8") | |
TEMP_FILE="_tmp$$.txt" | |
printf "pico-8 cartridge\n\n__lua__\nprinth([=[\n#include $(basename "$INPUT_P8")\n]=],'$TEMP_FILE',true)" > $TEMP_FILE | |
trap "rm $TEMP_FILE ; cd '$OLDPWD'" EXIT | |
pico8 -root_path "$PWD" -x $TEMP_FILE > /dev/null | |
python3 -m pip install luaparser > /dev/null | |
python3 -m luaparser $TEMP_FILE -o "$OLDPWD/$OUTPUT_JSON" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment