perl_highlight_rules.js 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. /* ***** BEGIN LICENSE BLOCK *****
  2. * Distributed under the BSD license:
  3. *
  4. * Copyright (c) 2010, Ajax.org B.V.
  5. * All rights reserved.
  6. *
  7. * Redistribution and use in source and binary forms, with or without
  8. * modification, are permitted provided that the following conditions are met:
  9. * * Redistributions of source code must retain the above copyright
  10. * notice, this list of conditions and the following disclaimer.
  11. * * Redistributions in binary form must reproduce the above copyright
  12. * notice, this list of conditions and the following disclaimer in the
  13. * documentation and/or other materials provided with the distribution.
  14. * * Neither the name of Ajax.org B.V. nor the
  15. * names of its contributors may be used to endorse or promote products
  16. * derived from this software without specific prior written permission.
  17. *
  18. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  19. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  20. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  21. * DISCLAIMED. IN NO EVENT SHALL AJAX.ORG B.V. BE LIABLE FOR ANY
  22. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  23. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  24. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  25. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  26. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  27. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  28. *
  29. * ***** END LICENSE BLOCK ***** */
  30. define(function(require, exports, module) {
  31. "use strict";
  32. var oop = require("../lib/oop");
  33. var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules;
  34. var PerlHighlightRules = function() {
  35. var keywords = (
  36. "base|constant|continue|else|elsif|for|foreach|format|goto|if|last|local|my|next|" +
  37. "no|package|parent|redo|require|scalar|sub|unless|until|while|use|vars"
  38. );
  39. var buildinConstants = ("ARGV|ENV|INC|SIG");
  40. var builtinFunctions = (
  41. "getprotobynumber|getprotobyname|getservbyname|gethostbyaddr|" +
  42. "gethostbyname|getservbyport|getnetbyaddr|getnetbyname|getsockname|" +
  43. "getpeername|setpriority|getprotoent|setprotoent|getpriority|" +
  44. "endprotoent|getservent|setservent|endservent|sethostent|socketpair|" +
  45. "getsockopt|gethostent|endhostent|setsockopt|setnetent|quotemeta|" +
  46. "localtime|prototype|getnetent|endnetent|rewinddir|wantarray|getpwuid|" +
  47. "closedir|getlogin|readlink|endgrent|getgrgid|getgrnam|shmwrite|" +
  48. "shutdown|readline|endpwent|setgrent|readpipe|formline|truncate|" +
  49. "dbmclose|syswrite|setpwent|getpwnam|getgrent|getpwent|ucfirst|sysread|" +
  50. "setpgrp|shmread|sysseek|sysopen|telldir|defined|opendir|connect|" +
  51. "lcfirst|getppid|binmode|syscall|sprintf|getpgrp|readdir|seekdir|" +
  52. "waitpid|reverse|unshift|symlink|dbmopen|semget|msgrcv|rename|listen|" +
  53. "chroot|msgsnd|shmctl|accept|unpack|exists|fileno|shmget|system|" +
  54. "unlink|printf|gmtime|msgctl|semctl|values|rindex|substr|splice|" +
  55. "length|msgget|select|socket|return|caller|delete|alarm|ioctl|index|" +
  56. "undef|lstat|times|srand|chown|fcntl|close|write|umask|rmdir|study|" +
  57. "sleep|chomp|untie|print|utime|mkdir|atan2|split|crypt|flock|chmod|" +
  58. "BEGIN|bless|chdir|semop|shift|reset|link|stat|chop|grep|fork|dump|" +
  59. "join|open|tell|pipe|exit|glob|warn|each|bind|sort|pack|eval|push|" +
  60. "keys|getc|kill|seek|sqrt|send|wait|rand|tied|read|time|exec|recv|" +
  61. "eof|chr|int|ord|exp|pos|pop|sin|log|abs|oct|hex|tie|cos|vec|END|ref|" +
  62. "map|die|uc|lc|do"
  63. );
  64. var keywordMapper = this.createKeywordMapper({
  65. "keyword": keywords,
  66. "constant.language": buildinConstants,
  67. "support.function": builtinFunctions
  68. }, "identifier");
  69. // regexp must not have capturing parentheses. Use (?:) instead.
  70. // regexps are ordered -> the first match is used
  71. this.$rules = {
  72. "start" : [
  73. {
  74. token : "comment.doc",
  75. regex : "^=(?:begin|item)\\b",
  76. next : "block_comment"
  77. }, {
  78. token : "string.regexp",
  79. regex : "[/](?:(?:\\[(?:\\\\]|[^\\]])+\\])|(?:\\\\/|[^\\]/]))*[/]\\w*\\s*(?=[).,;]|$)"
  80. }, {
  81. token : "string", // single line
  82. regex : '["](?:(?:\\\\.)|(?:[^"\\\\]))*?["]'
  83. }, {
  84. token : "string", // multi line string start
  85. regex : '["].*\\\\$',
  86. next : "qqstring"
  87. }, {
  88. token : "string", // single line
  89. regex : "['](?:(?:\\\\.)|(?:[^'\\\\]))*?[']"
  90. }, {
  91. token : "string", // multi line string start
  92. regex : "['].*\\\\$",
  93. next : "qstring"
  94. }, {
  95. token : "constant.numeric", // hex
  96. regex : "0x[0-9a-fA-F]+\\b"
  97. }, {
  98. token : "constant.numeric", // float
  99. regex : "[+-]?\\d+(?:(?:\\.\\d*)?(?:[eE][+-]?\\d+)?)?\\b"
  100. }, {
  101. token : keywordMapper,
  102. regex : "[a-zA-Z_$][a-zA-Z0-9_$]*\\b"
  103. }, {
  104. token : "keyword.operator",
  105. regex : "%#|\\$#|\\.\\.\\.|\\|\\|=|>>=|<<=|<=>|&&=|=>|!~|\\^=|&=|\\|=|\\.=|x=|%=|\\/=|\\*=|\\-=|\\+=|=~|\\*\\*|\\-\\-|\\.\\.|\\|\\||&&|\\+\\+|\\->|!=|==|>=|<=|>>|<<|,|=|\\?\\:|\\^|\\||x|%|\\/|\\*|<|&|\\\\|~|!|>|\\.|\\-|\\+|\\-C|\\-b|\\-S|\\-u|\\-t|\\-p|\\-l|\\-d|\\-f|\\-g|\\-s|\\-z|\\-k|\\-e|\\-O|\\-T|\\-B|\\-M|\\-A|\\-X|\\-W|\\-c|\\-R|\\-o|\\-x|\\-w|\\-r|\\b(?:and|cmp|eq|ge|gt|le|lt|ne|not|or|xor)"
  106. }, {
  107. token : "comment",
  108. regex : "#.*$"
  109. }, {
  110. token : "lparen",
  111. regex : "[[({]"
  112. }, {
  113. token : "rparen",
  114. regex : "[\\])}]"
  115. }, {
  116. token : "text",
  117. regex : "\\s+"
  118. }
  119. ],
  120. "qqstring" : [
  121. {
  122. token : "string",
  123. regex : '(?:(?:\\\\.)|(?:[^"\\\\]))*?"',
  124. next : "start"
  125. }, {
  126. token : "string",
  127. regex : '.+'
  128. }
  129. ],
  130. "qstring" : [
  131. {
  132. token : "string",
  133. regex : "(?:(?:\\\\.)|(?:[^'\\\\]))*?'",
  134. next : "start"
  135. }, {
  136. token : "string",
  137. regex : '.+'
  138. }
  139. ],
  140. "block_comment": [
  141. {
  142. token: "comment.doc",
  143. regex: "^=cut\\b",
  144. next: "start"
  145. },
  146. {
  147. defaultToken: "comment.doc"
  148. }
  149. ]
  150. };
  151. };
  152. oop.inherits(PerlHighlightRules, TextHighlightRules);
  153. exports.PerlHighlightRules = PerlHighlightRules;
  154. });