parse EOL as a token

This commit is contained in:
2026-05-15 00:16:13 -07:00
parent c8ad7e74e7
commit 64e5467062
8 changed files with 16909 additions and 15378 deletions
@@ -0,0 +1,249 @@
================================================================
shorthand if — single statement body, terminated by newline
================================================================
if (cond) honk()
toot()
----------------------------------------------------------------
(chunk
(shorthand_if_statement
condition: (identifier)
consequence: (function_call
name: (identifier)
arguments: (arguments)))
(function_call
name: (identifier)
arguments: (arguments)))
================================================================
shorthand if — single statement body, terminated by EOF
================================================================
if (cond) honk()
----------------------------------------------------------------
(chunk
(shorthand_if_statement
condition: (identifier)
consequence: (function_call
name: (identifier)
arguments: (arguments))))
================================================================
shorthand if — multi-statement body collected into shorthand
================================================================
if (is_falling()) wheeee() splat()
----------------------------------------------------------------
(chunk
(shorthand_if_statement
condition: (function_call
name: (identifier)
arguments: (arguments))
consequence: (function_call
name: (identifier)
arguments: (arguments))
consequence: (function_call
name: (identifier)
arguments: (arguments))))
================================================================
shorthand if — same-line else
================================================================
if (cond) honk() else toot()
----------------------------------------------------------------
(chunk
(shorthand_if_statement
condition: (identifier)
consequence: (function_call
name: (identifier)
arguments: (arguments))
alternative: (function_call
name: (identifier)
arguments: (arguments))))
================================================================
shorthand if — same-line multi-statement else
================================================================
if (cond) honk() else toot() squawk()
----------------------------------------------------------------
(chunk
(shorthand_if_statement
condition: (identifier)
consequence: (function_call
name: (identifier)
arguments: (arguments))
alternative: (function_call
name: (identifier)
arguments: (arguments))
alternative: (function_call
name: (identifier)
arguments: (arguments))))
================================================================
shorthand if nested in standard if — `else` on later line binds
to OUTER if, not the shorthand (PICO-8 line-significance)
================================================================
if is_noisy then
if (is_goose()) honk()
else
toot()
end
----------------------------------------------------------------
(chunk
(if_statement
condition: (identifier)
consequence: (block
(shorthand_if_statement
condition: (function_call
name: (identifier)
arguments: (arguments))
consequence: (function_call
name: (identifier)
arguments: (arguments))))
alternative: (else_statement
body: (block
(function_call
name: (identifier)
arguments: (arguments))))))
================================================================
shorthand if — line comment between body and newline still
terminates the shorthand at the newline (line comment is in
extras and is attached to the deepest enclosing node)
================================================================
if (cond) honk() -- inline
toot()
----------------------------------------------------------------
(chunk
(shorthand_if_statement
condition: (identifier)
consequence: (function_call
name: (identifier)
arguments: (arguments))
(comment
content: (comment_content)))
(function_call
name: (identifier)
arguments: (arguments)))
================================================================
shorthand if inside a do-block — newline before `end` terminates
shorthand, then `end` closes the do-block
================================================================
do
if (cond) honk()
end
----------------------------------------------------------------
(chunk
(do_statement
body: (block
(shorthand_if_statement
condition: (identifier)
consequence: (function_call
name: (identifier)
arguments: (arguments))))))
================================================================
shorthand while — multi-statement body, terminated by newline
================================================================
while (running) tick() draw()
cleanup()
----------------------------------------------------------------
(chunk
(shorthand_while_statement
condition: (identifier)
body: (function_call
name: (identifier)
arguments: (arguments))
body: (function_call
name: (identifier)
arguments: (arguments)))
(function_call
name: (identifier)
arguments: (arguments)))
================================================================
shorthand while — single statement body, terminated by EOF
================================================================
while (cond) tick()
----------------------------------------------------------------
(chunk
(shorthand_while_statement
condition: (identifier)
body: (function_call
name: (identifier)
arguments: (arguments))))
================================================================
nested shorthand ifs on the same line — a single newline must
terminate BOTH shorthands (otherwise the outer one greedily
absorbs the next-line statement)
================================================================
if (a) if (b) c()
d()
----------------------------------------------------------------
(chunk
(shorthand_if_statement
condition: (identifier)
consequence: (shorthand_if_statement
condition: (identifier)
consequence: (function_call
name: (identifier)
arguments: (arguments))))
(function_call
name: (identifier)
arguments: (arguments)))
================================================================
standard if with parenthesized condition coexists with shorthand
— GLR resolves on the token after `)` (then vs statement)
================================================================
if (cond) then a() end
if (cond) a()
----------------------------------------------------------------
(chunk
(if_statement
condition: (parenthesized_expression
(identifier))
consequence: (block
(function_call
name: (identifier)
arguments: (arguments))))
(shorthand_if_statement
condition: (identifier)
consequence: (function_call
name: (identifier)
arguments: (arguments))))