Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 3 additions & 22 deletions lib/spitfire.ex
Original file line number Diff line number Diff line change
Expand Up @@ -1195,28 +1195,9 @@ defmodule Spitfire do
nl -> [newlines: nl]
end

# Check if we have a semicolon right after -> (possibly after eol)
# Check if there's a leading semicolon right after ->
# Handles both ";expr" and "\n;expr" patterns
has_leading_semicolon =
case peek_token(parser) do
:";" ->
true

:eol ->
# Peek at the next token after eol without consuming
# We need to manually check the token sequence
with {:eol, _} <- parser.current_token,
# Look at the tokens list to find what comes after eol
[{:";", _} | _] <- parser.tokens do
true
else
_ -> false
end

_ ->
false
end
# A semicolon immediately after `->` (with optional newlines in between)
# starts the clause body with an implicit nil expression.
has_leading_semicolon = peek_token_skip_eol(parser) == :";"

parser = eat_eoe_at(parser, 1)

Expand Down
4 changes: 4 additions & 0 deletions test/spitfire_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -2301,6 +2301,10 @@ defmodule SpitfireTest do
assert Spitfire.parse("%e.(){}") == s2q("%e.(){}")
assert Spitfire.parse("%e.(1){}") == s2q("%e.(1){}")
assert Spitfire.parse("%e.(a, b){}") == s2q("%e.(a, b){}")

# with/else stab body with leading semicolon after newline
assert Spitfire.parse("with x <- 1 do :ok else _ -> \n;a end") ==
s2q("with x <- 1 do :ok else _ -> \n;a end")
end
end

Expand Down
Loading