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

  1. " Vim syntax file;
  2. " Language:    Perl
  3. " Maintainer:    Nick Hibma <nick.hibma@jrc.it>
  4. " Last change:    1998 Aug 26
  5. "
  6. " Original version: Sonia Heimann <niania@netsurf.org>
  7. " 1998/08/25 NWH Added perl_sync_dist
  8. " 1998/08/26 NWH Cleaned it up and added help files.
  9.  
  10. " Remove any old syntax stuff hanging around
  11. syn clear
  12. "
  13. " the following parameters are available for tuning the
  14. " perl syntax highlighting
  15. "
  16. "let perl_want_scope_in_variables = 1
  17. "let perl_extended_vars = 1
  18. "let perl_highlight_matches = 1
  19. "let perl_no_sync_on_sub = 1
  20. "let perl_sync_dist = 200
  21.  
  22.  
  23. " First, treat the the #!/bin/perl
  24. syn match  perlSharpBang         "^#!.\+$"
  25. " All other # are comment, when at the beginning of a line or after a space
  26. " (avoid m## case ...)
  27. syn match  perlComment         "^#\([^!].*\)\=$\|\s#.*" contains=perlTodo
  28.  
  29. "
  30. " POD documentation
  31. "
  32.  
  33. " POD starts with ^=head and ends with =cut
  34. " Set the variable "perl_embedded_pod" to use embedded POD syntax file.
  35.  
  36. if !exists("perl_embedded_pod")
  37.   syntax region perlPOD start=+^=head+ end=+=cut+
  38.   syn sync match perlSyncPOD grouphere perlPOD "^=head"
  39.   syn sync match perlSyncPOD groupthere NONE "^=cut"
  40. else
  41.   let b:embedded_pod = 1
  42.   source <sfile>:p:h/pod.vim
  43.   unlet b:embedded_pod
  44.  
  45.   syn region perlEmbeddedPod start="^=pod" start="^=head1" matchgroup=podCommand end="^=cut" contains=podCommand,podVerbatimLine,podSpecial,podFormat
  46.   syn sync match perlEmbeddedPod grouphere perlEmbeddedPod "^=pod"
  47.   syn sync match perlEmbeddedPod grouphere perlEmbeddedPod "^=head1"
  48.   syn sync match perlEmbeddedPod groupthere NONE "^=cut"
  49. endif
  50.  
  51.  
  52. "
  53. " Syncing to speed up processing
  54. "
  55. if !exists("perl_no_sync_on_sub")
  56.   syn sync match perlSync grouphere NONE "^package\s+"
  57.   syn sync match perlSync grouphere NONE "^sub\s\+"
  58. endif
  59.  
  60. if exists("perl_sync_dist")
  61.   execute "syn sync maxlines=" . perl_sync_dist
  62. else
  63.   syn sync maxlines=100
  64. endif
  65.  
  66.  
  67. "
  68. " All keywords
  69. "
  70. syn keyword perlLabel                   case default
  71. syn keyword perlConditional             if elsif unless else switch eq ne gt lt ge le cmp not and or xor
  72. syn keyword perlRepeat                  while for foreach do until
  73. syn keyword perlOperator                defined undef and or not bless ref
  74. syn keyword perlControl                 BEGIN END
  75.  
  76. syn keyword perlStatementStorageClass   my local
  77. syn keyword perlStatementControl        goto return last next continue redo
  78. syn keyword perlStatementScalar         chomp chop chr crypt index lc lcfirst length ord pack reverse rindex sprintf substr uc ucfirst
  79. syn keyword perlStatementRegexp         pos quotemeta split study
  80. syn keyword perlStatementNumeric        abs atan2 cos exp hex int log oct rand sin sqrt srand
  81. syn keyword perlStatementList           splice unshift shift push pop split join reverse grep map qw sort unpack
  82. syn keyword perlStatementHash           each exists keys values
  83. syn keyword perlStatementIOfunc         binmode close closedir dbmclose dbmopen die eof fileno flock format getc print printf read readdir rewinddir seek seekdir select syscall sysopen sysread syswrite tell telldir truncate warn write
  84. syn keyword perlStatementFixedlength    pack vec
  85. syn keyword perlStatementFiles          chdir chmod chown chroot fcntl glob ioctl link lstat mkdir open opendir readlink rename rmdir stat symlink umask unlink utime
  86. syn keyword perlStatementFlow           caller die dump eval exit wantarray
  87. syn keyword perlStatementInclude        use require
  88. syn keyword perlStatementScope          import
  89. syn keyword perlStatementProc           alarm exec fork getpgrp getppid getpriority kill pipe qx setpgrp setpriority sleep system times wait waitpid
  90. syn keyword perlStatementSocket         accept bind connect getpeername getsockname getsockopt listen recv send setsockopt shutdown socket socketpair
  91. syn keyword perlStatementIPC            msgctl msgget msgrcv msgsnd semctl semget semop shmctl shmget shmread shmwrite
  92. syn keyword perlStatementNetwork        endprotoent endservent gethostbyaddr gethostbyname gethostent getnetbyaddr getnetbyname getnetent getprotobyname getprotobynumber getprotoent getservbyname getservbyport getservent sethostent setnetent setprotoent setservent
  93. syn keyword perlStatementTime           gmtime localtime time times
  94. syn keyword perlStatementMisc           print warn formline reset scalar new delete STDIN STDOUT STDERR
  95.  
  96. syn keyword perlTodo contained TODO TBD FIXME
  97.  
  98. "
  99. " Perl Identifiers.
  100. "
  101.  
  102. " Plain identifier:
  103. "   Scalar identifier: $foo
  104. "   Array identifier: @foo
  105. "   Array Length: $#foo
  106. "   Hash identifier: %foo
  107. "   Function identifier: &foo
  108. "   Reference dereferences: @$foo, %$$foo, &$foo, $$foo, ...
  109.  
  110. " We do not process complex things such as @{${"foo"}}. Too complicated, and
  111. " too slow. And what is after the -> is *not* considered as part of the
  112. " variable - there again, too complicated and too slow.
  113.  
  114. " Special variables first ($^A, ...) and ($|, $', ...)
  115. syn match  perlVarPlain "$^[\u\\\"\[\]'&`+*.,;=%~^!@$<>(0-9-]"
  116. syn match  perlVarPlain "$[\\\"\[\]'&`+*.,;=%~^!@$<>(0-9-]"
  117. " Same as above, but avoids confusion in $::hello (equivalent to $main::hello)
  118. syn match  perlVarPlain "$:[^:]"
  119. " These variables are not recognized within matches.
  120. syn match perlVarNotInMatches "$[|)]"
  121. " This variable is not recognized within matches delimited by //.
  122. syn match perlVarSlash "$/"
  123.  
  124. " And plain identifiers
  125.  
  126. syn match perlPackageRef "\(\h\w*\)\=\(::\|'\)\I"me=e-1 contained
  127.  
  128. " To highlight packages in variables as a scope reference - i.e. in $pack::var,
  129. " pack:: is a scope, just set "perl_want_scope_in_variables"
  130. " If you *want* complex things like @{${"foo"}} to be processed,
  131. " just set the variable "perl_extended_vars"...
  132.  
  133. if exists("perl_want_scope_in_variables")
  134.   syn match perlVarPlain   "\\\=\(\$#\|[@%&$]\)\$*\(\I\i*\)\=\(\(::\|'\)\I\i*\)*\>" contains=perlPackageRef nextgroup=perlVarMember
  135. else
  136.   syn match perlVarPlain   "\\\=\(\$#\|[@%&$]\)\$*\(\I\i*\)\=\(\(::\|'\)\I\i*\)*\>" nextgroup=perlVarMember
  137. endif
  138.  
  139. if exists("perl_extended_vars")
  140.   syn region perlVarPlain start="\($#\|[@%\$]\){" skip="\\}" end="}" contains=perlVarPlain,perlVarNotInMatches,perlVarSlash nextgroup=perlVarMember
  141.   syn region perlVarMember start="\(->\)\={" skip="\\}" end="}" contained contains=perlVarPlain,perlVarNotInMatches,perlVarSlash nextgroup=perlVarMember
  142.   syn region perlVarMember start="\(->\)\=\[" skip="\\]" end="]" contained contains=perlVarPlain,perlVarNotInMatches,perlVarSlash nextgroup=perlVarMember
  143. endif
  144.  
  145. "
  146. " String and Character constants
  147. "
  148.  
  149. " Highlight special characters (those which have a backslash) differently
  150. syn match   perlSpecial           contained "\\\(\d\+\|[xX]\x\+\|.\)"
  151.  
  152. " "" String may contain variables
  153. syn match   perlCharacter         "'[^\\]'"
  154. syn match   perlSpecialCharacter  "'\\.'"
  155. " version < 5.2f
  156. "syn match   perlSpecialCharacter  "'\\[0-9][0-9][0-9]'"
  157. " versions >= 5.2f
  158. syn match   perlSpecialCharacter  "'\\\d\d\d'"
  159.  
  160. " Strings
  161. syn region  perlString            start=+"+  skip=+\\\\\|\\"+  end=+"+ contains=perlSpecial,perlVarPlain,perlVarNotInMatches,perlVarSlash
  162. " '' Strings may not contain anything
  163. syn region  perlStringUnexpanded  start=+'+  skip=+\\\\\|\\"+  end=+'+
  164. "contains=perlSpecial
  165. syn region  perlStringUnexpanded  start="qw("hs=s+2 skip="\\\\\|\\)" end=")"
  166. "contains=perlSpecial
  167.  
  168. " Shell commands
  169. syn region  perlShellCommand            start=+`+  skip=+\\\\\|\\"+  end=+`+ contains=perlSpecial,perlVarPlain
  170.  
  171. " Numbers
  172. syn match  perlNumber          "-\=\<\d\+L\=\>\|0[xX]\x\+\>"
  173.  
  174. " Constructs such as print <<EOF [...] EOF
  175. syn region perlUntilEOF start=+<<\(["`]\=\)EOF\1+hs=s+2 end=+^EOF$+ contains=perlSpecial,perlVarPlain,perlVarNotInMatches,perlVarSlash
  176. syn region perlUntilEOF start=+<<'EOF'+hs=s+2 end=+^EOF$+ contains=perlSpecial
  177. " When vim supports it, try to use something as
  178. " syntax region perlUntilEOF start=+<<\(["`]\=\)\([a-zA-Z]\+\)\1+s+2 end=+^\2$+
  179. " to allow any keyword, not just EOF. The \2 in the end pattern refers of
  180. " course to the second group in the start pattern.
  181.  
  182. "
  183. " Perl regexps, second version, thanks to Michael Firestone
  184. "
  185.  
  186. " any qq## expression
  187. syn match perlQQ "\<q[qxw]\=\([^\s\w]\).*[^\\]\(\\\\\)*\1" contains=perlVarPlain, perlVarSlash
  188. " Any m## match
  189. syn match perlMatchAny "\<m\([^\s\w]\).*[^\\]\(\\\\\)*\1[xosmige]*" contains=perlVarPlain,perlVarSlash
  190. " Plain m// match
  191. syn match perlMatchAny "\<m/.*[^\\]\(\\\\\)*/[xosmige]*" contains=perlVarPlain
  192. " Any s### substitute
  193. " s/// is handled separately, since it can't contain $/ as a variable.
  194. syn match perlSubstitute "\<s\([^\w\s]\).\{-}[^\\]\(\\\\\)*\1.\{-}[^\\]\(\\\\\)*\1[xosmige]*" contains=perlVarPlain,perlVarSlash
  195. syn match perlSubstitute "\<\(s\|y\|tr\)/.\{-}[^\\]\(\\\\\)*/.\{-}[^\\]\(\\\\\)*/[xosmige]*" contains=perlVarPlain
  196. " Note that the above rules don't match substitutions with empty
  197. " replacement texts (like s/deleteme//); these rules cover those.
  198. syn match perlSubstitute "\<s\([^\w\s]\).\{-}[^\\]\(\\\\\)*\1\1[xosmige]*" contains=perlVarPlain,perlVarSlash
  199. syn match perlSubstitute "\<\(s\|y\|tr\)/.\{-}[^\\]\(\\\\\)*//[xosmige]*" contains=perlVarPlain
  200. " The classical // construct
  201. syn match perlMatch "/\(\\/\|[^/]\)*[^\\]\(\\\\\)*/[xosmige]*" contains=perlVarPlain
  202.  
  203. syn match perlClassDecl        "^\s*package\>[^;]*"
  204.  
  205. "syn match  perlLineSkip     "\\$"
  206.  
  207. "
  208. " Functions
  209. "
  210.  
  211. " find ^sub foo { . Only highlight foo.
  212. " Function is sub foo { , sub foo( , sub foo;
  213. " Sneaky:  Instead of terminating the region at a '(' (the start of a
  214. " prototype), contain the prototype in the region and give it no
  215. " highlighting; that way, things inside the prototype that look like
  216. " variables won't be highlighted as variables.
  217. syn region perlFunction start=+^\s*sub\s\++ end=+[;{]+me=s-1 contains=perlFunction,perlFunctionPrototype
  218. syn match perlFunctionPrototype "([^)]*)" contained
  219. syn match perlStatementSub "sub" contained
  220.  
  221. if !exists("did_perl_syntax_inits")
  222.   let did_perl_syntax_inits = 1
  223.   " The default methods for highlighting.  Can be overridden later
  224.   hi link perlSharpBang  PreProc
  225.   hi link perlLabel        Label
  226.   hi link perlConditional    Conditional
  227.   hi link perlRepeat        Repeat
  228.   hi link perlOperator        Operator
  229.   hi link perlList        perlStatement
  230.   hi link perlMisc        perlStatement
  231.   hi link perlVarPlain    perlIdentifier
  232.   hi link perlVarMember    perlIdentifier
  233.   hi link perlVarNotInMatches    perlIdentifier
  234.   hi link perlVarSlash    perlIdentifier
  235.   hi link perlQQ    perlString
  236.   hi link perlUntilEOF    perlString
  237.   hi link perlStringUnexpanded    perlString
  238.   hi link perlCharacter        Character
  239.   hi link perlSpecialCharacter    perlSpecial
  240.   hi link perlMatchAny perlMatch
  241.   hi link perlSubstitute perlMatch
  242.   " I happen to prefer having matches and substitutions highlighted; if you
  243.   " agree, set the variable "perl_highlight_matches".
  244.   if exists("perl_highlight_matches")
  245.     hi link perlMatch    perlString
  246.   endif
  247.   hi link perlNumber        Number
  248.   hi link perlClassDecl        Typedef
  249.   hi link perlStorageClass    perlType
  250.   hi link perlPackageRef perlType
  251.   hi link perlInclude        Include
  252.   hi link perlControl        PreProc
  253.   hi link perlStatementStorageClass perlStatement
  254.   hi link perlStatementControl      perlStatement
  255.   hi link perlStatementScalar       perlStatement
  256.   hi link perlStatementRegexp       perlStatement
  257.   hi link perlStatementNumeric      perlStatement
  258.   hi link perlStatementList         perlStatement
  259.   hi link perlStatementHash         perlStatement
  260.   hi link perlStatementIOfunc       perlStatement
  261.   hi link perlStatementFixedlength  perlStatement
  262.   hi link perlStatementFiles        perlStatement
  263.   hi link perlStatementFlow         perlStatement
  264.   hi link perlStatementScope        perlStatement
  265.   hi link perlStatementInclude      perlStatement
  266.   hi link perlStatementProc         perlStatement
  267.   hi link perlStatementSocket       perlStatement
  268.   hi link perlStatementIPC          perlStatement
  269.   hi link perlStatementNetwork      perlStatement
  270.   hi link perlStatementTime         perlStatement
  271.   hi link perlStatementMisc         perlStatement
  272.   hi link perlStatementSub        perlStatement
  273.   hi link  perlStatement        Statement
  274.   hi link  perlType        Type
  275.   hi link  perlString        String
  276.   hi link  perlPOD            perlComment
  277.   hi link  perlShellCommand     Special
  278.   hi link  perlComment        Comment
  279.   hi link  perlSpecial        Special
  280.   hi link  perlTodo        Todo
  281.   hi link  perlFunction        Function
  282.   hi link  perlIdentifier    Identifier
  283. endif
  284.  
  285. let b:current_syntax = "perl"
  286.  
  287. " vim: ts=8
  288.