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 / mac / vim55rt.sit / runtime / syntax / perl.vim < prev    next >
Encoding:
Text File  |  1999-09-25  |  17.5 KB  |  353 lines  |  [TEXT/VIM!]

  1. " Vim syntax file
  2. " Language:        Perl
  3. " Maintainer:      Nick Hibma <hibma@skylink.it>
  4. " Last change:     1999 July 31
  5. " Location:        http://www.etla.net/~n_hibma/vim/syntax/perl.vim
  6. "
  7. " Please download most recent version first before mailing any comments.
  8. " See also the file perl.vim.regression.pl to check whether your
  9. " modifications work in the most odd cases
  10. "       http://www.etla.net/~n_hibma/vim/syntax/perl.vim.regression.pl
  11. "
  12. " Original version: Sonia Heimann <niania@netsurf.org>
  13. " Thanks to many people for their contribution. They made it work, not me.
  14.  
  15. " The following parameters are available for tuning the
  16. " perl syntax highlighting, with defaults given:
  17. "
  18. " let perl_include_pod = 0
  19. " let perl_want_scope_in_variables = 0
  20. " let perl_extended_vars = 0
  21. " unlet perl_string_as_statement
  22. " unlet perl_no_sync_on_sub
  23. " unlet perl_no_sync_on_global_var
  24. " let perl_sync_dist = 100
  25.  
  26. " Remove any old syntax stuff hanging around
  27. syn clear
  28.  
  29. " POD starts with ^=<word> and ends with ^=cut
  30.  
  31. if exists("perl_include_pod")
  32.   " Include a while extra syntax file
  33.   syntax include @Pod <sfile>:p:h/pod.vim
  34.   syntax region perlPOD start="^=[a-z]" end="^=cut" contains=@Pod,perlTodo keepend
  35. else
  36.   " Use only the bare minimum of rules
  37.   syntax region perlPOD start="^=[a-z]" end="^=cut"
  38. endif
  39.  
  40.  
  41. " All keywords
  42. "
  43. syn keyword perlLabel            case default
  44. syn keyword perlConditional      if elsif unless else switch eq ne gt lt ge le cmp not and or xor
  45. syn keyword perlRepeat           while for foreach do until
  46. syn keyword perlOperator         defined undef and or not bless ref
  47. syn keyword perlControl          BEGIN END
  48.  
  49. syn keyword perlStatementStorage my local
  50. syn keyword perlStatementControl goto return last next continue redo
  51. syn keyword perlStatementScalar  chomp chop chr crypt index lc lcfirst length ord pack reverse rindex sprintf substr uc ucfirst
  52. syn keyword perlStatementRegexp  pos quotemeta split study
  53. syn keyword perlStatementNumeric abs atan2 cos exp hex int log oct rand sin sqrt srand
  54. syn keyword perlStatementList    splice unshift shift push pop split join reverse grep map sort unpack
  55. syn keyword perlStatementHash    each exists keys values
  56. syn keyword perlStatementIOfunc  binmode carp close closedir confess croak dbmclose dbmopen die eof fileno flock getc print printf read readdir rewinddir seek seekdir select syscall sysopen sysread syswrite tell telldir truncate warn write
  57. syn keyword perlStatementVector  pack vec
  58. syn keyword perlStatementFiles   chdir chmod chown chroot fcntl glob ioctl link lstat mkdir open opendir readlink rename rmdir stat symlink umask unlink utime
  59. syn match   perlStatementFiles   "-[rwxoRWXOezsfdlpSbctugkTBMAC]\>"
  60. syn keyword perlStatementFlow    caller die dump eval exit wantarray
  61. syn keyword perlStatementInclude require
  62. syn match   perlStatementInclude "\(use\|no\)\s\+\(integer\>\|strict\>\|lib\>\|sigtrap\>\|subs\>\|vars\>\)\="
  63. syn keyword perlStatementScope   import
  64. syn keyword perlStatementProc    alarm exec fork getpgrp getppid getpriority kill pipe setpgrp setpriority sleep system times wait waitpid
  65. syn keyword perlStatementSocket  accept bind connect getpeername getsockname getsockopt listen recv send setsockopt shutdown socket socketpair
  66. syn keyword perlStatementIPC     msgctl msgget msgrcv msgsnd semctl semget semop shmctl shmget shmread shmwrite
  67. syn keyword perlStatementNetwork endprotoent endservent gethostbyaddr gethostbyname gethostent getnetbyaddr getnetbyname getnetent getprotobyname getprotobynumber getprotoent getservbyname getservbyport getservent sethostent setnetent setprotoent setservent
  68. syn keyword perlStatementPword   getgrent getgrgid getgrnam getlogia
  69. syn keyword perlStatementTime    gmtime localtime time times
  70.  
  71. syn keyword perlStatementMisc    print warn formline reset scalar new delete STDIN STDOUT STDERR
  72.  
  73. syn keyword perlTodo             TODO TBD FIXME XXX contained
  74.  
  75. " Perl Identifiers.
  76. "
  77. " Should be cleaned up to better handle identifiers in particular situations
  78. " (in hash keys for example)
  79. "
  80. " Plain identifiers: $foo, @foo, $#foo, %foo, &foo and dereferences $$foo, @$foo, etc.
  81. " We do not process complex things such as @{${"foo"}}. Too complicated, and
  82. " too slow. And what is after the -> is *not* considered as part of the
  83. " variable - there again, too complicated and too slow.
  84.  
  85. " Special variables first ($^A, ...) and ($|, $', ...)
  86. syn match perlVarPlain "$^[ADEFHILMOPSTWX]\="
  87. syn match perlVarPlain "$[\\\"\[\]'&`+*.,;=%~!@$<>(0-9-]"
  88. " Same as above, but avoids confusion in $::foo (equivalent to $main::foo)
  89. syn match perlVarPlain "$:[^:]"
  90. " These variables are not recognized within matches.
  91. syn match perlVarNotInMatches "$[|)]"
  92. " This variable is not recognized within matches delimited by m//.
  93. syn match perlVarSlash "$/"
  94.  
  95. " And plain identifiers
  96. syn match perlPackageRef "\(\h\w*\)\=\(::\|'\)\I"me=e-1 contained
  97.  
  98. " To highlight packages in variables as a scope reference - i.e. in $pack::var,
  99. " pack:: is a scope, just set "perl_want_scope_in_variables"
  100. " If you *want* complex things like @{${"foo"}} to be processed,
  101. " just set the variable "perl_extended_vars"...
  102.  
  103. " FIXME value between {} should be marked as string. is treated as such by Perl.
  104. " At the moment it is marked as something greyish instead of read. Probably todo
  105. " with transparency. Or maybe we should handle the bare word in that case. or make it into
  106.  
  107. if exists("perl_want_scope_in_variables")
  108.   syn match perlVarPlain   "\\\=\([@%&$]\|\$#\)\$*\(\I\i*\)\=\(\(::\|'\)\I\i*\)*\>" contains=perlPackageRef nextgroup=perlVarMember,perlVarSimpleMember
  109. else
  110.   syn match perlVarPlain   "\\\=\([@%&$]\|\$#\)\$*\(\I\i*\)\=\(\(::\|'\)\I\i*\)*\>" nextgroup=perlVarMember,perlVarSimpleMember
  111. endif
  112.  
  113. if exists("perl_extended_vars")
  114.   syn cluster perlExpr contains=perlStatementScalar,perlStatementRegexp,perlStatementNumeric,perlStatementList,perlStatementHash,perlStatementFiles,perlStatementTime,perlStatementMisc,perlVarPlain,perlVarNotInMatches,perlVarSlash,perlVarBlock,perlShellCommand,perlNumber,perlStringUnexpanded,perlString,perlQQ
  115.   syn region perlVarBlock matchgroup=perlVarPlain start="\($#\|[@%\$]\){" skip="\\}" end="}" contains=@perlExpr nextgroup=perlVarMember,perlVarSimpleMember
  116.   syn match perlVarPlain   "\\\=\(\$#\|[@%&$]\)\$*{\I\i*}" nextgroup=perlVarMember,perlVarSimpleMember
  117.   syn region perlVarMember matchgroup=perlVarPlain start="\(->\)\={" skip="\\}" end="}" contained contains=@perlExpr nextgroup=perlVarMember,perlVarSimpleMember
  118.   syn match perlVarSimpleMember "\(->\)\={\I\i*}" nextgroup=perlVarMember,perlVarSimpleMember contains=perlVarSimpleMemberName
  119.   syn match perlVarSimpleMemberName "\I\i*" contained
  120.   syn region perlVarMember matchgroup=perlVarPlain start="\(->\)\=\[" skip="\\]" end="]" contained contains=@perlExpr nextgroup=perlVarMember,perlVarSimpleMember
  121. endif
  122.  
  123.  
  124. " Special characters in strings and matches
  125. syn match perlSpecialString  "\\\(\d\+\|[xX]\x\+\|c\u\|.\)" contained
  126. syn match perlSpecialStringU "\\['\\]" contained
  127. syn match perlSpecialMatch   "{\d\(,\d\)\=}" contained
  128. syn match perlSpecialMatch   "\[\(\]\|-\)\=[^\[\]]*\(\[\|\-\)\=\]" contained
  129. syn match perlSpecialMatch   "[+*()?.]" contained
  130. syn match perlSpecialMatch   "(?[#:=!]" contained
  131. syn match perlSpecialMatch   "(?[imsx]\+)" contained
  132. " FIXME the line below does not work. It should mark end of line and
  133. " begin of line as perlSpecial.
  134. " syn match perlSpecialBEOM    "^\^\|\$$" contained
  135.  
  136. " Possible errors
  137. "
  138. " Highlight lines with only whitespace (only in blank delimited here documents) as errors
  139. syn match perlNotEmptyLine  "^\s\+$" contained
  140.  
  141. " Variable interpolation
  142. "
  143. " These items are interpolated inside "" strings and similar constructs.
  144. syn cluster perlInterpDQ contains=perlSpecialString,perlVarPlain,perlVarNotInMatches,perlVarSlash,perlVarBlock
  145. " These items are interpolated inside '' strings and similar constructs.
  146. syn cluster perlInterpSQ contains=perlSpecialStringU
  147. " These items are interpolated inside m// matches and s/// substitutions.
  148. syn cluster perlInterpSlash contains=perlSpecialString,perlSpecialMatch,perlVarPlain,perlVarBlock,perlSpecialBEOM
  149. " These items are interpolated inside m## matches and s### substitutions.
  150. syn cluster perlInterpMatch contains=@perlInterpSlash,perlVarSlash
  151.  
  152. " Shell commands
  153. syn region  perlShellCommand matchgroup=perlMatchStartEnd start="`" end="`" contains=@perlInterpDQ
  154.  
  155. " Constants
  156. "
  157. " Numbers
  158. syn match perlNumber "-\=\<\d\+L\=\>\|0[xX]\x\+\>"
  159.  
  160. " Simple version of searches and matches
  161. " caters for m//, m## and m[] (and the !/ variant)
  162. syn region perlMatch matchgroup=perlMatchStartEnd start=+[m!]/+ end=+/[xosmige]*+ contains=@perlInterpSlash
  163. syn region perlMatch matchgroup=perlMatchStartEnd start=+[m!]#+ end=+#[xosmige]*+ contains=@perlInterpMatch
  164. syn region perlMatch matchgroup=perlMatchStartEnd start=+[m!]\[+ end=+\][xosmige]*+ contains=@perlInterpMatch
  165.  
  166. " Below some hacks to recognise the // variant. This is virtually impossible to catch in all
  167. " cases as the / is used in so many other ways, but these should be the most obvious ones.
  168. syn region perlMatch matchgroup=perlMatchStartEnd start=+split /+lc=5 start=+=\~\s*/+lc=2 start=+[(~]/+lc=1 start=+\.\./+lc=2 start=+\s/[^= \t\d$@%]+lc=1,me=e-1,rs=e-1 start=+^/+ skip=+\\/+ end=+/[xosmige]*+ contains=@perlInterpSlash
  169.  
  170. " Substitutions
  171. " caters for s///, s### and s[][]
  172. " perlMatch is the first part, perlSubstitution is the substitution part
  173. syn region perlMatch matchgroup=perlMatchStartEnd start=+\<\(tr\|s\)/+ end=+/+me=e-1 contains=@perlInterpSlash nextgroup=perlSubstitution
  174. syn region perlMatch matchgroup=perlMatchStartEnd start=+\<\(tr\|s\)#+ end=+#+me=e-1 contains=@perlInterpMatch nextgroup=perlSubstitution
  175. syn region perlMatch matchgroup=perlMatchStartEnd start=+\<\(tr\|s\)\[+ end=+\]+ contains=@perlInterpMatch nextgroup=perlSubstitution
  176. syn region perlSubstitution matchgroup=perlMatchStartEnd start=+/+ end=+/[xosmigecd]*+ contained contains=@perlInterpSQ
  177. syn region perlSubstitution matchgroup=perlMatchStartEnd start=+#+ end=+#[xosmige]*+ contained contains=@perlInterpSQ
  178. syn region perlSubstitution matchgroup=perlMatchStartEnd start=+\[+ end=+\][xosmige]*+ contained contains=@perlInterpSQ
  179.  
  180. " Substitutions
  181. " caters for tr///, tr### and tr[][]
  182. " perlMatch is the first part, perlTranslation is the second, translator part.
  183. syn region perlMatch matchgroup=perlMatchStartEnd start=+\<\(tr\|y\)/+ end=+/+me=e-1 contains=@perlInterpSQ nextgroup=perlTranslation
  184. syn region perlMatch matchgroup=perlMatchStartEnd start=+\<\(tr\|y\)#+ end=+#+me=e-1 contains=@perlInterpSQ nextgroup=perlTranslation
  185. syn region perlMatch matchgroup=perlMatchStartEnd start=+\<\(tr\|y\)\[+ end=+\]+ contains=@perlInterpSQ nextgroup=perlTranslation
  186. syn region perlTranslation matchgroup=perlMatchStartEnd start=+/+ end=+/[xosmigecd]*+ contained contains=@perlInterpSQ
  187. syn region perlTranslation matchgroup=perlMatchStartEnd start=+#+ end=+#[xosmige]*+ contained contains=@perlInterpSQ
  188. syn region perlTranslation matchgroup=perlMatchStartEnd start=+\[+ end=+\][xosmige]*+ contained contains=@perlInterpSQ
  189.  
  190.  
  191. " Strings and q, qq and qw expressions
  192. syn region perlStringUnexpanded matchgroup=perlStringStartEnd start="'" end="'" contains=@perlInterpSQ
  193. syn region perlString matchgroup=perlStringStartEnd start=+"+  end=+"+ contains=@perlInterpDQ
  194. syn region perlQQ matchgroup=perlStringStartEnd start=+q[qx]#+ end=+#+ contains=@perlInterpDQ
  195. syn region perlQQ matchgroup=perlStringStartEnd start=+q[qx]|+ end=+|+ contains=@perlInterpDQ
  196. syn region perlQQ matchgroup=perlStringStartEnd start=+q[qx](+ end=+)+ contains=@perlInterpDQ
  197. syn region perlQQ matchgroup=perlStringStartEnd start=+q[qx]/+ end=+/+ contains=@perlInterpDQ
  198. syn region perlQQ matchgroup=perlStringStartEnd start=+qw\=#+  end=+#+ contains=@perlInterpSQ
  199. syn region perlQQ matchgroup=perlStringStartEnd start=+qw\=|+  end=+|+ contains=@perlInterpSQ
  200. syn region perlQQ matchgroup=perlStringStartEnd start=+qw\=(+  end=+)+ contains=@perlInterpSQ
  201. syn region perlQQ matchgroup=perlStringStartEnd start=+qw\=/+  end=+/+ contains=@perlInterpSQ
  202.  
  203. " Constructs such as print <<EOF [...] EOF
  204. "
  205. syn region  perlUntilEOF start=+<<EOF+hs=s+2 start=+<<"EOF"+hs=s+2 end="^EOF$" contains=@perlInterpDQ
  206. "syn region  perlUntilEOF start=+<<"EOF"+hs=s+2 end="^EOF$" contains=@perlInterpDQ
  207. syn region  perlUntilEOF start=+<<""+hs=s+2 end="^$" contains=@perlInterpDQ,perlNotEmptyLine
  208. syn region  perlUntilEOF start=+<<'EOF'+hs=s+2 end="^EOF$" contains=@perlInterpSQ
  209. syn region  perlUntilEOF start=+<<''+hs=s+2 end="^$" contains=@perlInterpSQ,perlNotEmptyLine
  210.  
  211. " Class declarations
  212. "
  213. syn match perlPackageDecl "^\s*package\>[^;]*" contains=perlStatementPackage
  214. syn keyword perlStatementPackage package contained
  215.  
  216. " Functions
  217. "       sub [name] [(prototype)] {
  218. "
  219. syn region perlFunction start="\s*sub\s\+"rs=s end="[;{]"he=e-1 contains=perlStatementSub,perlFunctionPrototype,perlFunctionPRef,perlFunctionName,perlComment
  220. syn keyword perlStatementSub sub contained
  221.  
  222. syn match perlFunctionPrototype "([^)]*)" contained
  223. if exists("perl_want_scope_in_variables")
  224.    syn match perlFunctionPRef "\h\w*::" contained
  225.    syn match perlFunctionName "\h\w*[^:]" contained
  226. else
  227.    syn match perlFunctionName "\h[[:alnum:]_:]*" contained
  228. endif
  229.  
  230.  
  231. " All other # are comments, except ^#!
  232. syn match  perlComment   "#.*" contains=perlTodo
  233. syn match  perlSharpBang "^#!.*"
  234.  
  235. " Formats
  236. syn region perlFormat matchgroup=perlStatementIOFunc start="^\s*format\s\+\k\+\s*=\s*$"rs=s+6 end="^\s*\.\s*$" contains=perlFormatName,perlFormatField,perlVarPlain
  237. syn match perlFormatName "format\s\+\k\+\s*="lc=7,me=e-1 contained
  238. syn match perlFormatField "[@^][|<>~]\+\(\.\.\.\)\=" contained
  239. syn match perlFormatField "[@^]#[#.]*" contained
  240. syn match perlFormatField "@\*" contained
  241. syn match perlFormatField "@[^A-Za-z_|<>~#*]"me=e-1 contained
  242. syn match perlFormatField "@$" contained
  243.  
  244.  
  245. if !exists("did_perl_syntax_inits")
  246.   let did_perl_syntax_inits = 1
  247.  
  248.   hi link perlSharpBang         PreProc
  249.   hi link perlControl           PreProc
  250.   hi link perlInclude           Include
  251.   hi link perlSpecial           Special
  252.   hi link perlString            String
  253.   hi link perlCharacter         Character
  254.   hi link perlNumber            Number
  255.   hi link perlType              Type
  256.   hi link perlIdentifier        Identifier
  257.   hi link perlLabel             Label
  258.   hi link perlStatement         Statement
  259.   hi link perlConditional       Conditional
  260.   hi link perlRepeat            Repeat
  261.   hi link perlOperator          Operator
  262.   hi link perlFunction          Function
  263.   hi link perlComment           Comment
  264.   hi link perlTodo              Todo
  265.   hi link perlList              perlStatement
  266.   hi link perlMisc              perlStatement
  267.   hi link perlVarPlain          perlIdentifier
  268.   hi link perlVarSimpleMember   perlIdentifier
  269.   hi link perlVarSimpleMemberName    perlString
  270.   hi link perlVarNotInMatches   perlIdentifier
  271.   hi link perlVarSlash          perlIdentifier
  272.   hi link perlQQ                perlString
  273.   hi link perlUntilEOF          perlString
  274.   hi link perlStringUnexpanded  perlString
  275.   hi link perlSubstitution      perlString
  276.   hi link perlTranslation       perlString
  277.   hi link perlMatch             perlString
  278.   hi link perlMatchStartEnd     perlStatement
  279.   if exists("perl_string_as_statement")
  280.      hi link perlStringStartEnd    perlStatement
  281.   else
  282.      hi link perlStringStartEnd    perlString
  283.   endif
  284.   hi link perlFormatName        perlIdentifier
  285.   hi link perlFormatField       perlString
  286.   hi link perlPackageDecl       perlType
  287.   hi link perlStorageClass      perlType
  288.   hi link perlPackageRef        perlType
  289.   hi link perlStatementPackage  perlStatement
  290.   hi link perlStatementSub      perlStatement
  291.   hi link perlStatementStorage  perlStatement
  292.   hi link perlStatementControl  perlStatement
  293.   hi link perlStatementScalar   perlStatement
  294.   hi link perlStatementRegexp   perlStatement
  295.   hi link perlStatementNumeric  perlStatement
  296.   hi link perlStatementList     perlStatement
  297.   hi link perlStatementHash     perlStatement
  298.   hi link perlStatementIOfunc   perlStatement
  299.   hi link perlStatementVector   perlStatement
  300.   hi link perlStatementFiles    perlStatement
  301.   hi link perlStatementFlow     perlStatement
  302.   hi link perlStatementScope    perlStatement
  303.   hi link perlStatementInclude  perlStatement
  304.   hi link perlStatementProc     perlStatement
  305.   hi link perlStatementSocket   perlStatement
  306.   hi link perlStatementIPC      perlStatement
  307.   hi link perlStatementNetwork  perlStatement
  308.   hi link perlStatementPword    perlStatement
  309.   hi link perlStatementTime     perlStatement
  310.   hi link perlStatementMisc     perlStatement
  311.   hi link perlFunctionName      perlIdentifier
  312.   hi link perlFunctionPRef      perlType
  313.   hi link perlPOD               perlComment
  314.   hi link perlShellCommand      perlString
  315.   hi link perlSpecialAscii      perlSpecial
  316.   hi link perlSpecialDollar     perlSpecial
  317.   hi link perlSpecialString     perlSpecial
  318.   hi link perlSpecialStringU    perlSpecial
  319.   hi link perlSpecialMatch      perlSpecial
  320.   hi link perlSpecialBEOM       perlSpecial
  321.  
  322.   " Possible errors
  323.   hi link perlNotEmptyLine   Error
  324. endif
  325.  
  326. " Syncing to speed up processing
  327. "
  328. if !exists("perl_no_sync_on_sub")
  329.   syn sync match perlSync grouphere NONE "^\s*package\s"
  330.   syn sync match perlSync grouphere perlFunction "^\s*sub\s"
  331.   syn sync match perlSync grouphere NONE "^}"
  332. endif
  333.  
  334. if !exists("perl_no_sync_on_global_var")
  335.   syn sync match perlSync grouphere NONE "^$\I[[:alnum:]_:]+\s*=\s*{"
  336.   syn sync match perlSync grouphere NONE "^[@%]\I[[:alnum:]_:]+\s*=\s*("
  337. endif
  338.  
  339. if exists("perl_sync_dist")
  340.   execute "syn sync maxlines=" . perl_sync_dist
  341. else
  342.   syn sync maxlines=100
  343. endif
  344.  
  345. syn sync match perlSyncPOD grouphere perlPOD "^=pod"
  346. syn sync match perlSyncPOD grouphere perlPOD "^=head"
  347. syn sync match perlSyncPOD grouphere perlPOD "^=item"
  348. syn sync match perlSyncPOD grouphere NONE "^=cut"
  349.  
  350. let b:current_syntax = "perl"
  351.  
  352. " vim: ts=8
  353.