Skip to content

Commit

Permalink
Basic support for recipe attribute arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
laniakea64 committed Jan 13, 2024
1 parent 685505e commit b9e0b22
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 3 deletions.
12 changes: 9 additions & 3 deletions syntax/just.vim
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ syn region justRawString start=/'/ end=/'/
syn region justRawString start=/'''/ end=/'''/
syn region justString start=/"/ skip=/\\\\\|\\"/ end=/"/ contains=justLineContinuation,justStringEscapeSequence
syn region justString start=/"""/ skip=/\\\\\|\\"/ end=/"""/ contains=justLineContinuation,justStringEscapeSequence

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
Expand Down Expand Up @@ -59,12 +61,15 @@ syn match justRecipeColon ":" contained

syn region justRecipeAttributes
\ matchgroup=justRecipeAttr start='\v^%(\\\n)@3<!\[' end='\V]'
\ contains=justRecipeAttr,justRecipeAttrSep
\ contains=justRecipeAttr,justRecipeAttrSep,justRecipeAttrArgs,justRecipeAttrArgError

syn keyword justRecipeAttr
\ confirm linux macos no-cd no-exit-message no-quiet private unix windows
\ contained
syn match justRecipeAttrSep ',' contained
syn region justRecipeAttrArgs matchgroup=justRecipeAttr start='\V(' end='\V)' contained
\ contains=@justStringLiterals
syn match justRecipeAttrArgError '\v\(%(\s|\\?\n)*\)' contained

syn match justRecipeDeclSimple "\v^\@?\h\k*%(%(\s|\\\n)*:\=@!)@="
\ transparent contains=justRecipeName
Expand Down Expand Up @@ -145,7 +150,7 @@ syn match justShellSet
syn region justShellSetValue
\ start='\V[' end='\V]'
\ contained
\ contains=justString,justRawString,justShellSetError
\ contains=@justStringLiterals,justShellSetError

syn match justShellSetError '\v\k+' contained

Expand All @@ -166,7 +171,7 @@ syn region justConditionalBraces start="\v\{\{@!" end="\v\}@=" transparent conta
syn region justConditionalBracesInInterp start="\v\{\{@!" end="\v\}@=" transparent contained contains=@justExprInInterp

syn match justLineLeadingSymbol "\v^%(\\\n)@3<!\s+\zs%(\@-|-\@|\@|-)"
syn match justLineContinuation "\\$" containedin=ALLBUT,justComment,justShebang,@justRawStrings,justPreBodyCommentError
syn match justLineContinuation "\\$" containedin=ALLBUT,justComment,justShebang,@justRawStrings,justPreBodyCommentError,justRecipeAttrArgError

syn region justBody
\ start=/\v^\z( +|\t+)%(#!)@!\S/
Expand Down Expand Up @@ -282,6 +287,7 @@ hi def link justRawString String
hi def link justRawStrRegexRepl String
hi def link justRecipeAt Special
hi def link justRecipeAttr Type
hi def link justRecipeAttrArgError Error
hi def link justRecipeAttrSep Operator
hi def link justRecipeColon Operator
hi def link justRecipeDepParamsParen Delimiter
Expand Down
16 changes: 16 additions & 0 deletions tests/cases/invalid.html
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,19 @@
<span class="String">value</span>
<span class="String">'''</span> <span class="Error">param1</span> <span class="Statement">+</span> <span class="Statement">$</span> <span class="Identifier">param2</span><span class="Operator">:</span>
<span class="Number"> env</span>

<span class="Type">[confirm</span><span class="Error">()</span><span class="Type">]</span>
<span class="Function">argless-attribute1</span><span class="Operator">:</span>
<span class="Number"> /bin/false</span>

<span class="Type">[confirm</span><span class="Error">( )</span><span class="Type">]</span>
<span class="Function">argless-attribute2</span><span class="Operator">:</span>
<span class="Number"> /bin/false</span>

<span class="Type">[confirm</span> <span class="Special">\</span>
<span class="Error">(</span>
<span class="Error"> </span>
<span class="Error"> \</span>
<span class="Error">)</span> <span class="Type">]</span>
<span class="Function">argless-attribute3</span><span class="Operator">:</span>
<span class="Number"> /bin/false</span>
16 changes: 16 additions & 0 deletions tests/cases/invalid.just
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,19 @@ non-default-param-after-default4 param0='''
value
''' param1 + $ param2:
env

[confirm()]
argless-attribute1:
/bin/false

[confirm( )]
argless-attribute2:
/bin/false

[confirm \
(

\
) ]
argless-attribute3:
/bin/false
23 changes: 23 additions & 0 deletions tests/cases/recipes-with-extras.html
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,29 @@
<span class="Function">multiline-attr-no-continuations</span><span class="Operator">:</span>
<span class="Number"> /bin/true</span>


<span class="Type">[confirm(</span><span class="String">"confirm2: Are you sure?"</span><span class="Type">)]</span>
<span class="Function">confirm2</span><span class="Operator">:</span>
<span class="Number"> python3 -c pass</span>

<span class="Type">[confirm</span> <span class="Type">(</span>
<span class="String">'''</span>
<span class="String"> confirm3: Are you sure?'''</span> <span class="Special">\</span>
<span class="Type">)</span>
<span class="Type">]</span>
<span class="Function">confirm3</span><span class="Operator">:</span>
<span class="Number"> python3 -c pass</span>

<span class="Type">[confirm</span> <span class="Special">\</span>
<span class="Type">(</span> <span class="Special">\</span>
<span class="String">"</span>
<span class="String">confirm4: Are you sure? [y/N]</span>
<span class="String">&gt;"</span>
<span class="Type">)]</span>
<span class="Function">confirm4</span><span class="Operator">:</span>
<span class="Number"> python3 -c pass</span>


somevar <span class="Operator">:=</span> <span class="String">"1"</span>
<span class="Function">interp_with_func_with_arg</span> <span class="Identifier">foo</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">foo</span><span class="Normal">)</span><span class="Delimiter">}}</span>
Expand Down
23 changes: 23 additions & 0 deletions tests/cases/recipes-with-extras.just
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,29 @@ runpwd_then_error:
multiline-attr-no-continuations:
/bin/true


[confirm("confirm2: Are you sure?")]
confirm2:
python3 -c pass

[confirm (
'''
confirm3: Are you sure?''' \
)
]
confirm3:
python3 -c pass

[confirm \
( \
"
confirm4: Are you sure? [y/N]
>"
)]
confirm4:
python3 -c pass


somevar := "1"
interp_with_func_with_arg foo:
echo {{quote(foo)}}
Expand Down

0 comments on commit b9e0b22

Please sign in to comment.