eiffel_highlight_rules.js 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. /* ***** BEGIN LICENSE BLOCK *****
  2. * Distributed under the BSD license:
  3. *
  4. * Copyright (c) 2014, 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 EiffelHighlightRules = function() {
  35. var keywords = "across|agent|alias|all|attached|as|assign|attribute|check|" +
  36. "class|convert|create|debug|deferred|detachable|do|else|elseif|end|" +
  37. "ensure|expanded|export|external|feature|from|frozen|if|inherit|" +
  38. "inspect|invariant|like|local|loop|not|note|obsolete|old|once|" +
  39. "Precursor|redefine|rename|require|rescue|retry|select|separate|" +
  40. "some|then|undefine|until|variant|when";
  41. var operatorKeywords = "and|implies|or|xor";
  42. var languageConstants = "Void";
  43. var booleanConstants = "True|False";
  44. var languageVariables = "Current|Result";
  45. var keywordMapper = this.createKeywordMapper({
  46. "constant.language": languageConstants,
  47. "constant.language.boolean": booleanConstants,
  48. "variable.language": languageVariables,
  49. "keyword.operator": operatorKeywords,
  50. "keyword": keywords
  51. }, "identifier", true);
  52. var simpleString = /(?:[^"%\b\f\v]|%[A-DFHLNQR-V%'"()<>]|%\/(?:0[xX][\da-fA-F](?:_*[\da-fA-F])*|0[cC][0-7](?:_*[0-7])*|0[bB][01](?:_*[01])*|\d(?:_*\d)*)\/)+?/;
  53. this.$rules = {
  54. "start": [{
  55. token : "string.quoted.other", // Aligned-verbatim-strings (verbatim option not supported)
  56. regex : /"\[/,
  57. next: "aligned_verbatim_string"
  58. }, {
  59. token : "string.quoted.other", // Non-aligned-verbatim-strings (verbatim option not supported)
  60. regex : /"\{/,
  61. next: "non-aligned_verbatim_string"
  62. }, {
  63. token : "string.quoted.double",
  64. regex : /"(?:[^%\b\f\n\r\v]|%[A-DFHLNQR-V%'"()<>]|%\/(?:0[xX][\da-fA-F](?:_*[\da-fA-F])*|0[cC][0-7](?:_*[0-7])*|0[bB][01](?:_*[01])*|\d(?:_*\d)*)\/)*?"/
  65. }, {
  66. token : "comment.line.double-dash",
  67. regex : /--.*/
  68. }, {
  69. token : "constant.character",
  70. regex : /'(?:[^%\b\f\n\r\t\v]|%[A-DFHLNQR-V%'"()<>]|%\/(?:0[xX][\da-fA-F](?:_*[\da-fA-F])*|0[cC][0-7](?:_*[0-7])*|0[bB][01](?:_*[01])*|\d(?:_*\d)*)\/)'/
  71. }, {
  72. token : "constant.numeric", // hexa | octal | bin
  73. regex : /\b0(?:[xX][\da-fA-F](?:_*[\da-fA-F])*|[cC][0-7](?:_*[0-7])*|[bB][01](?:_*[01])*)\b/
  74. }, {
  75. token : "constant.numeric",
  76. regex : /(?:\d(?:_*\d)*)?\.(?:(?:\d(?:_*\d)*)?[eE][+-]?)?\d(?:_*\d)*|\d(?:_*\d)*\.?/
  77. }, {
  78. token : "paren.lparen",
  79. regex : /[\[({]|<<|\|\(/
  80. }, {
  81. token : "paren.rparen",
  82. regex : /[\])}]|>>|\|\)/
  83. }, {
  84. token : "keyword.operator", // punctuation
  85. regex : /:=|->|\.(?=\w)|[;,:?]/
  86. }, {
  87. token : "keyword.operator",
  88. regex : /\\\\|\|\.\.\||\.\.|\/[~\/]?|[><\/]=?|[-+*^=~]/
  89. }, {
  90. token : function (v) {
  91. var result = keywordMapper (v);
  92. if (result === "identifier" && v === v.toUpperCase ()) {
  93. result = "entity.name.type";
  94. }
  95. return result;
  96. },
  97. regex : /[a-zA-Z][a-zA-Z\d_]*\b/
  98. }, {
  99. token : "text",
  100. regex : /\s+/
  101. }
  102. ],
  103. "aligned_verbatim_string" : [{
  104. token : "string",
  105. regex : /]"/,
  106. next : "start"
  107. }, {
  108. token : "string",
  109. regex : simpleString
  110. }
  111. ],
  112. "non-aligned_verbatim_string" : [{
  113. token : "string.quoted.other",
  114. regex : /}"/,
  115. next : "start"
  116. }, {
  117. token : "string.quoted.other",
  118. regex : simpleString
  119. }
  120. ]};
  121. };
  122. oop.inherits(EiffelHighlightRules, TextHighlightRules);
  123. exports.EiffelHighlightRules = EiffelHighlightRules;
  124. });