vsariola / pakettic

TIC-80 cartridge packer
MIT License
19 stars 4 forks source link

Parser doesn't handle local variable declaration with no initial value #13

Closed grahambates closed 7 months ago

grahambates commented 7 months ago

Declaring a variable with no initial value is supported in TIC-80's Lua implementation, but results in a ParseException in Pakettic:

local x
Traceback (most recent call last):                                                                                                                                                                                                                                         
  File "/usr/local/bin/pakettic", line 8, in <module>
    sys.exit(main())
             ^^^^^^
  File "/usr/local/lib/python3.11/site-packages/pakettic/main.py", line 175, in main
    root = parser.parse_string(code)
           ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/pakettic/parser.py", line 294, in parse_string
    return chunk.parse_string(x, parse_all=True)[0]
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/pyparsing/core.py", line 1141, in parse_string
    raise exc.with_traceback(None)
pyparsing.exceptions.ParseException: Expected end of text, found 'local'  (at char 0), (line:1, col:1)

This example is handled fine, even though only one of the vars is set:

local x,y,z = 0
vsariola commented 7 months ago

Who uses locals ;) Sounds like a trivial thing to fix, but I don't have time to investigate until Dec 14. Do you need a fix asap?

vsariola commented 7 months ago

Hmm... I am unable to replicate, a file with just local x or function TIC()local x end seem to pack just fine. What version you are on?

vsariola commented 7 months ago

Checking the changelogs, 1.3.0 has 0e47, you probably are on 1.2.0 or earlier. Can you try pip install pakettic --upgrade and see if this solves your issue?

grahambates commented 7 months ago

Yeah you're right I was on 1.2