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