Skip to content

Commit

Permalink
Improve matching of interpolations
Browse files Browse the repository at this point in the history
  • Loading branch information
laniakea64 committed Apr 9, 2024
1 parent a9ee95f commit a2777b4
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 3 deletions.
8 changes: 5 additions & 3 deletions syntax/just.vim
Original file line number Diff line number Diff line change
Expand Up @@ -180,14 +180,14 @@ syn match justLineContinuation "\\$" containedin=ALLBUT,justComment,justShebang,
syn region justBody
\ start=/\v^\z( +|\t+)%(#!)@!\S/
\ skip='\v\\\n|\n\s*$'
\ end="\v\n\z1@!"
\ end="\v\n\z1@!|%(^\S)@2<=\_.@="
\ contains=justInterpolation,@justOtherCurlyBraces,justLineLeadingSymbol,justLineContinuation,justComment,justStringInsideBody,justIndentError
\ contained

syn region justShebangBody
\ start="\v^\z( +|\t+)#!"
\ skip='\v\\\n|\n\s*$'
\ end="\v\n\z1@!"
\ end="\v\n\z1@!|%(^\S)@2<=\_.@="
\ contains=justInterpolation,@justOtherCurlyBraces,justLineContinuation,justComment,justShebang,justStringInShebangBody,justShebangIndentError
\ contained

Expand All @@ -198,7 +198,8 @@ syn match justShebangIndentError '\v^ +\zs\t\s*\S@='

syn region justInterpolation
\ matchgroup=justInterpolationDelim
\ start="\v%(^\z(\s+)@>.*)@<=\{\{\{@!" end="\v%(%(\\\n\z1|\S)\s*)@<=\}\}|$"
\ start="\v\{\{\{@!" end="\v%(%(\\\n\s|\S)\s*)@<=\}\}|$"
\ matchgroup=justInterpError end='^\S'
\ contained
\ contains=@justExprInInterp

Expand Down Expand Up @@ -289,6 +290,7 @@ hi def link justExport Statement
hi def link justFunction Function
hi def link justImportStatement Include
hi def link justIndentError Error
hi def link justInterpError Error
hi def link justInterpolation Normal
hi def link justInterpolationDelim Delimiter
hi def link justLineContinuation Special
Expand Down
5 changes: 5 additions & 0 deletions tests/cases/invalid.html
Original file line number Diff line number Diff line change
Expand Up @@ -99,3 +99,8 @@
<span class="Error">)</span> <span class="Type">]</span>
<span class="Function">argless-attribute3</span><span class="Operator">:</span>
<span class="Number"> /bin/false</span>

<span class="Function">invalid_multi_line_interp</span><span class="Operator">:</span>
<span class="Number"> echo </span><span class="Delimiter">{{</span><span class="String">"foo"</span><span class="Normal"> </span><span class="Operator">+</span><span class="Normal"> </span><span class="Special">\</span>
<span class="Error">b</span>ar }}
echo this line is not part of the recipe body
5 changes: 5 additions & 0 deletions tests/cases/invalid.just
Original file line number Diff line number Diff line change
Expand Up @@ -99,3 +99,8 @@ argless-attribute2:
) ]
argless-attribute3:
/bin/false

invalid_multi_line_interp:
echo {{"foo" + \
bar }}
echo this line is not part of the recipe body
5 changes: 5 additions & 0 deletions tests/cases/line-continuations.html
Original file line number Diff line number Diff line change
Expand Up @@ -168,3 +168,8 @@
<span class="Function">test13</span><span class="Operator">:</span> <span class="Function">a</span><span class="Special">\</span>

<span class="Number"> echo Test13</span>

<span class="Function">continued_interpolation</span><span class="Operator">:</span>
<span class="Number"> echo </span><span class="Delimiter">{{</span><span class="String">"foo "</span><span class="Normal"> </span><span class="Operator">+</span><span class="Normal"> </span><span class="Special">\</span>
<span class="Normal"> </span><span class="Identifier">f2</span><span class="Normal"> </span><span class="Special">\</span>
<span class="Normal"> </span><span class="Delimiter">}}</span>
5 changes: 5 additions & 0 deletions tests/cases/line-continuations.just
Original file line number Diff line number Diff line change
Expand Up @@ -168,3 +168,8 @@ test12: \
test13: a\

echo Test13

continued_interpolation:
echo {{"foo " + \
f2 \
}}
9 changes: 9 additions & 0 deletions tests/cases/tricky.html
Original file line number Diff line number Diff line change
Expand Up @@ -142,3 +142,12 @@

<span class="Number"> </span>
<span class="Number"> echo end</span>

<span class="Function">triple-quoted-multiline-interp</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="String">"""</span>
<span class="String">[package]</span>
<span class="String">name = "foo"</span>
<span class="String">edition = "2021"</span>

<span class="String">[dependencies]</span>
<span class="String">"""</span><span class="Normal">)</span><span class="Delimiter">}}</span><span class="Number"> &gt; </span><span class="Delimiter">{{</span><span class="Function">quote</span><span class="Normal">(</span><span class="Function">cache_directory</span><span class="Normal">() </span><span class="Operator">/</span><span class="Normal"> </span><span class="String">'Cargo.toml-'</span><span class="Normal"> </span><span class="Operator">+</span><span class="Normal"> </span><span class="Identifier">valid_uuid</span><span class="Normal">)</span><span class="Delimiter">}}</span>
9 changes: 9 additions & 0 deletions tests/cases/tricky.just
Original file line number Diff line number Diff line change
Expand Up @@ -142,3 +142,12 @@ skip-all-whitespace-lines2:
echo end
triple-quoted-multiline-interp:
echo {{quote("""
[package]
name = "foo"
edition = "2021"
[dependencies]
""")}} > {{quote(cache_directory() / 'Cargo.toml-' + valid_uuid)}}

0 comments on commit a2777b4

Please sign in to comment.