Skip to content

Commit

Permalink
Support more line continuations in shell-expanded string syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
laniakea64 committed Oct 5, 2024
1 parent 52266f0 commit e4a92e6
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 6 deletions.
15 changes: 9 additions & 6 deletions syntax/just.vim
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ syn region justShellExpandRawString start=/\v\k@1<!x'''/ end=/'''/
\ contains=justShellExpandVarRaw,justDollarEscape
syn region justShellExpandString
\ start=/\v\k@1<!x"/ skip=/\\\\\|\\"/ end=/"/
\ contains=justStringEscapeSequence,justStringUEscapeSequence,justStringEscapeError,justShellExpandVar,justDollarEscape
\ contains=justStringEscapeSequence,justStringUEscapeSequence,justStringEscapeError,justShellExpandVar,justDollarEscape,justDollarEscapeSplit
syn region justShellExpandString
\ start=/\v\k@1<!x"""/ skip=/\\\\\|\\"/ end=/"""/
\ contains=justStringEscapeSequence,justStringUEscapeSequence,justStringEscapeError,justShellExpandVar,justDollarEscape
\ contains=justStringEscapeSequence,justStringUEscapeSequence,justStringEscapeError,justShellExpandVar,justDollarEscape,justDollarEscapeSplit

syn cluster justStringLiterals
\ contains=justRawString,justString,justShellExpandRawString,justShellExpandString
Expand All @@ -59,8 +59,8 @@ syn match justRegexReplacement

syn region justRawStrRegexRepl start=/\v'/ end=/'/ contained contains=justRegexCapture,justDollarEscape
syn region justRawStrRegexRepl start=/\v'''/ end=/'''/ contained contains=justRegexCapture,justDollarEscape
syn region justStringRegexRepl start=/\v"/ skip=/\\\\\|\\"/ end=/"/ contained contains=justStringEscapeSequence,justStringUEscapeSequence,justStringEscapeError,justRegexCapture,justDollarEscape
syn region justStringRegexRepl start=/\v"""/ skip=/\\\\\|\\"/ end=/"""/ contained contains=justStringEscapeSequence,justStringUEscapeSequence,justStringEscapeError,justRegexCapture,justDollarEscape
syn region justStringRegexRepl start=/\v"/ skip=/\\\\\|\\"/ end=/"/ contained contains=justStringEscapeSequence,justStringUEscapeSequence,justStringEscapeError,justRegexCapture,justDollarEscape,justDollarEscapeSplit
syn region justStringRegexRepl start=/\v"""/ skip=/\\\\\|\\"/ end=/"""/ contained contains=justStringEscapeSequence,justStringUEscapeSequence,justStringEscapeError,justRegexCapture,justDollarEscape,justDollarEscapeSplit
syn match justRegexCapture '\v\$%(\w+|\{\w+\})' contained
syn cluster justStringsWithRegexCapture contains=justRawStrRegexRepl,justStringRegexRepl

Expand Down Expand Up @@ -282,13 +282,15 @@ syn match justShellExpandVarRaw '\v\$%(\{\_[^}]*\}|\w+)' contained contains=just
syn match justShellExpandRawDefaultDelimiter '\V:-' contained nextgroup=justShellExpandRawDefaultValue
syn match justShellExpandRawDefaultValue '\v\_[^}]*' contained
syn match justShellExpandVar '\v\$%(\w|\\\n\s*)+' contained
syn region justShellExpandVar start='\V${' end='}' contains=justShellExpandDefault,justStringEscapeSequence,justStringUEscapeSequence,justStringEscapeError
syn region justShellExpandVar start='\v\$%(\\\n\s*)*\{' end='\V}' contains=justShellExpandDefaultDelimiter,justStringEscapeSequence,justStringUEscapeSequence,justStringEscapeError
syn match justShellExpandDefaultDelimiter '\v:%(\\\n\s*)*-@=' contained nextgroup=justShellExpandDefault
syn region justShellExpandDefault
\ matchgroup=justShellExpandDefaultDelimiter start='\V:-' end='\v\}@='
\ matchgroup=justShellExpandDefaultDelimiter start='\V-' end='\v\}@='
\ contained
\ contains=justStringEscapeSequence,justStringUEscapeSequence,justStringEscapeError

syn match justDollarEscape '\V$$' contained
syn match justDollarEscapeSplit '\v\$%(\\\n\s*)*\$' contained

syn cluster justExprBase contains=@justAllStrings,@justBuiltInFunctions,justConditional,justOperator,justConstant
syn cluster justExpr contains=@justExprBase,justExprParen,justConditionalBraces,justReplaceRegex
Expand Down Expand Up @@ -334,6 +336,7 @@ hi def link justConditional Conditional
hi def link justConstant Constant
hi def link justCurlyBraces Special
hi def link justDollarEscape Special
hi def link justDollarEscapeSplit Special
hi def link justExport Statement
hi def link justFunction Function
hi def link justImportStatement Include
Expand Down
15 changes: 15 additions & 0 deletions tests/cases/expressions.html
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,21 @@
<span class="Character"> baz</span>
<span class="Character"> </span><span class="PreProc">}</span>
<span class="String">'''</span>
shell_expanded8 <span class="Operator">:=</span> <span class="String">x"""</span>
<span class="String"> </span><span class="Special">$</span><span class="Special">\</span>
<span class="Special"> $</span><span class="Special">\</span>
<span class="String"> </span><span class="PreProc">$</span><span class="Special">\</span>
<span class="PreProc"> {</span><span class="Special">\</span>
<span class="PreProc"> F</span><span class="Special">\</span>
<span class="PreProc"> O</span><span class="Special">\</span>
<span class="PreProc"> O</span><span class="Special">\</span>
<span class="PreProc"> </span><span class="Operator">:</span><span class="Special">\</span>
<span class="Operator"> -</span><span class="Special">\</span>
<span class="Character"> f</span><span class="Special">\</span>
<span class="Character"> o</span><span class="Special">\</span>
<span class="Character"> o</span><span class="Special">\</span>
<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>)

Expand Down
15 changes: 15 additions & 0 deletions tests/cases/expressions.just
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,21 @@ shell_expanded7 := x'''
baz
}
'''
shell_expanded8 := x"""
$\
$\
$\
{\
F\
O\
O\
:\
-\
f\
o\
o\
}\
"""

_true := assert('1' != '0', '1 is not 0')

Expand Down

0 comments on commit e4a92e6

Please sign in to comment.