blob: ae0f2175800ef13730885682764730038cddeb50 [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 Moolenaar269f5952016-07-15 22:54:41 +02004" Last Change: 2016 Jul 15
Bram Moolenaar071d4272004-06-13 20:20:40 +00005
Bram Moolenaar269f5952016-07-15 22:54:41 +02006" AWK ref. is: Alfred V. Aho, Brian W. Kernighan, Peter J. Weinberger
Bram Moolenaar071d4272004-06-13 20:20:40 +00007" 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
Bram Moolenaar269f5952016-07-15 22:54:41 +020012" (also available and updated 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
Bram Moolenaar269f5952016-07-15 22:54:41 +020022" Quit when a syntax file was already loaded
23if exists("b:current_syntax")
Bram Moolenaar071d4272004-06-13 20:20:40 +000024 finish
25endif
26
Bram Moolenaarb8ff1fb2012-02-04 21:59:01 +010027let s:cpo_save = &cpo
28set cpo&vim
29
Bram Moolenaar071d4272004-06-13 20:20:40 +000030" A bunch of useful Awk keywords
31" AWK ref. p. 188
32syn keyword awkStatement break continue delete exit
33syn keyword awkStatement function getline next
34syn keyword awkStatement print printf return
Bram Moolenaar269f5952016-07-15 22:54:41 +020035" GAWK ref. Chapter 7-9
36syn keyword awkStatement switch nextfile
37syn keyword awkStatement func
Bram Moolenaar8a94d872015-01-25 13:02:57 +010038"
39" GAWK ref. Chapter 9, Functions
Bram Moolenaar8a94d872015-01-25 13:02:57 +010040" Numeric Functions
Bram Moolenaar269f5952016-07-15 22:54:41 +020041syn keyword awkFunction atan2 cos exp int intdiv log rand sin sqrt srand
Bram Moolenaar8a94d872015-01-25 13:02:57 +010042" String Manipulation Functions
43syn keyword awkFunction asort asort1 gensub gsub index length match
44syn keyword awkFunction patsplit split sprintf strtonum sub substr
Bram Moolenaar071d4272004-06-13 20:20:40 +000045syn keyword awkFunction tolower toupper
Bram Moolenaar8a94d872015-01-25 13:02:57 +010046" Input Output Functions
47syn keyword awkFunction close fflush system
48" Time Functions
49syn keyword awkFunction mktime strftime systime
50" Bit Manipulation Functions
51syn keyword awkFunction and compl lshift or rshift xor
Bram Moolenaar269f5952016-07-15 22:54:41 +020052" Getting Type Functions
53syn keyword awkFunction isarray typeof
Bram Moolenaar8a94d872015-01-25 13:02:57 +010054" String-Translation Functions
55syn keyword awkFunction bindtextdomain dcgettext dcngetext
Bram Moolenaar071d4272004-06-13 20:20:40 +000056
57syn keyword awkConditional if else
Bram Moolenaar269f5952016-07-15 22:54:41 +020058syn keyword awkRepeat while for do
Bram Moolenaar071d4272004-06-13 20:20:40 +000059
Bram Moolenaar269f5952016-07-15 22:54:41 +020060syn keyword awkTodo contained TODO
Bram Moolenaar071d4272004-06-13 20:20:40 +000061
Bram Moolenaar269f5952016-07-15 22:54:41 +020062syn keyword awkPatterns BEGIN END BEGINFILE ENDFILE
Bram Moolenaar8a94d872015-01-25 13:02:57 +010063
64" GAWK ref. Chapter 7
65" Built-in Variables That Control awk
66syn keyword awkVariables BINMODE CONVFMT FIELDWIDTHS FPAT FS
67syn keyword awkVariables IGNORECASE LINT OFMT OFS ORS PREC
68syn keyword awkVariables ROUNDMODE RS SUBSEP TEXTDOMAIN
69" Built-in Variables That Convey Information
70syn keyword awkVariables ARGC ARGV ARGIND ENVIRON ERRNO FILENAME
71syn keyword awkVariables FNR NF FUNCTAB NR PROCINFO RLENGTH RSTART
72syn keyword awkVariables RT SYMTAB
Bram Moolenaar071d4272004-06-13 20:20:40 +000073
Bram Moolenaar071d4272004-06-13 20:20:40 +000074
75" Octal format character.
76syn match awkSpecialCharacter display contained "\\[0-7]\{1,3\}"
Bram Moolenaar071d4272004-06-13 20:20:40 +000077" Hex format character.
78syn match awkSpecialCharacter display contained "\\x[0-9A-Fa-f]\+"
79
80syn match awkFieldVars "\$\d\+"
81
Bram Moolenaar269f5952016-07-15 22:54:41 +020082" catch errors caused by wrong parenthesis
83syn region awkParen transparent start="(" end=")" contains=ALLBUT,awkParenError,awkSpecialCharacter,awkArrayElement,awkArrayArray,awkTodo,awkRegExp,awkBrktRegExp,awkBrackets,awkCharClass,awkComment
Bram Moolenaar071d4272004-06-13 20:20:40 +000084syn match awkParenError display ")"
Bram Moolenaar269f5952016-07-15 22:54:41 +020085"syn match awkInParen display contained "[{}]"
Bram Moolenaar071d4272004-06-13 20:20:40 +000086
87" 64 lines for complex &&'s, and ||'s in a big "if"
88syn sync ccomment awkParen maxlines=64
89
90" Search strings & Regular Expressions therein.
91syn region awkSearch oneline start="^[ \t]*/"ms=e start="\(,\|!\=\~\)[ \t]*/"ms=e skip="\\\\\|\\/" end="/" contains=awkBrackets,awkRegExp,awkSpecialCharacter
92syn region awkBrackets contained start="\[\^\]\="ms=s+2 start="\[[^\^]"ms=s+1 end="\]"me=e-1 contains=awkBrktRegExp,awkCharClass
93syn region awkSearch oneline start="[ \t]*/"hs=e skip="\\\\\|\\/" end="/" contains=awkBrackets,awkRegExp,awkSpecialCharacter
94
95syn match awkCharClass contained "\[:[^:\]]*:\]"
96syn match awkBrktRegExp contained "\\.\|.\-[^]]"
97syn match awkRegExp contained "/\^"ms=s+1
98syn match awkRegExp contained "\$/"me=e-1
99syn match awkRegExp contained "[?.*{}|+]"
100
101" String and Character constants
102" Highlight special characters (those which have a backslash) differently
Bram Moolenaar1aeaf8c2012-05-18 13:46:39 +0200103syn region awkString start=+"+ skip=+\\\\\|\\"+ end=+"+ contains=@Spell,awkSpecialCharacter,awkSpecialPrintf
Bram Moolenaar071d4272004-06-13 20:20:40 +0000104syn match awkSpecialCharacter contained "\\."
105
106" Some of these combinations may seem weird, but they work.
107syn match awkSpecialPrintf contained "%[-+ #]*\d*\.\=\d*[cdefgiosuxEGX%]"
108
109" Numbers, allowing signs (both -, and +)
110" Integer number.
111syn match awkNumber display "[+-]\=\<\d\+\>"
112" Floating point number.
113syn match awkFloat display "[+-]\=\<\d\+\.\d+\>"
114" Floating point number, starting with a dot.
115syn match awkFloat display "[+-]\=\<.\d+\>"
116syn case ignore
117"floating point number, with dot, optional exponent
118syn match awkFloat display "\<\d\+\.\d*\(e[-+]\=\d\+\)\=\>"
119"floating point number, starting with a dot, optional exponent
120syn match awkFloat display "\.\d\+\(e[-+]\=\d\+\)\=\>"
121"floating point number, without dot, with exponent
122syn match awkFloat display "\<\d\+e[-+]\=\d\+\>"
123syn case match
124
125"syn match awkIdentifier "\<[a-zA-Z_][a-zA-Z0-9_]*\>"
126
127" Arithmetic operators: +, and - take care of ++, and --
Bram Moolenaar8a94d872015-01-25 13:02:57 +0100128syn match awkOperator "+\|-\|\*\|/\|%\|="
129syn match awkOperator "+=\|-=\|\*=\|/=\|%="
130syn match awkOperator "^\|^="
Bram Moolenaar071d4272004-06-13 20:20:40 +0000131
132" Comparison expressions.
Bram Moolenaar8a94d872015-01-25 13:02:57 +0100133syn match awkExpression "==\|>=\|=>\|<=\|=<\|\!="
134syn match awkExpression "\~\|\!\~"
135syn match awkExpression "?\|:"
136syn keyword awkExpression in
Bram Moolenaar071d4272004-06-13 20:20:40 +0000137
138" Boolean Logic (OR, AND, NOT)
Bram Moolenaar269f5952016-07-15 22:54:41 +0200139syn match awkBoolLogic "||\|&&\|\!"
Bram Moolenaar071d4272004-06-13 20:20:40 +0000140
141" This is overridden by less-than & greater-than.
142" Put this above those to override them.
143" Put this in a 'match "\<printf\=\>.*;\="' to make it not override
144" less/greater than (most of the time), but it won't work yet because
Bram Moolenaar1aeaf8c2012-05-18 13:46:39 +0200145" keywords always have precedence over match & region.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000146" File I/O: (print foo, bar > "filename") & for nawk (getline < "filename")
147"syn match awkFileIO contained ">"
148"syn match awkFileIO contained "<"
149
150" Expression separators: ';' and ','
151syn match awkSemicolon ";"
152syn match awkComma ","
153
Bram Moolenaar1aeaf8c2012-05-18 13:46:39 +0200154syn match awkComment "#.*" contains=@Spell,awkTodo
Bram Moolenaar071d4272004-06-13 20:20:40 +0000155
156syn match awkLineSkip "\\$"
157
158" Highlight array element's (recursive arrays allowed).
159" Keeps nested array names' separate from normal array elements.
160" Keeps numbers separate from normal array elements (variables).
161syn match awkArrayArray contained "[^][, \t]\+\["me=e-1
162syn match awkArrayElement contained "[^][, \t]\+"
163syn region awkArray transparent start="\[" end="\]" contains=awkArray,awkArrayElement,awkArrayArray,awkNumber,awkFloat
164
165" 10 should be enough.
166" (for the few instances where it would be more than "oneline")
167syn sync ccomment awkArray maxlines=10
168
Bram Moolenaar269f5952016-07-15 22:54:41 +0200169" Define the default highlighting.
170" Only used when an item doesn't have highlighting yet
171hi def link awkConditional Conditional
172hi def link awkFunction Function
173hi def link awkRepeat Repeat
174hi def link awkStatement Statement
175hi def link awkString String
176hi def link awkSpecialPrintf Special
177hi def link awkSpecialCharacter Special
178hi def link awkSearch String
179hi def link awkBrackets awkRegExp
180hi def link awkBrktRegExp awkNestRegExp
181hi def link awkCharClass awkNestRegExp
182hi def link awkNestRegExp Keyword
183hi def link awkRegExp Special
184hi def link awkNumber Number
185hi def link awkFloat Float
186hi def link awkFileIO Special
187hi def link awkOperator Special
188hi def link awkExpression Special
189hi def link awkBoolLogic Special
190hi def link awkPatterns Special
191hi def link awkVariables Special
192hi def link awkFieldVars Special
193hi def link awkLineSkip Special
194hi def link awkSemicolon Special
195hi def link awkComma Special
196hi def link awkIdentifier Identifier
197hi def link awkComment Comment
198hi def link awkTodo Todo
199" Change this if you want nested array names to be highlighted.
200hi def link awkArrayArray awkArray
201hi def link awkArrayElement Special
202hi def link awkParenError awkError
203hi def link awkInParen awkError
204hi def link awkError Error
Bram Moolenaar071d4272004-06-13 20:20:40 +0000205
206let b:current_syntax = "awk"
207
Bram Moolenaarb8ff1fb2012-02-04 21:59:01 +0100208let &cpo = s:cpo_save
209unlet s:cpo_save
210
Bram Moolenaar071d4272004-06-13 20:20:40 +0000211" vim: ts=8