blob: 40491eea1a2c0bcb6d648235fc49004e8083d691 [file] [log] [blame]
Bram Moolenaar071d4272004-06-13 20:20:40 +00001" Vim syntax file
2" Language: awk, nawk, gawk, mawk
Bram Moolenaarb8ff1fb2012-02-04 21:59:01 +01003" Maintainer: Antonio Colombo <azc100@gmail.com>
Bram Moolenaar8a94d872015-01-25 13:02:57 +01004" Last Change: 2014 Oct 21
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
Bram Moolenaar8a94d872015-01-25 13:02:57 +010011" Effective AWK Programming, Fourth Edition, O'Reilly, 2015
12" (also available with the gawk source distribution)
Bram Moolenaar071d4272004-06-13 20:20:40 +000013
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
24if version < 600
25 syn clear
26elseif exists("b:current_syntax")
27 finish
28endif
29
Bram Moolenaarb8ff1fb2012-02-04 21:59:01 +010030let s:cpo_save = &cpo
31set cpo&vim
32
Bram Moolenaar071d4272004-06-13 20:20:40 +000033" A bunch of useful Awk keywords
34" AWK ref. p. 188
35syn keyword awkStatement break continue delete exit
36syn keyword awkStatement function getline next
37syn keyword awkStatement print printf return
Bram Moolenaar8a94d872015-01-25 13:02:57 +010038" GAWK ref. Chapter 7
Bram Moolenaar071d4272004-06-13 20:20:40 +000039syn keyword awkStatement nextfile
Bram Moolenaar8a94d872015-01-25 13:02:57 +010040"
41" GAWK ref. Chapter 9, Functions
42"
43" Numeric Functions
44syn keyword awkFunction atan2 cos div exp int log rand sin sqrt srand
45" String Manipulation Functions
46syn keyword awkFunction asort asort1 gensub gsub index length match
47syn keyword awkFunction patsplit split sprintf strtonum sub substr
Bram Moolenaar071d4272004-06-13 20:20:40 +000048syn keyword awkFunction tolower toupper
Bram Moolenaar8a94d872015-01-25 13:02:57 +010049" Input Output Functions
50syn keyword awkFunction close fflush system
51" Time Functions
52syn keyword awkFunction mktime strftime systime
53" Bit Manipulation Functions
54syn keyword awkFunction and compl lshift or rshift xor
55" Getting Type Function
56syn keyword awkFunction isarray
57" String-Translation Functions
58syn keyword awkFunction bindtextdomain dcgettext dcngetext
Bram Moolenaar071d4272004-06-13 20:20:40 +000059
60syn keyword awkConditional if else
61syn keyword awkRepeat while for
62
63syn keyword awkTodo contained TODO
64
65syn keyword awkPatterns BEGIN END
Bram Moolenaar8a94d872015-01-25 13:02:57 +010066
67" GAWK ref. Chapter 7
68" Built-in Variables That Control awk
69syn keyword awkVariables BINMODE CONVFMT FIELDWIDTHS FPAT FS
70syn keyword awkVariables IGNORECASE LINT OFMT OFS ORS PREC
71syn keyword awkVariables ROUNDMODE RS SUBSEP TEXTDOMAIN
72" Built-in Variables That Convey Information
73syn keyword awkVariables ARGC ARGV ARGIND ENVIRON ERRNO FILENAME
74syn keyword awkVariables FNR NF FUNCTAB NR PROCINFO RLENGTH RSTART
75syn keyword awkVariables RT SYMTAB
Bram Moolenaar071d4272004-06-13 20:20:40 +000076
77syn keyword awkRepeat do
78
79" Octal format character.
80syn match awkSpecialCharacter display contained "\\[0-7]\{1,3\}"
81syn keyword awkStatement func nextfile
82" Hex format character.
83syn match awkSpecialCharacter display contained "\\x[0-9A-Fa-f]\+"
84
85syn match awkFieldVars "\$\d\+"
86
87"catch errors caused by wrong parenthesis
88syn region awkParen transparent start="(" end=")" contains=ALLBUT,awkParenError,awkSpecialCharacter,awkArrayElement,awkArrayArray,awkTodo,awkRegExp,awkBrktRegExp,awkBrackets,awkCharClass
89syn match awkParenError display ")"
90syn match awkInParen display contained "[{}]"
91
92" 64 lines for complex &&'s, and ||'s in a big "if"
93syn sync ccomment awkParen maxlines=64
94
95" Search strings & Regular Expressions therein.
96syn region awkSearch oneline start="^[ \t]*/"ms=e start="\(,\|!\=\~\)[ \t]*/"ms=e skip="\\\\\|\\/" end="/" contains=awkBrackets,awkRegExp,awkSpecialCharacter
97syn region awkBrackets contained start="\[\^\]\="ms=s+2 start="\[[^\^]"ms=s+1 end="\]"me=e-1 contains=awkBrktRegExp,awkCharClass
98syn region awkSearch oneline start="[ \t]*/"hs=e skip="\\\\\|\\/" end="/" contains=awkBrackets,awkRegExp,awkSpecialCharacter
99
100syn match awkCharClass contained "\[:[^:\]]*:\]"
101syn match awkBrktRegExp contained "\\.\|.\-[^]]"
102syn match awkRegExp contained "/\^"ms=s+1
103syn match awkRegExp contained "\$/"me=e-1
104syn match awkRegExp contained "[?.*{}|+]"
105
106" String and Character constants
107" Highlight special characters (those which have a backslash) differently
Bram Moolenaar1aeaf8c2012-05-18 13:46:39 +0200108syn region awkString start=+"+ skip=+\\\\\|\\"+ end=+"+ contains=@Spell,awkSpecialCharacter,awkSpecialPrintf
Bram Moolenaar071d4272004-06-13 20:20:40 +0000109syn match awkSpecialCharacter contained "\\."
110
111" Some of these combinations may seem weird, but they work.
112syn match awkSpecialPrintf contained "%[-+ #]*\d*\.\=\d*[cdefgiosuxEGX%]"
113
114" Numbers, allowing signs (both -, and +)
115" Integer number.
116syn match awkNumber display "[+-]\=\<\d\+\>"
117" Floating point number.
118syn match awkFloat display "[+-]\=\<\d\+\.\d+\>"
119" Floating point number, starting with a dot.
120syn match awkFloat display "[+-]\=\<.\d+\>"
121syn case ignore
122"floating point number, with dot, optional exponent
123syn match awkFloat display "\<\d\+\.\d*\(e[-+]\=\d\+\)\=\>"
124"floating point number, starting with a dot, optional exponent
125syn match awkFloat display "\.\d\+\(e[-+]\=\d\+\)\=\>"
126"floating point number, without dot, with exponent
127syn match awkFloat display "\<\d\+e[-+]\=\d\+\>"
128syn case match
129
130"syn match awkIdentifier "\<[a-zA-Z_][a-zA-Z0-9_]*\>"
131
132" Arithmetic operators: +, and - take care of ++, and --
Bram Moolenaar8a94d872015-01-25 13:02:57 +0100133syn match awkOperator "+\|-\|\*\|/\|%\|="
134syn match awkOperator "+=\|-=\|\*=\|/=\|%="
135syn match awkOperator "^\|^="
Bram Moolenaar071d4272004-06-13 20:20:40 +0000136
137" Comparison expressions.
Bram Moolenaar8a94d872015-01-25 13:02:57 +0100138syn match awkExpression "==\|>=\|=>\|<=\|=<\|\!="
139syn match awkExpression "\~\|\!\~"
140syn match awkExpression "?\|:"
141syn keyword awkExpression in
Bram Moolenaar071d4272004-06-13 20:20:40 +0000142
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
Bram Moolenaar1aeaf8c2012-05-18 13:46:39 +0200150" keywords always have precedence over match & region.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000151" 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 ','
156syn match awkSemicolon ";"
157syn match awkComma ","
158
Bram Moolenaar1aeaf8c2012-05-18 13:46:39 +0200159syn match awkComment "#.*" contains=@Spell,awkTodo
Bram Moolenaar071d4272004-06-13 20:20:40 +0000160
161syn 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).
166syn match awkArrayArray contained "[^][, \t]\+\["me=e-1
167syn match awkArrayElement contained "[^][, \t]\+"
168syn 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")
172syn sync ccomment awkArray maxlines=10
173
174" define the default highlighting
175" For version 5.7 and earlier: only when not done already
Bram Moolenaar1aeaf8c2012-05-18 13:46:39 +0200176" For version 5.8 and later: only when an item doesn't have highlighting yet
Bram Moolenaar071d4272004-06-13 20:20:40 +0000177if 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
Bram Moolenaar8a94d872015-01-25 13:02:57 +0100205 HiLink awkOperator Special
206 HiLink awkExpression Special
Bram Moolenaar071d4272004-06-13 20:20:40 +0000207 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
230endif
231
232let b:current_syntax = "awk"
233
Bram Moolenaarb8ff1fb2012-02-04 21:59:01 +0100234let &cpo = s:cpo_save
235unlet s:cpo_save
236
Bram Moolenaar071d4272004-06-13 20:20:40 +0000237" vim: ts=8