Skip to content

Commit

Permalink
Fix highlighting of replacement capture substitutions in `replace_reg…
Browse files Browse the repository at this point in the history
…ex` calls with trailing comma
  • Loading branch information
laniakea64 committed May 1, 2024
1 parent 58f6405 commit 6a15805
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 2 deletions.
9 changes: 7 additions & 2 deletions syntax/just.vim
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,13 @@ syn region justString start=/"""/ skip=/\\\\\|\\"/ end=/"""/ contains=justLineCo
syn cluster justStringLiterals contains=justRawString,justString
syn cluster justAllStrings contains=justBacktick,justRawString,justString

syn match justRegexReplacement /\v,%(\_s|\\\n)*%('\_[^']*'|'''%(\_.%(''')@!)*\_.?''')%(\_s|\\\n)*\)/me=e-1 transparent contained contains=@justExpr,@justStringsWithRegexCapture
syn match justRegexReplacement /\v,%(\_s|\\\n)*%("%(\_[^"]|\\")*"|"""%(\_.%(""")@!)*\_.?""")%(\_s|\\\n)*\)/me=e-1 transparent contained contains=@justExpr,@justStringsWithRegexCapture
syn match justRegexReplacement
\ /\v,%(\_s|\\\n)*%('\_[^']*'|'''%(\_.%(''')@!)*\_.?''')%(\_s|\\\n)*%(,%(\_s|\\\n)*)?\)/me=e-1
\ transparent contained contains=@justExpr,@justStringsWithRegexCapture
syn match justRegexReplacement
\ /\v,%(\_s|\\\n)*%("%(\_[^"]|\\")*"|"""%(\_.%(""")@!)*\_.?""")%(\_s|\\\n)*%(,%(\_s|\\\n)*)?\)/me=e-1
\ transparent contained contains=@justExpr,@justStringsWithRegexCapture

syn region justRawStrRegexRepl start=/\v'/ end=/'/ contained contains=justRegexCapture
syn region justRawStrRegexRepl start=/\v'''/ end=/'''/ contained contains=justRegexCapture
syn region justStringRegexRepl start=/\v"/ skip=/\\\\\|\\"/ end=/"/ contained contains=justLineContinuation,justStringEscapeSequence,justRegexCapture
Expand Down
12 changes: 12 additions & 0 deletions tests/cases/replace_regex-captures.html
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,18 @@
foo8 <span class="Operator">:=</span> <span class="Function">replace_regex</span>(<span class="String">"test123"</span>, <span class="String">'\w(\d+)'</span>, <span class="String">'''</span>
<span class="String"> \t'</span><span class="Constant">$1</span><span class="String">'''</span>)

foo9 <span class="Operator">:=</span> <span class="Function">replace_regex</span>(<span class="String">"trailing comma is accepted after the final argument,"</span>,
<span class="String">"(</span><span class="Special">\\</span><span class="String">W+)"</span>, <span class="Special">\</span>
<span class="String">"</span><span class="Constant">${1}</span><span class="String">_</span><span class="Constant">$1</span><span class="String">"</span>,
)

foo10 <span class="Operator">:=</span> <span class="Function">replace_regex</span>(<span class="String">"_abcdef"</span>,
<span class="String">'(\w)[a-z]+'</span>, <span class="Special">\</span>

<span class="String">'</span><span class="Constant">${1}</span><span class="String">'</span>
, <span class="Special">\</span>
)

not_a_replacement <span class="Operator">:=</span> <span class="String">'test $1 test '</span>
not_a_replacement_2 <span class="Operator">:=</span> <span class="String">"test $Abc_ test"</span>

Expand Down
12 changes: 12 additions & 0 deletions tests/cases/replace_regex-captures.just
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,18 @@ foo7 := replace_regex("Some text.", '([^a-z])', '$$1')
foo8 := replace_regex("test123", '\w(\d+)', '''
\t'$1''')

foo9 := replace_regex("trailing comma is accepted after the final argument,",
"(\\W+)", \
"${1}_$1",
)

foo10 := replace_regex("_abcdef",
'(\w)[a-z]+', \

'${1}'
, \
)

not_a_replacement := 'test $1 test '
not_a_replacement_2 := "test $Abc_ test"

Expand Down

0 comments on commit 6a15805

Please sign in to comment.