OLD | NEW |
| 1 // CodeMirror, copyright (c) by Marijn Haverbeke and others |
| 2 // Distributed under an MIT license: http://codemirror.net/LICENSE |
| 3 |
| 4 (function(mod) { |
| 5 if (typeof exports == "object" && typeof module == "object") // CommonJS |
| 6 mod(require("../../lib/codemirror")); |
| 7 else if (typeof define == "function" && define.amd) // AMD |
| 8 define(["../../lib/codemirror"], mod); |
| 9 else // Plain browser env |
| 10 mod(CodeMirror); |
| 11 })(function(CodeMirror) { |
| 12 "use strict"; |
| 13 |
1 CodeMirror.defineMode("clike", function(config, parserConfig) { | 14 CodeMirror.defineMode("clike", function(config, parserConfig) { |
2 var indentUnit = config.indentUnit, | 15 var indentUnit = config.indentUnit, |
3 statementIndentUnit = parserConfig.statementIndentUnit || indentUnit, | 16 statementIndentUnit = parserConfig.statementIndentUnit || indentUnit, |
4 dontAlignCalls = parserConfig.dontAlignCalls, | 17 dontAlignCalls = parserConfig.dontAlignCalls, |
5 keywords = parserConfig.keywords || {}, | 18 keywords = parserConfig.keywords || {}, |
6 builtin = parserConfig.builtin || {}, | 19 builtin = parserConfig.builtin || {}, |
7 blockKeywords = parserConfig.blockKeywords || {}, | 20 blockKeywords = parserConfig.blockKeywords || {}, |
8 atoms = parserConfig.atoms || {}, | 21 atoms = parserConfig.atoms || {}, |
9 hooks = parserConfig.hooks || {}, | 22 hooks = parserConfig.hooks || {}, |
10 multiLineStrings = parserConfig.multiLineStrings; | 23 multiLineStrings = parserConfig.multiLineStrings; |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
156 }, | 169 }, |
157 | 170 |
158 electricChars: "{}", | 171 electricChars: "{}", |
159 blockCommentStart: "/*", | 172 blockCommentStart: "/*", |
160 blockCommentEnd: "*/", | 173 blockCommentEnd: "*/", |
161 lineComment: "//", | 174 lineComment: "//", |
162 fold: "brace" | 175 fold: "brace" |
163 }; | 176 }; |
164 }); | 177 }); |
165 | 178 |
166 (function() { | |
167 function words(str) { | 179 function words(str) { |
168 var obj = {}, words = str.split(" "); | 180 var obj = {}, words = str.split(" "); |
169 for (var i = 0; i < words.length; ++i) obj[words[i]] = true; | 181 for (var i = 0; i < words.length; ++i) obj[words[i]] = true; |
170 return obj; | 182 return obj; |
171 } | 183 } |
172 var cKeywords = "auto if break int case long char register continue return def
ault short do sizeof " + | 184 var cKeywords = "auto if break int case long char register continue return def
ault short do sizeof " + |
173 "double static else struct entry switch extern typedef float union for unsig
ned " + | 185 "double static else struct entry switch extern typedef float union for unsig
ned " + |
174 "goto while enum void const signed volatile"; | 186 "goto while enum void const signed volatile"; |
175 | 187 |
176 function cppHook(stream, state) { | 188 function cppHook(stream, state) { |
177 if (!state.startOfLine) return false; | 189 if (!state.startOfLine) return false; |
178 for (;;) { | 190 for (;;) { |
179 if (stream.skipTo("\\")) { | 191 if (stream.skipTo("\\")) { |
180 stream.next(); | 192 stream.next(); |
181 if (stream.eol()) { | 193 if (stream.eol()) { |
182 state.tokenize = cppHook; | 194 state.tokenize = cppHook; |
183 break; | 195 break; |
184 } | 196 } |
185 } else { | 197 } else { |
186 stream.skipToEnd(); | 198 stream.skipToEnd(); |
187 state.tokenize = null; | 199 state.tokenize = null; |
188 break; | 200 break; |
189 } | 201 } |
190 } | 202 } |
191 return "meta"; | 203 return "meta"; |
192 } | 204 } |
193 | 205 |
| 206 function cpp11StringHook(stream, state) { |
| 207 stream.backUp(1); |
| 208 // Raw strings. |
| 209 if (stream.match(/(R|u8R|uR|UR|LR)/)) { |
| 210 var match = stream.match(/"([^\s\\()]{0,16})\(/); |
| 211 if (!match) { |
| 212 return false; |
| 213 } |
| 214 state.cpp11RawStringDelim = match[1]; |
| 215 state.tokenize = tokenRawString; |
| 216 return tokenRawString(stream, state); |
| 217 } |
| 218 // Unicode strings/chars. |
| 219 if (stream.match(/(u8|u|U|L)/)) { |
| 220 if (stream.match(/["']/, /* eat */ false)) { |
| 221 return "string"; |
| 222 } |
| 223 return false; |
| 224 } |
| 225 // Ignore this hook. |
| 226 stream.next(); |
| 227 return false; |
| 228 } |
| 229 |
194 // C#-style strings where "" escapes a quote. | 230 // C#-style strings where "" escapes a quote. |
195 function tokenAtString(stream, state) { | 231 function tokenAtString(stream, state) { |
196 var next; | 232 var next; |
197 while ((next = stream.next()) != null) { | 233 while ((next = stream.next()) != null) { |
198 if (next == '"' && !stream.eat('"')) { | 234 if (next == '"' && !stream.eat('"')) { |
199 state.tokenize = null; | 235 state.tokenize = null; |
200 break; | 236 break; |
201 } | 237 } |
202 } | 238 } |
203 return "string"; | 239 return "string"; |
204 } | 240 } |
205 | 241 |
206 function mimes(ms, mode) { | 242 // C++11 raw string literal is <prefix>"<delim>( anything )<delim>", where |
207 for (var i = 0; i < ms.length; ++i) CodeMirror.defineMIME(ms[i], mode); | 243 // <delim> can be a string up to 16 characters long. |
| 244 function tokenRawString(stream, state) { |
| 245 // Escape characters that have special regex meanings. |
| 246 var delim = state.cpp11RawStringDelim.replace(/[^\w\s]/g, '\\$&'); |
| 247 var match = stream.match(new RegExp(".*?\\)" + delim + '"')); |
| 248 if (match) |
| 249 state.tokenize = null; |
| 250 else |
| 251 stream.skipToEnd(); |
| 252 return "string"; |
208 } | 253 } |
209 | 254 |
210 mimes(["text/x-csrc", "text/x-c", "text/x-chdr"], { | 255 function def(mimes, mode) { |
| 256 if (typeof mimes == "string") mimes = [mimes]; |
| 257 var words = []; |
| 258 function add(obj) { |
| 259 if (obj) for (var prop in obj) if (obj.hasOwnProperty(prop)) |
| 260 words.push(prop); |
| 261 } |
| 262 add(mode.keywords); |
| 263 add(mode.builtin); |
| 264 add(mode.atoms); |
| 265 if (words.length) { |
| 266 mode.helperType = mimes[0]; |
| 267 CodeMirror.registerHelper("hintWords", mimes[0], words); |
| 268 } |
| 269 |
| 270 for (var i = 0; i < mimes.length; ++i) |
| 271 CodeMirror.defineMIME(mimes[i], mode); |
| 272 } |
| 273 |
| 274 def(["text/x-csrc", "text/x-c", "text/x-chdr"], { |
211 name: "clike", | 275 name: "clike", |
212 keywords: words(cKeywords), | 276 keywords: words(cKeywords), |
213 blockKeywords: words("case do else for if switch while struct"), | 277 blockKeywords: words("case do else for if switch while struct"), |
214 atoms: words("null"), | 278 atoms: words("null"), |
215 hooks: {"#": cppHook} | 279 hooks: {"#": cppHook}, |
| 280 modeProps: {fold: ["brace", "include"]} |
216 }); | 281 }); |
217 mimes(["text/x-c++src", "text/x-c++hdr"], { | 282 |
| 283 def(["text/x-c++src", "text/x-c++hdr"], { |
218 name: "clike", | 284 name: "clike", |
219 keywords: words(cKeywords + " asm dynamic_cast namespace reinterpret_cast tr
y bool explicit new " + | 285 keywords: words(cKeywords + " asm dynamic_cast namespace reinterpret_cast tr
y bool explicit new " + |
220 "static_cast typeid catch operator template typename class f
riend private " + | 286 "static_cast typeid catch operator template typename class f
riend private " + |
221 "this using const_cast inline public throw virtual delete mu
table protected " + | 287 "this using const_cast inline public throw virtual delete mu
table protected " + |
222 "wchar_t"), | 288 "wchar_t alignas alignof constexpr decltype nullptr noexcept
thread_local final " + |
| 289 "static_assert override"), |
223 blockKeywords: words("catch class do else finally for if struct switch try w
hile"), | 290 blockKeywords: words("catch class do else finally for if struct switch try w
hile"), |
224 atoms: words("true false null"), | 291 atoms: words("true false null"), |
225 hooks: {"#": cppHook} | 292 hooks: { |
| 293 "#": cppHook, |
| 294 "u": cpp11StringHook, |
| 295 "U": cpp11StringHook, |
| 296 "L": cpp11StringHook, |
| 297 "R": cpp11StringHook |
| 298 }, |
| 299 modeProps: {fold: ["brace", "include"]} |
226 }); | 300 }); |
227 CodeMirror.defineMIME("text/x-java", { | 301 def("text/x-java", { |
228 name: "clike", | 302 name: "clike", |
229 keywords: words("abstract assert boolean break byte case catch char class co
nst continue default " + | 303 keywords: words("abstract assert boolean break byte case catch char class co
nst continue default " + |
230 "do double else enum extends final finally float for goto if
implements import " + | 304 "do double else enum extends final finally float for goto if
implements import " + |
231 "instanceof int interface long native new package private pr
otected public " + | 305 "instanceof int interface long native new package private pr
otected public " + |
232 "return short static strictfp super switch synchronized this
throw throws transient " + | 306 "return short static strictfp super switch synchronized this
throw throws transient " + |
233 "try void volatile while"), | 307 "try void volatile while"), |
234 blockKeywords: words("catch class do else finally for if switch try while"), | 308 blockKeywords: words("catch class do else finally for if switch try while"), |
235 atoms: words("true false null"), | 309 atoms: words("true false null"), |
236 hooks: { | 310 hooks: { |
237 "@": function(stream) { | 311 "@": function(stream) { |
238 stream.eatWhile(/[\w\$_]/); | 312 stream.eatWhile(/[\w\$_]/); |
239 return "meta"; | 313 return "meta"; |
240 } | 314 } |
241 } | 315 }, |
| 316 modeProps: {fold: ["brace", "import"]} |
242 }); | 317 }); |
243 CodeMirror.defineMIME("text/x-csharp", { | 318 def("text/x-csharp", { |
244 name: "clike", | 319 name: "clike", |
245 keywords: words("abstract as base break case catch checked class const conti
nue" + | 320 keywords: words("abstract as base break case catch checked class const conti
nue" + |
246 " default delegate do else enum event explicit extern finall
y fixed for" + | 321 " default delegate do else enum event explicit extern finall
y fixed for" + |
247 " foreach goto if implicit in interface internal is lock nam
espace new" + | 322 " foreach goto if implicit in interface internal is lock nam
espace new" + |
248 " operator out override params private protected public read
only ref return sealed" + | 323 " operator out override params private protected public read
only ref return sealed" + |
249 " sizeof stackalloc static struct switch this throw try type
of unchecked" + | 324 " sizeof stackalloc static struct switch this throw try type
of unchecked" + |
250 " unsafe using virtual void volatile while add alias ascendi
ng descending dynamic from get" + | 325 " unsafe using virtual void volatile while add alias ascendi
ng descending dynamic from get" + |
251 " global group into join let orderby partial remove select s
et value var yield"), | 326 " global group into join let orderby partial remove select s
et value var yield"), |
252 blockKeywords: words("catch class do else finally for foreach if struct swit
ch try while"), | 327 blockKeywords: words("catch class do else finally for foreach if struct swit
ch try while"), |
253 builtin: words("Boolean Byte Char DateTime DateTimeOffset Decimal Double" + | 328 builtin: words("Boolean Byte Char DateTime DateTimeOffset Decimal Double" + |
254 " Guid Int16 Int32 Int64 Object SByte Single String TimeSpan
UInt16 UInt32" + | 329 " Guid Int16 Int32 Int64 Object SByte Single String TimeSpan
UInt16 UInt32" + |
255 " UInt64 bool byte char decimal double short int long object
" + | 330 " UInt64 bool byte char decimal double short int long object
" + |
256 " sbyte float string ushort uint ulong"), | 331 " sbyte float string ushort uint ulong"), |
257 atoms: words("true false null"), | 332 atoms: words("true false null"), |
258 hooks: { | 333 hooks: { |
259 "@": function(stream, state) { | 334 "@": function(stream, state) { |
260 if (stream.eat('"')) { | 335 if (stream.eat('"')) { |
261 state.tokenize = tokenAtString; | 336 state.tokenize = tokenAtString; |
262 return tokenAtString(stream, state); | 337 return tokenAtString(stream, state); |
263 } | 338 } |
264 stream.eatWhile(/[\w\$_]/); | 339 stream.eatWhile(/[\w\$_]/); |
265 return "meta"; | 340 return "meta"; |
266 } | 341 } |
267 } | 342 } |
268 }); | 343 }); |
269 CodeMirror.defineMIME("text/x-scala", { | 344 def("text/x-scala", { |
270 name: "clike", | 345 name: "clike", |
271 keywords: words( | 346 keywords: words( |
272 | 347 |
273 /* scala */ | 348 /* scala */ |
274 "abstract case catch class def do else extends false final finally for for
Some if " + | 349 "abstract case catch class def do else extends false final finally for for
Some if " + |
275 "implicit import lazy match new null object override package private prote
cted return " + | 350 "implicit import lazy match new null object override package private prote
cted return " + |
276 "sealed super this throw trait try trye type val var while with yield _ :
= => <- <: " + | 351 "sealed super this throw trait try trye type val var while with yield _ :
= => <- <: " + |
277 "<% >: # @ " + | 352 "<% >: # @ " + |
278 | 353 |
279 /* package scala */ | 354 /* package scala */ |
(...skipping 16 matching lines...) Expand all Loading... |
296 ), | 371 ), |
297 blockKeywords: words("catch class do else finally for forSome if match switc
h try while"), | 372 blockKeywords: words("catch class do else finally for forSome if match switc
h try while"), |
298 atoms: words("true false null"), | 373 atoms: words("true false null"), |
299 hooks: { | 374 hooks: { |
300 "@": function(stream) { | 375 "@": function(stream) { |
301 stream.eatWhile(/[\w\$_]/); | 376 stream.eatWhile(/[\w\$_]/); |
302 return "meta"; | 377 return "meta"; |
303 } | 378 } |
304 } | 379 } |
305 }); | 380 }); |
306 mimes(["x-shader/x-vertex", "x-shader/x-fragment"], { | 381 def(["x-shader/x-vertex", "x-shader/x-fragment"], { |
307 name: "clike", | 382 name: "clike", |
308 keywords: words("float int bool void " + | 383 keywords: words("float int bool void " + |
309 "vec2 vec3 vec4 ivec2 ivec3 ivec4 bvec2 bvec3 bvec4 " + | 384 "vec2 vec3 vec4 ivec2 ivec3 ivec4 bvec2 bvec3 bvec4 " + |
310 "mat2 mat3 mat4 " + | 385 "mat2 mat3 mat4 " + |
311 "sampler1D sampler2D sampler3D samplerCube " + | 386 "sampler1D sampler2D sampler3D samplerCube " + |
312 "sampler1DShadow sampler2DShadow" + | 387 "sampler1DShadow sampler2DShadow" + |
313 "const attribute uniform varying " + | 388 "const attribute uniform varying " + |
314 "break continue discard return " + | 389 "break continue discard return " + |
315 "for while do if else struct " + | 390 "for while do if else struct " + |
316 "in out inout"), | 391 "in out inout"), |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
350 "gl_NormalScale gl_DepthRange gl_ClipPlane " + | 425 "gl_NormalScale gl_DepthRange gl_ClipPlane " + |
351 "gl_Point gl_FrontMaterial gl_BackMaterial gl_LightSource gl_Lig
htModel " + | 426 "gl_Point gl_FrontMaterial gl_BackMaterial gl_LightSource gl_Lig
htModel " + |
352 "gl_FrontLightModelProduct gl_BackLightModelProduct " + | 427 "gl_FrontLightModelProduct gl_BackLightModelProduct " + |
353 "gl_TextureColor gl_EyePlaneS gl_EyePlaneT gl_EyePlaneR gl_EyePl
aneQ " + | 428 "gl_TextureColor gl_EyePlaneS gl_EyePlaneT gl_EyePlaneR gl_EyePl
aneQ " + |
354 "gl_FogParameters " + | 429 "gl_FogParameters " + |
355 "gl_MaxLights gl_MaxClipPlanes gl_MaxTextureUnits gl_MaxTextureC
oords " + | 430 "gl_MaxLights gl_MaxClipPlanes gl_MaxTextureUnits gl_MaxTextureC
oords " + |
356 "gl_MaxVertexAttribs gl_MaxVertexUniformComponents gl_MaxVarying
Floats " + | 431 "gl_MaxVertexAttribs gl_MaxVertexUniformComponents gl_MaxVarying
Floats " + |
357 "gl_MaxVertexTextureImageUnits gl_MaxTextureImageUnits " + | 432 "gl_MaxVertexTextureImageUnits gl_MaxTextureImageUnits " + |
358 "gl_MaxFragmentUniformComponents gl_MaxCombineTextureImageUnits
" + | 433 "gl_MaxFragmentUniformComponents gl_MaxCombineTextureImageUnits
" + |
359 "gl_MaxDrawBuffers"), | 434 "gl_MaxDrawBuffers"), |
360 hooks: {"#": cppHook} | 435 hooks: {"#": cppHook}, |
| 436 modeProps: {fold: ["brace", "include"]} |
361 }); | 437 }); |
362 }()); | 438 |
| 439 }); |
OLD | NEW |