From 74da824a4255ce650afa02ee6a95aeccadc332f9 Mon Sep 17 00:00:00 2001 From: Michael Davis Date: Mon, 8 May 2023 14:20:21 -0500 Subject: [PATCH] Allow case expressions to be empty This is not technically valid but it improves highlighting for the 'end' token when writing out case expressions. --- grammar.js | 2 +- test/corpus/expressions.txt | 16 ++++++++++++++++ test/highlight/expressions.erl | 7 +++++++ 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/grammar.js b/grammar.js index 64df85f..5ba07b6 100644 --- a/grammar.js +++ b/grammar.js @@ -386,7 +386,7 @@ module.exports = grammar({ "case", field("subject", $._expression), "of", - sep($.clause, ";"), + optional(sep($.clause, ";")), "end" ), diff --git a/test/corpus/expressions.txt b/test/corpus/expressions.txt index 4390436..f24016f 100644 --- a/test/corpus/expressions.txt +++ b/test/corpus/expressions.txt @@ -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))) diff --git a/test/highlight/expressions.erl b/test/highlight/expressions.erl index 0dcadea..8e0ac39 100644 --- a/test/highlight/expressions.erl +++ b/test/highlight/expressions.erl @@ -39,3 +39,10 @@ State#state.config#config.pid %% ^ operator %% ^ type %% ^ property + +case Foo of +%% <- keyword +%% ^ variable +%% ^ keyword +end +%% <- keyword