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