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 / unix / vim-6.2.tar.bz2 / vim-6.2.tar / vim62 / runtime / syntax / awk.vim < prev    next >
Encoding:
Text File  |  2002-06-23  |  7.5 KB  |  217 lines

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