diff --git a/lib/spitfire.ex b/lib/spitfire.ex index be54d5c..7d8688f 100644 --- a/lib/spitfire.ex +++ b/lib/spitfire.ex @@ -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) diff --git a/test/spitfire_test.exs b/test/spitfire_test.exs index 1dff579..9b0109f 100644 --- a/test/spitfire_test.exs +++ b/test/spitfire_test.exs @@ -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