Skip to content

Commit

Permalink
semantically better highlight choices for conditional expression oper…
Browse files Browse the repository at this point in the history
…ators and subsequent dependencies delimiter
  • Loading branch information
laniakea64 committed Dec 15, 2024
1 parent ec52d02 commit 383384b
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 21 deletions.
12 changes: 7 additions & 5 deletions syntax/just.vim
Original file line number Diff line number Diff line change
Expand Up @@ -268,9 +268,10 @@ syn match justRecipeDepParenName '\v%(\(\n?)@3<=%(\_s|\\\n)*\h\k*'

syn cluster justBuiltInFunctions contains=justFunctionCall,justUserDefinedError

syn match justOperator "\V=="
syn match justOperator "\V!="
syn match justOperator "\V=~"
syn match justConditionalOperator "\V=="
syn match justConditionalOperator "\V!="
syn match justConditionalOperator "\V=~"

syn match justOperator "\V+"
syn match justOperator "\V/"

Expand All @@ -294,7 +295,7 @@ syn region justShellExpandDefault
syn match justDollarEscape '\V$$' contained
syn match justDollarEscapeSplit '\v\$%(\\\n\s*)*\$' contained

syn cluster justExprBase contains=@justAllStrings,@justBuiltInFunctions,justConditional,justOperator,justConstant
syn cluster justExprBase contains=@justAllStrings,@justBuiltInFunctions,justConditional,justConditionalOperator,justOperator,justConstant
syn cluster justExpr contains=@justExprBase,justExprParen,justConditionalBraces,justReplaceRegex
syn cluster justExprInInterp contains=@justExprBase,justName,justExprParenInInterp,justConditionalBracesInInterp,justReplaceRegexInInterp

