home *** CD-ROM | disk | FTP | other *** search
/ vim.ftp.fu-berlin.de / 2015-02-03.vim.ftp.fu-berlin.de.tar / vim.ftp.fu-berlin.de / runtime / dos / syntax / awk.vim < prev    next >
Encoding:
Text File  |  2012-05-31  |  7.8 KB  |  223 lines

  1. " Vim syntax file
  2. " Language:    awk, nawk, gawk, mawk
  3. " Maintainer:    Antonio Colombo <azc100@gmail.com>
  4. " Last Change:    2012 May 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.  
  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.  
  17. " TODO:
  18. " Dig into the commented out syntax expressions below.
  19.  
  20. " For version 5.x: Clear all syntax items
  21. " For version 6.x: Quit when a syntax file was already loaded
  22. if version < 600
  23.   syn clear
  24. elseif exists("b:current_syntax")
  25.   finish
  26. endif
  27.  
  28. let s:cpo_save = &cpo
  29. set cpo&vim
  30.  
  31. " A bunch of useful Awk keywords
  32. " AWK  ref. p. 188
  33. syn keyword awkStatement    break continue delete exit
  34. syn keyword awkStatement    function getline next
  35. syn keyword awkStatement    print printf return
  36. " GAWK ref. p. 117
  37. syn keyword awkStatement    nextfile
  38. " AWK  ref. p. 42, GAWK ref. p. 142-166
  39. syn keyword awkFunction    atan2 close cos exp fflush int log rand sin sqrt srand
  40. syn keyword awkFunction    gsub index length match split sprintf sub
  41. syn keyword awkFunction    substr system
  42. " GAWK ref. p. 142-166
  43. syn keyword awkFunction    asort gensub mktime strftime strtonum systime
  44. syn keyword awkFunction    tolower toupper
  45. syn keyword awkFunction    and or xor compl lshift rshift
  46. syn keyword awkFunction    dcgettext bindtextdomain
  47.  
  48. syn keyword awkConditional    if else
  49. syn keyword awkRepeat    while for
  50.  
  51. syn keyword awkTodo        contained TODO
  52.  
  53. syn keyword awkPatterns    BEGIN END
  54. " AWK  ref. p. 36
  55. syn keyword awkVariables    ARGC ARGV FILENAME FNR FS NF NR
  56. syn keyword awkVariables    OFMT OFS ORS RLENGTH RS RSTART SUBSEP
  57. " GAWK ref. p. 120-126
  58. syn keyword awkVariables    ARGIND BINMODE CONVFMT ENVIRON ERRNO
  59. syn keyword awkVariables    FIELDWIDTHS IGNORECASE LINT PROCINFO
  60. syn keyword awkVariables    RT RLENGTH TEXTDOMAIN
  61.  
  62. syn keyword awkRepeat    do
  63.  
  64. " Octal format character.
  65. syn match   awkSpecialCharacter display contained "\\[0-7]\{1,3\}"
  66. syn keyword awkStatement    func nextfile
  67. " Hex   format character.
  68. syn match   awkSpecialCharacter display contained "\\x[0-9A-Fa-f]\+"
  69.  
  70. syn match   awkFieldVars    "\$\d\+"
  71.  
  72. "catch errors caused by wrong parenthesis
  73. syn region    awkParen    transparent start="(" end=")" contains=ALLBUT,awkParenError,awkSpecialCharacter,awkArrayElement,awkArrayArray,awkTodo,awkRegExp,awkBrktRegExp,awkBrackets,awkCharClass
  74. syn match    awkParenError    display ")"
  75. syn match    awkInParen    display contained "[{}]"
  76.  
  77. " 64 lines for complex &&'s, and ||'s in a big "if"
  78. syn sync ccomment awkParen maxlines=64
  79.  
  80. " Search strings & Regular Expressions therein.
  81. syn region  awkSearch    oneline start="^[ \t]*/"ms=e start="\(,\|!\=\~\)[ \t]*/"ms=e skip="\\\\\|\\/" end="/" contains=awkBrackets,awkRegExp,awkSpecialCharacter
  82. syn region  awkBrackets    contained start="\[\^\]\="ms=s+2 start="\[[^\^]"ms=s+1 end="\]"me=e-1 contains=awkBrktRegExp,awkCharClass
  83. syn region  awkSearch    oneline start="[ \t]*/"hs=e skip="\\\\\|\\/" end="/" contains=awkBrackets,awkRegExp,awkSpecialCharacter
  84.  
  85. syn match   awkCharClass    contained "\[:[^:\]]*:\]"
  86. syn match   awkBrktRegExp    contained "\\.\|.\-[^]]"
  87. syn match   awkRegExp    contained "/\^"ms=s+1
  88. syn match   awkRegExp    contained "\$/"me=e-1
  89. syn match   awkRegExp    contained "[?.*{}|+]"
  90.  
  91. " String and Character constants
  92. " Highlight special characters (those which have a backslash) differently
  93. syn region  awkString    start=+"+  skip=+\\\\\|\\"+  end=+"+  contains=@Spell,awkSpecialCharacter,awkSpecialPrintf
  94. syn match   awkSpecialCharacter contained "\\."
  95.  
  96. " Some of these combinations may seem weird, but they work.
  97. syn match   awkSpecialPrintf    contained "%[-+ #]*\d*\.\=\d*[cdefgiosuxEGX%]"
  98.  
  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.  
  115. "syn match  awkIdentifier    "\<[a-zA-Z_][a-zA-Z0-9_]*\>"
  116.  
  117. " Arithmetic operators: +, and - take care of ++, and --
  118. "syn match   awkOperator    "+\|-\|\*\|/\|%\|="
  119. "syn match   awkOperator    "+=\|-=\|\*=\|/=\|%="
  120. "syn match   awkOperator    "^\|^="
  121.  
  122. " Comparison expressions.
  123. "syn match   awkExpression    "==\|>=\|=>\|<=\|=<\|\!="
  124. "syn match   awkExpression    "\~\|\!\~"
  125. "syn match   awkExpression    "?\|:"
  126. "syn keyword awkExpression    in
  127.  
  128. " Boolean Logic (OR, AND, NOT)
  129. "syn match  awkBoolLogic    "||\|&&\|\!"
  130.  
  131. " This is overridden by less-than & greater-than.
  132. " Put this above those to override them.
  133. " Put this in a 'match "\<printf\=\>.*;\="' to make it not override
  134. " less/greater than (most of the time), but it won't work yet because
  135. " keywords always have precedence over match & region.
  136. " File I/O: (print foo, bar > "filename") & for nawk (getline < "filename")
  137. "syn match  awkFileIO        contained ">"
  138. "syn match  awkFileIO        contained "<"
  139.  
  140. " Expression separators: ';' and ','
  141. syn match  awkSemicolon    ";"
  142. syn match  awkComma        ","
  143.  
  144. syn match  awkComment    "#.*" contains=@Spell,awkTodo
  145.  
  146. syn match  awkLineSkip    "\\$"
  147.  
  148. " Highlight array element's (recursive arrays allowed).
  149. " Keeps nested array names' separate from normal array elements.
  150. " Keeps numbers separate from normal array elements (variables).
  151. syn match  awkArrayArray    contained "[^][, \t]\+\["me=e-1
  152. syn match  awkArrayElement      contained "[^][, \t]\+"
  153. syn region awkArray        transparent start="\[" end="\]" contains=awkArray,awkArrayElement,awkArrayArray,awkNumber,awkFloat
  154.  
  155. " 10 should be enough.
  156. " (for the few instances where it would be more than "oneline")
  157. syn sync ccomment awkArray maxlines=10
  158.  
  159. " define the default highlighting
  160. " For version 5.7 and earlier: only when not done already
  161. " For version 5.8 and later: only when an item doesn't have highlighting yet
  162. if version >= 508 || !exists("did_awk_syn_inits")
  163.   if version < 508
  164.     let did_awk_syn_inits = 1
  165.     command -nargs=+ HiLink hi link <args>
  166.   else
  167.     command -nargs=+ HiLink hi def link <args>
  168.   endif
  169.  
  170.   HiLink awkConditional        Conditional
  171.   HiLink awkFunction        Function
  172.   HiLink awkRepeat        Repeat
  173.   HiLink awkStatement        Statement
  174.  
  175.   HiLink awkString        String
  176.   HiLink awkSpecialPrintf    Special
  177.   HiLink awkSpecialCharacter    Special
  178.  
  179.   HiLink awkSearch        String
  180.   HiLink awkBrackets        awkRegExp
  181.   HiLink awkBrktRegExp        awkNestRegExp
  182.   HiLink awkCharClass        awkNestRegExp
  183.   HiLink awkNestRegExp        Keyword
  184.   HiLink awkRegExp        Special
  185.  
  186.   HiLink awkNumber        Number
  187.   HiLink awkFloat        Float
  188.  
  189.   HiLink awkFileIO        Special
  190.   "HiLink awkOperator        Special
  191.   "HiLink awkExpression        Special
  192.   HiLink awkBoolLogic        Special
  193.  
  194.   HiLink awkPatterns        Special
  195.   HiLink awkVariables        Special
  196.   HiLink awkFieldVars        Special
  197.  
  198.   HiLink awkLineSkip        Special
  199.   HiLink awkSemicolon        Special
  200.   HiLink awkComma        Special
  201.   "HiLink awkIdentifier        Identifier
  202.  
  203.   HiLink awkComment        Comment
  204.   HiLink awkTodo        Todo
  205.  
  206.   " Change this if you want nested array names to be highlighted.
  207.   HiLink awkArrayArray        awkArray
  208.   HiLink awkArrayElement    Special
  209.  
  210.   HiLink awkParenError        awkError
  211.   HiLink awkInParen        awkError
  212.   HiLink awkError        Error
  213.  
  214.   delcommand HiLink
  215. endif
  216.  
  217. let b:current_syntax = "awk"
  218.  
  219. let &cpo = s:cpo_save
  220. unlet s:cpo_save
  221.  
  222. " vim: ts=8
  223.