7
|
1 " Vim syntax file
|
|
2 " Language: awk, nawk, gawk, mawk
|
3312
|
3 " Maintainer: Antonio Colombo <azc100@gmail.com>
|
6530
|
4 " Last Change: 2014 Oct 21
|
7
|
5
|
|
6 " AWK ref. is: Alfred V. Aho, Brian W. Kernighan, Peter J. Weinberger
|
|
7 " The AWK Programming Language, Addison-Wesley, 1988
|
|
8
|
|
9 " GAWK ref. is: Arnold D. Robbins
|
|
10 " Effective AWK Programming, Third Edition, O'Reilly, 2001
|
6530
|
11 " Effective AWK Programming, Fourth Edition, O'Reilly, 2015
|
|
12 " (also available with the gawk source distribution)
|
7
|
13
|
|
14 " MAWK is a "new awk" meaning it implements AWK ref.
|
|
15 " mawk conforms to the Posix 1003.2 (draft 11.3)
|
|
16 " definition of the AWK language which contains a few features
|
|
17 " not described in the AWK book, and mawk provides a small number of extensions.
|
|
18
|
|
19 " TODO:
|
|
20 " Dig into the commented out syntax expressions below.
|
|
21
|
|
22 " For version 5.x: Clear all syntax items
|
|
23 " For version 6.x: Quit when a syntax file was already loaded
|
|
24 if version < 600
|
|
25 syn clear
|
|
26 elseif exists("b:current_syntax")
|
|
27 finish
|
|
28 endif
|
|
29
|
3312
|
30 let s:cpo_save = &cpo
|
|
31 set cpo&vim
|
|
32
|
7
|
33 " A bunch of useful Awk keywords
|
|
34 " AWK ref. p. 188
|
|
35 syn keyword awkStatement break continue delete exit
|
|
36 syn keyword awkStatement function getline next
|
|
37 syn keyword awkStatement print printf return
|
6530
|
38 " GAWK ref. Chapter 7
|
7
|
39 syn keyword awkStatement nextfile
|
6530
|
40 "
|
|
41 " GAWK ref. Chapter 9, Functions
|
|
42 "
|
|
43 " Numeric Functions
|
|
44 syn keyword awkFunction atan2 cos div exp int log rand sin sqrt srand
|
|
45 " String Manipulation Functions
|
|
46 syn keyword awkFunction asort asort1 gensub gsub index length match
|
|
47 syn keyword awkFunction patsplit split sprintf strtonum sub substr
|
7
|
48 syn keyword awkFunction tolower toupper
|
6530
|
49 " Input Output Functions
|
|
50 syn keyword awkFunction close fflush system
|
|
51 " Time Functions
|
|
52 syn keyword awkFunction mktime strftime systime
|
|
53 " Bit Manipulation Functions
|
|
54 syn keyword awkFunction and compl lshift or rshift xor
|
|
55 " Getting Type Function
|
|
56 syn keyword awkFunction isarray
|
|
57 " String-Translation Functions
|
|
58 syn keyword awkFunction bindtextdomain dcgettext dcngetext
|
7
|
59
|
|
60 syn keyword awkConditional if else
|
|
61 syn keyword awkRepeat while for
|
|
62
|
|
63 syn keyword awkTodo contained TODO
|
|
64
|
|
65 syn keyword awkPatterns BEGIN END
|
6530
|
66
|
|
67 " GAWK ref. Chapter 7
|
|
68 " Built-in Variables That Control awk
|
|
69 syn keyword awkVariables BINMODE CONVFMT FIELDWIDTHS FPAT FS
|
|
70 syn keyword awkVariables IGNORECASE LINT OFMT OFS ORS PREC
|
|
71 syn keyword awkVariables ROUNDMODE RS SUBSEP TEXTDOMAIN
|
|
72 " Built-in Variables That Convey Information
|
|
73 syn keyword awkVariables ARGC ARGV ARGIND ENVIRON ERRNO FILENAME
|
|
74 syn keyword awkVariables FNR NF FUNCTAB NR PROCINFO RLENGTH RSTART
|
|
75 syn keyword awkVariables RT SYMTAB
|
7
|
76
|
|
77 syn keyword awkRepeat do
|
|
78
|
|
79 " Octal format character.
|
|
80 syn match awkSpecialCharacter display contained "\\[0-7]\{1,3\}"
|
|
81 syn keyword awkStatement func nextfile
|
|
82 " Hex format character.
|
|
83 syn match awkSpecialCharacter display contained "\\x[0-9A-Fa-f]\+"
|
|
84
|
|
85 syn match awkFieldVars "\$\d\+"
|
|
86
|
|
87 "catch errors caused by wrong parenthesis
|
|
88 syn region awkParen transparent start="(" end=")" contains=ALLBUT,awkParenError,awkSpecialCharacter,awkArrayElement,awkArrayArray,awkTodo,awkRegExp,awkBrktRegExp,awkBrackets,awkCharClass
|
|
89 syn match awkParenError display ")"
|
|
90 syn match awkInParen display contained "[{}]"
|
|
91
|
|
92 " 64 lines for complex &&'s, and ||'s in a big "if"
|
|
93 syn sync ccomment awkParen maxlines=64
|
|
94
|
|
95 " Search strings & Regular Expressions therein.
|
|
96 syn region awkSearch oneline start="^[ \t]*/"ms=e start="\(,\|!\=\~\)[ \t]*/"ms=e skip="\\\\\|\\/" end="/" contains=awkBrackets,awkRegExp,awkSpecialCharacter
|
|
97 syn region awkBrackets contained start="\[\^\]\="ms=s+2 start="\[[^\^]"ms=s+1 end="\]"me=e-1 contains=awkBrktRegExp,awkCharClass
|
|
98 syn region awkSearch oneline start="[ \t]*/"hs=e skip="\\\\\|\\/" end="/" contains=awkBrackets,awkRegExp,awkSpecialCharacter
|
|
99
|
|
100 syn match awkCharClass contained "\[:[^:\]]*:\]"
|
|
101 syn match awkBrktRegExp contained "\\.\|.\-[^]]"
|
|
102 syn match awkRegExp contained "/\^"ms=s+1
|
|
103 syn match awkRegExp contained "\$/"me=e-1
|
|
104 syn match awkRegExp contained "[?.*{}|+]"
|
|
105
|
|
106 " String and Character constants
|
|
107 " Highlight special characters (those which have a backslash) differently
|
3513
|
108 syn region awkString start=+"+ skip=+\\\\\|\\"+ end=+"+ contains=@Spell,awkSpecialCharacter,awkSpecialPrintf
|
7
|
109 syn match awkSpecialCharacter contained "\\."
|
|
110
|
|
111 " Some of these combinations may seem weird, but they work.
|
|
112 syn match awkSpecialPrintf contained "%[-+ #]*\d*\.\=\d*[cdefgiosuxEGX%]"
|
|
113
|
|
114 " Numbers, allowing signs (both -, and +)
|
|
115 " Integer number.
|
|
116 syn match awkNumber display "[+-]\=\<\d\+\>"
|
|
117 " Floating point number.
|
|
118 syn match awkFloat display "[+-]\=\<\d\+\.\d+\>"
|
|
119 " Floating point number, starting with a dot.
|
|
120 syn match awkFloat display "[+-]\=\<.\d+\>"
|
|
121 syn case ignore
|
|
122 "floating point number, with dot, optional exponent
|
|
123 syn match awkFloat display "\<\d\+\.\d*\(e[-+]\=\d\+\)\=\>"
|
|
124 "floating point number, starting with a dot, optional exponent
|
|
125 syn match awkFloat display "\.\d\+\(e[-+]\=\d\+\)\=\>"
|
|
126 "floating point number, without dot, with exponent
|
|
127 syn match awkFloat display "\<\d\+e[-+]\=\d\+\>"
|
|
128 syn case match
|
|
129
|
|
130 "syn match awkIdentifier "\<[a-zA-Z_][a-zA-Z0-9_]*\>"
|
|
131
|
|
132 " Arithmetic operators: +, and - take care of ++, and --
|
6530
|
133 syn match awkOperator "+\|-\|\*\|/\|%\|="
|
|
134 syn match awkOperator "+=\|-=\|\*=\|/=\|%="
|
|
135 syn match awkOperator "^\|^="
|
7
|
136
|
|
137 " Comparison expressions.
|
6530
|
138 syn match awkExpression "==\|>=\|=>\|<=\|=<\|\!="
|
|
139 syn match awkExpression "\~\|\!\~"
|
|
140 syn match awkExpression "?\|:"
|
|
141 syn keyword awkExpression in
|
7
|
142
|
|
143 " Boolean Logic (OR, AND, NOT)
|
|
144 "syn match awkBoolLogic "||\|&&\|\!"
|
|
145
|
|
146 " This is overridden by less-than & greater-than.
|
|
147 " Put this above those to override them.
|
|
148 " Put this in a 'match "\<printf\=\>.*;\="' to make it not override
|
|
149 " less/greater than (most of the time), but it won't work yet because
|
3513
|
150 " keywords always have precedence over match & region.
|
7
|
151 " File I/O: (print foo, bar > "filename") & for nawk (getline < "filename")
|
|
152 "syn match awkFileIO contained ">"
|
|
153 "syn match awkFileIO contained "<"
|
|
154
|
|
155 " Expression separators: ';' and ','
|
|
156 syn match awkSemicolon ";"
|
|
157 syn match awkComma ","
|
|
158
|
3513
|
159 syn match awkComment "#.*" contains=@Spell,awkTodo
|
7
|
160
|
|
161 syn match awkLineSkip "\\$"
|
|
162
|
|
163 " Highlight array element's (recursive arrays allowed).
|
|
164 " Keeps nested array names' separate from normal array elements.
|
|
165 " Keeps numbers separate from normal array elements (variables).
|
|
166 syn match awkArrayArray contained "[^][, \t]\+\["me=e-1
|
|
167 syn match awkArrayElement contained "[^][, \t]\+"
|
|
168 syn region awkArray transparent start="\[" end="\]" contains=awkArray,awkArrayElement,awkArrayArray,awkNumber,awkFloat
|
|
169
|
|
170 " 10 should be enough.
|
|
171 " (for the few instances where it would be more than "oneline")
|
|
172 syn sync ccomment awkArray maxlines=10
|
|
173
|
|
174 " define the default highlighting
|
|
175 " For version 5.7 and earlier: only when not done already
|
3513
|
176 " For version 5.8 and later: only when an item doesn't have highlighting yet
|
7
|
177 if version >= 508 || !exists("did_awk_syn_inits")
|
|
178 if version < 508
|
|
179 let did_awk_syn_inits = 1
|
|
180 command -nargs=+ HiLink hi link <args>
|
|
181 else
|
|
182 command -nargs=+ HiLink hi def link <args>
|
|
183 endif
|
|
184
|
|
185 HiLink awkConditional Conditional
|
|
186 HiLink awkFunction Function
|
|
187 HiLink awkRepeat Repeat
|
|
188 HiLink awkStatement Statement
|
|
189
|
|
190 HiLink awkString String
|
|
191 HiLink awkSpecialPrintf Special
|
|
192 HiLink awkSpecialCharacter Special
|
|
193
|
|
194 HiLink awkSearch String
|
|
195 HiLink awkBrackets awkRegExp
|
|
196 HiLink awkBrktRegExp awkNestRegExp
|
|
197 HiLink awkCharClass awkNestRegExp
|
|
198 HiLink awkNestRegExp Keyword
|
|
199 HiLink awkRegExp Special
|
|
200
|
|
201 HiLink awkNumber Number
|
|
202 HiLink awkFloat Float
|
|
203
|
|
204 HiLink awkFileIO Special
|
6530
|
205 HiLink awkOperator Special
|
|
206 HiLink awkExpression Special
|
7
|
207 HiLink awkBoolLogic Special
|
|
208
|
|
209 HiLink awkPatterns Special
|
|
210 HiLink awkVariables Special
|
|
211 HiLink awkFieldVars Special
|
|
212
|
|
213 HiLink awkLineSkip Special
|
|
214 HiLink awkSemicolon Special
|
|
215 HiLink awkComma Special
|
|
216 "HiLink awkIdentifier Identifier
|
|
217
|
|
218 HiLink awkComment Comment
|
|
219 HiLink awkTodo Todo
|
|
220
|
|
221 " Change this if you want nested array names to be highlighted.
|
|
222 HiLink awkArrayArray awkArray
|
|
223 HiLink awkArrayElement Special
|
|
224
|
|
225 HiLink awkParenError awkError
|
|
226 HiLink awkInParen awkError
|
|
227 HiLink awkError Error
|
|
228
|
|
229 delcommand HiLink
|
|
230 endif
|
|
231
|
|
232 let b:current_syntax = "awk"
|
|
233
|
3312
|
234 let &cpo = s:cpo_save
|
|
235 unlet s:cpo_save
|
|
236
|
7
|
237 " vim: ts=8
|