2 if (typeof exports
== "object" && typeof module
== "object") // CommonJS
3 mod(require("../../lib/codemirror"));
4 else if (typeof define
== "function" && define
.amd
) // AMD
5 define(["../../lib/codemirror"], mod
);
6 else // Plain browser env
8 })(function(CodeMirror
) {
11 CodeMirror
.defineMode("clike", function(config
, parserConfig
) {
12 var indentUnit
= config
.indentUnit
,
13 statementIndentUnit
= parserConfig
.statementIndentUnit
|| indentUnit
,
14 dontAlignCalls
= parserConfig
.dontAlignCalls
,
15 keywords
= parserConfig
.keywords
|| {},
16 builtin
= parserConfig
.builtin
|| {},
17 blockKeywords
= parserConfig
.blockKeywords
|| {},
18 atoms
= parserConfig
.atoms
|| {},
19 hooks
= parserConfig
.hooks
|| {},
20 multiLineStrings
= parserConfig
.multiLineStrings
;
21 var isOperatorChar
= /[+\-*&%=<>!?|\/]/;
25 function tokenBase(stream
, state
) {
26 var ch
= stream
.next();
28 var result
= hooks
[ch
](stream
, state
);
29 if (result
!== false) return result
;
31 if (ch
== '"' || ch
== "'") {
32 state
.tokenize
= tokenString(ch
);
33 return state
.tokenize(stream
, state
);
35 if (/[\[\]{}\(\),;\:\.]/.test(ch
)) {
40 stream
.eatWhile(/[\w\.]/);
44 if (stream
.eat("*")) {
45 state
.tokenize
= tokenComment
;
46 return tokenComment(stream
, state
);
48 if (stream
.eat("/")) {
53 if (isOperatorChar
.test(ch
)) {
54 stream
.eatWhile(isOperatorChar
);
57 stream
.eatWhile(/[\w\$_]/);
58 var cur
= stream
.current();
59 if (keywords
.propertyIsEnumerable(cur
)) {
60 if (blockKeywords
.propertyIsEnumerable(cur
)) curPunc
= "newstatement";
63 if (builtin
.propertyIsEnumerable(cur
)) {
64 if (blockKeywords
.propertyIsEnumerable(cur
)) curPunc
= "newstatement";
67 if (atoms
.propertyIsEnumerable(cur
)) return "atom";
71 function tokenString(quote
) {
72 return function(stream
, state
) {
73 var escaped
= false, next
, end
= false;
74 while ((next
= stream
.next()) != null) {
75 if (next
== quote
&& !escaped
) {end
= true; break;}
76 escaped
= !escaped
&& next
== "\\";
78 if (end
|| !(escaped
|| multiLineStrings
))
79 state
.tokenize
= null;
84 function tokenComment(stream
, state
) {
85 var maybeEnd
= false, ch
;
86 while (ch
= stream
.next()) {
87 if (ch
== "/" && maybeEnd
) {
88 state
.tokenize
= null;
91 maybeEnd
= (ch
== "*");
96 function Context(indented
, column
, type
, align
, prev
) {
97 this.indented
= indented
;
103 function pushContext(state
, col
, type
) {
104 var indent
= state
.indented
;
105 if (state
.context
&& state
.context
.type
== "statement")
106 indent
= state
.context
.indented
;
107 return state
.context
= new Context(indent
, col
, type
, null, state
.context
);
109 function popContext(state
) {
110 var t
= state
.context
.type
;
111 if (t
== ")" || t
== "]" || t
== "}")
112 state
.indented
= state
.context
.indented
;
113 return state
.context
= state
.context
.prev
;
119 startState: function(basecolumn
) {
122 context
: new Context((basecolumn
|| 0) - indentUnit
, 0, "top", false),
128 token: function(stream
, state
) {
129 var ctx
= state
.context
;
131 if (ctx
.align
== null) ctx
.align
= false;
132 state
.indented
= stream
.indentation();
133 state
.startOfLine
= true;
135 if (stream
.eatSpace()) return null;
137 var style
= (state
.tokenize
|| tokenBase
)(stream
, state
);
138 if (style
== "comment" || style
== "meta") return style
;
139 if (ctx
.align
== null) ctx
.align
= true;
141 if ((curPunc
== ";" || curPunc
== ":" || curPunc
== ",") && ctx
.type
== "statement") popContext(state
);
142 else if (curPunc
== "{") pushContext(state
, stream
.column(), "}");
143 else if (curPunc
== "[") pushContext(state
, stream
.column(), "]");
144 else if (curPunc
== "(") pushContext(state
, stream
.column(), ")");
145 else if (curPunc
== "}") {
146 while (ctx
.type
== "statement") ctx
= popContext(state
);
147 if (ctx
.type
== "}") ctx
= popContext(state
);
148 while (ctx
.type
== "statement") ctx
= popContext(state
);
150 else if (curPunc
== ctx
.type
) popContext(state
);
151 else if (((ctx
.type
== "}" || ctx
.type
== "top") && curPunc
!= ';') || (ctx
.type
== "statement" && curPunc
== "newstatement"))
152 pushContext(state
, stream
.column(), "statement");
153 state
.startOfLine
= false;
157 indent: function(state
, textAfter
) {
158 if (state
.tokenize
!= tokenBase
&& state
.tokenize
!= null) return CodeMirror
.Pass
;
159 var ctx
= state
.context
, firstChar
= textAfter
&& textAfter
.charAt(0);
160 if (ctx
.type
== "statement" && firstChar
== "}") ctx
= ctx
.prev
;
161 var closing
= firstChar
== ctx
.type
;
162 if (ctx
.type
== "statement") return ctx
.indented
+ (firstChar
== "{" ? 0 : statementIndentUnit
);
163 else if (ctx
.align
&& (!dontAlignCalls
|| ctx
.type
!= ")")) return ctx
.column
+ (closing
? 0 : 1);
164 else if (ctx
.type
== ")" && !closing
) return ctx
.indented
+ statementIndentUnit
;
165 else return ctx
.indented
+ (closing
? 0 : indentUnit
);
169 blockCommentStart
: "/*",
170 blockCommentEnd
: "*/",
177 function words(str
) {
178 var obj
= {}, words
= str
.split(" ");
179 for (var i
= 0; i
< words
.length
; ++i
) obj
[words
[i
]] = true;
182 var cKeywords
= "auto if break int case long char register continue return default short do sizeof " +
183 "double static else struct entry switch extern typedef float union for unsigned " +
184 "goto while enum void const signed volatile";
186 function cppHook(stream
, state
) {
187 if (!state
.startOfLine
) return false;
189 if (stream
.skipTo("\\")) {
192 state
.tokenize
= cppHook
;
197 state
.tokenize
= null;
204 function cpp11StringHook(stream
, state
) {
207 if (stream
.match(/(R|u8R|uR|UR|LR)/)) {
208 var match
= stream
.match(/"(.{0,16})\(/);
212 state
.cpp11RawStringDelim
= match
[1];
213 state
.tokenize
= tokenRawString
;
214 return tokenRawString(stream
, state
);
216 // Unicode strings/chars.
217 if (stream
.match(/(u8|u|U|L)/)) {
218 if (stream
.match(/["']/, /* eat */ false)) {
228 // C#-style strings where "" escapes a quote.
229 function tokenAtString(stream
, state
) {
231 while ((next
= stream
.next()) != null) {
232 if (next
== '"' && !stream
.eat('"')) {
233 state
.tokenize
= null;
240 // C++11 raw string literal is <prefix>"<delim>( anything )<delim>", where
241 // <delim> can be a string up to 16 characters long.
242 function tokenRawString(stream
, state
) {
243 var closingSequence
= new RegExp(".*?\\)" + state
.cpp11RawStringDelim
+ '"');
244 var match
= stream
.match(closingSequence
);
246 state
.tokenize
= null;
253 function def(mimes
, mode
) {
256 if (obj
) for (var prop
in obj
) if (obj
.hasOwnProperty(prop
))
263 mode
.helperType
= mimes
[0];
264 CodeMirror
.registerHelper("hintWords", mimes
[0], words
);
267 for (var i
= 0; i
< mimes
.length
; ++i
)
268 CodeMirror
.defineMIME(mimes
[i
], mode
);
271 def(["text/x-csrc", "text/x-c", "text/x-chdr"], {
273 keywords
: words(cKeywords
),
274 blockKeywords
: words("case do else for if switch while struct"),
275 atoms
: words("null"),
276 hooks
: {"#": cppHook
},
277 modeProps
: {fold
: ["brace", "include"]}
280 def(["text/x-c++src", "text/x-c++hdr"], {
282 keywords
: words(cKeywords
+ " asm dynamic_cast namespace reinterpret_cast try bool explicit new " +
283 "static_cast typeid catch operator template typename class friend private " +
284 "this using const_cast inline public throw virtual delete mutable protected " +
285 "wchar_t alignas alignof constexpr decltype nullptr noexcept thread_local final " +
286 "static_assert override"),
287 blockKeywords
: words("catch class do else finally for if struct switch try while"),
288 atoms
: words("true false null"),
291 "u": cpp11StringHook
,
292 "U": cpp11StringHook
,
293 "L": cpp11StringHook
,
296 modeProps
: {fold
: ["brace", "include"]}
298 CodeMirror
.defineMIME("text/x-java", {
300 keywords
: words("abstract assert boolean break byte case catch char class const continue default " +
301 "do double else enum extends final finally float for goto if implements import " +
302 "instanceof int interface long native new package private protected public " +
303 "return short static strictfp super switch synchronized this throw throws transient " +
304 "try void volatile while"),
305 blockKeywords
: words("catch class do else finally for if switch try while"),
306 atoms
: words("true false null"),
308 "@": function(stream
) {
309 stream
.eatWhile(/[\w\$_]/);
313 modeProps
: {fold
: ["brace", "import"]}
315 CodeMirror
.defineMIME("text/x-csharp", {
317 keywords
: words("abstract as base break case catch checked class const continue" +
318 " default delegate do else enum event explicit extern finally fixed for" +
319 " foreach goto if implicit in interface internal is lock namespace new" +
320 " operator out override params private protected public readonly ref return sealed" +
321 " sizeof stackalloc static struct switch this throw try typeof unchecked" +
322 " unsafe using virtual void volatile while add alias ascending descending dynamic from get" +
323 " global group into join let orderby partial remove select set value var yield"),
324 blockKeywords
: words("catch class do else finally for foreach if struct switch try while"),
325 builtin
: words("Boolean Byte Char DateTime DateTimeOffset Decimal Double" +
326 " Guid Int16 Int32 Int64 Object SByte Single String TimeSpan UInt16 UInt32" +
327 " UInt64 bool byte char decimal double short int long object" +
328 " sbyte float string ushort uint ulong"),
329 atoms
: words("true false null"),
331 "@": function(stream
, state
) {
332 if (stream
.eat('"')) {
333 state
.tokenize
= tokenAtString
;
334 return tokenAtString(stream
, state
);
336 stream
.eatWhile(/[\w\$_]/);
341 CodeMirror
.defineMIME("text/x-scala", {
346 "abstract case catch class def do else extends false final finally for forSome if " +
347 "implicit import lazy match new null object override package private protected return " +
348 "sealed super this throw trait try trye type val var while with yield _ : = => <- <: " +
352 "assert assume require print println printf readLine readBoolean readByte readShort " +
353 "readChar readInt readLong readFloat readDouble " +
355 "AnyVal App Application Array BufferedIterator BigDecimal BigInt Char Console Either " +
356 "Enumeration Equiv Error Exception Fractional Function IndexedSeq Integral Iterable " +
357 "Iterator List Map Numeric Nil NotNull Option Ordered Ordering PartialFunction PartialOrdering " +
358 "Product Proxy Range Responder Seq Serializable Set Specializable Stream StringBuilder " +
359 "StringContext Symbol Throwable Traversable TraversableOnce Tuple Unit Vector :: #:: " +
361 /* package java.lang */
362 "Boolean Byte Character CharSequence Class ClassLoader Cloneable Comparable " +
363 "Compiler Double Exception Float Integer Long Math Number Object Package Pair Process " +
364 "Runtime Runnable SecurityManager Short StackTraceElement StrictMath String " +
365 "StringBuffer System Thread ThreadGroup ThreadLocal Throwable Triple Void"
369 blockKeywords
: words("catch class do else finally for forSome if match switch try while"),
370 atoms
: words("true false null"),
372 "@": function(stream
) {
373 stream
.eatWhile(/[\w\$_]/);
378 def(["x-shader/x-vertex", "x-shader/x-fragment"], {
380 keywords
: words("float int bool void " +
381 "vec2 vec3 vec4 ivec2 ivec3 ivec4 bvec2 bvec3 bvec4 " +
383 "sampler1D sampler2D sampler3D samplerCube " +
384 "sampler1DShadow sampler2DShadow" +
385 "const attribute uniform varying " +
386 "break continue discard return " +
387 "for while do if else struct " +
389 blockKeywords
: words("for while do if else struct"),
390 builtin
: words("radians degrees sin cos tan asin acos atan " +
391 "pow exp log exp2 sqrt inversesqrt " +
392 "abs sign floor ceil fract mod min max clamp mix step smootstep " +
393 "length distance dot cross normalize ftransform faceforward " +
394 "reflect refract matrixCompMult " +
395 "lessThan lessThanEqual greaterThan greaterThanEqual " +
396 "equal notEqual any all not " +
397 "texture1D texture1DProj texture1DLod texture1DProjLod " +
398 "texture2D texture2DProj texture2DLod texture2DProjLod " +
399 "texture3D texture3DProj texture3DLod texture3DProjLod " +
400 "textureCube textureCubeLod " +
401 "shadow1D shadow2D shadow1DProj shadow2DProj " +
402 "shadow1DLod shadow2DLod shadow1DProjLod shadow2DProjLod " +
403 "dFdx dFdy fwidth " +
404 "noise1 noise2 noise3 noise4"),
405 atoms
: words("true false " +
406 "gl_FragColor gl_SecondaryColor gl_Normal gl_Vertex " +
407 "gl_MultiTexCoord0 gl_MultiTexCoord1 gl_MultiTexCoord2 gl_MultiTexCoord3 " +
408 "gl_MultiTexCoord4 gl_MultiTexCoord5 gl_MultiTexCoord6 gl_MultiTexCoord7 " +
410 "gl_Position gl_PointSize gl_ClipVertex " +
411 "gl_FrontColor gl_BackColor gl_FrontSecondaryColor gl_BackSecondaryColor " +
412 "gl_TexCoord gl_FogFragCoord " +
413 "gl_FragCoord gl_FrontFacing " +
414 "gl_FragColor gl_FragData gl_FragDepth " +
415 "gl_ModelViewMatrix gl_ProjectionMatrix gl_ModelViewProjectionMatrix " +
416 "gl_TextureMatrix gl_NormalMatrix gl_ModelViewMatrixInverse " +
417 "gl_ProjectionMatrixInverse gl_ModelViewProjectionMatrixInverse " +
418 "gl_TexureMatrixTranspose gl_ModelViewMatrixInverseTranspose " +
419 "gl_ProjectionMatrixInverseTranspose " +
420 "gl_ModelViewProjectionMatrixInverseTranspose " +
421 "gl_TextureMatrixInverseTranspose " +
422 "gl_NormalScale gl_DepthRange gl_ClipPlane " +
423 "gl_Point gl_FrontMaterial gl_BackMaterial gl_LightSource gl_LightModel " +
424 "gl_FrontLightModelProduct gl_BackLightModelProduct " +
425 "gl_TextureColor gl_EyePlaneS gl_EyePlaneT gl_EyePlaneR gl_EyePlaneQ " +
426 "gl_FogParameters " +
427 "gl_MaxLights gl_MaxClipPlanes gl_MaxTextureUnits gl_MaxTextureCoords " +
428 "gl_MaxVertexAttribs gl_MaxVertexUniformComponents gl_MaxVaryingFloats " +
429 "gl_MaxVertexTextureImageUnits gl_MaxTextureImageUnits " +
430 "gl_MaxFragmentUniformComponents gl_MaxCombineTextureImageUnits " +
431 "gl_MaxDrawBuffers"),
432 hooks
: {"#": cppHook
},
433 modeProps
: {fold
: ["brace", "include"]}