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