From: Simon Ruderich Date: Sun, 26 Apr 2009 11:37:39 +0000 (+0200) Subject: perl: Add syntax file, last change 2007-03-13. X-Git-Url: https://ruderich.org/simon/gitweb/?a=commitdiff_plain;h=6c7ddcc7e336a56649038f5e34d79d24f9f79aa9;p=config%2Fdotfiles.git perl: Add syntax file, last change 2007-03-13. --- diff --git a/syntax/perl.vim b/syntax/perl.vim new file mode 100644 index 0000000..23bc805 --- /dev/null +++ b/syntax/perl.vim @@ -0,0 +1,565 @@ +" Vim syntax file +" Language: Perl +" Maintainer: Nick Hibma +" Last Change: 2007 March 13 +" Location: http://www.van-laarhoven.org/vim/syntax/perl.vim +" +" Please download most recent version first before mailing +" any comments. +" See also the file perl.vim.regression.pl to check whether your +" modifications work in the most odd cases +" http://www.van-laarhoven.org/vim/syntax/perl.vim.regression.pl +" +" Original version: Sonia Heimann +" Thanks to many people for their contribution. + +" The following parameters are available for tuning the +" perl syntax highlighting, with defaults given: +" +" unlet perl_include_pod +" unlet perl_want_scope_in_variables +" unlet perl_extended_vars +" unlet perl_string_as_statement +" unlet perl_no_sync_on_sub +" unlet perl_no_sync_on_global_var +" let perl_sync_dist = 100 +" unlet perl_fold +" unlet perl_fold_blocks +" let perl_nofold_packages = 1 +" let perl_nofold_subs = 1 + +" Remove any old syntax stuff that was loaded (5.x) or quit when a syntax file +" was already loaded (6.x). +if version < 600 + syntax clear +elseif exists("b:current_syntax") + finish +endif + +" Unset perl_fold if it set but vim doesn't support it. +if version < 600 && exists("perl_fold") + unlet perl_fold +endif + + +" POD starts with ^= and ends with ^=cut + +if exists("perl_include_pod") + " Include a while extra syntax file + syn include @Pod syntax/pod.vim + unlet b:current_syntax + if exists("perl_fold") + syn region perlPOD start="^=[a-z]" end="^=cut" contains=@Pod,@Spell,perlTodo keepend fold + syn region perlPOD start="^=cut" end="^=cut" contains=perlTodo keepend fold + else + syn region perlPOD start="^=[a-z]" end="^=cut" contains=@Pod,@Spell,perlTodo keepend + syn region perlPOD start="^=cut" end="^=cut" contains=perlTodo keepend + endif +else + " Use only the bare minimum of rules + if exists("perl_fold") + syn region perlPOD start="^=[a-z]" end="^=cut" fold + else + syn region perlPOD start="^=[a-z]" end="^=cut" + endif +endif + + +" All keywords +" +if exists("perl_fold") && exists("perl_fold_blocks") + syn match perlConditional "\" + syn match perlConditional "\" + syn match perlConditional "\" + syn match perlConditional "\" nextgroup=perlElseIfError skipwhite skipnl skipempty +else + syn keyword perlConditional if elsif unless + syn keyword perlConditional else nextgroup=perlElseIfError skipwhite skipnl skipempty +endif +syn keyword perlConditional switch eq ne gt lt ge le cmp not and or xor err +if exists("perl_fold") && exists("perl_fold_blocks") + syn match perlRepeat "\" + syn match perlRepeat "\" + syn match perlRepeat "\" + syn match perlRepeat "\" + syn match perlRepeat "\" + syn match perlRepeat "\" +else + syn keyword perlRepeat while for foreach do until continue +endif +syn keyword perlOperator defined undef and or not bless ref +if exists("perl_fold") + " if BEGIN/END would be a keyword the perlBEGINENDFold does not work + syn match perlControl "\" contained +else + syn keyword perlControl BEGIN END CHECK INIT +endif + +syn keyword perlStatementStorage my local our +syn keyword perlStatementControl goto return last next redo +syn keyword perlStatementScalar chomp chop chr crypt index lc lcfirst length ord pack reverse rindex sprintf substr uc ucfirst +syn keyword perlStatementRegexp pos quotemeta split study +syn keyword perlStatementNumeric abs atan2 cos exp hex int log oct rand sin sqrt srand +syn keyword perlStatementList splice unshift shift push pop split join reverse grep map sort unpack +syn keyword perlStatementHash each exists keys values tie tied untie +syn keyword perlStatementIOfunc carp confess croak dbmclose dbmopen die syscall +syn keyword perlStatementFiledesc binmode close closedir eof fileno getc lstat print printf readdir readline readpipe rewinddir select stat tell telldir write nextgroup=perlFiledescStatementNocomma skipwhite +syn keyword perlStatementFiledesc fcntl flock ioctl open opendir read seek seekdir sysopen sysread sysseek syswrite truncate nextgroup=perlFiledescStatementComma skipwhite +syn keyword perlStatementVector pack vec +syn keyword perlStatementFiles chdir chmod chown chroot glob link mkdir readlink rename rmdir symlink umask unlink utime +syn match perlStatementFiles "-[rwxoRWXOezsfdlpSbctugkTBMAC]\>" +syn keyword perlStatementFlow caller die dump eval exit wantarray +syn keyword perlStatementInclude require +syn match perlStatementInclude "\<\(use\|no\)\s\+\(\(integer\|strict\|lib\|sigtrap\|subs\|vars\|warnings\|utf8\|byte\|base\|fields\)\>\)\=" +syn keyword perlStatementScope import +syn keyword perlStatementProc alarm exec fork getpgrp getppid getpriority kill pipe setpgrp setpriority sleep system times wait waitpid +syn keyword perlStatementSocket accept bind connect getpeername getsockname getsockopt listen recv send setsockopt shutdown socket socketpair +syn keyword perlStatementIPC msgctl msgget msgrcv msgsnd semctl semget semop shmctl shmget shmread shmwrite +syn keyword perlStatementNetwork endhostent endnetent endprotoent endservent gethostbyaddr gethostbyname gethostent getnetbyaddr getnetbyname getnetent getprotobyname getprotobynumber getprotoent getservbyname getservbyport getservent sethostent setnetent setprotoent setservent +syn keyword perlStatementPword getpwuid getpwnam getpwent setpwent endpwent getgrent getgrgid getlogin getgrnam setgrent endgrent +syn keyword perlStatementTime gmtime localtime time times + +syn keyword perlStatementMisc warn formline reset scalar delete prototype lock +syn keyword perlStatementNew new + +syn keyword perlTodo TODO TBD FIXME XXX contained + +" Perl Identifiers. +" +" Should be cleaned up to better handle identifiers in particular situations +" (in hash keys for example) +" +" Plain identifiers: $foo, @foo, $#foo, %foo, &foo and dereferences $$foo, @$foo, etc. +" We do not process complex things such as @{${"foo"}}. Too complicated, and +" too slow. And what is after the -> is *not* considered as part of the +" variable - there again, too complicated and too slow. + +" Special variables first ($^A, ...) and ($|, $', ...) +syn match perlVarPlain "$^[ADEFHILMOPSTWX]\=" +syn match perlVarPlain "$[\\\"\[\]'&`+*.,;=%~!?@#$<>(-]" +syn match perlVarPlain "$\(0\|[1-9][0-9]*\)" +" Same as above, but avoids confusion in $::foo (equivalent to $main::foo) +syn match perlVarPlain "$:[^:]" +" These variables are not recognized within matches. +syn match perlVarNotInMatches "$[|)]" +" This variable is not recognized within matches delimited by m//. +syn match perlVarSlash "$/" + +" And plain identifiers +syn match perlPackageRef "\(\h\w*\)\=\(::\|'\)\I"me=e-1 contained + +" To highlight packages in variables as a scope reference - i.e. in $pack::var, +" pack:: is a scope, just set "perl_want_scope_in_variables" +" If you *want* complex things like @{${"foo"}} to be processed, +" just set the variable "perl_extended_vars"... + +" FIXME value between {} should be marked as string. is treated as such by Perl. +" At the moment it is marked as something greyish instead of read. Probably todo +" with transparency. Or maybe we should handle the bare word in that case. or make it into + +if exists("perl_want_scope_in_variables") + syn match perlVarPlain "\\\=\([@$]\|\$#\)\$*\(\I\i*\)\=\(\(::\|'\)\I\i*\)*\>" contains=perlPackageRef nextgroup=perlVarMember,perlVarSimpleMember,perlMethod + syn match perlVarPlain2 "\\\=%\$*\(\I\i*\)\=\(\(::\|'\)\I\i*\)*\>" contains=perlPackageRef nextgroup=perlVarMember,perlVarSimpleMember,perlMethod + syn match perlFunctionName "\\\=&\$*\(\I\i*\)\=\(\(::\|'\)\I\i*\)*\>" contains=perlPackageRef nextgroup=perlVarMember,perlVarSimpleMember +else + syn match perlVarPlain "\\\=\([@$]\|\$#\)\$*\(\I\i*\)\=\(\(::\|'\)\I\i*\)*\>" nextgroup=perlVarMember,perlVarSimpleMember,perlMethod + syn match perlVarPlain2 "\\\=%\$*\(\I\i*\)\=\(\(::\|'\)\I\i*\)*\>" nextgroup=perlVarMember,perlVarSimpleMember,perlMethod + syn match perlFunctionName "\\\=&\$*\(\I\i*\)\=\(\(::\|'\)\I\i*\)*\>" nextgroup=perlVarMember,perlVarSimpleMember +endif + +if exists("perl_extended_vars") + syn cluster perlExpr contains=perlStatementScalar,perlStatementRegexp,perlStatementNumeric,perlStatementList,perlStatementHash,perlStatementFiles,perlStatementTime,perlStatementMisc,perlVarPlain,perlVarPlain2,perlVarNotInMatches,perlVarSlash,perlVarBlock,perlShellCommand,perlFloat,perlNumber,perlStringUnexpanded,perlString,perlQQ + syn region perlVarBlock matchgroup=perlVarPlain start="\($#\|[@%$]\)\$*{" skip="\\}" end="}" contains=@perlExpr nextgroup=perlVarMember,perlVarSimpleMember + syn region perlVarBlock matchgroup=perlVarPlain start="&\$*{" skip="\\}" end="}" contains=@perlExpr + syn match perlVarPlain "\\\=\(\$#\|[@%&$]\)\$*{\I\i*}" nextgroup=perlVarMember,perlVarSimpleMember + syn region perlVarMember matchgroup=perlVarPlain start="\(->\)\={" skip="\\}" end="}" contained contains=@perlExpr nextgroup=perlVarMember,perlVarSimpleMember + syn match perlVarSimpleMember "\(->\)\={\I\i*}" nextgroup=perlVarMember,perlVarSimpleMember contains=perlVarSimpleMemberName contained + syn match perlVarSimpleMemberName "\I\i*" contained + syn region perlVarMember matchgroup=perlVarPlain start="\(->\)\=\[" skip="\\]" end="]" contained contains=@perlExpr nextgroup=perlVarMember,perlVarSimpleMember + syn match perlMethod "\(->\)\I\i*" contained +endif + +" File Descriptors +syn match perlFiledescRead "[<]\h\w\+[>]" + +syn match perlFiledescStatementComma "(\=\s*\u\w*\s*,"me=e-1 transparent contained contains=perlFiledescStatement +syn match perlFiledescStatementNocomma "(\=\s*\u\w*\s*[^, \t]"me=e-1 transparent contained contains=perlFiledescStatement + +syn match perlFiledescStatement "\u\w*" contained + +" Special characters in strings and matches +syn match perlSpecialString "\\\(\d\+\|[xX]\x\+\|c\u\|.\)" contained +syn match perlSpecialStringU "\\['\\]" contained +syn match perlSpecialMatch "{\d\+\(,\(\d\+\)\=\)\=}" contained +syn match perlSpecialMatch "\[\(\]\|-\)\=[^\[\]]*\(\[\|\-\)\=\]" contained +syn match perlSpecialMatch "[+*()?.]" contained +syn match perlSpecialMatch "(?[#:=!]" contained +syn match perlSpecialMatch "(?[imsx]\+)" contained +" FIXME the line below does not work. It should mark end of line and +" begin of line as perlSpecial. +" syn match perlSpecialBEOM "^\^\|\$$" contained + +" Possible errors +" +" Highlight lines with only whitespace (only in blank delimited here documents) as errors +syn match perlNotEmptyLine "^\s\+$" contained +" Highlight '} else if (...) {', it should be '} else { if (...) { ' or +" '} elsif (...) {'. +"syn keyword perlElseIfError if contained + +" Variable interpolation +" +" These items are interpolated inside "" strings and similar constructs. +syn cluster perlInterpDQ contains=perlSpecialString,perlVarPlain,perlVarNotInMatches,perlVarSlash,perlVarBlock +" These items are interpolated inside '' strings and similar constructs. +syn cluster perlInterpSQ contains=perlSpecialStringU +" These items are interpolated inside m// matches and s/// substitutions. +syn cluster perlInterpSlash contains=perlSpecialString,perlSpecialMatch,perlVarPlain,perlVarBlock,perlSpecialBEOM +" These items are interpolated inside m## matches and s### substitutions. +syn cluster perlInterpMatch contains=@perlInterpSlash,perlVarSlash + +" Shell commands +syn region perlShellCommand matchgroup=perlMatchStartEnd start="`" end="`" contains=@perlInterpDQ + +" Constants +" +" Numbers +syn match perlNumber "[-+]\=\(\<\d[[:digit:]_]*L\=\>\|0[xX]\x[[:xdigit:]_]*\>\)" +syn match perlFloat "[-+]\=\<\d[[:digit:]_]*[eE][\-+]\=\d\+" +syn match perlFloat "[-+]\=\<\d[[:digit:]_]*\.[[:digit:]_]*\([eE][\-+]\=\d\+\)\=" +syn match perlFloat "[-+]\=\<\.[[:digit:]_]\+\([eE][\-+]\=\d\+\)\=" + + +" Simple version of searches and matches +" caters for m//, m##, m{} and m[] (and the !/ variant) +syn region perlMatch matchgroup=perlMatchStartEnd start=+[m!]/+ end=+/[cgimosx]*+ contains=@perlInterpSlash +syn region perlMatch matchgroup=perlMatchStartEnd start=+[m!]#+ end=+#[cgimosx]*+ contains=@perlInterpMatch +syn region perlMatch matchgroup=perlMatchStartEnd start=+[m!]{+ end=+}[cgimosx]*+ contains=@perlInterpMatch +syn region perlMatch matchgroup=perlMatchStartEnd start=+[m!]\[+ end=+\][cgimosx]*+ contains=@perlInterpMatch + +" A special case for m!!x which allows for comments and extra whitespace in the pattern +syn region perlMatch matchgroup=perlMatchStartEnd start=+[m!]!+ end=+![cgimosx]*+ contains=@perlInterpSlash,perlComment + +" Below some hacks to recognise the // variant. This is virtually impossible to catch in all +" cases as the / is used in so many other ways, but these should be the most obvious ones. +syn region perlMatch matchgroup=perlMatchStartEnd start=+^split /+lc=5 start=+[^$@%]\ operator forces a bareword to the left of it to be interpreted as +" a string +syn match perlString "\<\I\i*\s*=>"me=e-2 + +" Strings and q, qq, qw and qr expressions + +" Brackets in qq() +syn region perlBrackets start=+(+ end=+)+ contained transparent contains=perlBrackets,@perlStringSQ + +syn region perlStringUnexpanded matchgroup=perlStringStartEnd start="'" end="'" contains=@perlInterpSQ +syn region perlString matchgroup=perlStringStartEnd start=+"+ end=+"+ contains=@perlInterpDQ +syn region perlQQ matchgroup=perlStringStartEnd start=+\= 600 + " XXX Any statements after the identifier are in perlString colour (i.e. + " 'if $a' in 'print <~]\+\(\.\.\.\)\=" contained +syn match perlFormatField "[@^]#[#.]*" contained +syn match perlFormatField "@\*" contained +syn match perlFormatField "@[^A-Za-z_|<>~#*]"me=e-1 contained +syn match perlFormatField "@$" contained + +" __END__ and __DATA__ clauses +if exists("perl_fold") + syntax region perlDATA start="^__\(DATA\|END\)__$" skip="." end="." contains=perlPOD,@perlDATA fold +else + syntax region perlDATA start="^__\(DATA\|END\)__$" skip="." end="." contains=perlPOD,@perlDATA +endif + + +" +" Folding + +if exists("perl_fold") + if !exists("perl_nofold_packages") + syn region perlPackageFold start="^package \S\+;\s*\(#.*\)\=$" end="^1;\s*\(#.*\)\=$" end="\n\+package"me=s-1 transparent fold keepend + endif + if !exists("perl_nofold_subs") + syn region perlSubFold start="^\z(\s*\)\.*[^};]$" end="^\z1}\s*\(#.*\)\=$" transparent fold keepend + syn region perlSubFold start="^\z(\s*\)\<\(BEGIN\|END\|CHECK\|INIT\)\>.*[^};]$" end="^\z1}\s*$" transparent fold keepend + endif + + if exists("perl_fold_blocks") + syn region perlBlockFold start="^\z(\s*\)\(if\|elsif\|unless\|for\|while\|until\)\s*(.*)\(\s*{\)\=\s*\(#.*\)\=$" start="^\z(\s*\)foreach\s*\(\(my\|our\)\=\s*\S\+\s*\)\=(.*)\(\s*{\)\=\s*\(#.*\)\=$" end="^\z1}\s*;\=\(#.*\)\=$" transparent fold keepend + syn region perlBlockFold start="^\z(\s*\)\(do\|else\)\(\s*{\)\=\s*\(#.*\)\=$" end="^\z1}\s*while" end="^\z1}\s*;\=\(#.*\)\=$" transparent fold keepend + endif + + setlocal foldmethod=syntax + syn sync fromstart +else + " fromstart above seems to set minlines even if perl_fold is not set. + syn sync minlines=0 +endif + + +if version >= 508 || !exists("did_perl_syn_inits") + if version < 508 + let did_perl_syn_inits = 1 + command -nargs=+ HiLink hi link + else + command -nargs=+ HiLink hi def link + endif + + " The default highlighting. + HiLink perlSharpBang PreProc + HiLink perlControl PreProc + HiLink perlInclude Include + HiLink perlSpecial Special + HiLink perlString String + HiLink perlCharacter Character + HiLink perlNumber Number + HiLink perlFloat Float + HiLink perlType Type + HiLink perlIdentifier Identifier + HiLink perlLabel Label + HiLink perlStatement Statement + HiLink perlConditional Conditional + HiLink perlRepeat Repeat + HiLink perlOperator Operator + HiLink perlFunction Function + HiLink perlFunctionPrototype perlFunction + HiLink perlComment Comment + HiLink perlTodo Todo + if exists("perl_string_as_statement") + HiLink perlStringStartEnd perlStatement + else + HiLink perlStringStartEnd perlString + endif + HiLink perlList perlStatement + HiLink perlMisc perlStatement + HiLink perlVarPlain perlIdentifier + HiLink perlVarPlain2 perlIdentifier + HiLink perlFiledescRead perlIdentifier + HiLink perlFiledescStatement perlIdentifier + HiLink perlVarSimpleMember perlIdentifier + HiLink perlVarSimpleMemberName perlString + HiLink perlVarNotInMatches perlIdentifier + HiLink perlVarSlash perlIdentifier + HiLink perlQQ perlString + if version >= 600 + HiLink perlHereDoc perlString + else + HiLink perlHereIdentifier perlStringStartEnd + HiLink perlUntilEOFDQ perlString + HiLink perlUntilEOFSQ perlString + HiLink perlUntilEmptyDQ perlString + HiLink perlUntilEmptySQ perlString + HiLink perlUntilEOF perlString + endif + HiLink perlStringUnexpanded perlString + HiLink perlSubstitutionSQ perlString + HiLink perlSubstitutionDQ perlString + HiLink perlSubstitutionSlash perlString + HiLink perlSubstitutionHash perlString + HiLink perlSubstitutionBracket perlString + HiLink perlSubstitutionCurly perlString + HiLink perlSubstitutionPling perlString + HiLink perlTranslationSlash perlString + HiLink perlTranslationHash perlString + HiLink perlTranslationBracket perlString + HiLink perlTranslationCurly perlString + HiLink perlMatch perlString + HiLink perlMatchStartEnd perlStatement + HiLink perlFormatName perlIdentifier + HiLink perlFormatField perlString + HiLink perlPackageDecl perlType + HiLink perlStorageClass perlType + HiLink perlPackageRef perlType + HiLink perlStatementPackage perlStatement + HiLink perlStatementSub perlStatement + HiLink perlStatementStorage perlStatement + HiLink perlStatementControl perlStatement + HiLink perlStatementScalar perlStatement + HiLink perlStatementRegexp perlStatement + HiLink perlStatementNumeric perlStatement + HiLink perlStatementList perlStatement + HiLink perlStatementHash perlStatement + HiLink perlStatementIOfunc perlStatement + HiLink perlStatementFiledesc perlStatement + HiLink perlStatementVector perlStatement + HiLink perlStatementFiles perlStatement + HiLink perlStatementFlow perlStatement + HiLink perlStatementScope perlStatement + HiLink perlStatementInclude perlStatement + HiLink perlStatementProc perlStatement + HiLink perlStatementSocket perlStatement + HiLink perlStatementIPC perlStatement + HiLink perlStatementNetwork perlStatement + HiLink perlStatementPword perlStatement + HiLink perlStatementTime perlStatement + HiLink perlStatementMisc perlStatement + HiLink perlStatementNew perlStatement + HiLink perlFunctionName perlIdentifier + HiLink perlMethod perlIdentifier + HiLink perlFunctionPRef perlType + HiLink perlPOD perlComment + HiLink perlShellCommand perlString + HiLink perlSpecialAscii perlSpecial + HiLink perlSpecialDollar perlSpecial + HiLink perlSpecialString perlSpecial + HiLink perlSpecialStringU perlSpecial + HiLink perlSpecialMatch perlSpecial + HiLink perlSpecialBEOM perlSpecial + HiLink perlDATA perlComment + + HiLink perlBrackets Error + + " Possible errors + HiLink perlNotEmptyLine Error + HiLink perlElseIfError Error + + delcommand HiLink +endif + +" Syncing to speed up processing +" +if !exists("perl_no_sync_on_sub") + syn sync match perlSync grouphere NONE "^\s*\