Skip to content

Commit

Permalink
Remove justBuiltInFunctionsError
Browse files Browse the repository at this point in the history
  • Loading branch information
laniakea64 committed Dec 26, 2023
1 parent bc965c8 commit f3c0eb1
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 44 deletions.
5 changes: 4 additions & 1 deletion justfile
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ update-last-changed *force:

# Some functions are intentionally omitted from these lists because they're handled as special cases:
# - error
# - replace_regex
functionsWithArgs := '''
absolute_path
capitalize
Expand All @@ -88,6 +87,7 @@ functionsWithArgs := '''
path_exists
quote
replace
replace_regex
semver_matches
sha256
sha256_file
Expand Down Expand Up @@ -120,6 +120,9 @@ zeroArgFunctions := '''
'''
allFunctions := functionsWithArgs + zeroArgFunctions

@functions:
echo $({{justq}} --evaluate allFunctions | sort)

# generate an optimized Vim-style "very magic" regex snippet from a list of literal strings to match
optrx +strings:
#!/usr/bin/env python3
Expand Down
20 changes: 8 additions & 12 deletions syntax/just.vim
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,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,justBuiltInFunctionsError,justPreBodyCommentError
syn match justLineContinuation "\\$" containedin=ALLBUT,justComment,justShebang,@justRawStrings,justPreBodyCommentError

