Skip to content

Commit

Permalink
Initial support for \u{...} escape sequences
Browse files Browse the repository at this point in the history
  • Loading branch information
laniakea64 committed Oct 1, 2024
1 parent 42d6485 commit 639f9cb
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 14 deletions.
33 changes: 19 additions & 14 deletions syntax/just.vim
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,19 @@ syn region justBacktick start=/`/ end=/`/
syn region justBacktick start=/```/ end=/```/
syn region justRawString start=/'/ end=/'/
syn region justRawString start=/'''/ end=/'''/
syn region justString start=/"/ skip=/\\\\\|\\"/ end=/"/ contains=justStringEscapeSequence
syn region justString start=/"""/ skip=/\\\\\|\\"/ end=/"""/ contains=justStringEscapeSequence
syn region justString start=/"/ skip=/\\\\\|\\"/ end=/"/ contains=justStringEscapeSequence,justStringUEscapeSequence
syn region justString start=/"""/ skip=/\\\\\|\\"/ end=/"""/ contains=justStringEscapeSequence,justStringUEscapeSequence

syn region justShellExpandRawString start=/\v\k@1<!x'/ end=/'/
\ contains=justShellExpandVarRaw,justDollarEscape
syn region justShellExpandRawString start=/\v\k@1<!x'''/ end=/'''/
\ contains=justShellExpandVarRaw,justDollarEscape
syn region justShellExpandString
\ start=/\v\k@1<!x"/ skip=/\\\\\|\\"/ end=/"/
\ contains=justStringEscapeSequence,justShellExpandVar,justDollarEscape
\ contains=justStringEscapeSequence,justStringUEscapeSequence,justShellExpandVar,justDollarEscape
syn region justShellExpandString
\ start=/\v\k@1<!x"""/ skip=/\\\\\|\\"/ end=/"""/
\ contains=justStringEscapeSequence,justShellExpandVar,justDollarEscape
\ contains=justStringEscapeSequence,justStringUEscapeSequence,justShellExpandVar,justDollarEscape

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,justRegexCapture,justDollarEscape
syn region justStringRegexRepl start=/\v"""/ skip=/\\\\\|\\"/ end=/"""/ contained contains=justStringEscapeSequence,justRegexCapture,justDollarEscape
syn region justStringRegexRepl start=/\v"/ skip=/\\\\\|\\"/ end=/"/ contained contains=justStringEscapeSequence,justStringUEscapeSequence,justRegexCapture,justDollarEscape
syn region justStringRegexRepl start=/\v"""/ skip=/\\\\\|\\"/ end=/"""/ contained contains=justStringEscapeSequence,justStringUEscapeSequence,justRegexCapture,justDollarEscape
syn match justRegexCapture '\v\$%(\w+|\{\w+\})' contained
syn cluster justStringsWithRegexCapture contains=justRawStrRegexRepl,justStringRegexRepl

Expand All @@ -72,6 +72,7 @@ syn region justStringInShebangBody start=/\v\\@1<!'/ end=/'/ contained contains=
syn region justStringInShebangBody start=/\v\\@1<!"/ skip=/\v\\@1<!\\"/ end=/"/ contained contains=justInterpolation,@justOtherCurlyBraces,justShebangIndentError

syn match justStringEscapeSequence '\v\\[tnr"\\]' contained
syn match justStringUEscapeSequence '\v\\u\{[0-9A-Fa-f]{1,6}\}' contained

syn match justAssignmentOperator "\V:=" contained

Expand Down Expand Up @@ -276,12 +277,15 @@ syn match justOperator "\V/"
syn keyword justConstant
\ HEX HEXLOWER HEXUPPER

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

syn match justDollarEscape '\V$$' contained

Expand Down Expand Up @@ -365,9 +369,9 @@ hi def link justSetKeywords Keyword
hi def link justShebang SpecialComment
hi def link justShebangBody Number
hi def link justShebangIndentError Error
hi def link justShellExpandDefault Operator
hi def link justShellExpandDefaultValue Character
hi def link justShellExpandRawDefault Operator
hi def link justShellExpandDefault Character
hi def link justShellExpandDefaultDelimiter Operator
hi def link justShellExpandRawDefaultDelimiter Operator
hi def link justShellExpandRawDefaultValue Character
hi def link justShellExpandRawString String
hi def link justShellExpandString String
Expand All @@ -379,6 +383,7 @@ hi def link justStringEscapeSequence Special
hi def link justStringInShebangBody String
hi def link justStringInsideBody String
hi def link justStringRegexRepl String
hi def link justStringUEscapeSequence Special
hi def link justUnexport Statement
hi def link justUserDefinedError Exception
hi def link justVariadicPrefix Statement
Expand Down
10 changes: 10 additions & 0 deletions tests/cases/expressions.html
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,13 @@
<span class="Type">[private]</span>
hidden <span class="Operator">:=</span> <span class="String">'foo'</span>
not_hidden <span class="Operator">:=</span> <span class="String">'-'</span> <span class="Operator">+</span> hidden

u_escape <span class="Operator">:=</span> <span class="String">"test </span><span class="Special">\u{1F916}</span><span class="String"> test"</span>
u_escape_triple_quoted <span class="Operator">:=</span> <span class="String">"""</span>
<span class="String"> test</span>
<span class="String"> </span><span class="Special">\u{1f9Ea}</span>
<span class="String"> test</span>
<span class="String">"""</span>
u_escape_shell_expanded <span class="Operator">:=</span> <span class="String">x"shell </span><span class="PreProc">${FOO</span><span class="Operator">:-</span><span class="Character">(</span><span class="Special">\u{1f41a}</span><span class="Character">)</span><span class="PreProc">}</span><span class="String"> shell"</span>
u_escape_in_replace_regex <span class="Operator">:=</span> <span class="Function">replace_regex</span>(<span class="String">'foo'</span>, <span class="String">'^.'</span>, <span class="String">"</span><span class="Special">\u{46}</span><span class="String">"</span>)
not_u_escape <span class="Operator">:=</span> <span class="String">'\u{1F916}'</span>
10 changes: 10 additions & 0 deletions tests/cases/expressions.just
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,13 @@ now_utc := datetime_utc('%Y-%m-%d %H:%M:%S %Z')
[private]
hidden := 'foo'
not_hidden := '-' + hidden

u_escape := "test \u{1F916} test"
u_escape_triple_quoted := """
test
\u{1f9Ea}
test
"""
u_escape_shell_expanded := x"shell ${FOO:-(\u{1f41a})} shell"
u_escape_in_replace_regex := replace_regex('foo', '^.', "\u{46}")
not_u_escape := '\u{1F916}'

0 comments on commit 639f9cb

Please sign in to comment.