Expand Down Expand Up @@ -335,6 +336,7 @@ hi def link justComment Comment
hi def link justCommentInBody Comment
hi def link justCommentTodo Todo
hi def link justConditional Conditional
hi def link justConditionalOperator Conditional
hi def link justConstant Constant
hi def link justCurlyBraces Special
hi def link justDollarEscape Special
Expand Down Expand Up @@ -366,7 +368,7 @@ hi def link justRecipeAttrSep Operator
hi def link justRecipeAttrValueColon Operator
hi def link justRecipeColon Operator
hi def link justRecipeDepParamsParen Delimiter
hi def link justRecipeSubsequentDeps Operator
hi def link justRecipeSubsequentDeps Delimiter
hi def link justRegexCapture Identifier
hi def link justSet Statement
hi def link justSetDeprecatedKeywords Underlined
Expand Down
2 changes: 1 addition & 1 deletion tests/cases/expressions.html
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
<span class="Character"> </span><span class="PreProc">}</span><span class="Special">\</span>
<span class="String">"""</span>

_true <span class="Operator">:=</span> <span class="Exception">assert</span>(<span class="String">'1'</span> <span class="Operator">!=</span> <span class="String">'0'</span>, <span class="String">'1 is not 0'</span>)
_true <span class="Operator">:=</span> <span class="Exception">assert</span>(<span class="String">'1'</span> <span class="Conditional">!=</span> <span class="String">'0'</span>, <span class="String">'1 is not 0'</span>)

shell_command <span class="Operator">:=</span> <span class="Function">shell</span>(<span class="String">'echo "$@"'</span>, _true, random1)

Expand Down
2 changes: 1 addition & 1 deletion tests/cases/invalid.html
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
<span class="Number">&Tab;echo </span><span class="String">"</span><span class="Special">{{{{</span><span class="Error">{{{{{</span><span class="String">Odd number of opening curly braces is an error.}}}}}"</span>

<span class="Function">early-interpolation-close</span> <span class="Identifier">foo</span><span class="Operator">:</span>
<span class="Number"> echo </span><span class="Delimiter">{{</span><span class="Normal"> </span><span class="Conditional">if</span><span class="Normal"> </span><span class="Identifier">foo</span><span class="Normal"> </span><span class="Operator">==</span><span class="Normal"> </span><span class="String">"bar"</span><span class="Normal"> { </span><span class="String">"hello"</span><span class="Normal"> } </span><span class="Conditional">else</span><span class="Normal"> { </span><span class="String">"goodbye"</span><span class="Normal"> </span><span class="Delimiter">}}</span><span class="Number">}</span>
<span class="Number"> echo </span><span class="Delimiter">{{</span><span class="Normal"> </span><span class="Conditional">if</span><span class="Normal"> </span><span class="Identifier">foo</span><span class="Normal"> </span><span class="Conditional">==</span><span class="Normal"> </span><span class="String">"bar"</span><span class="Normal"> { </span><span class="String">"hello"</span><span class="Normal"> } </span><span class="Conditional">else</span><span class="Normal"> { </span><span class="String">"goodbye"</span><span class="Normal"> </span><span class="Delimiter">}}</span><span class="Number">}</span>
<span class="Function">other-recipe</span><span class="Operator">:</span>
<span class="Number">&Tab;echo interpolation ended in last recipe</span>

Expand Down
16 changes: 8 additions & 8 deletions tests/cases/kitchen-sink.html
Original file line number Diff line number Diff line change
Expand Up @@ -94,13 +94,13 @@
_another_var <span class="Operator">:=</span> <span class="Function">env_var_or_default</span>(<span class="String">"HOME"</span>, <span class="Function">justfile_directory</span>())
python <span class="Operator">:=</span> <span class="Special">`which python`</span>

exists <span class="Operator">:=</span> <span class="Conditional">if</span> <span class="Function">path_exists</span>(<span class="Function">just_executable</span>()) <span class="Operator">=~</span> <span class="String">'^/User'</span> { <span class="Function">uuid</span>() } <span class="Conditional">else</span> { <span class="String">'yeah'</span> }
exists <span class="Operator">:=</span> <span class="Conditional">if</span> <span class="Function">path_exists</span>(<span class="Function">just_executable</span>()) <span class="Conditional">=~</span> <span class="String">'^/User'</span> { <span class="Function">uuid</span>() } <span class="Conditional">else</span> { <span class="String">'yeah'</span> }

foo <span class="Operator">:=</span> <span class="Conditional">if</span> <span class="Function">env_var</span>(<span class="String">"_"</span>) <span class="Operator">==</span> <span class="String">"/usr/bin/env"</span> { <span class="Special">`touch /tmp/a_file`</span> } <span class="Conditional">else</span> { <span class="String">"dummy-value"</span> }
foo_b <span class="Operator">:=</span> <span class="Conditional">if</span> <span class="String">"hello"</span> <span class="Operator">==</span> <span class="String">"goodbye"</span> { <span class="String">"xyz"</span> } <span class="Conditional">else</span> { <span class="Conditional">if</span> <span class="String">"no"</span> <span class="Operator">==</span> <span class="String">"no"</span> { <span class="String">"yep"</span>} <span class="Conditional">else</span> { <span class="Exception">error</span>(<span class="String">"123"</span>) } }
foo_c <span class="Operator">:=</span> <span class="Conditional">if</span> <span class="String">"hello"</span> <span class="Operator">==</span> <span class="String">"goodbye"</span> {
foo <span class="Operator">:=</span> <span class="Conditional">if</span> <span class="Function">env_var</span>(<span class="String">"_"</span>) <span class="Conditional">==</span> <span class="String">"/usr/bin/env"</span> { <span class="Special">`touch /tmp/a_file`</span> } <span class="Conditional">else</span> { <span class="String">"dummy-value"</span> }
foo_b <span class="Operator">:=</span> <span class="Conditional">if</span> <span class="String">"hello"</span> <span class="Conditional">==</span> <span class="String">"goodbye"</span> { <span class="String">"xyz"</span> } <span class="Conditional">else</span> { <span class="Conditional">if</span> <span class="String">"no"</span> <span class="Conditional">==</span> <span class="String">"no"</span> { <span class="String">"yep"</span>} <span class="Conditional">else</span> { <span class="Exception">error</span>(<span class="String">"123"</span>) } }
foo_c <span class="Operator">:=</span> <span class="Conditional">if</span> <span class="String">"hello"</span> <span class="Conditional">==</span> <span class="String">"goodbye"</span> {
<span class="String">"xyz"</span>
} <span class="Conditional">else</span> <span class="Conditional">if</span> <span class="String">"a"</span> <span class="Operator">==</span> <span class="String">"a"</span> {
} <span class="Conditional">else</span> <span class="Conditional">if</span> <span class="String">"a"</span> <span class="Conditional">==</span> <span class="String">"a"</span> {
<span class="String">"abc"</span>
} <span class="Conditional">else</span> {
<span class="String">"123"</span>
Expand All @@ -111,7 +111,7 @@


<span class="Function">bar2</span> <span class="Identifier">foo_stuff</span><span class="Operator">:</span>
<span class="Number"> echo </span><span class="Delimiter">{{</span><span class="Normal"> </span><span class="Conditional">if</span><span class="Normal"> </span><span class="Identifier">foo_stuff</span><span class="Normal"> </span><span class="Operator">==</span><span class="Normal"> </span><span class="String">"bar"</span><span class="Normal"> { </span><span class="String">"hello"</span><span class="Normal"> } </span><span class="Conditional">else</span><span class="Normal"> { </span><span class="String">"goodbye"</span><span class="Normal"> } </span><span class="Delimiter">}}</span>
<span class="Number"> echo </span><span class="Delimiter">{{</span><span class="Normal"> </span><span class="Conditional">if</span><span class="Normal"> </span><span class="Identifier">foo_stuff</span><span class="Normal"> </span><span class="Conditional">==</span><span class="Normal"> </span><span class="String">"bar"</span><span class="Normal"> { </span><span class="String">"hello"</span><span class="Normal"> } </span><span class="Conditional">else</span><span class="Normal"> { </span><span class="String">"goodbye"</span><span class="Normal"> } </span><span class="Delimiter">}}</span>

<span class="Function">executable</span><span class="Operator">:</span>
<span class="Number"> </span><span class="Special">@</span><span class="Number">echo The executable is at: </span><span class="Delimiter">{{</span><span class="Function">just_executable</span><span class="Normal">()</span><span class="Delimiter">}}</span>
Expand All @@ -131,7 +131,7 @@
<span class="Number"> </span><span class="Special">@</span><span class="Number">echo </span><span class="String">"Starting server with database $DATABASE_ADDRESS on port $SERVER_PORT…"</span>


shebang <span class="Operator">:=</span> <span class="Conditional">if</span> <span class="Function">os</span>() <span class="Operator">==</span> <span class="String">'windows'</span> {
shebang <span class="Operator">:=</span> <span class="Conditional">if</span> <span class="Function">os</span>() <span class="Conditional">==</span> <span class="String">'windows'</span> {
<span class="String">'powershell.exe'</span>
} <span class="Conditional">else</span> {
<span class="String">'/usr/bin/env pwsh'</span>
Expand Down Expand Up @@ -205,7 +205,7 @@
<span class="Function">a</span><span class="Operator">:</span>
<span class="Number"> echo </span><span class="String">'A!'</span>

<span class="Function">b</span><span class="Operator">:</span> <span class="Function">a</span> <span class="Operator">&amp;&amp;</span> <span class="Function">d</span>
<span class="Function">b</span><span class="Operator">:</span> <span class="Function">a</span> <span class="Delimiter">&amp;&amp;</span> <span class="Function">d</span>
<span class="Number"> echo </span><span class="String">'B start!'</span>
<span class="Number"> just -f </span><span class="Delimiter">{{</span><span class="Function">justfile</span><span class="Normal">()</span><span class="Delimiter">}}</span><span class="Number"> c</span>
<span class="Number"> echo </span><span class="String">'B end!'</span>
Expand Down
2 changes: 1 addition & 1 deletion tests/cases/line-continuations.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<span class="String">'456'</span> <span class="Operator">+</span> <span class="Special">\</span>
<span class="Conditional">if</span> <span class="Special">\</span>
<span class="String">'a'</span> <span class="Special">\</span>
<span class="Operator">!=</span> <span class="Special">\</span>
<span class="Conditional">!=</span> <span class="Special">\</span>
<span class="String">'b'</span> <span class="Special">\</span>
{<span class="Special">\</span>
<span class="String">'\789'</span>} <span class="Special">\</span>
Expand Down
6 changes: 3 additions & 3 deletions tests/cases/recipes-with-extras.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<span class="Number"> /bin/echo </span><span class="Delimiter">{{</span><span class="Function">quote</span><span class="Normal">(</span><span class="Identifier">firstparam</span><span class="Normal">)</span><span class="Delimiter">}}</span>
<span class="Number"> /bin/echo </span><span class="Delimiter">{{</span><span class="Function">quote</span><span class="Normal">(</span><span class="Identifier">secondparam</span><span class="Normal">)</span><span class="Delimiter">}}</span>

<span class="Function">dependency3</span> <span class="Identifier">theparam</span><span class="Operator">=</span><span class="Delimiter">(</span><span class="String">'a'</span> <span class="Operator">+</span> (<span class="Conditional">if</span> <span class="Function">env_var_or_default</span>(<span class="String">'FOO'</span>, <span class="Function">blake3_file</span>(<span class="Function">justfile</span>())) <span class="Operator">==</span> <span class="String">'1'</span> { <span class="String">' With Foo'</span>} <span class="Conditional">else</span> { <span class="String">' none '</span> <span class="Operator">+</span> p1 <span class="Operator">/</span> p2 }) <span class="Operator">/</span> <span class="String">'b'</span><span class="Delimiter">)</span><span class="Operator">:</span>
<span class="Function">dependency3</span> <span class="Identifier">theparam</span><span class="Operator">=</span><span class="Delimiter">(</span><span class="String">'a'</span> <span class="Operator">+</span> (<span class="Conditional">if</span> <span class="Function">env_var_or_default</span>(<span class="String">'FOO'</span>, <span class="Function">blake3_file</span>(<span class="Function">justfile</span>())) <span class="Conditional">==</span> <span class="String">'1'</span> { <span class="String">' With Foo'</span>} <span class="Conditional">else</span> { <span class="String">' none '</span> <span class="Operator">+</span> p1 <span class="Operator">/</span> p2 }) <span class="Operator">/</span> <span class="String">'b'</span><span class="Delimiter">)</span><span class="Operator">:</span>
<span class="Number"> echo </span><span class="Delimiter">{{</span><span class="Function">quote</span><span class="Normal">(</span><span class="Identifier">theparam</span><span class="Normal">)</span><span class="Delimiter">}}</span>

<span class="Function">dependency4</span><span class="Operator">:</span>
Expand Down Expand Up @@ -98,10 +98,10 @@
<span class="Number">&Tab;echo </span><span class="Delimiter">{{</span><span class="Function">join</span><span class="Normal">(</span><span class="String">'test'</span><span class="Normal">,</span><span class="Identifier">foo</span><span class="Normal">, </span><span class="Special">`echo Bar`</span><span class="Normal">, </span><span class="Identifier">somevar</span><span class="Normal">, </span><span class="String">"2"</span><span class="Normal">)</span><span class="Delimiter">}}</span>
<span class="Number">&Tab;echo </span><span class="Delimiter">{{</span><span class="Function">quote</span><span class="Normal">(</span><span class="Function">blake3</span><span class="Normal">(</span><span class="Identifier">foo</span><span class="Operator">+</span><span class="String">"-"</span><span class="Normal">))</span><span class="Delimiter">}}</span>
<span class="Number">&Tab;echo </span><span class="Delimiter">{{</span><span class="Function">quote</span><span class="Normal">(</span><span class="String">'x'</span><span class="Normal"> </span><span class="Operator">+</span><span class="Normal"> </span><span class="Function">blake3</span><span class="Normal">(</span><span class="Identifier">foo</span><span class="Operator">+</span><span class="String">"-"</span><span class="Operator">+</span><span class="Normal"> </span><span class="Identifier">foo</span><span class="Operator">+</span><span class="String">'-'</span><span class="Operator">+</span><span class="Identifier">foo</span><span class="Normal">) </span><span class="Operator">+</span><span class="Normal"> </span><span class="Identifier">foo</span><span class="Operator">+</span><span class="Normal"> </span><span class="String">'y'</span><span class="Normal">)</span><span class="Delimiter">}}</span>
<span class="Number">&Tab;echo </span><span class="Delimiter">{{</span><span class="Function">quote</span><span class="Normal">(</span><span class="Conditional">if</span><span class="Normal"> </span><span class="Identifier">foo</span><span class="Normal"> </span><span class="Operator">==</span><span class="Normal"> </span><span class="String">'123'</span><span class="Normal"> { </span><span class="String">'321'</span><span class="Normal"> } </span><span class="Conditional">else</span><span class="Normal"> { </span><span class="String">'foo bar'</span><span class="Normal"> } )</span><span class="Delimiter">}}</span>
<span class="Number">&Tab;echo </span><span class="Delimiter">{{</span><span class="Function">quote</span><span class="Normal">(</span><span class="Conditional">if</span><span class="Normal"> </span><span class="Identifier">foo</span><span class="Normal"> </span><span class="Conditional">==</span><span class="Normal"> </span><span class="String">'123'</span><span class="Normal"> { </span><span class="String">'321'</span><span class="Normal"> } </span><span class="Conditional">else</span><span class="Normal"> { </span><span class="String">'foo bar'</span><span class="Normal"> } )</span><span class="Delimiter">}}</span>

<span class="Function">interp_with_conditional</span> <span class="Identifier">foo</span><span class="Operator">:</span>
<span class="Number">&Tab;echo </span><span class="Delimiter">{{</span><span class="Conditional">if</span><span class="Normal"> </span><span class="Identifier">foo</span><span class="Normal"> </span><span class="Operator">!=</span><span class="Normal"> </span><span class="String">'foo'</span><span class="Normal"> { </span><span class="Function">quote</span><span class="Normal">(</span><span class="Identifier">foo</span><span class="Normal">) } </span><span class="Conditional">else</span><span class="Normal"> { </span><span class="Identifier">foo</span><span class="Normal"> </span><span class="Operator">/</span><span class="Normal"> </span><span class="Identifier">foo</span><span class="Normal"> } </span><span class="Delimiter">}}</span>
<span class="Number">&Tab;echo </span><span class="Delimiter">{{</span><span class="Conditional">if</span><span class="Normal"> </span><span class="Identifier">foo</span><span class="Normal"> </span><span class="Conditional">!=</span><span class="Normal"> </span><span class="String">'foo'</span><span class="Normal"> { </span><span class="Function">quote</span><span class="Normal">(</span><span class="Identifier">foo</span><span class="Normal">) } </span><span class="Conditional">else</span><span class="Normal"> { </span><span class="Identifier">foo</span><span class="Normal"> </span><span class="Operator">/</span><span class="Normal"> </span><span class="Identifier">foo</span><span class="Normal"> } </span><span class="Delimiter">}}</span>

<span class="Type">[no-quiet]</span>
<span class="Function">loud</span><span class="Operator">:</span>
Expand Down
Loading

0 comments on commit 383384b

Please sign in to comment.