OLD | NEW |
(Empty) | |
| 1 CodeMirror.defineMode("clike", function(config, parserConfig) { |
| 2 var indentUnit = config.indentUnit, |
| 3 statementIndentUnit = parserConfig.statementIndentUnit || indentUnit, |
| 4 dontAlignCalls = parserConfig.dontAlignCalls, |
| 5 keywords = parserConfig.keywords || {}, |
| 6 builtin = parserConfig.builtin || {}, |
| 7 blockKeywords = parserConfig.blockKeywords || {}, |
| 8 atoms = parserConfig.atoms || {}, |
| 9 hooks = parserConfig.hooks || {}, |
| 10 multiLineStrings = parserConfig.multiLineStrings; |
| 11 var isOperatorChar = /[+\-*&%=<>!?|\/]/; |
| 12 |
| 13 var curPunc; |
| 14 |
| 15 function tokenBase(stream, state) { |
| 16 var ch = stream.next(); |
| 17 if (hooks[ch]) { |
| 18 var result = hooks[ch](stream, state); |
| 19 if (result !== false) return result; |
| 20 } |
| 21 if (ch == '"' || ch == "'") { |
| 22 state.tokenize = tokenString(ch); |
| 23 return state.tokenize(stream, state); |
| 24 } |
| 25 if (/[\[\]{}\(\),;\:\.]/.test(ch)) { |
| 26 curPunc = ch; |
| 27 return null; |
| 28 } |
| 29 if (/\d/.test(ch)) { |
| 30 stream.eatWhile(/[\w\.]/); |
| 31 return "number"; |
| 32 } |
| 33 if (ch == "/") { |
| 34 if (stream.eat("*")) { |
| 35 state.tokenize = tokenComment; |
| 36 return tokenComment(stream, state); |
| 37 } |
| 38 if (stream.eat("/")) { |
| 39 stream.skipToEnd(); |
| 40 return "comment"; |
| 41 } |
| 42 } |
| 43 if (isOperatorChar.test(ch)) { |
| 44 stream.eatWhile(isOperatorChar); |
| 45 return "operator"; |
| 46 } |
| 47 stream.eatWhile(/[\w\$_]/); |
| 48 var cur = stream.current(); |
| 49 if (keywords.propertyIsEnumerable(cur)) { |
| 50 if (blockKeywords.propertyIsEnumerable(cur)) curPunc = "newstatement"; |
| 51 return "keyword"; |
| 52 } |
| 53 if (builtin.propertyIsEnumerable(cur)) { |
| 54 if (blockKeywords.propertyIsEnumerable(cur)) curPunc = "newstatement"; |
| 55 return "builtin"; |
| 56 } |
| 57 if (atoms.propertyIsEnumerable(cur)) return "atom"; |
| 58 return "variable"; |
| 59 } |
| 60 |
| 61 function tokenString(quote) { |
| 62 return function(stream, state) { |
| 63 var escaped = false, next, end = false; |
| 64 while ((next = stream.next()) != null) { |
| 65 if (next == quote && !escaped) {end = true; break;} |
| 66 escaped = !escaped && next == "\\"; |
| 67 } |
| 68 if (end || !(escaped || multiLineStrings)) |
| 69 state.tokenize = null; |
| 70 return "string"; |
| 71 }; |
| 72 } |
| 73 |
| 74 function tokenComment(stream, state) { |
| 75 var maybeEnd = false, ch; |
| 76 while (ch = stream.next()) { |
| 77 if (ch == "/" && maybeEnd) { |
| 78 state.tokenize = null; |
| 79 break; |
| 80 } |
| 81 maybeEnd = (ch == "*"); |
| 82 } |
| 83 return "comment"; |
| 84 } |
| 85 |
| 86 function Context(indented, column, type, align, prev) { |
| 87 this.indented = indented; |
| 88 this.column = column; |
| 89 this.type = type; |
| 90 this.align = align; |
| 91 this.prev = prev; |
| 92 } |
| 93 function pushContext(state, col, type) { |
| 94 var indent = state.indented; |
| 95 if (state.context && state.context.type == "statement") |
| 96 indent = state.context.indented; |
| 97 return state.context = new Context(indent, col, type, null, state.context); |
| 98 } |
| 99 function popContext(state) { |
| 100 var t = state.context.type; |
| 101 if (t == ")" || t == "]" || t == "}") |
| 102 state.indented = state.context.indented; |
| 103 return state.context = state.context.prev; |
| 104 } |
| 105 |
| 106 // Interface |
| 107 |
| 108 return { |
| 109 startState: function(basecolumn) { |
| 110 return { |
| 111 tokenize: null, |
| 112 context: new Context((basecolumn || 0) - indentUnit, 0, "top", false), |
| 113 indented: 0, |
| 114 startOfLine: true |
| 115 }; |
| 116 }, |
| 117 |
| 118 token: function(stream, state) { |
| 119 var ctx = state.context; |
| 120 if (stream.sol()) { |
| 121 if (ctx.align == null) ctx.align = false; |
| 122 state.indented = stream.indentation(); |
| 123 state.startOfLine = true; |
| 124 } |
| 125 if (stream.eatSpace()) return null; |
| 126 curPunc = null; |
| 127 var style = (state.tokenize || tokenBase)(stream, state); |
| 128 if (style == "comment" || style == "meta") return style; |
| 129 if (ctx.align == null) ctx.align = true; |
| 130 |
| 131 if ((curPunc == ";" || curPunc == ":" || curPunc == ",") && ctx.type == "s
tatement") popContext(state); |
| 132 else if (curPunc == "{") pushContext(state, stream.column(), "}"); |
| 133 else if (curPunc == "[") pushContext(state, stream.column(), "]"); |
| 134 else if (curPunc == "(") pushContext(state, stream.column(), ")"); |
| 135 else if (curPunc == "}") { |
| 136 while (ctx.type == "statement") ctx = popContext(state); |
| 137 if (ctx.type == "}") ctx = popContext(state); |
| 138 while (ctx.type == "statement") ctx = popContext(state); |
| 139 } |
| 140 else if (curPunc == ctx.type) popContext(state); |
| 141 else if (((ctx.type == "}" || ctx.type == "top") && curPunc != ';') || (ct
x.type == "statement" && curPunc == "newstatement")) |
| 142 pushContext(state, stream.column(), "statement"); |
| 143 state.startOfLine = false; |
| 144 return style; |
| 145 }, |
| 146 |
| 147 indent: function(state, textAfter) { |
| 148 if (state.tokenize != tokenBase && state.tokenize != null) return CodeMirr
or.Pass; |
| 149 var ctx = state.context, firstChar = textAfter && textAfter.charAt(0); |
| 150 if (ctx.type == "statement" && firstChar == "}") ctx = ctx.prev; |
| 151 var closing = firstChar == ctx.type; |
| 152 if (ctx.type == "statement") return ctx.indented + (firstChar == "{" ? 0 :
statementIndentUnit); |
| 153 else if (ctx.align && (!dontAlignCalls || ctx.type != ")")) return ctx.col
umn + (closing ? 0 : 1); |
| 154 else if (ctx.type == ")" && !closing) return ctx.indented + statementInden
tUnit; |
| 155 else return ctx.indented + (closing ? 0 : indentUnit); |
| 156 }, |
| 157 |
| 158 electricChars: "{}", |
| 159 blockCommentStart: "/*", |
| 160 blockCommentEnd: "*/", |
| 161 lineComment: "//" |
| 162 }; |
| 163 }); |
| 164 |
| 165 (function() { |
| 166 function words(str) { |
| 167 var obj = {}, words = str.split(" "); |
| 168 for (var i = 0; i < words.length; ++i) obj[words[i]] = true; |
| 169 return obj; |
| 170 } |
| 171 var cKeywords = "auto if break int case long char register continue return def
ault short do sizeof " + |
| 172 "double static else struct entry switch extern typedef float union for unsig
ned " + |
| 173 "goto while enum void const signed volatile"; |
| 174 |
| 175 function cppHook(stream, state) { |
| 176 if (!state.startOfLine) return false; |
| 177 for (;;) { |
| 178 if (stream.skipTo("\\")) { |
| 179 stream.next(); |
| 180 if (stream.eol()) { |
| 181 state.tokenize = cppHook; |
| 182 break; |
| 183 } |
| 184 } else { |
| 185 stream.skipToEnd(); |
| 186 state.tokenize = null; |
| 187 break; |
| 188 } |
| 189 } |
| 190 return "meta"; |
| 191 } |
| 192 |
| 193 // C#-style strings where "" escapes a quote. |
| 194 function tokenAtString(stream, state) { |
| 195 var next; |
| 196 while ((next = stream.next()) != null) { |
| 197 if (next == '"' && !stream.eat('"')) { |
| 198 state.tokenize = null; |
| 199 break; |
| 200 } |
| 201 } |
| 202 return "string"; |
| 203 } |
| 204 |
| 205 function mimes(ms, mode) { |
| 206 for (var i = 0; i < ms.length; ++i) CodeMirror.defineMIME(ms[i], mode); |
| 207 } |
| 208 |
| 209 mimes(["text/x-csrc", "text/x-c", "text/x-chdr"], { |
| 210 name: "clike", |
| 211 keywords: words(cKeywords), |
| 212 blockKeywords: words("case do else for if switch while struct"), |
| 213 atoms: words("null"), |
| 214 hooks: {"#": cppHook} |
| 215 }); |
| 216 mimes(["text/x-c++src", "text/x-c++hdr"], { |
| 217 name: "clike", |
| 218 keywords: words(cKeywords + " asm dynamic_cast namespace reinterpret_cast tr
y bool explicit new " + |
| 219 "static_cast typeid catch operator template typename class f
riend private " + |
| 220 "this using const_cast inline public throw virtual delete mu
table protected " + |
| 221 "wchar_t"), |
| 222 blockKeywords: words("catch class do else finally for if struct switch try w
hile"), |
| 223 atoms: words("true false null"), |
| 224 hooks: {"#": cppHook} |
| 225 }); |
| 226 CodeMirror.defineMIME("text/x-java", { |
| 227 name: "clike", |
| 228 keywords: words("abstract assert boolean break byte case catch char class co
nst continue default " + |
| 229 "do double else enum extends final finally float for goto if
implements import " + |
| 230 "instanceof int interface long native new package private pr
otected public " + |
| 231 "return short static strictfp super switch synchronized this
throw throws transient " + |
| 232 "try void volatile while"), |
| 233 blockKeywords: words("catch class do else finally for if switch try while"), |
| 234 atoms: words("true false null"), |
| 235 hooks: { |
| 236 "@": function(stream) { |
| 237 stream.eatWhile(/[\w\$_]/); |
| 238 return "meta"; |
| 239 } |
| 240 } |
| 241 }); |
| 242 CodeMirror.defineMIME("text/x-csharp", { |
| 243 name: "clike", |
| 244 keywords: words("abstract as base break case catch checked class const conti
nue" + |
| 245 " default delegate do else enum event explicit extern finall
y fixed for" + |
| 246 " foreach goto if implicit in interface internal is lock nam
espace new" + |
| 247 " operator out override params private protected public read
only ref return sealed" + |
| 248 " sizeof stackalloc static struct switch this throw try type
of unchecked" + |
| 249 " unsafe using virtual void volatile while add alias ascendi
ng descending dynamic from get" + |
| 250 " global group into join let orderby partial remove select s
et value var yield"), |
| 251 blockKeywords: words("catch class do else finally for foreach if struct swit
ch try while"), |
| 252 builtin: words("Boolean Byte Char DateTime DateTimeOffset Decimal Double" + |
| 253 " Guid Int16 Int32 Int64 Object SByte Single String TimeSpan
UInt16 UInt32" + |
| 254 " UInt64 bool byte char decimal double short int long object
" + |
| 255 " sbyte float string ushort uint ulong"), |
| 256 atoms: words("true false null"), |
| 257 hooks: { |
| 258 "@": function(stream, state) { |
| 259 if (stream.eat('"')) { |
| 260 state.tokenize = tokenAtString; |
| 261 return tokenAtString(stream, state); |
| 262 } |
| 263 stream.eatWhile(/[\w\$_]/); |
| 264 return "meta"; |
| 265 } |
| 266 } |
| 267 }); |
| 268 CodeMirror.defineMIME("text/x-scala", { |
| 269 name: "clike", |
| 270 keywords: words( |
| 271 |
| 272 /* scala */ |
| 273 "abstract case catch class def do else extends false final finally for for
Some if " + |
| 274 "implicit import lazy match new null object override package private prote
cted return " + |
| 275 "sealed super this throw trait try trye type val var while with yield _ :
= => <- <: " + |
| 276 "<% >: # @ " + |
| 277 |
| 278 /* package scala */ |
| 279 "assert assume require print println printf readLine readBoolean readByte
readShort " + |
| 280 "readChar readInt readLong readFloat readDouble " + |
| 281 |
| 282 "AnyVal App Application Array BufferedIterator BigDecimal BigInt Char Cons
ole Either " + |
| 283 "Enumeration Equiv Error Exception Fractional Function IndexedSeq Integral
Iterable " + |
| 284 "Iterator List Map Numeric Nil NotNull Option Ordered Ordering PartialFunc
tion PartialOrdering " + |
| 285 "Product Proxy Range Responder Seq Serializable Set Specializable Stream S
tringBuilder " + |
| 286 "StringContext Symbol Throwable Traversable TraversableOnce Tuple Unit Vec
tor :: #:: " + |
| 287 |
| 288 /* package java.lang */ |
| 289 "Boolean Byte Character CharSequence Class ClassLoader Cloneable Comparabl
e " + |
| 290 "Compiler Double Exception Float Integer Long Math Number Object Package P
air Process " + |
| 291 "Runtime Runnable SecurityManager Short StackTraceElement StrictMath Strin
g " + |
| 292 "StringBuffer System Thread ThreadGroup ThreadLocal Throwable Triple Void" |
| 293 |
| 294 |
| 295 ), |
| 296 blockKeywords: words("catch class do else finally for forSome if match switc
h try while"), |
| 297 atoms: words("true false null"), |
| 298 hooks: { |
| 299 "@": function(stream) { |
| 300 stream.eatWhile(/[\w\$_]/); |
| 301 return "meta"; |
| 302 } |
| 303 } |
| 304 }); |
| 305 mimes(["x-shader/x-vertex", "x-shader/x-fragment"], { |
| 306 name: "clike", |
| 307 keywords: words("float int bool void " + |
| 308 "vec2 vec3 vec4 ivec2 ivec3 ivec4 bvec2 bvec3 bvec4 " + |
| 309 "mat2 mat3 mat4 " + |
| 310 "sampler1D sampler2D sampler3D samplerCube " + |
| 311 "sampler1DShadow sampler2DShadow" + |
| 312 "const attribute uniform varying " + |
| 313 "break continue discard return " + |
| 314 "for while do if else struct " + |
| 315 "in out inout"), |
| 316 blockKeywords: words("for while do if else struct"), |
| 317 builtin: words("radians degrees sin cos tan asin acos atan " + |
| 318 "pow exp log exp2 sqrt inversesqrt " + |
| 319 "abs sign floor ceil fract mod min max clamp mix step smoots
tep " + |
| 320 "length distance dot cross normalize ftransform faceforward
" + |
| 321 "reflect refract matrixCompMult " + |
| 322 "lessThan lessThanEqual greaterThan greaterThanEqual " + |
| 323 "equal notEqual any all not " + |
| 324 "texture1D texture1DProj texture1DLod texture1DProjLod " + |
| 325 "texture2D texture2DProj texture2DLod texture2DProjLod " + |
| 326 "texture3D texture3DProj texture3DLod texture3DProjLod " + |
| 327 "textureCube textureCubeLod " + |
| 328 "shadow1D shadow2D shadow1DProj shadow2DProj " + |
| 329 "shadow1DLod shadow2DLod shadow1DProjLod shadow2DProjLod " + |
| 330 "dFdx dFdy fwidth " + |
| 331 "noise1 noise2 noise3 noise4"), |
| 332 atoms: words("true false " + |
| 333 "gl_FragColor gl_SecondaryColor gl_Normal gl_Vertex " + |
| 334 "gl_MultiTexCoord0 gl_MultiTexCoord1 gl_MultiTexCoord2 gl_MultiT
exCoord3 " + |
| 335 "gl_MultiTexCoord4 gl_MultiTexCoord5 gl_MultiTexCoord6 gl_MultiT
exCoord7 " + |
| 336 "gl_FogCoord " + |
| 337 "gl_Position gl_PointSize gl_ClipVertex " + |
| 338 "gl_FrontColor gl_BackColor gl_FrontSecondaryColor gl_BackSecond
aryColor " + |
| 339 "gl_TexCoord gl_FogFragCoord " + |
| 340 "gl_FragCoord gl_FrontFacing " + |
| 341 "gl_FragColor gl_FragData gl_FragDepth " + |
| 342 "gl_ModelViewMatrix gl_ProjectionMatrix gl_ModelViewProjectionMa
trix " + |
| 343 "gl_TextureMatrix gl_NormalMatrix gl_ModelViewMatrixInverse " + |
| 344 "gl_ProjectionMatrixInverse gl_ModelViewProjectionMatrixInverse
" + |
| 345 "gl_TexureMatrixTranspose gl_ModelViewMatrixInverseTranspose " + |
| 346 "gl_ProjectionMatrixInverseTranspose " + |
| 347 "gl_ModelViewProjectionMatrixInverseTranspose " + |
| 348 "gl_TextureMatrixInverseTranspose " + |
| 349 "gl_NormalScale gl_DepthRange gl_ClipPlane " + |
| 350 "gl_Point gl_FrontMaterial gl_BackMaterial gl_LightSource gl_Lig
htModel " + |
| 351 "gl_FrontLightModelProduct gl_BackLightModelProduct " + |
| 352 "gl_TextureColor gl_EyePlaneS gl_EyePlaneT gl_EyePlaneR gl_EyePl
aneQ " + |
| 353 "gl_FogParameters " + |
| 354 "gl_MaxLights gl_MaxClipPlanes gl_MaxTextureUnits gl_MaxTextureC
oords " + |
| 355 "gl_MaxVertexAttribs gl_MaxVertexUniformComponents gl_MaxVarying
Floats " + |
| 356 "gl_MaxVertexTextureImageUnits gl_MaxTextureImageUnits " + |
| 357 "gl_MaxFragmentUniformComponents gl_MaxCombineTextureImageUnits
" + |
| 358 "gl_MaxDrawBuffers"), |
| 359 hooks: {"#": cppHook} |
| 360 }); |
| 361 }()); |
OLD | NEW |