dot_highlight_rules.js 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. define(function(require, exports, module) {
  2. "use strict";
  3. var oop = require("../lib/oop");
  4. var lang = require("../lib/lang");
  5. var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules;
  6. var DocCommentHighlightRules = require("./doc_comment_highlight_rules").DocCommentHighlightRules;
  7. var DotHighlightRules = function() {
  8. var keywords = lang.arrayToMap(
  9. ("strict|node|edge|graph|digraph|subgraph").split("|")
  10. );
  11. var attributes = lang.arrayToMap(
  12. ("damping|k|url|area|arrowhead|arrowsize|arrowtail|aspect|bb|bgcolor|center|charset|clusterrank|color|colorscheme|comment|compound|concentrate|constraint|decorate|defaultdist|dim|dimen|dir|diredgeconstraints|distortion|dpi|edgeurl|edgehref|edgetarget|edgetooltip|epsilon|esep|fillcolor|fixedsize|fontcolor|fontname|fontnames|fontpath|fontsize|forcelabels|gradientangle|group|headurl|head_lp|headclip|headhref|headlabel|headport|headtarget|headtooltip|height|href|id|image|imagepath|imagescale|label|labelurl|label_scheme|labelangle|labeldistance|labelfloat|labelfontcolor|labelfontname|labelfontsize|labelhref|labeljust|labelloc|labeltarget|labeltooltip|landscape|layer|layerlistsep|layers|layerselect|layersep|layout|len|levels|levelsgap|lhead|lheight|lp|ltail|lwidth|margin|maxiter|mclimit|mindist|minlen|mode|model|mosek|nodesep|nojustify|normalize|nslimit|nslimit1|ordering|orientation|outputorder|overlap|overlap_scaling|pack|packmode|pad|page|pagedir|pencolor|penwidth|peripheries|pin|pos|quadtree|quantum|rank|rankdir|ranksep|ratio|rects|regular|remincross|repulsiveforce|resolution|root|rotate|rotation|samehead|sametail|samplepoints|scale|searchsize|sep|shape|shapefile|showboxes|sides|size|skew|smoothing|sortv|splines|start|style|stylesheet|tailurl|tail_lp|tailclip|tailhref|taillabel|tailport|tailtarget|tailtooltip|target|tooltip|truecolor|vertices|viewport|voro_margin|weight|width|xlabel|xlp|z").split("|")
  13. );
  14. this.$rules = {
  15. "start" : [
  16. {
  17. token : "comment",
  18. regex : /\/\/.*$/
  19. }, {
  20. token : "comment",
  21. regex : /#.*$/
  22. }, {
  23. token : "comment", // multi line comment
  24. merge : true,
  25. regex : /\/\*/,
  26. next : "comment"
  27. }, {
  28. token : "string",
  29. regex : "'(?=.)",
  30. next : "qstring"
  31. }, {
  32. token : "string",
  33. regex : '"(?=.)',
  34. next : "qqstring"
  35. }, {
  36. token : "constant.numeric",
  37. regex : /[+\-]?\d+(?:(?:\.\d*)?(?:[eE][+\-]?\d+)?)?\b/
  38. }, {
  39. token : "keyword.operator",
  40. regex : /\+|=|\->/
  41. }, {
  42. token : "punctuation.operator",
  43. regex : /,|;/
  44. }, {
  45. token : "paren.lparen",
  46. regex : /[\[{]/
  47. }, {
  48. token : "paren.rparen",
  49. regex : /[\]}]/
  50. }, {
  51. token: "comment",
  52. regex: /^#!.*$/
  53. }, {
  54. token: function(value) {
  55. if (keywords.hasOwnProperty(value.toLowerCase())) {
  56. return "keyword";
  57. }
  58. else if (attributes.hasOwnProperty(value.toLowerCase())) {
  59. return "variable";
  60. }
  61. else {
  62. return "text";
  63. }
  64. },
  65. regex: "\\-?[a-zA-Z_][a-zA-Z0-9_\\-]*"
  66. }
  67. ],
  68. "comment" : [
  69. {
  70. token : "comment", // closing comment
  71. regex : ".*?\\*\\/",
  72. merge : true,
  73. next : "start"
  74. }, {
  75. token : "comment", // comment spanning whole line
  76. merge : true,
  77. regex : ".+"
  78. }
  79. ],
  80. "qqstring" : [
  81. {
  82. token : "string",
  83. regex : '[^"\\\\]+',
  84. merge : true
  85. }, {
  86. token : "string",
  87. regex : "\\\\$",
  88. next : "qqstring",
  89. merge : true
  90. }, {
  91. token : "string",
  92. regex : '"|$',
  93. next : "start",
  94. merge : true
  95. }
  96. ],
  97. "qstring" : [
  98. {
  99. token : "string",
  100. regex : "[^'\\\\]+",
  101. merge : true
  102. }, {
  103. token : "string",
  104. regex : "\\\\$",
  105. next : "qstring",
  106. merge : true
  107. }, {
  108. token : "string",
  109. regex : "'|$",
  110. next : "start",
  111. merge : true
  112. }
  113. ]
  114. };
  115. };
  116. oop.inherits(DotHighlightRules, TextHighlightRules);
  117. exports.DotHighlightRules = DotHighlightRules;
  118. });