home *** CD-ROM | disk | FTP | other *** search
/ Chip 2000 February / OpenLinux 2.3 CD.iso / live / usr / share / vim / syntax / awk.vim < prev    next >
Encoding:
Text File  |  1999-08-10  |  6.9 KB  |  200 lines

  1. " Vim syntax file
  2. " Language:    awk, nawk, gawk, mawk
  3. " Maintainer:    Antonio Colombo <antonio.colombo@jrc.org>
  4. " Last change:    1997 November 29
  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, A User's Guide for GNU Awk
  11. " Edition 1.0.3, Free Software Foundation, 1997
  12.  
  13. " MAWK is a "new awk" meaning it implements AWK ref.
  14. " mawk conforms to the Posix 1003.2 (draft 11.3)
  15. " definition of the AWK language which contains a few features
  16. " not described in the AWK book, and mawk provides a small number of extensions.
  17.  
  18. " TODO:
  19. " Dig into the commented out syntax expressions below.
  20.  
  21. " Remove any old syntax stuff hanging around
  22. syn clear
  23.  
  24. " A bunch of useful Awk keywords
  25. " AWK  ref. p. 188
  26. syn keyword awkStatement    break continue delete exit
  27. syn keyword awkStatement    function getline next
  28. syn keyword awkStatement    print printf return
  29. " GAWK ref. p. 268
  30. syn keyword awkStatement    nextfile
  31. " AWK  ref. p. 42, GAWK ref. p. 272
  32. syn keyword awkFunction    atan2 close cos exp int log rand sin sqrt srand
  33. syn keyword awkFunction    gsub index length match split sprintf sub
  34. syn keyword awkFunction    substr system
  35. " GAWK ref. p. 273-274
  36. syn keyword awkFunction    fflush gensub tolower toupper
  37. syn keyword awkFunction    systime strftime
  38.  
  39. syn keyword awkConditional    if else
  40. syn keyword awkRepeat    while for
  41.  
  42. syn keyword awkTodo        contained TODO
  43.  
  44. syn keyword awkPatterns    BEGIN END
  45. " AWK  ref. p. 36
  46. syn keyword awkVariables    ARGC ARGV FILENAME FNR FS NF NR
  47. syn keyword awkVariables    OFMT OFS ORS RLENGTH RS RSTART SUBSEP
  48. " GAWK ref. p. 260
  49. syn keyword awkVariables    ARGIND CONVFMT ENVIRON ERRNO
  50. syn keyword awkVariables    FIELDWIDTHS IGNORECASE RT RLENGTH
  51.  
  52. syn keyword awkRepeat    do
  53.  
  54. " Octal format character.
  55. syn match   awkSpecialCharacter contained "\\[0-7]\{1,3\}"
  56. syn keyword awkStatement    func nextfile
  57. " Hex   format character.
  58. syn match   awkSpecialCharacter contained "\\x[0-9A-Fa-f]\+"
  59.  
  60. syn match   awkFieldVars    "\$\d\+"
  61.  
  62. "catch errors caused by wrong parenthesis
  63. syn region    awkParen    transparent start="(" end=")" contains=ALLBUT,awkParenError,awkSpecialCharacter,awkArrayElement,awkArrayArray,awkTodo,awkRegExp,awkBrktRegExp,awkBrackets,awkCharClass
  64. syn match    awkParenError    ")"
  65. syn match    awkInParen    contained "[{}]"
  66.  
  67. " 64 lines for complex &&'s, and ||'s in a big "if"
  68. syn sync ccomment awkParen maxlines=64
  69.  
  70. " Search strings & Regular Expressions therein.
  71. syn region  awkSearch    oneline start="^[ \t]*/"ms=e start="\(,\|!\=\~\)[ \t]*/"ms=e skip="\\\\\|\\/" end="/" contains=awkBrackets,awkRegExp,awkSpecialCharacter
  72. syn region  awkBrackets    contained start="\[\^\]\="ms=s+2 start="\[[^\^]"ms=s+1 end="\]"me=e-1 contains=awkBrktRegExp,awkCharClass
  73. syn region  awkSearch    oneline start="[ \t]*/"hs=e skip="\\\\\|\\/" end="/" contains=awkBrackets,awkRegExp,awkSpecialCharacter
  74.  
  75. syn match   awkCharClass    contained "\[:[^:\]]*:\]"
  76. syn match   awkBrktRegExp    contained "\\.\|.\-[^]]"
  77. syn match   awkRegExp    contained "/\^"ms=s+1
  78. syn match   awkRegExp    contained "\$/"me=e-1
  79. syn match   awkRegExp    contained "[?.*{}|+]"
  80.  
  81. " String and Character constants
  82. " Highlight special characters (those which have a backslash) differently
  83. syn region  awkString    start=+"+  skip=+\\\\\|\\"+  end=+"+  contains=awkSpecialCharacter,awkSpecialPrintf
  84. syn match   awkSpecialCharacter contained "\\."
  85.  
  86. " Some of these combinations may seem weird, but they work.
  87. syn match   awkSpecialPrintf    contained "%[-+ #]*\d*\.\=\d*[cdefgiosuxEGX%]"
  88.  
  89. " Numbers, allowing signs (both -, and +)
  90. " Integer number.
  91. syn match  awkNumber        "[+-]\=\<\d\+\>"
  92. " Floating point number.
  93. syn match  awkFloat        "[+-]\=\<\d\+\.\d+\>"
  94. " Floating point number, starting with a dot.
  95. syn match  awkFloat        "[+-]\=\<.\d+\>"
  96. syn case ignore
  97. "floating point number, with dot, optional exponent
  98. syn match  awkFloat    "\<\d\+\.\d*\(e[-+]\=\d\+\)\=\>"
  99. "floating point number, starting with a dot, optional exponent
  100. syn match  awkFloat    "\.\d\+\(e[-+]\=\d\+\)\=\>"
  101. "floating point number, without dot, with exponent
  102. syn match  awkFloat    "\<\d\+e[-+]\=\d\+\>"
  103. syn case match
  104.  
  105. "syn match  awkIdentifier    "\<[a-zA-Z_][a-zA-Z0-9_]*\>"
  106.  
  107. " Arithmetic operators: +, and - take care of ++, and --
  108. "syn match   awkOperator    "+\|-\|\*\|/\|%\|="
  109. "syn match   awkOperator    "+=\|-=\|\*=\|/=\|%="
  110. "syn match   awkOperator    "^\|^="
  111.  
  112. " Comparison expressions.
  113. "syn match   awkExpression    "==\|>=\|=>\|<=\|=<\|\!="
  114. "syn match   awkExpression    "\~\|\!\~"
  115. "syn match   awkExpression    "?\|:"
  116. "syn keyword awkExpression    in
  117.  
  118. " Boolean Logic (OR, AND, NOT)
  119. "syn match  awkBoolLogic    "||\|&&\|\!"
  120.  
  121. " This is overridden by less-than & greater-than.
  122. " Put this above those to override them.
  123. " Put this in a 'match "\<printf\=\>.*;\="' to make it not override
  124. " less/greater than (most of the time), but it won't work yet because
  125. " keywords allways have precedence over match & region.
  126. " File I/O: (print foo, bar > "filename") & for nawk (getline < "filename")
  127. "syn match  awkFileIO        contained ">"
  128. "syn match  awkFileIO        contained "<"
  129.  
  130. " Expression separators: ';' and ','
  131. syn match  awkSemicolon    ";"
  132. syn match  awkComma        ","
  133.  
  134. syn match  awkComment    "#.*" contains=awkTodo
  135.  
  136. syn match  awkLineSkip    "\\$"
  137.  
  138. " Highlight array element's (recursive arrays allowed).
  139. " Keeps nested array names' separate from normal array elements.
  140. " Keeps numbers separate from normal array elements (variables).
  141. syn match  awkArrayArray    contained "[^][, \t]*\["me=e-1
  142. syn match  awkArrayElement    contained "[^][, \t]*"
  143. syn region awkArray        transparent start="\[" end="\]" contains=awkArray,awkArrayElement,awkArrayArray,awkNumber,awkFloat
  144.  
  145. " 10 should be enough.
  146. " (for the few instances where it would be more than "oneline")
  147. syn sync ccomment awkArray maxlines=10
  148.  
  149. if !exists("did_awk_syntax_inits")
  150.   let did_awk_syntax_inits = 1
  151.   " The default methods for highlighting.  Can be overridden later
  152.   hi link awkConditional    Conditional
  153.   hi link awkFunction    Function
  154.   hi link awkRepeat    Repeat
  155.   hi link awkStatement    Statement
  156.  
  157.   hi link awkString    String
  158.   hi link awkSpecialPrintf Special
  159.   hi link awkSpecialCharacter Special
  160.  
  161.   hi link awkSearch    String
  162.   hi link awkBrackets    awkRegExp
  163.   hi link awkBrktRegExp    awkNestRegExp
  164.   hi link awkCharClass    awkNestRegExp
  165.   hi link awkNestRegExp    Keyword
  166.   hi link awkRegExp    Special
  167.  
  168.   hi link awkNumber    Number
  169.   hi link awkFloat    Float
  170.  
  171.   hi link awkFileIO    Special
  172.   "hi link awkOperator    Special
  173.   "hi link awkExpression    Special
  174.   hi link awkBoolLogic    Special
  175.  
  176.   hi link awkPatterns    Special
  177.   hi link awkVariables    Special
  178.   hi link awkFieldVars    Special
  179.  
  180.   hi link awkLineSkip    Special
  181.   hi link awkSemicolon    Special
  182.   hi link awkComma    Special
  183.   "hi link awkIdentifier    Identifier
  184.  
  185.   hi link awkComment    Comment
  186.   hi link awkTodo    Todo
  187.  
  188.   " Change this if you want nested array names to be highlighted.
  189.   hi link awkArrayArray    awkArray
  190.   hi link awkArrayElement Special
  191.  
  192.   hi link awkParenError    awkError
  193.   hi link awkInParen    awkError
  194.   hi link awkError    Error
  195. endif
  196.  
  197. let b:current_syntax = "awk"
  198.  
  199. " vim: ts=8
  200.