Vito | 79952b9 | 2024-04-26 22:36:20 +0200 | [diff] [blame] | 1 | " Vim compiler file |
| 2 | " Language: jq |
| 3 | " Maintainer: Vito <vito.blog@gmail.com> |
| 4 | " Last Change: 2024 Apr 17 |
| 5 | " Upstream: https://github.com/vito-c/jq.vim |
Eisuke Kawashima | fbbaa6e | 2025-04-16 18:20:59 +0200 | [diff] [blame] | 6 | " 2025 Apr 16 by Vim Project (set 'cpoptions' for line continuation, #17121) |
Vito | 79952b9 | 2024-04-26 22:36:20 +0200 | [diff] [blame] | 7 | " |
| 8 | " Quit when a (custom) syntax file was already loaded |
| 9 | if exists('b:current_syntax') |
| 10 | finish |
| 11 | endif |
| 12 | |
Eisuke Kawashima | fbbaa6e | 2025-04-16 18:20:59 +0200 | [diff] [blame] | 13 | let s:cpo_save = &cpo |
| 14 | set cpo&vim |
| 15 | |
Vito | 79952b9 | 2024-04-26 22:36:20 +0200 | [diff] [blame] | 16 | " syn include @jqHtml syntax/html.vim " Doc comment HTML |
| 17 | |
| 18 | " jqTodo |
| 19 | syntax keyword jqTodo contained TODO FIXME NOTE XXX |
| 20 | |
| 21 | " jqKeywords |
| 22 | syntax keyword jqKeywords and or not empty |
| 23 | syntax keyword jqKeywords try catch |
| 24 | syntax keyword jqKeywords reduce as label break foreach |
| 25 | syntax keyword jqKeywords import include module modulemeta |
| 26 | syntax keyword jqKeywords env nth has in while error stderr debug |
| 27 | |
| 28 | " jqConditional |
| 29 | syntax keyword jqConditional if then elif else end |
| 30 | |
| 31 | " jqConditions |
| 32 | syntax keyword jqCondtions true false null |
| 33 | |
| 34 | " jqSpecials |
| 35 | syntax keyword jqType type |
| 36 | syntax match jqType /[\|;]/ " not really a type I did this for coloring reasons though :help group-name |
| 37 | syntax region jqParentheses start=+(+ end=+)+ fold transparent |
| 38 | |
| 39 | " jq Functions |
| 40 | syntax keyword jqFunction add all any arrays ascii_downcase floor |
| 41 | syntax keyword jqFunction ascii_upcase booleans bsearch builtins capture combinations |
| 42 | syntax keyword jqFunction \contains del delpaths endswith explode |
| 43 | syntax keyword jqFunction finites first flatten format from_entries |
| 44 | syntax keyword jqFunction fromdate fromdateiso8601 fromjson fromstream get_jq_origin |
| 45 | syntax keyword jqFunction get_prog_origin get_search_list getpath gmtime group_by |
| 46 | syntax keyword jqFunction gsub halt halt_error implode index indices infinite |
| 47 | syntax keyword jqFunction input input_filename input_line_number inputs inside |
| 48 | syntax keyword jqFunction isempty isfinite isinfinite isnan isnormal iterables |
| 49 | syntax keyword jqFunction join keys keys_unsorted last leaf_paths |
| 50 | syntax keyword jqFunction length limit localtime ltrimstr map map_values |
| 51 | syntax keyword jqFunction match max max_by min min_by |
| 52 | syntax keyword jqFunction mktime nan normals now |
| 53 | syntax keyword jqFunction nulls numbers objects path paths range |
| 54 | syntax keyword jqFunction recurse recurse_down repeat reverse rindex |
| 55 | syntax keyword jqFunction rtrimstr scalars scalars_or_empty scan select |
| 56 | syntax keyword jqFunction setpath sort sort_by split splits with_entries |
| 57 | syntax keyword jqFunction startswith strflocaltime strftime strings strptime sub |
| 58 | syntax keyword jqFunction test to_entries todate todateiso8601 tojson __loc__ |
| 59 | syntax keyword jqFunction tonumber tostream tostring transpose truncate_stream |
| 60 | syntax keyword jqFunction unique unique_by until utf8bytelength values walk |
| 61 | " TODO: $__loc__ is going to be a pain |
| 62 | |
| 63 | " jq Math Functions |
| 64 | syntax keyword jqFunction acos acosh asin asinh atan atanh cbrt ceil cos cosh |
| 65 | syntax keyword jqFunction erf erfc exp exp10 exp2 expm1 fabs floor gamma j0 j1 |
| 66 | syntax keyword jqFunction lgamma lgamma_r log log10 log1p log2 logb nearbyint |
| 67 | syntax keyword jqFunction pow10 rint round significand sin sinh sqrt tan tanh |
| 68 | syntax keyword jqFunction tgamma trunc y0 y1 |
| 69 | syntax keyword jqFunction atan2 copysign drem fdim fmax fmin fmod frexp hypot |
| 70 | syntax keyword jqFunction jn ldexp modf nextafter nexttoward pow remainder |
| 71 | syntax keyword jqFunction scalb scalbln yn |
| 72 | syntax keyword jqFunction fma |
| 73 | |
| 74 | " jq SQL-style Operators |
| 75 | syntax keyword jqFunction INDEX JOIN IN |
| 76 | |
| 77 | " Macro |
| 78 | syntax match jqMacro "@\%(text\|json\|html\|uri\|[ct]sv\|sh\|base64d\?\)\>" |
| 79 | |
| 80 | " Comments |
| 81 | syntax match jqComment "#.*" contains=jqTodo |
| 82 | |
| 83 | " Variables |
| 84 | syn match jqVariables /$[_A-Za-z0-9]\+/ |
| 85 | |
| 86 | " Definition |
| 87 | syntax keyword jqKeywords def nextgroup=jqNameDefinition skipwhite |
| 88 | syn match jqNameDefinition /\<[_A-Za-z0-9]\+\>/ contained nextgroup=jqPostNameDefinition |
| 89 | syn match jqNameDefinition /`[^`]\+`/ contained nextgroup=jqPostNameDefinition |
| 90 | |
| 91 | " Strings |
| 92 | syn region jqError start=+'+ end=+'\|$\|[;)]\@=+ |
| 93 | syn region jqString matchgroup=jqQuote |
| 94 | \ start=+"+ skip=+\\[\\"]+ end=+"+ |
| 95 | \ contains=@Spell,jqInterpolation |
| 96 | syn region jqInterpolation matchgroup=jqInterpolationDelimiter |
| 97 | \ start=+\%([^\\]\%(\\\\\)*\\\)\@<!\\(+ end=+)+ |
| 98 | \ contained contains=TOP |
| 99 | |
| 100 | " Operators |
| 101 | syn match jqOperator /:\|\([-+*/%<>=]\|\/\/\)=\?\|[!|]=\|?\/\// |
| 102 | "syn region jqRange matchgroup=jqSquareBracket start=+\[+ skip=+:+ end=+\]+ |
| 103 | |
| 104 | " Errors |
| 105 | syn keyword jqError _assign _flatten _modify _nwise _plus _negate _minus _multiply |
| 106 | syn keyword jqError _divide _mod _strindices _equal _notequal _less _greater _lesseq |
| 107 | syn keyword jqError _greatereq _sort_by_impl _group_by_impl _min_by_impl _max_by_impl _match_impl _input |
| 108 | " TODO: these errors should show up when doing def _flatten: as well |
| 109 | |
| 110 | " Numbers |
| 111 | syn match jqNumber /\<0[dDfFlL]\?\>/ " Just a bare 0 |
| 112 | syn match jqNumber /\<[1-9]\d*[dDfFlL]\?\>/ " A multi-digit number - octal numbers with leading 0's are deprecated in Scala |
| 113 | |
| 114 | if !exists('jq_quote_highlight') |
| 115 | highlight def link jqQuote String |
| 116 | else |
| 117 | highlight def link jqQuote Type |
| 118 | endif |
| 119 | |
| 120 | hi def link jqCondtions Boolean |
| 121 | hi def link jqVariables Identifier |
| 122 | hi def link jqNameDefinition Function |
| 123 | hi def link jqTodo Todo |
| 124 | hi def link jqComment Comment |
| 125 | hi def link jqKeywords Keyword |
| 126 | hi def link jqType Type |
| 127 | hi def link jqOperator Operator |
| 128 | hi def link jqFunction Function |
| 129 | hi def link jqMacro Macro |
| 130 | hi def link jqError Error |
| 131 | hi def link jqString String |
| 132 | hi def link jqInterpolationDelimiter Delimiter |
| 133 | hi def link jqConditional Conditional |
| 134 | hi def link jqNumber Number |
Eisuke Kawashima | fbbaa6e | 2025-04-16 18:20:59 +0200 | [diff] [blame] | 135 | |
| 136 | let &cpo = s:cpo_save |
| 137 | unlet s:cpo_save |