Skip to content

Commit

Permalink
Allow case expressions to be empty
Browse files Browse the repository at this point in the history
This is not technically valid but it improves highlighting for the
'end' token when writing out case expressions.
  • Loading branch information
the-mikedavis committed May 8, 2023
1 parent ce0ed25 commit 74da824
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
2 changes: 1 addition & 1 deletion grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ module.exports = grammar({
"case",
field("subject", $._expression),
"of",
sep($.clause, ";"),
optional(sep($.clause, ";")),
"end"
),

Expand Down
16 changes: 16 additions & 0 deletions test/corpus/expressions.txt
Original file line number Diff line number Diff line change
Expand Up @@ -736,3 +736,19 @@ Multi-line anonymous function within larger expression
(arguments
(atom))))))
(arguments))))

================================================================================
case with no body
================================================================================

%% This is not actually valid but improves highlighting.
case Foo of
end.

--------------------------------------------------------------------------------

(source
(line_comment
(comment_content))
(case
(variable)))
7 changes: 7 additions & 0 deletions test/highlight/expressions.erl
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,10 @@ State#state.config#config.pid
%% ^ operator
%% ^ type
%% ^ property

case Foo of
%% <- keyword
%% ^ variable
%% ^ keyword
end
%% <- keyword

0 comments on commit 74da824

Please sign in to comment.