Skip to content

Commit

Permalink
do not treat '- 1' (with space) as one token, per pico8 behaviour
Browse files Browse the repository at this point in the history
  • Loading branch information
thisismypassport committed Oct 17, 2023
1 parent de6a137 commit 7d2a49b
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 0 deletions.
1 change: 1 addition & 0 deletions pico_tokenize.py
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,7 @@ def count_tokens(tokens):
continue

if token.value in ("-", "~") and i+1 < len(tokens) and tokens[i+1].type == TokenType.number and \
token.endidx == tokens[i+1].idx and \
i-1 >= 0 and tokens[i-1].type not in (TokenType.number, TokenType.string, TokenType.ident) and \
tokens[i-1].value not in (")", "]", "}", ";", "end"):
continue
Expand Down
1 change: 1 addition & 0 deletions run_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ def run():
run_stdout_test("linttab", "bad.p8", "--lint", "--error-format", "tabbed",
output="bad-tab.txt", norm_stdout=norm_paths, exit_code=2)
run_stdout_test("count", "bad.p8", "--count", output="badcount.txt")
run_stdout_test("countminus", "minus.p8", "--count", output="minuscount.txt")
run_stdout_test("error", "worse.p8", "--lint", output="worse.txt", norm_stdout=norm_paths, exit_code=1)
run_test("script", "script.p8", "script.p8", "--script", path_join("test_input", "my_script.py"),
"--script-args", "my-script-arg", "--my-script-opt", "123")
Expand Down
3 changes: 3 additions & 0 deletions test_compare/minuscount.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
tokens: 40 0%
chars: 146 0%
compressed: 63 0%
8 changes: 8 additions & 0 deletions test_input/minus.p8
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
__lua__
local ok = -1, (~2)
local ok = -1, (~2)
local ok = -1, (~2)
local ok = -1, (~2)
local ok = -1, (~2)
local bad = - 1, ~ 2
local worse = 1-2, (1)~2

0 comments on commit 7d2a49b

Please sign in to comment.