]>
iEval git - gruntmaster-page.git/blob - js/95-clike.js
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
= /[+\-*&%=<>!?|\/]/;
15 function tokenBase(stream
, state
) {
16 var ch
= stream
.next();
18 var result
= hooks
[ch
](stream
, state
);
19 if (result
!== false) return result
;
21 if (ch
== '"' || ch
== "'") {
22 state
.tokenize
= tokenString(ch
);
23 return state
.tokenize(stream
, state
);
25 if (/[\[\]{}\(\),;\:\.]/.test(ch
)) {
30 stream
.eatWhile(/[\w\.]/);
34 if (stream
.eat("*")) {
35 state
.tokenize
= tokenComment
;
36 return tokenComment(stream
, state
);
38 if (stream
.eat("/")) {
43 if (isOperatorChar
.test(ch
)) {
44 stream
.eatWhile(isOperatorChar
);
47 stream
.eatWhile(/[\w\$_]/);
48 var cur
= stream
.current();
49 if (keywords
.propertyIsEnumerable(cur
)) {
50 if (blockKeywords
.propertyIsEnumerable(cur
)) curPunc
= "newstatement";
53 if (builtin
.propertyIsEnumerable(cur
)) {
54 if (blockKeywords
.propertyIsEnumerable(cur
)) curPunc
= "newstatement";
57 if (atoms
.propertyIsEnumerable(cur
)) return "atom";
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
== "\\";
68 if (end
|| !(escaped
|| multiLineStrings
))
69 state
.tokenize
= null;
74 function tokenComment(stream
, state
) {
75 var maybeEnd
= false, ch
;
76 while (ch
= stream
.next()) {
77 if (ch
== "/" && maybeEnd
) {
78 state
.tokenize
= null;
81 maybeEnd
= (ch
== "*");
86 function Context(indented
, column
, type
, align
, prev
) {
87 this.indented
= indented
;
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
);
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
;
109 startState: function(basecolumn
) {
112 context
: new Context((basecolumn
|| 0) - indentUnit
, 0, "top", false),
118 token: function(stream
, state
) {
119 var ctx
= state
.context
;
121 if (ctx
.align
== null) ctx
.align
= false;
122 state
.indented
= stream
.indentation();
123 state
.startOfLine
= true;
125 if (stream
.eatSpace()) return 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;
131 if ((curPunc
== ";" || curPunc
== ":" || curPunc
== ",") && ctx
.type
== "statement") 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
);
140 else if (curPunc
== ctx
.type
) popContext(state
);
141 else if (((ctx
.type
== "}" || ctx
.type
== "top") && curPunc
!= ';') || (ctx
.type
== "statement" && curPunc
== "newstatement"))
142 pushContext(state
, stream
.column(), "statement");
143 state
.startOfLine
= false;
147 indent: function(state
, textAfter
) {
148 if (state
.tokenize
!= tokenBase
&& state
.tokenize
!= null) return CodeMirror
.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
.column
+ (closing
? 0 : 1);
154 else if (ctx
.type
== ")" && !closing
) return ctx
.indented
+ statementIndentUnit
;
155 else return ctx
.indented
+ (closing
? 0 : indentUnit
);
159 blockCommentStart
: "/*",
160 blockCommentEnd
: "*/",
167 function words(str
) {
168 var obj
= {}, words
= str
.split(" ");
169 for (var i
= 0; i
< words
.length
; ++i
) obj
[words
[i
]] = true;
172 var cKeywords
= "auto if break int case long char register continue return default short do sizeof " +
173 "double static else struct entry switch extern typedef float union for unsigned " +
174 "goto while enum void const signed volatile";
176 function cppHook(stream
, state
) {
177 if (!state
.startOfLine
) return false;
179 if (stream
.skipTo("\\")) {
182 state
.tokenize
= cppHook
;
187 state
.tokenize
= null;
194 // C#-style strings where "" escapes a quote.
195 function tokenAtString(stream
, state
) {
197 while ((next
= stream
.next()) != null) {
198 if (next
== '"' && !stream
.eat('"')) {
199 state
.tokenize
= null;
206 function def(mimes
, mode
) {
209 if (obj
) for (var prop
in obj
) if (obj
.hasOwnProperty(prop
))
216 mode
.helperType
= mimes
[0];
217 CodeMirror
.registerHelper("hintWords", mimes
[0], words
);
220 for (var i
= 0; i
< mimes
.length
; ++i
)
221 CodeMirror
.defineMIME(mimes
[i
], mode
);
224 def(["text/x-csrc", "text/x-c", "text/x-chdr"], {
226 keywords
: words(cKeywords
),
227 blockKeywords
: words("case do else for if switch while struct"),
228 atoms
: words("null"),
229 hooks
: {"#": cppHook
},
230 modeProps
: {fold
: ["brace", "include"]}
233 def(["text/x-c++src", "text/x-c++hdr"], {
235 keywords
: words(cKeywords
+ " asm dynamic_cast namespace reinterpret_cast try bool explicit new " +
236 "static_cast typeid catch operator template typename class friend private " +
237 "this using const_cast inline public throw virtual delete mutable protected " +
239 blockKeywords
: words("catch class do else finally for if struct switch try while"),
240 atoms
: words("true false null"),
241 hooks
: {"#": cppHook
},
242 modeProps
: {fold
: ["brace", "include"]}
244 CodeMirror
.defineMIME("text/x-java", {
246 keywords
: words("abstract assert boolean break byte case catch char class const continue default " +
247 "do double else enum extends final finally float for goto if implements import " +
248 "instanceof int interface long native new package private protected public " +
249 "return short static strictfp super switch synchronized this throw throws transient " +
250 "try void volatile while"),
251 blockKeywords
: words("catch class do else finally for if switch try while"),
252 atoms
: words("true false null"),
254 "@": function(stream
) {
255 stream
.eatWhile(/[\w\$_]/);
259 modeProps
: {fold
: ["brace", "import"]}
261 CodeMirror
.defineMIME("text/x-csharp", {
263 keywords
: words("abstract as base break case catch checked class const continue" +
264 " default delegate do else enum event explicit extern finally fixed for" +
265 " foreach goto if implicit in interface internal is lock namespace new" +
266 " operator out override params private protected public readonly ref return sealed" +
267 " sizeof stackalloc static struct switch this throw try typeof unchecked" +
268 " unsafe using virtual void volatile while add alias ascending descending dynamic from get" +
269 " global group into join let orderby partial remove select set value var yield"),
270 blockKeywords
: words("catch class do else finally for foreach if struct switch try while"),
271 builtin
: words("Boolean Byte Char DateTime DateTimeOffset Decimal Double" +
272 " Guid Int16 Int32 Int64 Object SByte Single String TimeSpan UInt16 UInt32" +
273 " UInt64 bool byte char decimal double short int long object" +
274 " sbyte float string ushort uint ulong"),
275 atoms
: words("true false null"),
277 "@": function(stream
, state
) {
278 if (stream
.eat('"')) {
279 state
.tokenize
= tokenAtString
;
280 return tokenAtString(stream
, state
);
282 stream
.eatWhile(/[\w\$_]/);
287 CodeMirror
.defineMIME("text/x-scala", {
292 "abstract case catch class def do else extends false final finally for forSome if " +
293 "implicit import lazy match new null object override package private protected return " +
294 "sealed super this throw trait try trye type val var while with yield _ : = => <- <: " +
298 "assert assume require print println printf readLine readBoolean readByte readShort " +
299 "readChar readInt readLong readFloat readDouble " +
301 "AnyVal App Application Array BufferedIterator BigDecimal BigInt Char Console Either " +
302 "Enumeration Equiv Error Exception Fractional Function IndexedSeq Integral Iterable " +
303 "Iterator List Map Numeric Nil NotNull Option Ordered Ordering PartialFunction PartialOrdering " +
304 "Product Proxy Range Responder Seq Serializable Set Specializable Stream StringBuilder " +
305 "StringContext Symbol Throwable Traversable TraversableOnce Tuple Unit Vector :: #:: " +
307 /* package java.lang */
308 "Boolean Byte Character CharSequence Class ClassLoader Cloneable Comparable " +
309 "Compiler Double Exception Float Integer Long Math Number Object Package Pair Process " +
310 "Runtime Runnable SecurityManager Short StackTraceElement StrictMath String " +
311 "StringBuffer System Thread ThreadGroup ThreadLocal Throwable Triple Void"
315 blockKeywords
: words("catch class do else finally for forSome if match switch try while"),
316 atoms
: words("true false null"),
318 "@": function(stream
) {
319 stream
.eatWhile(/[\w\$_]/);
324 def(["x-shader/x-vertex", "x-shader/x-fragment"], {
326 keywords
: words("float int bool void " +
327 "vec2 vec3 vec4 ivec2 ivec3 ivec4 bvec2 bvec3 bvec4 " +
329 "sampler1D sampler2D sampler3D samplerCube " +
330 "sampler1DShadow sampler2DShadow" +
331 "const attribute uniform varying " +
332 "break continue discard return " +
333 "for while do if else struct " +
335 blockKeywords
: words("for while do if else struct"),
336 builtin
: words("radians degrees sin cos tan asin acos atan " +
337 "pow exp log exp2 sqrt inversesqrt " +
338 "abs sign floor ceil fract mod min max clamp mix step smootstep " +
339 "length distance dot cross normalize ftransform faceforward " +
340 "reflect refract matrixCompMult " +
341 "lessThan lessThanEqual greaterThan greaterThanEqual " +
342 "equal notEqual any all not " +
343 "texture1D texture1DProj texture1DLod texture1DProjLod " +
344 "texture2D texture2DProj texture2DLod texture2DProjLod " +
345 "texture3D texture3DProj texture3DLod texture3DProjLod " +
346 "textureCube textureCubeLod " +
347 "shadow1D shadow2D shadow1DProj shadow2DProj " +
348 "shadow1DLod shadow2DLod shadow1DProjLod shadow2DProjLod " +
349 "dFdx dFdy fwidth " +
350 "noise1 noise2 noise3 noise4"),
351 atoms
: words("true false " +
352 "gl_FragColor gl_SecondaryColor gl_Normal gl_Vertex " +
353 "gl_MultiTexCoord0 gl_MultiTexCoord1 gl_MultiTexCoord2 gl_MultiTexCoord3 " +
354 "gl_MultiTexCoord4 gl_MultiTexCoord5 gl_MultiTexCoord6 gl_MultiTexCoord7 " +
356 "gl_Position gl_PointSize gl_ClipVertex " +
357 "gl_FrontColor gl_BackColor gl_FrontSecondaryColor gl_BackSecondaryColor " +
358 "gl_TexCoord gl_FogFragCoord " +
359 "gl_FragCoord gl_FrontFacing " +
360 "gl_FragColor gl_FragData gl_FragDepth " +
361 "gl_ModelViewMatrix gl_ProjectionMatrix gl_ModelViewProjectionMatrix " +
362 "gl_TextureMatrix gl_NormalMatrix gl_ModelViewMatrixInverse " +
363 "gl_ProjectionMatrixInverse gl_ModelViewProjectionMatrixInverse " +
364 "gl_TexureMatrixTranspose gl_ModelViewMatrixInverseTranspose " +
365 "gl_ProjectionMatrixInverseTranspose " +
366 "gl_ModelViewProjectionMatrixInverseTranspose " +
367 "gl_TextureMatrixInverseTranspose " +
368 "gl_NormalScale gl_DepthRange gl_ClipPlane " +
369 "gl_Point gl_FrontMaterial gl_BackMaterial gl_LightSource gl_LightModel " +
370 "gl_FrontLightModelProduct gl_BackLightModelProduct " +
371 "gl_TextureColor gl_EyePlaneS gl_EyePlaneT gl_EyePlaneR gl_EyePlaneQ " +
372 "gl_FogParameters " +
373 "gl_MaxLights gl_MaxClipPlanes gl_MaxTextureUnits gl_MaxTextureCoords " +
374 "gl_MaxVertexAttribs gl_MaxVertexUniformComponents gl_MaxVaryingFloats " +
375 "gl_MaxVertexTextureImageUnits gl_MaxTextureImageUnits " +
376 "gl_MaxFragmentUniformComponents gl_MaxCombineTextureImageUnits " +
377 "gl_MaxDrawBuffers"),
378 hooks
: {"#": cppHook
},
379 modeProps
: {fold
: ["brace", "include"]}
This page took 0.073513 seconds and 5 git commands to generate.