syn region justBody
\ start=/\v^\z( +|\t+)%(#!)@!\S/
Expand Down Expand Up @@ -189,17 +189,16 @@ syn match justCurlyBraces '\v\{{4}' contained
syn match justBadCurlyBraces '\v\{{5}\ze[^{]' contained
syn cluster justOtherCurlyBraces contains=justCurlyBraces,justBadCurlyBraces

syn match justBuiltInFunctionsError '\v\w+%(\s|\\\n)*\('
syn match justFunctionCall "\v\w+%(\s|\\\n)*\(@=" transparent contains=justBuiltInFunction

syn match justBuiltInFunction "\v%(a%(bsolute_pat|rc)h|c%(apitalize|lean)|e%(nv%(_var%(_or_default)?)?|xtension)|file_%(name|stem)|j%(oin|ust%(_executable|file%(_directory)?))|kebabcase|lowerca%(melca)?se|pa%(rent_directory|th_exists)|quote|replace|s%(emver_matches|h%(a256%(_file)?|outy%(kebab|snake)case)|nakecase)|t%(itlecase|rim%(_%(end|start)%(_match%(es)?)?)?)|u%(pperca%(melca)?se|uid)|without_extension|invocation_directory%(_native)?|num_cpus|os%(_family)?)%(%(\s|\\\n)*\()@="
syn keyword justBuiltInFunction
\ absolute_path arch capitalize clean env env_var env_var_or_default extension file_name file_stem invocation_directory invocation_directory_native join just_executable justfile justfile_directory kebabcase lowercamelcase lowercase num_cpus os os_family parent_directory path_exists quote replace replace_regex semver_matches sha256 sha256_file shoutykebabcase shoutysnakecase snakecase titlecase trim trim_end trim_end_match trim_end_matches trim_start trim_start_match trim_start_matches uppercamelcase uppercase uuid without_extension
\ contained

syn match justUserDefinedError "\verror%(%(\s|\\\n)*\()@="

syn match justReplaceRegex '\vreplace_regex%(\s|\\\n)*\(@=' transparent contains=justReplaceRegexKw nextgroup=justReplaceRegexCall
syn match justReplaceRegexInInterp '\vreplace_regex%(\s|\\\n)*\(@=' transparent contains=justReplaceRegexKw nextgroup=justReplaceRegexCallInInterp

syn keyword justReplaceRegexKw replace_regex contained
hi link justReplaceRegexKw justBuiltInFunction
syn match justReplaceRegex '\vreplace_regex%(\s|\\\n)*\(@=' transparent contains=justBuiltInFunction nextgroup=justReplaceRegexCall
syn match justReplaceRegexInInterp '\vreplace_regex%(\s|\\\n)*\(@=' transparent contains=justBuiltInFunction nextgroup=justReplaceRegexCallInInterp

syn region justReplaceRegexCall
\ matchgroup=justReplaceRegexCall
Expand All @@ -212,15 +211,13 @@ syn region justReplaceRegexCallInInterp
\ transparent contained
\ contains=@justExprInInterp,justRegexReplacement

syn match justBuiltInFunctionsError "\v%(arch|invocation_directory%(_native)?|just%(_executable|file%(_directory)?)|num_cpus|os%(_family)?|uuid)%(\s|\\\n)*\(%(\_s|\\\n)*%(%([^)[:space:]\\]|\\\n@!)%(\_s|\\\n)*)+\)"

syn match justParameterLineContinuation '\v%(\s|\\\n)*' contained nextgroup=justParameterError

syn match justRecipeDepParenName '\v%(\(%(\s|\\\n)*)@<=\h\k*'
\ transparent contained
\ contains=justFunction

syn cluster justBuiltInFunctions contains=justBuiltInFunction,justUserDefinedError,justBuiltInFunctionsError
syn cluster justBuiltInFunctions contains=justFunctionCall,justUserDefinedError

syn match justOperator "\V=="
syn match justOperator "\V!="
Expand All @@ -246,7 +243,6 @@ hi def link justBadCurlyBraces Error
hi def link justBody Number
hi def link justBoolean Boolean
hi def link justBuiltInFunction Function
hi def link justBuiltInFunctionsError Error
hi def link justComment Comment
hi def link justCommentTodo Todo
hi def link justConditional Conditional
Expand Down
22 changes: 5 additions & 17 deletions tests/cases/invalid.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,27 +13,13 @@
(the next line is not a recipe body)...
this text should not be highlighted

badfunc1 <span class="Operator">:=</span> <span class="Error">arch(foo)</span> <span class="Operator">+</span> <span class="Error">os(foo)</span> <span class="Operator">+</span> <span class="Error">os_family(foo)</span>

badfunc2 <span class="Operator">:=</span> <span class="Error">invocation_directory(bar)</span> <span class="Operator">/</span> <span class="Error">invocation_directory_native(bar)</span>
badfunc3 <span class="Operator">:=</span> <span class="Error">justfile_directory(bar)</span> <span class="Operator">/</span> <span class="Error">justfile(bar, foo)</span>

badfunc4 <span class="Operator">:=</span> <span class="Error">justfile (</span>
<span class="Error"> abc def</span>
<span class="Error">)</span>

badfunc5 <span class="Operator">:=</span> <span class="Error">num_cpus(\)</span>
badfunc5 <span class="Operator">:=</span> <span class="Function">num_cpus</span>(\)

not_a_recipe_name <span class="Comment">#comment:</span>
not a recipe body

nonexistant_func <span class="Operator">:=</span> <span class="Error">blahuuid(</span>)
nonexistant_func2 <span class="Operator">:=</span> <span class="Error">blah_replace_regex(</span><span class="String">'foo'</span>, <span class="String">'([^o])'</span>, <span class="String">'$1'</span>)

not_a_recipe_start
not a recipe body
<span class="Function">badfunc_in_interpolation</span><span class="Operator">:</span>
<span class="Number"> </span><span class="Delimiter">{{</span><span class="Error">just_executable(this)</span><span class="Delimiter">}}</span><span class="Number"> </span><span class="Delimiter">{{</span><span class="Function">quote</span><span class="Normal">( </span><span class="Error">uuid(random, foo)</span><span class="Normal"> )</span><span class="Delimiter">}}</span>
nonexistant_func <span class="Operator">:=</span> blahuuid()
nonexistant_func2 <span class="Operator">:=</span> blah_replace_regex(<span class="String">'foo'</span>, <span class="String">'([^o])'</span>, <span class="String">'$1'</span>)

<span class="Function">invalid_recipe_body</span><span class="Operator">:</span>
<span class="Error"> </span>echo <span class="String">'My indentation mixes spaces and tabs!'</span>
Expand All @@ -50,6 +36,8 @@
<span class="Number"> echo </span><span class="String">'valid again</span>
<span class="String"> </span><span class="Error"> </span><span class="String">not valid'</span>

not_a_recipe_start
not a recipe body
<span class="Function">bad_but_not_mixed_indentation</span><span class="Operator">:</span>
<span class="Number"> echo </span><span class="String">'tab indent'</span>
echo <span class="String">'space indent'</span>
Expand Down
16 changes: 2 additions & 14 deletions tests/cases/invalid.just
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,6 @@ export FOO
(the next line is not a recipe body)...
this text should not be highlighted

badfunc1 := arch(foo) + os(foo) + os_family(foo)

badfunc2 := invocation_directory(bar) / invocation_directory_native(bar)
badfunc3 := justfile_directory(bar) / justfile(bar, foo)

badfunc4 := justfile (
abc def
)

badfunc5 := num_cpus(\)

not_a_recipe_name #comment:
Expand All @@ -30,11 +21,6 @@ not_a_recipe_name #comment:
nonexistant_func := blahuuid()
nonexistant_func2 := blah_replace_regex('foo', '([^o])', '$1')

not_a_recipe_start
not a recipe body
badfunc_in_interpolation:
{{just_executable(this)}} {{quote( uuid(random, foo) )}}

invalid_recipe_body:
echo 'My indentation mixes spaces and tabs!'
echo 'My indentation mixes tabs and spaces!'
Expand All @@ -50,6 +36,8 @@ invalid_recipe_body4:
echo 'valid again
not valid'

not_a_recipe_start
not a recipe body
bad_but_not_mixed_indentation:
echo 'tab indent'
echo 'space indent'
Expand Down

0 comments on commit f3c0eb1

Please sign in to comment.