michael@0: (function(mod) { michael@0: if (typeof exports == "object" && typeof module == "object") // CommonJS michael@0: mod(require("../../lib/codemirror")); michael@0: else if (typeof define == "function" && define.amd) // AMD michael@0: define(["../../lib/codemirror"], mod); michael@0: else // Plain browser env michael@0: mod(CodeMirror); michael@0: })(function(CodeMirror) { michael@0: "use strict"; michael@0: michael@0: CodeMirror.defineMode("clike", function(config, parserConfig) { michael@0: var indentUnit = config.indentUnit, michael@0: statementIndentUnit = parserConfig.statementIndentUnit || indentUnit, michael@0: dontAlignCalls = parserConfig.dontAlignCalls, michael@0: keywords = parserConfig.keywords || {}, michael@0: builtin = parserConfig.builtin || {}, michael@0: blockKeywords = parserConfig.blockKeywords || {}, michael@0: atoms = parserConfig.atoms || {}, michael@0: hooks = parserConfig.hooks || {}, michael@0: multiLineStrings = parserConfig.multiLineStrings; michael@0: var isOperatorChar = /[+\-*&%=<>!?|\/]/; michael@0: michael@0: var curPunc; michael@0: michael@0: function tokenBase(stream, state) { michael@0: var ch = stream.next(); michael@0: if (hooks[ch]) { michael@0: var result = hooks[ch](stream, state); michael@0: if (result !== false) return result; michael@0: } michael@0: if (ch == '"' || ch == "'") { michael@0: state.tokenize = tokenString(ch); michael@0: return state.tokenize(stream, state); michael@0: } michael@0: if (/[\[\]{}\(\),;\:\.]/.test(ch)) { michael@0: curPunc = ch; michael@0: return null; michael@0: } michael@0: if (/\d/.test(ch)) { michael@0: stream.eatWhile(/[\w\.]/); michael@0: return "number"; michael@0: } michael@0: if (ch == "/") { michael@0: if (stream.eat("*")) { michael@0: state.tokenize = tokenComment; michael@0: return tokenComment(stream, state); michael@0: } michael@0: if (stream.eat("/")) { michael@0: stream.skipToEnd(); michael@0: return "comment"; michael@0: } michael@0: } michael@0: if (isOperatorChar.test(ch)) { michael@0: stream.eatWhile(isOperatorChar); michael@0: return "operator"; michael@0: } michael@0: stream.eatWhile(/[\w\$_]/); michael@0: var cur = stream.current(); michael@0: if (keywords.propertyIsEnumerable(cur)) { michael@0: if (blockKeywords.propertyIsEnumerable(cur)) curPunc = "newstatement"; michael@0: return "keyword"; michael@0: } michael@0: if (builtin.propertyIsEnumerable(cur)) { michael@0: if (blockKeywords.propertyIsEnumerable(cur)) curPunc = "newstatement"; michael@0: return "builtin"; michael@0: } michael@0: if (atoms.propertyIsEnumerable(cur)) return "atom"; michael@0: return "variable"; michael@0: } michael@0: michael@0: function tokenString(quote) { michael@0: return function(stream, state) { michael@0: var escaped = false, next, end = false; michael@0: while ((next = stream.next()) != null) { michael@0: if (next == quote && !escaped) {end = true; break;} michael@0: escaped = !escaped && next == "\\"; michael@0: } michael@0: if (end || !(escaped || multiLineStrings)) michael@0: state.tokenize = null; michael@0: return "string"; michael@0: }; michael@0: } michael@0: michael@0: function tokenComment(stream, state) { michael@0: var maybeEnd = false, ch; michael@0: while (ch = stream.next()) { michael@0: if (ch == "/" && maybeEnd) { michael@0: state.tokenize = null; michael@0: break; michael@0: } michael@0: maybeEnd = (ch == "*"); michael@0: } michael@0: return "comment"; michael@0: } michael@0: michael@0: function Context(indented, column, type, align, prev) { michael@0: this.indented = indented; michael@0: this.column = column; michael@0: this.type = type; michael@0: this.align = align; michael@0: this.prev = prev; michael@0: } michael@0: function pushContext(state, col, type) { michael@0: var indent = state.indented; michael@0: if (state.context && state.context.type == "statement") michael@0: indent = state.context.indented; michael@0: return state.context = new Context(indent, col, type, null, state.context); michael@0: } michael@0: function popContext(state) { michael@0: var t = state.context.type; michael@0: if (t == ")" || t == "]" || t == "}") michael@0: state.indented = state.context.indented; michael@0: return state.context = state.context.prev; michael@0: } michael@0: michael@0: // Interface michael@0: michael@0: return { michael@0: startState: function(basecolumn) { michael@0: return { michael@0: tokenize: null, michael@0: context: new Context((basecolumn || 0) - indentUnit, 0, "top", false), michael@0: indented: 0, michael@0: startOfLine: true michael@0: }; michael@0: }, michael@0: michael@0: token: function(stream, state) { michael@0: var ctx = state.context; michael@0: if (stream.sol()) { michael@0: if (ctx.align == null) ctx.align = false; michael@0: state.indented = stream.indentation(); michael@0: state.startOfLine = true; michael@0: } michael@0: if (stream.eatSpace()) return null; michael@0: curPunc = null; michael@0: var style = (state.tokenize || tokenBase)(stream, state); michael@0: if (style == "comment" || style == "meta") return style; michael@0: if (ctx.align == null) ctx.align = true; michael@0: michael@0: if ((curPunc == ";" || curPunc == ":" || curPunc == ",") && ctx.type == "statement") popContext(state); michael@0: else if (curPunc == "{") pushContext(state, stream.column(), "}"); michael@0: else if (curPunc == "[") pushContext(state, stream.column(), "]"); michael@0: else if (curPunc == "(") pushContext(state, stream.column(), ")"); michael@0: else if (curPunc == "}") { michael@0: while (ctx.type == "statement") ctx = popContext(state); michael@0: if (ctx.type == "}") ctx = popContext(state); michael@0: while (ctx.type == "statement") ctx = popContext(state); michael@0: } michael@0: else if (curPunc == ctx.type) popContext(state); michael@0: else if (((ctx.type == "}" || ctx.type == "top") && curPunc != ';') || (ctx.type == "statement" && curPunc == "newstatement")) michael@0: pushContext(state, stream.column(), "statement"); michael@0: state.startOfLine = false; michael@0: return style; michael@0: }, michael@0: michael@0: indent: function(state, textAfter) { michael@0: if (state.tokenize != tokenBase && state.tokenize != null) return CodeMirror.Pass; michael@0: var ctx = state.context, firstChar = textAfter && textAfter.charAt(0); michael@0: if (ctx.type == "statement" && firstChar == "}") ctx = ctx.prev; michael@0: var closing = firstChar == ctx.type; michael@0: if (ctx.type == "statement") return ctx.indented + (firstChar == "{" ? 0 : statementIndentUnit); michael@0: else if (ctx.align && (!dontAlignCalls || ctx.type != ")")) return ctx.column + (closing ? 0 : 1); michael@0: else if (ctx.type == ")" && !closing) return ctx.indented + statementIndentUnit; michael@0: else return ctx.indented + (closing ? 0 : indentUnit); michael@0: }, michael@0: michael@0: electricChars: "{}", michael@0: blockCommentStart: "/*", michael@0: blockCommentEnd: "*/", michael@0: lineComment: "//", michael@0: fold: "brace" michael@0: }; michael@0: }); michael@0: michael@0: (function() { michael@0: function words(str) { michael@0: var obj = {}, words = str.split(" "); michael@0: for (var i = 0; i < words.length; ++i) obj[words[i]] = true; michael@0: return obj; michael@0: } michael@0: var cKeywords = "auto if break int case long char register continue return default short do sizeof " + michael@0: "double static else struct entry switch extern typedef float union for unsigned " + michael@0: "goto while enum void const signed volatile"; michael@0: michael@0: function cppHook(stream, state) { michael@0: if (!state.startOfLine) return false; michael@0: for (;;) { michael@0: if (stream.skipTo("\\")) { michael@0: stream.next(); michael@0: if (stream.eol()) { michael@0: state.tokenize = cppHook; michael@0: break; michael@0: } michael@0: } else { michael@0: stream.skipToEnd(); michael@0: state.tokenize = null; michael@0: break; michael@0: } michael@0: } michael@0: return "meta"; michael@0: } michael@0: michael@0: function cpp11StringHook(stream, state) { michael@0: stream.backUp(1); michael@0: // Raw strings. michael@0: if (stream.match(/(R|u8R|uR|UR|LR)/)) { michael@0: var match = stream.match(/"(.{0,16})\(/); michael@0: if (!match) { michael@0: return false; michael@0: } michael@0: state.cpp11RawStringDelim = match[1]; michael@0: state.tokenize = tokenRawString; michael@0: return tokenRawString(stream, state); michael@0: } michael@0: // Unicode strings/chars. michael@0: if (stream.match(/(u8|u|U|L)/)) { michael@0: if (stream.match(/["']/, /* eat */ false)) { michael@0: return "string"; michael@0: } michael@0: return false; michael@0: } michael@0: // Ignore this hook. michael@0: stream.next(); michael@0: return false; michael@0: } michael@0: michael@0: // C#-style strings where "" escapes a quote. michael@0: function tokenAtString(stream, state) { michael@0: var next; michael@0: while ((next = stream.next()) != null) { michael@0: if (next == '"' && !stream.eat('"')) { michael@0: state.tokenize = null; michael@0: break; michael@0: } michael@0: } michael@0: return "string"; michael@0: } michael@0: michael@0: // C++11 raw string literal is "( anything )", where michael@0: // can be a string up to 16 characters long. michael@0: function tokenRawString(stream, state) { michael@0: var closingSequence = new RegExp(".*?\\)" + state.cpp11RawStringDelim + '"'); michael@0: var match = stream.match(closingSequence); michael@0: if (match) { michael@0: state.tokenize = null; michael@0: } else { michael@0: stream.skipToEnd(); michael@0: } michael@0: return "string"; michael@0: } michael@0: michael@0: function def(mimes, mode) { michael@0: var words = []; michael@0: function add(obj) { michael@0: if (obj) for (var prop in obj) if (obj.hasOwnProperty(prop)) michael@0: words.push(prop); michael@0: } michael@0: add(mode.keywords); michael@0: add(mode.builtin); michael@0: add(mode.atoms); michael@0: if (words.length) { michael@0: mode.helperType = mimes[0]; michael@0: CodeMirror.registerHelper("hintWords", mimes[0], words); michael@0: } michael@0: michael@0: for (var i = 0; i < mimes.length; ++i) michael@0: CodeMirror.defineMIME(mimes[i], mode); michael@0: } michael@0: michael@0: def(["text/x-csrc", "text/x-c", "text/x-chdr"], { michael@0: name: "clike", michael@0: keywords: words(cKeywords), michael@0: blockKeywords: words("case do else for if switch while struct"), michael@0: atoms: words("null"), michael@0: hooks: {"#": cppHook}, michael@0: modeProps: {fold: ["brace", "include"]} michael@0: }); michael@0: michael@0: def(["text/x-c++src", "text/x-c++hdr"], { michael@0: name: "clike", michael@0: keywords: words(cKeywords + " asm dynamic_cast namespace reinterpret_cast try bool explicit new " + michael@0: "static_cast typeid catch operator template typename class friend private " + michael@0: "this using const_cast inline public throw virtual delete mutable protected " + michael@0: "wchar_t alignas alignof constexpr decltype nullptr noexcept thread_local final " + michael@0: "static_assert override"), michael@0: blockKeywords: words("catch class do else finally for if struct switch try while"), michael@0: atoms: words("true false null"), michael@0: hooks: { michael@0: "#": cppHook, michael@0: "u": cpp11StringHook, michael@0: "U": cpp11StringHook, michael@0: "L": cpp11StringHook, michael@0: "R": cpp11StringHook michael@0: }, michael@0: modeProps: {fold: ["brace", "include"]} michael@0: }); michael@0: CodeMirror.defineMIME("text/x-java", { michael@0: name: "clike", michael@0: keywords: words("abstract assert boolean break byte case catch char class const continue default " + michael@0: "do double else enum extends final finally float for goto if implements import " + michael@0: "instanceof int interface long native new package private protected public " + michael@0: "return short static strictfp super switch synchronized this throw throws transient " + michael@0: "try void volatile while"), michael@0: blockKeywords: words("catch class do else finally for if switch try while"), michael@0: atoms: words("true false null"), michael@0: hooks: { michael@0: "@": function(stream) { michael@0: stream.eatWhile(/[\w\$_]/); michael@0: return "meta"; michael@0: } michael@0: }, michael@0: modeProps: {fold: ["brace", "import"]} michael@0: }); michael@0: CodeMirror.defineMIME("text/x-csharp", { michael@0: name: "clike", michael@0: keywords: words("abstract as base break case catch checked class const continue" + michael@0: " default delegate do else enum event explicit extern finally fixed for" + michael@0: " foreach goto if implicit in interface internal is lock namespace new" + michael@0: " operator out override params private protected public readonly ref return sealed" + michael@0: " sizeof stackalloc static struct switch this throw try typeof unchecked" + michael@0: " unsafe using virtual void volatile while add alias ascending descending dynamic from get" + michael@0: " global group into join let orderby partial remove select set value var yield"), michael@0: blockKeywords: words("catch class do else finally for foreach if struct switch try while"), michael@0: builtin: words("Boolean Byte Char DateTime DateTimeOffset Decimal Double" + michael@0: " Guid Int16 Int32 Int64 Object SByte Single String TimeSpan UInt16 UInt32" + michael@0: " UInt64 bool byte char decimal double short int long object" + michael@0: " sbyte float string ushort uint ulong"), michael@0: atoms: words("true false null"), michael@0: hooks: { michael@0: "@": function(stream, state) { michael@0: if (stream.eat('"')) { michael@0: state.tokenize = tokenAtString; michael@0: return tokenAtString(stream, state); michael@0: } michael@0: stream.eatWhile(/[\w\$_]/); michael@0: return "meta"; michael@0: } michael@0: } michael@0: }); michael@0: CodeMirror.defineMIME("text/x-scala", { michael@0: name: "clike", michael@0: keywords: words( michael@0: michael@0: /* scala */ michael@0: "abstract case catch class def do else extends false final finally for forSome if " + michael@0: "implicit import lazy match new null object override package private protected return " + michael@0: "sealed super this throw trait try trye type val var while with yield _ : = => <- <: " + michael@0: "<% >: # @ " + michael@0: michael@0: /* package scala */ michael@0: "assert assume require print println printf readLine readBoolean readByte readShort " + michael@0: "readChar readInt readLong readFloat readDouble " + michael@0: michael@0: "AnyVal App Application Array BufferedIterator BigDecimal BigInt Char Console Either " + michael@0: "Enumeration Equiv Error Exception Fractional Function IndexedSeq Integral Iterable " + michael@0: "Iterator List Map Numeric Nil NotNull Option Ordered Ordering PartialFunction PartialOrdering " + michael@0: "Product Proxy Range Responder Seq Serializable Set Specializable Stream StringBuilder " + michael@0: "StringContext Symbol Throwable Traversable TraversableOnce Tuple Unit Vector :: #:: " + michael@0: michael@0: /* package java.lang */ michael@0: "Boolean Byte Character CharSequence Class ClassLoader Cloneable Comparable " + michael@0: "Compiler Double Exception Float Integer Long Math Number Object Package Pair Process " + michael@0: "Runtime Runnable SecurityManager Short StackTraceElement StrictMath String " + michael@0: "StringBuffer System Thread ThreadGroup ThreadLocal Throwable Triple Void" michael@0: michael@0: michael@0: ), michael@0: blockKeywords: words("catch class do else finally for forSome if match switch try while"), michael@0: atoms: words("true false null"), michael@0: hooks: { michael@0: "@": function(stream) { michael@0: stream.eatWhile(/[\w\$_]/); michael@0: return "meta"; michael@0: } michael@0: } michael@0: }); michael@0: def(["x-shader/x-vertex", "x-shader/x-fragment"], { michael@0: name: "clike", michael@0: keywords: words("float int bool void " + michael@0: "vec2 vec3 vec4 ivec2 ivec3 ivec4 bvec2 bvec3 bvec4 " + michael@0: "mat2 mat3 mat4 " + michael@0: "sampler1D sampler2D sampler3D samplerCube " + michael@0: "sampler1DShadow sampler2DShadow" + michael@0: "const attribute uniform varying " + michael@0: "break continue discard return " + michael@0: "for while do if else struct " + michael@0: "in out inout"), michael@0: blockKeywords: words("for while do if else struct"), michael@0: builtin: words("radians degrees sin cos tan asin acos atan " + michael@0: "pow exp log exp2 sqrt inversesqrt " + michael@0: "abs sign floor ceil fract mod min max clamp mix step smootstep " + michael@0: "length distance dot cross normalize ftransform faceforward " + michael@0: "reflect refract matrixCompMult " + michael@0: "lessThan lessThanEqual greaterThan greaterThanEqual " + michael@0: "equal notEqual any all not " + michael@0: "texture1D texture1DProj texture1DLod texture1DProjLod " + michael@0: "texture2D texture2DProj texture2DLod texture2DProjLod " + michael@0: "texture3D texture3DProj texture3DLod texture3DProjLod " + michael@0: "textureCube textureCubeLod " + michael@0: "shadow1D shadow2D shadow1DProj shadow2DProj " + michael@0: "shadow1DLod shadow2DLod shadow1DProjLod shadow2DProjLod " + michael@0: "dFdx dFdy fwidth " + michael@0: "noise1 noise2 noise3 noise4"), michael@0: atoms: words("true false " + michael@0: "gl_FragColor gl_SecondaryColor gl_Normal gl_Vertex " + michael@0: "gl_MultiTexCoord0 gl_MultiTexCoord1 gl_MultiTexCoord2 gl_MultiTexCoord3 " + michael@0: "gl_MultiTexCoord4 gl_MultiTexCoord5 gl_MultiTexCoord6 gl_MultiTexCoord7 " + michael@0: "gl_FogCoord " + michael@0: "gl_Position gl_PointSize gl_ClipVertex " + michael@0: "gl_FrontColor gl_BackColor gl_FrontSecondaryColor gl_BackSecondaryColor " + michael@0: "gl_TexCoord gl_FogFragCoord " + michael@0: "gl_FragCoord gl_FrontFacing " + michael@0: "gl_FragColor gl_FragData gl_FragDepth " + michael@0: "gl_ModelViewMatrix gl_ProjectionMatrix gl_ModelViewProjectionMatrix " + michael@0: "gl_TextureMatrix gl_NormalMatrix gl_ModelViewMatrixInverse " + michael@0: "gl_ProjectionMatrixInverse gl_ModelViewProjectionMatrixInverse " + michael@0: "gl_TexureMatrixTranspose gl_ModelViewMatrixInverseTranspose " + michael@0: "gl_ProjectionMatrixInverseTranspose " + michael@0: "gl_ModelViewProjectionMatrixInverseTranspose " + michael@0: "gl_TextureMatrixInverseTranspose " + michael@0: "gl_NormalScale gl_DepthRange gl_ClipPlane " + michael@0: "gl_Point gl_FrontMaterial gl_BackMaterial gl_LightSource gl_LightModel " + michael@0: "gl_FrontLightModelProduct gl_BackLightModelProduct " + michael@0: "gl_TextureColor gl_EyePlaneS gl_EyePlaneT gl_EyePlaneR gl_EyePlaneQ " + michael@0: "gl_FogParameters " + michael@0: "gl_MaxLights gl_MaxClipPlanes gl_MaxTextureUnits gl_MaxTextureCoords " + michael@0: "gl_MaxVertexAttribs gl_MaxVertexUniformComponents gl_MaxVaryingFloats " + michael@0: "gl_MaxVertexTextureImageUnits gl_MaxTextureImageUnits " + michael@0: "gl_MaxFragmentUniformComponents gl_MaxCombineTextureImageUnits " + michael@0: "gl_MaxDrawBuffers"), michael@0: hooks: {"#": cppHook}, michael@0: modeProps: {fold: ["brace", "include"]} michael@0: }); michael@0: }()); michael@0: michael@0: });