2 " Language: awk, nawk, gawk, mawk
3 " Maintainer: Antonio Colombo <azc10@yahoo.com>
4 " Last Change: 2005 Mar 16
6 " AWK ref. is: Alfred V. Aho, Brian W. Kernighan, Peter J. Weinberger
7 " The AWK Programming Language, Addison-Wesley, 1988
9 " GAWK ref. is: Arnold D. Robbins
10 " Effective AWK Programming, Third Edition, O'Reilly, 2001
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.
18 " Dig into the commented out syntax expressions below.
20 " For version 5.x: Clear all syntax items
21 " For version 6.x: Quit when a syntax file was already loaded
24 elseif exists("b:current_syntax")
28 " A bunch of useful Awk keywords
30 syn keyword awkStatement break continue delete exit
31 syn keyword awkStatement function getline next
32 syn keyword awkStatement print printf return
34 syn keyword awkStatement nextfile
35 " AWK ref. p. 42, GAWK ref. p. 142-166
36 syn keyword awkFunction atan2 close cos exp fflush int log rand sin sqrt srand
37 syn keyword awkFunction gsub index length match split sprintf sub
38 syn keyword awkFunction substr system
39 " GAWK ref. p. 142-166
40 syn keyword awkFunction asort gensub mktime strftime strtonum systime
41 syn keyword awkFunction tolower toupper
42 syn keyword awkFunction and or xor compl lshift rshift
43 syn keyword awkFunction dcgettext bindtextdomain
45 syn keyword awkConditional if else
46 syn keyword awkRepeat while for
48 syn keyword awkTodo contained TODO
50 syn keyword awkPatterns BEGIN END
52 syn keyword awkVariables ARGC ARGV FILENAME FNR FS NF NR
53 syn keyword awkVariables OFMT OFS ORS RLENGTH RS RSTART SUBSEP
54 " GAWK ref. p. 120-126
55 syn keyword awkVariables ARGIND BINMODE CONVFMT ENVIRON ERRNO
56 syn keyword awkVariables FIELDWIDTHS IGNORECASE LINT PROCINFO
57 syn keyword awkVariables RT RLENGTH TEXTDOMAIN
59 syn keyword awkRepeat do
61 " Octal format character.
62 syn match awkSpecialCharacter display contained "\\[0-7]\{1,3\}"
63 syn keyword awkStatement func nextfile
64 " Hex format character.
65 syn match awkSpecialCharacter display contained "\\x[0-9A-Fa-f]\+"
67 syn match awkFieldVars "\$\d\+"
69 "catch errors caused by wrong parenthesis
70 syn region awkParen transparent start="(" end=")" contains=ALLBUT,awkParenError,awkSpecialCharacter,awkArrayElement,awkArrayArray,awkTodo,awkRegExp,awkBrktRegExp,awkBrackets,awkCharClass
71 syn match awkParenError display ")"
72 syn match awkInParen display contained "[{}]"
74 " 64 lines for complex &&'s, and ||'s in a big "if"
75 syn sync ccomment awkParen maxlines=64
77 " Search strings & Regular Expressions therein.
78 syn region awkSearch oneline start="^[ \t]*/"ms=e start="\(,\|!\=\~\)[ \t]*/"ms=e skip="\\\\\|\\/" end="/" contains=awkBrackets,awkRegExp,awkSpecialCharacter
79 syn region awkBrackets contained start="\[\^\]\="ms=s+2 start="\[[^\^]"ms=s+1 end="\]"me=e-1 contains=awkBrktRegExp,awkCharClass
80 syn region awkSearch oneline start="[ \t]*/"hs=e skip="\\\\\|\\/" end="/" contains=awkBrackets,awkRegExp,awkSpecialCharacter
82 syn match awkCharClass contained "\[:[^:\]]*:\]"
83 syn match awkBrktRegExp contained "\\.\|.\-[^]]"
84 syn match awkRegExp contained "/\^"ms=s+1
85 syn match awkRegExp contained "\$/"me=e-1
86 syn match awkRegExp contained "[?.*{}|+]"
88 " String and Character constants
89 " Highlight special characters (those which have a backslash) differently
90 syn region awkString start=+"+ skip=+\\\\\|\\"+ end=+"+ contains=awkSpecialCharacter,awkSpecialPrintf
91 syn match awkSpecialCharacter contained "\\."
93 " Some of these combinations may seem weird, but they work.
94 syn match awkSpecialPrintf contained "%[-+ #]*\d*\.\=\d*[cdefgiosuxEGX%]"
96 " Numbers, allowing signs (both -, and +)
98 syn match awkNumber display "[+-]\=\<\d\+\>"
99 " Floating point number.
100 syn match awkFloat display "[+-]\=\<\d\+\.\d+\>"
101 " Floating point number, starting with a dot.
102 syn match awkFloat display "[+-]\=\<.\d+\>"
104 "floating point number, with dot, optional exponent
105 syn match awkFloat display "\<\d\+\.\d*\(e[-+]\=\d\+\)\=\>"
106 "floating point number, starting with a dot, optional exponent
107 syn match awkFloat display "\.\d\+\(e[-+]\=\d\+\)\=\>"
108 "floating point number, without dot, with exponent
109 syn match awkFloat display "\<\d\+e[-+]\=\d\+\>"
112 "syn match awkIdentifier "\<[a-zA-Z_][a-zA-Z0-9_]*\>"
114 " Arithmetic operators: +, and - take care of ++, and --
115 "syn match awkOperator "+\|-\|\*\|/\|%\|="
116 "syn match awkOperator "+=\|-=\|\*=\|/=\|%="
117 "syn match awkOperator "^\|^="
119 " Comparison expressions.
120 "syn match awkExpression "==\|>=\|=>\|<=\|=<\|\!="
121 "syn match awkExpression "\~\|\!\~"
122 "syn match awkExpression "?\|:"
123 "syn keyword awkExpression in
125 " Boolean Logic (OR, AND, NOT)
126 "syn match awkBoolLogic "||\|&&\|\!"
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 "<"
137 " Expression separators: ';' and ','
138 syn match awkSemicolon ";"
139 syn match awkComma ","
141 syn match awkComment "#.*" contains=awkTodo
143 syn match awkLineSkip "\\$"
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).
148 syn match awkArrayArray contained "[^][, \t]\+\["me=e-1
149 syn match awkArrayElement contained "[^][, \t]\+"
150 syn region awkArray transparent start="\[" end="\]" contains=awkArray,awkArrayElement,awkArrayArray,awkNumber,awkFloat
152 " 10 should be enough.
153 " (for the few instances where it would be more than "oneline")
154 syn sync ccomment awkArray maxlines=10
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
159 if version >= 508 || !exists("did_awk_syn_inits")
161 let did_awk_syn_inits = 1
162 command -nargs=+ HiLink hi link <args>
164 command -nargs=+ HiLink hi def link <args>
167 HiLink awkConditional Conditional
168 HiLink awkFunction Function
169 HiLink awkRepeat Repeat
170 HiLink awkStatement Statement
172 HiLink awkString String
173 HiLink awkSpecialPrintf Special
174 HiLink awkSpecialCharacter Special
176 HiLink awkSearch String
177 HiLink awkBrackets awkRegExp
178 HiLink awkBrktRegExp awkNestRegExp
179 HiLink awkCharClass awkNestRegExp
180 HiLink awkNestRegExp Keyword
181 HiLink awkRegExp Special
183 HiLink awkNumber Number
184 HiLink awkFloat Float
186 HiLink awkFileIO Special
187 "HiLink awkOperator Special
188 "HiLink awkExpression Special
189 HiLink awkBoolLogic Special
191 HiLink awkPatterns Special
192 HiLink awkVariables Special
193 HiLink awkFieldVars Special
195 HiLink awkLineSkip Special
196 HiLink awkSemicolon Special
197 HiLink awkComma Special
198 "HiLink awkIdentifier Identifier
200 HiLink awkComment Comment
203 " Change this if you want nested array names to be highlighted.
204 HiLink awkArrayArray awkArray
205 HiLink awkArrayElement Special
207 HiLink awkParenError awkError
208 HiLink awkInParen awkError
209 HiLink awkError Error
214 let b:current_syntax = "awk"