awk.vim 8.0 KB

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