|
| 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 | +/* |
| 31 | + * TODO: python delimiters |
| 32 | + */ |
| 33 | + |
| 34 | +define(function(require, exports, module) { |
| 35 | +"use strict"; |
| 36 | + |
| 37 | +var oop = require("../lib/oop"); |
| 38 | +var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules; |
| 39 | + |
| 40 | +var PlotDeviceHighlightRules = function() { |
| 41 | + |
| 42 | + var keywords = ( |
| 43 | + "and|as|assert|break|class|continue|def|del|elif|else|except|exec|" + |
| 44 | + "finally|for|from|global|if|import|in|is|lambda|not|or|pass|print|" + |
| 45 | + "raise|return|try|while|with|yield" + |
| 46 | + "|adict|odict|ddict|BezierPath|Bezier|ClippingPath|Color|Context|Family|Font|Stylesheet|Grob|Image|PlotDeviceError|Oval|PathElement|Curve|Point|Rect|Text|Transform|TransformContext|Variable" |
| 47 | + ); |
| 48 | + |
| 49 | + var builtinConstants = ( |
| 50 | + "True|False|None|NotImplemented|Ellipsis|__debug__" |
| 51 | + ); |
| 52 | + |
| 53 | + var builtinNumConstants = "DEFAULT|FRAME|PAGE|BEVEL|BOOLEAN|BUTT|BUTTON|CENTER|CLOSE|CMYK|CORNER|CURVETO|DEFAULT_HEIGHT|DEFAULT_WIDTH|FORTYFIVE|HEIGHT|HSB|JUSTIFY|KEY_BACKSPACE|KEY_DOWN|KEY_ESC|KEY_LEFT|KEY_RIGHT|KEY_TAB|KEY_UP|LEFT|LINETO|MITER|MOVETO|NORMAL|NUMBER|RGB|GREY|RIGHT|ROUND|SQUARE|TEXT|WIDTH|DEGREES|RADIANS|PERCENT|cm|inch|mm|pi|tau" |
| 54 | + |
| 55 | + var builtinFunctions = ( |
| 56 | + "abs|divmod|input|open|staticmethod|all|enumerate|int|ord|str|any|" + |
| 57 | + "eval|isinstance|pow|sum|basestring|execfile|issubclass|print|super|" + |
| 58 | + "binfile|iter|property|tuple|bool|filter|len|range|type|bytearray|" + |
| 59 | + "float|list|raw_input|unichr|callable|format|locals|reduce|unicode|" + |
| 60 | + "chr|frozenset|long|reload|vars|classmethod|getattr|map|repr|xrange|" + |
| 61 | + "cmp|globals|max|reversed|zip|compile|hasattr|memoryview|round|" + |
| 62 | + "__import__|complex|hash|min|set|apply|delattr|help|next|setattr|" + |
| 63 | + "buffer|dict|hex|object|slice|coerce|dir|id|oct|sorted|intern" + |
| 64 | + "|plot|measure|stylesheet|order|ordered|shuffled|addvar|align|arrow|autoclosepath|autotext|background|beginclip|beginpath|bezier|canvas|capstyle|choice|clip|closepath|color|colormode|colorrange|colors|curveto|drawpath|ellipse|endclip|endpath|export|files|fill|findpath|findvar|font|fonts|fontsize|grid|image|imagesize|joinstyle|line|lineheight|lineto|moveto|pen|plotstyle|nofill|nostroke|outputmode|oval|pop|push|random|rect|reset|rotate|save|scale|size|skew|speed|star|state_vars|stroke|strokewidth|text|textheight|textmetrics|textpath|textwidth|transform|translate|var|ximport" |
| 65 | + ); |
| 66 | + |
| 67 | + var colorEntities = ('aliceblue|antiquewhite|aqua|aquamarine|azure|bark|beige|bisque|black|blanchedalmond|blue|blueviolet|brown|burlywood|cadetblue|chartreuse|chocolate|coral|cornflowerblue|cornsilk|crimson|cyan|darkblue|darkcyan|darkgoldenrod|darkgray|darkgreen|darkkhaki|darkmagenta|darkolivegreen|darkorange|darkorchid|darkred|darksalmon|darkseagreen|darkslateblue|darkslategray|darkturquoise|darkviolet|deeppink|deepskyblue|dimgray|dimgrey|dodgerblue|firebrick|floralwhite|forestgreen|fuchsia|gainsboro|ghostwhite|gold|goldenrod|gray|green|greenyellow|grey|honeydew|hotpink|indianred|indigo|ivory|khaki|lavender|lavenderblush|lawngreen|lemonchiffon|lightblue|lightcoral|lightcyan|lightgoldenrodyellow|lightgreen|lightgrey|lightpink|lightsalmon|lightseagreen|lightskyblue|lightslategray|lightsteelblue|lightyellow|lime|limegreen|linen|maroon|mediumaquamarine|mediumblue|mediumorchid|mediumpurple|mediumseagreen|mediumslateblue|mediumspringgreen|mediumturquoise|mediumvioletred|midnightblue|mintcream|mistyrose|moccasin|navajowhite|navy|oldlace|olive|olivedrab|orange|orangered|orchid|palegoldenrod|palegreen|paleturquoise|palevioletred|papayawhip|peachpuff|peru|pink|plum|powderblue|purple|red|rosybrown|royalblue|saddlebrown|salmon|sandybrown|seagreen|seashell|sienna|silver|skyblue|slateblue|slategray|snow|springgreen|steelblue|tan|teal|thistle|tomato|transparent|turquoise|violet|wheat|white|whitesmoke|yellow|yellowgreen'); |
| 68 | + var colorCodes = '(#?[a-f0-9]{3}([a-f0-9]{3}([a-f0-9]{2})?)?\\b)' |
| 69 | + |
| 70 | + //var futureReserved = ""; |
| 71 | + var keywordMapper = this.createKeywordMapper({ |
| 72 | + "invalid.deprecated": "debugger", |
| 73 | + "support.function": builtinFunctions, |
| 74 | + //"invalid.illegal": futureReserved, |
| 75 | + "constant.language": builtinConstants, |
| 76 | + "constant.numeric": builtinNumConstants, |
| 77 | + "keyword": keywords |
| 78 | + }, "identifier"); |
| 79 | + |
| 80 | + var strPre = "(?:r|u|ur|R|U|UR|Ur|uR)?"; |
| 81 | + |
| 82 | + var decimalInteger = "(?:(?:[1-9]\\d*)|(?:0))"; |
| 83 | + var octInteger = "(?:0[oO]?[0-7]+)"; |
| 84 | + var hexInteger = "(?:0[xX][\\dA-Fa-f]+)"; |
| 85 | + var binInteger = "(?:0[bB][01]+)"; |
| 86 | + var integer = "(?:" + decimalInteger + "|" + octInteger + "|" + hexInteger + "|" + binInteger + ")"; |
| 87 | + |
| 88 | + var exponent = "(?:[eE][+-]?\\d+)"; |
| 89 | + var fraction = "(?:\\.\\d+)"; |
| 90 | + var intPart = "(?:\\d+)"; |
| 91 | + var pointFloat = "(?:(?:" + intPart + "?" + fraction + ")|(?:" + intPart + "\\.))"; |
| 92 | + var exponentFloat = "(?:(?:" + pointFloat + "|" + intPart + ")" + exponent + ")"; |
| 93 | + var floatNumber = "(?:" + exponentFloat + "|" + pointFloat + ")"; |
| 94 | + var colorString = "'(" + colorCodes + "|" + colorEntities + ")'" |
| 95 | + var qcolorString = '"(' + colorCodes + '|' + colorEntities + ')"' |
| 96 | + |
| 97 | + var stringEscape = "\\\\(x[0-9A-Fa-f]{2}|[0-7]{3}|[\\\\abfnrtv'\"]|U[0-9A-Fa-f]{8}|u[0-9A-Fa-f]{4})"; |
| 98 | + |
| 99 | + this.$rules = { |
| 100 | + "start" : [ { |
| 101 | + token : "comment", |
| 102 | + regex : "#.*$" |
| 103 | + }, { |
| 104 | + token : "keyword", |
| 105 | + regex : '\\bdef\\b|\\bclass\\b', |
| 106 | + next : "define" |
| 107 | + }, { |
| 108 | + token : "constant.numeric", // string containing a hex or named color |
| 109 | + regex : colorString |
| 110 | + }, { |
| 111 | + token : "constant.numeric", // string containing a hex or named color |
| 112 | + regex : qcolorString |
| 113 | + }, { |
| 114 | + token : "string", // multi line """ string start |
| 115 | + regex : strPre + '"{3}', |
| 116 | + next : "qqstring3" |
| 117 | + }, { |
| 118 | + token : "string", // " string |
| 119 | + regex : strPre + '"(?=.)', |
| 120 | + next : "qqstring" |
| 121 | + }, { |
| 122 | + token : "string", // multi line ''' string start |
| 123 | + regex : strPre + "'{3}", |
| 124 | + next : "qstring3" |
| 125 | + }, { |
| 126 | + token : "string", // ' string |
| 127 | + regex : strPre + "'(?=.)", |
| 128 | + next : "qstring" |
| 129 | + }, { |
| 130 | + token : "constant.numeric", // imaginary |
| 131 | + regex : "(?:" + floatNumber + "|\\d+)[jJ]\\b" |
| 132 | + }, { |
| 133 | + token : "constant.numeric", // float |
| 134 | + regex : floatNumber |
| 135 | + }, { |
| 136 | + token : "constant.numeric", // long integer |
| 137 | + regex : integer + "[lL]\\b" |
| 138 | + }, { |
| 139 | + token : "constant.numeric", // integer |
| 140 | + regex : integer + "\\b" |
| 141 | + }, { |
| 142 | + token : keywordMapper, |
| 143 | + regex : "[a-zA-Z_$][a-zA-Z0-9_$]*\\b" |
| 144 | + }, { |
| 145 | + token : "keyword.operator", |
| 146 | + regex : "\\+|\\-|\\*|\\*\\*|\\/|\\/\\/|%|<<|>>|&|\\||\\^|~|<|>|<=|=>|==|!=|<>|=" |
| 147 | + }, { |
| 148 | + token : "paren.lparen", |
| 149 | + regex : "[\\[\\(\\{]" |
| 150 | + }, { |
| 151 | + token : "paren.rparen", |
| 152 | + regex : "[\\]\\)\\}]" |
| 153 | + }, { |
| 154 | + token : "text", |
| 155 | + regex : "\\s+" |
| 156 | + } ], |
| 157 | + "define":[ |
| 158 | + { |
| 159 | + token : "constant.language", |
| 160 | + regex : "def|class" |
| 161 | + }, |
| 162 | + { |
| 163 | + token : "variable.language", |
| 164 | + regex : "[A-Za-z_][A-Za-z0-9_]*", |
| 165 | + next : "start" |
| 166 | + }, |
| 167 | + { |
| 168 | + token : "text", |
| 169 | + regex : "\\s+" |
| 170 | + } |
| 171 | + ], |
| 172 | + "qqstring3" : [ { |
| 173 | + token : "constant.language.escape", |
| 174 | + regex : stringEscape |
| 175 | + }, { |
| 176 | + token : "string", // multi line """ string end |
| 177 | + regex : '"{3}', |
| 178 | + next : "start" |
| 179 | + }, { |
| 180 | + defaultToken : "string" |
| 181 | + } ], |
| 182 | + "qstring3" : [ { |
| 183 | + token : "constant.language.escape", |
| 184 | + regex : stringEscape |
| 185 | + }, { |
| 186 | + token : "string", // multi line ''' string end |
| 187 | + regex : "'{3}", |
| 188 | + next : "start" |
| 189 | + }, { |
| 190 | + defaultToken : "string" |
| 191 | + } ], |
| 192 | + "qqstring" : [{ |
| 193 | + token : "constant.language.escape", |
| 194 | + regex : stringEscape |
| 195 | + }, { |
| 196 | + token : "string", |
| 197 | + regex : "\\\\$", |
| 198 | + next : "qqstring" |
| 199 | + }, { |
| 200 | + token : "string", |
| 201 | + regex : '"|$', |
| 202 | + next : "start" |
| 203 | + }, { |
| 204 | + defaultToken: "string" |
| 205 | + }], |
| 206 | + "qstring" : [{ |
| 207 | + token : "constant.language.escape", |
| 208 | + regex : stringEscape |
| 209 | + }, { |
| 210 | + token : "string", |
| 211 | + regex : "\\\\$", |
| 212 | + next : "qstring" |
| 213 | + }, { |
| 214 | + token : "string", |
| 215 | + regex : "'|$", |
| 216 | + next : "start" |
| 217 | + }, { |
| 218 | + defaultToken: "string" |
| 219 | + }] |
| 220 | + }; |
| 221 | +}; |
| 222 | + |
| 223 | +oop.inherits(PlotDeviceHighlightRules, TextHighlightRules); |
| 224 | + |
| 225 | +exports.PlotDeviceHighlightRules = PlotDeviceHighlightRules; |
| 226 | +}); |
0 commit comments