dansanderson / picotool

Tools and Python libraries for manipulating Pico-8 game files. http://www.lexaloffle.com/pico-8.php
MIT License
376 stars 45 forks source link

build command fails on bitwise and #70

Closed vincent-io closed 3 years ago

vincent-io commented 4 years ago

Pico-8 version 0.2.0 introduced the & operator to do bitwise and (deprecating https://pico-8.fandom.com/wiki/Band), but this is not supported by picotool:

Traceback (most recent call last):
  File "picotool/p8tool", line 8, in <module>
    sys.exit(tool.main(sys.argv[1:]))
  File "picotool/pico8/tool.py", line 592, in main
    return args.func(args)
  File "picotool/pico8/build/build.py", line 255, in do_build
    infh, version=game.DEFAULT_VERSION)
  File "picotool/pico8/lua/lua.py", line 132, in from_lines
    result.update_from_lines(lines)
  File "picotool/pico8/lua/lua.py", line 141, in update_from_lines
    self._lexer.process_lines(lines)
  File "picotool/pico8/lua/lexer.py", line 470, in process_lines
    self._process_line(line)
  File "picotool/pico8/lua/lexer.py", line 458, in _process_line
    self._cur_charno + 1)
pico8.lua.lexer.LexerError: Syntax error (remaining:b'&recording[ticks] == 1 ) then\n') at line 640 char 31
hsandt commented 4 years ago

Same thing for | (bor, same error), ^^ (xor), << (shl), >> (shr), >>> (lshr), <<> (rotl), >>< (rotr). | has the same error as &, the others trigger

pico8.lua.parser.ParserError: exp2 in binop

hsandt commented 4 years ago

Not sure why, but adding b'&', b'|', b'^^', b'<<', b'>>', b'>>>', b'<<>', b'>><' in BINOP_PATS in parser.lua is not enough, now I get:

... File ".../picotool/pico8/lua/parser.py", line 719, in _exp return self._exp_binop(exp_term) File ".../picotool/pico8/lua/parser.py", line 751, in _exp_binop exp_second = self._assert(self._exp_term(), 'exp2 in binop') File ".../picotool/pico8/lua/parser.py", line 339, in _assert raise ParserError(desc, token=self._peek()) pico8.lua.parser.ParserError: exp2 in binop at line 117 char 24

dansanderson commented 3 years ago

I added the binary operators in 54b84fe74b95c98a562822b2c42f6b3e9f4c0690. (Your change may not have worked because the lexer patterns are ordering sensitive, e.g. >>> has to come before >>.)

I added the unary operators in dd7b9b40ec5f7598cc36d009f30286aa0b0d575a.