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