Differential D134 Diff 321 branches/5.3.x/core/ckeditor/ckfinder/plugins/fileeditor/codemirror/mode/javascript/javascript.js
Changeset View
Changeset View
Standalone View
Standalone View
branches/5.3.x/core/ckeditor/ckfinder/plugins/fileeditor/codemirror/mode/javascript/javascript.js
Property | Old Value | New Value |
---|---|---|
svn:eol-style | null | LF |
CodeMirror.defineMode("javascript", function(config, parserConfig) { | CodeMirror.defineMode("javascript", function(config, parserConfig) { | ||||
var indentUnit = config.indentUnit; | var indentUnit = config.indentUnit; | ||||
var jsonMode = parserConfig.json; | var jsonMode = parserConfig.json; | ||||
// Tokenizer | // Tokenizer | ||||
var keywords = function(){ | var keywords = function(){ | ||||
function kw(type) {return {type: type, style: "keyword"};} | function kw(type) {return {type: type, style: "keyword"};} | ||||
var A = kw("keyword a"), B = kw("keyword b"), C = kw("keyword c"); | var A = kw("keyword a"), B = kw("keyword b"), C = kw("keyword c"); | ||||
var operator = kw("operator"), atom = {type: "atom", style: "atom"}; | var operator = kw("operator"), atom = {type: "atom", style: "atom"}; | ||||
return { | return { | ||||
"if": A, "while": A, "with": A, "else": B, "do": B, "try": B, "finally": B, | "if": A, "while": A, "with": A, "else": B, "do": B, "try": B, "finally": B, | ||||
"return": C, "break": C, "continue": C, "new": C, "delete": C, "throw": C, | "return": C, "break": C, "continue": C, "new": C, "delete": C, "throw": C, | ||||
"var": kw("var"), "const": kw("var"), "let": kw("var"), | "var": kw("var"), "const": kw("var"), "let": kw("var"), | ||||
"function": kw("function"), "catch": kw("catch"), | "function": kw("function"), "catch": kw("catch"), | ||||
"for": kw("for"), "switch": kw("switch"), "case": kw("case"), "default": kw("default"), | "for": kw("for"), "switch": kw("switch"), "case": kw("case"), "default": kw("default"), | ||||
"in": operator, "typeof": operator, "instanceof": operator, | "in": operator, "typeof": operator, "instanceof": operator, | ||||
"true": atom, "false": atom, "null": atom, "undefined": atom, "NaN": atom, "Infinity": atom | "true": atom, "false": atom, "null": atom, "undefined": atom, "NaN": atom, "Infinity": atom | ||||
}; | }; | ||||
}(); | }(); | ||||
var isOperatorChar = /[+\-*&%=<>!?|]/; | var isOperatorChar = /[+\-*&%=<>!?|]/; | ||||
function chain(stream, state, f) { | function chain(stream, state, f) { | ||||
state.tokenize = f; | state.tokenize = f; | ||||
return f(stream, state); | return f(stream, state); | ||||
} | } | ||||
function nextUntilUnescaped(stream, end) { | function nextUntilUnescaped(stream, end) { | ||||
var escaped = false, next; | var escaped = false, next; | ||||
while ((next = stream.next()) != null) { | while ((next = stream.next()) != null) { | ||||
if (next == end && !escaped) | if (next == end && !escaped) | ||||
return false; | return false; | ||||
escaped = !escaped && next == "\\"; | escaped = !escaped && next == "\\"; | ||||
} | } | ||||
return escaped; | return escaped; | ||||
} | } | ||||
// Used as scratch variables to communicate multiple values without | // Used as scratch variables to communicate multiple values without | ||||
// consing up tons of objects. | // consing up tons of objects. | ||||
var type, content; | var type, content; | ||||
function ret(tp, style, cont) { | function ret(tp, style, cont) { | ||||
type = tp; content = cont; | type = tp; content = cont; | ||||
return style; | return style; | ||||
} | } | ||||
function jsTokenBase(stream, state) { | function jsTokenBase(stream, state) { | ||||
var ch = stream.next(); | var ch = stream.next(); | ||||
if (ch == '"' || ch == "'") | if (ch == '"' || ch == "'") | ||||
return chain(stream, state, jsTokenString(ch)); | return chain(stream, state, jsTokenString(ch)); | ||||
else if (/[\[\]{}\(\),;\:\.]/.test(ch)) | else if (/[\[\]{}\(\),;\:\.]/.test(ch)) | ||||
return ret(ch); | return ret(ch); | ||||
else if (ch == "0" && stream.eat(/x/i)) { | else if (ch == "0" && stream.eat(/x/i)) { | ||||
stream.eatWhile(/[\da-f]/i); | stream.eatWhile(/[\da-f]/i); | ||||
return ret("number", "number"); | return ret("number", "number"); | ||||
} | } | ||||
else if (/\d/.test(ch)) { | else if (/\d/.test(ch)) { | ||||
stream.match(/^\d*(?:\.\d*)?(?:[eE][+\-]?\d+)?/); | stream.match(/^\d*(?:\.\d*)?(?:[eE][+\-]?\d+)?/); | ||||
return ret("number", "number"); | return ret("number", "number"); | ||||
} | } | ||||
else if (ch == "/") { | else if (ch == "/") { | ||||
if (stream.eat("*")) { | if (stream.eat("*")) { | ||||
return chain(stream, state, jsTokenComment); | return chain(stream, state, jsTokenComment); | ||||
} | } | ||||
else if (stream.eat("/")) { | else if (stream.eat("/")) { | ||||
stream.skipToEnd(); | stream.skipToEnd(); | ||||
return ret("comment", "comment"); | return ret("comment", "comment"); | ||||
} | } | ||||
else if (state.reAllowed) { | else if (state.reAllowed) { | ||||
nextUntilUnescaped(stream, "/"); | nextUntilUnescaped(stream, "/"); | ||||
stream.eatWhile(/[gimy]/); // 'y' is "sticky" option in Mozilla | stream.eatWhile(/[gimy]/); // 'y' is "sticky" option in Mozilla | ||||
return ret("regexp", "string-2"); | return ret("regexp", "string-2"); | ||||
} | } | ||||
else { | else { | ||||
stream.eatWhile(isOperatorChar); | stream.eatWhile(isOperatorChar); | ||||
return ret("operator", null, stream.current()); | return ret("operator", null, stream.current()); | ||||
} | } | ||||
} | } | ||||
else if (ch == "#") { | else if (ch == "#") { | ||||
stream.skipToEnd(); | stream.skipToEnd(); | ||||
return ret("error", "error"); | return ret("error", "error"); | ||||
} | } | ||||
else if (isOperatorChar.test(ch)) { | else if (isOperatorChar.test(ch)) { | ||||
stream.eatWhile(isOperatorChar); | stream.eatWhile(isOperatorChar); | ||||
return ret("operator", null, stream.current()); | return ret("operator", null, stream.current()); | ||||
} | } | ||||
else { | else { | ||||
stream.eatWhile(/[\w\$_]/); | stream.eatWhile(/[\w\$_]/); | ||||
var word = stream.current(), known = keywords.propertyIsEnumerable(word) && keywords[word]; | var word = stream.current(), known = keywords.propertyIsEnumerable(word) && keywords[word]; | ||||
return (known && state.kwAllowed) ? ret(known.type, known.style, word) : | return (known && state.kwAllowed) ? ret(known.type, known.style, word) : | ||||
ret("variable", "variable", word); | ret("variable", "variable", word); | ||||
} | } | ||||
} | } | ||||
function jsTokenString(quote) { | function jsTokenString(quote) { | ||||
return function(stream, state) { | return function(stream, state) { | ||||
if (!nextUntilUnescaped(stream, quote)) | if (!nextUntilUnescaped(stream, quote)) | ||||
state.tokenize = jsTokenBase; | state.tokenize = jsTokenBase; | ||||
return ret("string", "string"); | return ret("string", "string"); | ||||
}; | }; | ||||
} | } | ||||
function jsTokenComment(stream, state) { | function jsTokenComment(stream, state) { | ||||
var maybeEnd = false, ch; | var maybeEnd = false, ch; | ||||
while (ch = stream.next()) { | while (ch = stream.next()) { | ||||
if (ch == "/" && maybeEnd) { | if (ch == "/" && maybeEnd) { | ||||
state.tokenize = jsTokenBase; | state.tokenize = jsTokenBase; | ||||
break; | break; | ||||
} | } | ||||
maybeEnd = (ch == "*"); | maybeEnd = (ch == "*"); | ||||
} | } | ||||
return ret("comment", "comment"); | return ret("comment", "comment"); | ||||
} | } | ||||
// Parser | // Parser | ||||
var atomicTypes = {"atom": true, "number": true, "variable": true, "string": true, "regexp": true}; | var atomicTypes = {"atom": true, "number": true, "variable": true, "string": true, "regexp": true}; | ||||
function JSLexical(indented, column, type, align, prev, info) { | function JSLexical(indented, column, type, align, prev, info) { | ||||
this.indented = indented; | this.indented = indented; | ||||
this.column = column; | this.column = column; | ||||
this.type = type; | this.type = type; | ||||
this.prev = prev; | this.prev = prev; | ||||
this.info = info; | this.info = info; | ||||
if (align != null) this.align = align; | if (align != null) this.align = align; | ||||
} | } | ||||
function inScope(state, varname) { | function inScope(state, varname) { | ||||
for (var v = state.localVars; v; v = v.next) | for (var v = state.localVars; v; v = v.next) | ||||
if (v.name == varname) return true; | if (v.name == varname) return true; | ||||
} | } | ||||
function parseJS(state, style, type, content, stream) { | function parseJS(state, style, type, content, stream) { | ||||
var cc = state.cc; | var cc = state.cc; | ||||
// Communicate our context to the combinators. | // Communicate our context to the combinators. | ||||
// (Less wasteful than consing up a hundred closures on every call.) | // (Less wasteful than consing up a hundred closures on every call.) | ||||
cx.state = state; cx.stream = stream; cx.marked = null, cx.cc = cc; | cx.state = state; cx.stream = stream; cx.marked = null, cx.cc = cc; | ||||
if (!state.lexical.hasOwnProperty("align")) | if (!state.lexical.hasOwnProperty("align")) | ||||
state.lexical.align = true; | state.lexical.align = true; | ||||
while(true) { | while(true) { | ||||
var combinator = cc.length ? cc.pop() : jsonMode ? expression : statement; | var combinator = cc.length ? cc.pop() : jsonMode ? expression : statement; | ||||
if (combinator(type, content)) { | if (combinator(type, content)) { | ||||
while(cc.length && cc[cc.length - 1].lex) | while(cc.length && cc[cc.length - 1].lex) | ||||
cc.pop()(); | cc.pop()(); | ||||
if (cx.marked) return cx.marked; | if (cx.marked) return cx.marked; | ||||
if (type == "variable" && inScope(state, content)) return "variable-2"; | if (type == "variable" && inScope(state, content)) return "variable-2"; | ||||
return style; | return style; | ||||
} | } | ||||
} | } | ||||
} | } | ||||
// Combinator utils | // Combinator utils | ||||
var cx = {state: null, column: null, marked: null, cc: null}; | var cx = {state: null, column: null, marked: null, cc: null}; | ||||
function pass() { | function pass() { | ||||
for (var i = arguments.length - 1; i >= 0; i--) cx.cc.push(arguments[i]); | for (var i = arguments.length - 1; i >= 0; i--) cx.cc.push(arguments[i]); | ||||
} | } | ||||
function cont() { | function cont() { | ||||
pass.apply(null, arguments); | pass.apply(null, arguments); | ||||
return true; | return true; | ||||
} | } | ||||
function register(varname) { | function register(varname) { | ||||
var state = cx.state; | var state = cx.state; | ||||
if (state.context) { | if (state.context) { | ||||
cx.marked = "def"; | cx.marked = "def"; | ||||
for (var v = state.localVars; v; v = v.next) | for (var v = state.localVars; v; v = v.next) | ||||
if (v.name == varname) return; | if (v.name == varname) return; | ||||
state.localVars = {name: varname, next: state.localVars}; | state.localVars = {name: varname, next: state.localVars}; | ||||
} | } | ||||
} | } | ||||
// Combinators | // Combinators | ||||
var defaultVars = {name: "this", next: {name: "arguments"}}; | var defaultVars = {name: "this", next: {name: "arguments"}}; | ||||
function pushcontext() { | function pushcontext() { | ||||
if (!cx.state.context) cx.state.localVars = defaultVars; | if (!cx.state.context) cx.state.localVars = defaultVars; | ||||
cx.state.context = {prev: cx.state.context, vars: cx.state.localVars}; | cx.state.context = {prev: cx.state.context, vars: cx.state.localVars}; | ||||
} | } | ||||
function popcontext() { | function popcontext() { | ||||
cx.state.localVars = cx.state.context.vars; | cx.state.localVars = cx.state.context.vars; | ||||
cx.state.context = cx.state.context.prev; | cx.state.context = cx.state.context.prev; | ||||
} | } | ||||
function pushlex(type, info) { | function pushlex(type, info) { | ||||
var result = function() { | var result = function() { | ||||
var state = cx.state; | var state = cx.state; | ||||
state.lexical = new JSLexical(state.indented, cx.stream.column(), type, null, state.lexical, info) | state.lexical = new JSLexical(state.indented, cx.stream.column(), type, null, state.lexical, info) | ||||
}; | }; | ||||
result.lex = true; | result.lex = true; | ||||
return result; | return result; | ||||
} | } | ||||
function poplex() { | function poplex() { | ||||
var state = cx.state; | var state = cx.state; | ||||
if (state.lexical.prev) { | if (state.lexical.prev) { | ||||
if (state.lexical.type == ")") | if (state.lexical.type == ")") | ||||
state.indented = state.lexical.indented; | state.indented = state.lexical.indented; | ||||
state.lexical = state.lexical.prev; | state.lexical = state.lexical.prev; | ||||
} | } | ||||
} | } | ||||
poplex.lex = true; | poplex.lex = true; | ||||
function expect(wanted) { | function expect(wanted) { | ||||
return function expecting(type) { | return function expecting(type) { | ||||
if (type == wanted) return cont(); | if (type == wanted) return cont(); | ||||
else if (wanted == ";") return pass(); | else if (wanted == ";") return pass(); | ||||
else return cont(arguments.callee); | else return cont(arguments.callee); | ||||
}; | }; | ||||
} | } | ||||
function statement(type) { | function statement(type) { | ||||
if (type == "var") return cont(pushlex("vardef"), vardef1, expect(";"), poplex); | if (type == "var") return cont(pushlex("vardef"), vardef1, expect(";"), poplex); | ||||
if (type == "keyword a") return cont(pushlex("form"), expression, statement, poplex); | if (type == "keyword a") return cont(pushlex("form"), expression, statement, poplex); | ||||
if (type == "keyword b") return cont(pushlex("form"), statement, poplex); | if (type == "keyword b") return cont(pushlex("form"), statement, poplex); | ||||
if (type == "{") return cont(pushlex("}"), block, poplex); | if (type == "{") return cont(pushlex("}"), block, poplex); | ||||
if (type == ";") return cont(); | if (type == ";") return cont(); | ||||
if (type == "function") return cont(functiondef); | if (type == "function") return cont(functiondef); | ||||
if (type == "for") return cont(pushlex("form"), expect("("), pushlex(")"), forspec1, expect(")"), | if (type == "for") return cont(pushlex("form"), expect("("), pushlex(")"), forspec1, expect(")"), | ||||
poplex, statement, poplex); | poplex, statement, poplex); | ||||
if (type == "variable") return cont(pushlex("stat"), maybelabel); | if (type == "variable") return cont(pushlex("stat"), maybelabel); | ||||
if (type == "switch") return cont(pushlex("form"), expression, pushlex("}", "switch"), expect("{"), | if (type == "switch") return cont(pushlex("form"), expression, pushlex("}", "switch"), expect("{"), | ||||
block, poplex, poplex); | block, poplex, poplex); | ||||
if (type == "case") return cont(expression, expect(":")); | if (type == "case") return cont(expression, expect(":")); | ||||
if (type == "default") return cont(expect(":")); | if (type == "default") return cont(expect(":")); | ||||
if (type == "catch") return cont(pushlex("form"), pushcontext, expect("("), funarg, expect(")"), | if (type == "catch") return cont(pushlex("form"), pushcontext, expect("("), funarg, expect(")"), | ||||
statement, poplex, popcontext); | statement, poplex, popcontext); | ||||
return pass(pushlex("stat"), expression, expect(";"), poplex); | return pass(pushlex("stat"), expression, expect(";"), poplex); | ||||
} | } | ||||
function expression(type) { | function expression(type) { | ||||
if (atomicTypes.hasOwnProperty(type)) return cont(maybeoperator); | if (atomicTypes.hasOwnProperty(type)) return cont(maybeoperator); | ||||
if (type == "function") return cont(functiondef); | if (type == "function") return cont(functiondef); | ||||
if (type == "keyword c") return cont(maybeexpression); | if (type == "keyword c") return cont(maybeexpression); | ||||
if (type == "(") return cont(pushlex(")"), maybeexpression, expect(")"), poplex, maybeoperator); | if (type == "(") return cont(pushlex(")"), maybeexpression, expect(")"), poplex, maybeoperator); | ||||
if (type == "operator") return cont(expression); | if (type == "operator") return cont(expression); | ||||
if (type == "[") return cont(pushlex("]"), commasep(expression, "]"), poplex, maybeoperator); | if (type == "[") return cont(pushlex("]"), commasep(expression, "]"), poplex, maybeoperator); | ||||
if (type == "{") return cont(pushlex("}"), commasep(objprop, "}"), poplex, maybeoperator); | if (type == "{") return cont(pushlex("}"), commasep(objprop, "}"), poplex, maybeoperator); | ||||
return cont(); | return cont(); | ||||
} | } | ||||
function maybeexpression(type) { | function maybeexpression(type) { | ||||
if (type.match(/[;\}\)\],]/)) return pass(); | if (type.match(/[;\}\)\],]/)) return pass(); | ||||
return pass(expression); | return pass(expression); | ||||
} | } | ||||
function maybeoperator(type, value) { | function maybeoperator(type, value) { | ||||
if (type == "operator" && /\+\+|--/.test(value)) return cont(maybeoperator); | if (type == "operator" && /\+\+|--/.test(value)) return cont(maybeoperator); | ||||
if (type == "operator" || type == ":") return cont(expression); | if (type == "operator" || type == ":") return cont(expression); | ||||
if (type == ";") return; | if (type == ";") return; | ||||
if (type == "(") return cont(pushlex(")"), commasep(expression, ")"), poplex, maybeoperator); | if (type == "(") return cont(pushlex(")"), commasep(expression, ")"), poplex, maybeoperator); | ||||
if (type == ".") return cont(property, maybeoperator); | if (type == ".") return cont(property, maybeoperator); | ||||
if (type == "[") return cont(pushlex("]"), expression, expect("]"), poplex, maybeoperator); | if (type == "[") return cont(pushlex("]"), expression, expect("]"), poplex, maybeoperator); | ||||
} | } | ||||
function maybelabel(type) { | function maybelabel(type) { | ||||
if (type == ":") return cont(poplex, statement); | if (type == ":") return cont(poplex, statement); | ||||
return pass(maybeoperator, expect(";"), poplex); | return pass(maybeoperator, expect(";"), poplex); | ||||
} | } | ||||
function property(type) { | function property(type) { | ||||
if (type == "variable") {cx.marked = "property"; return cont();} | if (type == "variable") {cx.marked = "property"; return cont();} | ||||
} | } | ||||
function objprop(type) { | function objprop(type) { | ||||
if (type == "variable") cx.marked = "property"; | if (type == "variable") cx.marked = "property"; | ||||
if (atomicTypes.hasOwnProperty(type)) return cont(expect(":"), expression); | if (atomicTypes.hasOwnProperty(type)) return cont(expect(":"), expression); | ||||
} | } | ||||
function commasep(what, end) { | function commasep(what, end) { | ||||
function proceed(type) { | function proceed(type) { | ||||
if (type == ",") return cont(what, proceed); | if (type == ",") return cont(what, proceed); | ||||
if (type == end) return cont(); | if (type == end) return cont(); | ||||
return cont(expect(end)); | return cont(expect(end)); | ||||
} | } | ||||
return function commaSeparated(type) { | return function commaSeparated(type) { | ||||
if (type == end) return cont(); | if (type == end) return cont(); | ||||
else return pass(what, proceed); | else return pass(what, proceed); | ||||
}; | }; | ||||
} | } | ||||
function block(type) { | function block(type) { | ||||
if (type == "}") return cont(); | if (type == "}") return cont(); | ||||
return pass(statement, block); | return pass(statement, block); | ||||
} | } | ||||
function vardef1(type, value) { | function vardef1(type, value) { | ||||
if (type == "variable"){register(value); return cont(vardef2);} | if (type == "variable"){register(value); return cont(vardef2);} | ||||
return cont(); | return cont(); | ||||
} | } | ||||
function vardef2(type, value) { | function vardef2(type, value) { | ||||
if (value == "=") return cont(expression, vardef2); | if (value == "=") return cont(expression, vardef2); | ||||
if (type == ",") return cont(vardef1); | if (type == ",") return cont(vardef1); | ||||
} | } | ||||
function forspec1(type) { | function forspec1(type) { | ||||
if (type == "var") return cont(vardef1, forspec2); | if (type == "var") return cont(vardef1, forspec2); | ||||
if (type == ";") return pass(forspec2); | if (type == ";") return pass(forspec2); | ||||
if (type == "variable") return cont(formaybein); | if (type == "variable") return cont(formaybein); | ||||
return pass(forspec2); | return pass(forspec2); | ||||
} | } | ||||
function formaybein(type, value) { | function formaybein(type, value) { | ||||
if (value == "in") return cont(expression); | if (value == "in") return cont(expression); | ||||
return cont(maybeoperator, forspec2); | return cont(maybeoperator, forspec2); | ||||
} | } | ||||
function forspec2(type, value) { | function forspec2(type, value) { | ||||
if (type == ";") return cont(forspec3); | if (type == ";") return cont(forspec3); | ||||
if (value == "in") return cont(expression); | if (value == "in") return cont(expression); | ||||
return cont(expression, expect(";"), forspec3); | return cont(expression, expect(";"), forspec3); | ||||
} | } | ||||
function forspec3(type) { | function forspec3(type) { | ||||
if (type != ")") cont(expression); | if (type != ")") cont(expression); | ||||
} | } | ||||
function functiondef(type, value) { | function functiondef(type, value) { | ||||
if (type == "variable") {register(value); return cont(functiondef);} | if (type == "variable") {register(value); return cont(functiondef);} | ||||
if (type == "(") return cont(pushlex(")"), pushcontext, commasep(funarg, ")"), poplex, statement, popcontext); | if (type == "(") return cont(pushlex(")"), pushcontext, commasep(funarg, ")"), poplex, statement, popcontext); | ||||
} | } | ||||
function funarg(type, value) { | function funarg(type, value) { | ||||
if (type == "variable") {register(value); return cont();} | if (type == "variable") {register(value); return cont();} | ||||
} | } | ||||
// Interface | // Interface | ||||
return { | return { | ||||
startState: function(basecolumn) { | startState: function(basecolumn) { | ||||
return { | return { | ||||
tokenize: jsTokenBase, | tokenize: jsTokenBase, | ||||
reAllowed: true, | reAllowed: true, | ||||
kwAllowed: true, | kwAllowed: true, | ||||
cc: [], | cc: [], | ||||
lexical: new JSLexical((basecolumn || 0) - indentUnit, 0, "block", false), | lexical: new JSLexical((basecolumn || 0) - indentUnit, 0, "block", false), | ||||
localVars: parserConfig.localVars, | localVars: parserConfig.localVars, | ||||
context: parserConfig.localVars && {vars: parserConfig.localVars}, | context: parserConfig.localVars && {vars: parserConfig.localVars}, | ||||
indented: 0 | indented: 0 | ||||
}; | }; | ||||
}, | }, | ||||
token: function(stream, state) { | token: function(stream, state) { | ||||
if (stream.sol()) { | if (stream.sol()) { | ||||
if (!state.lexical.hasOwnProperty("align")) | if (!state.lexical.hasOwnProperty("align")) | ||||
state.lexical.align = false; | state.lexical.align = false; | ||||
state.indented = stream.indentation(); | state.indented = stream.indentation(); | ||||
} | } | ||||
if (stream.eatSpace()) return null; | if (stream.eatSpace()) return null; | ||||
var style = state.tokenize(stream, state); | var style = state.tokenize(stream, state); | ||||
if (type == "comment") return style; | if (type == "comment") return style; | ||||
state.reAllowed = !!(type == "operator" || type == "keyword c" || type.match(/^[\[{}\(,;:]$/)); | state.reAllowed = !!(type == "operator" || type == "keyword c" || type.match(/^[\[{}\(,;:]$/)); | ||||
state.kwAllowed = type != '.'; | state.kwAllowed = type != '.'; | ||||
return parseJS(state, style, type, content, stream); | return parseJS(state, style, type, content, stream); | ||||
}, | }, | ||||
indent: function(state, textAfter) { | indent: function(state, textAfter) { | ||||
if (state.tokenize != jsTokenBase) return 0; | if (state.tokenize != jsTokenBase) return 0; | ||||
var firstChar = textAfter && textAfter.charAt(0), lexical = state.lexical; | var firstChar = textAfter && textAfter.charAt(0), lexical = state.lexical; | ||||
if (lexical.type == "stat" && firstChar == "}") lexical = lexical.prev; | if (lexical.type == "stat" && firstChar == "}") lexical = lexical.prev; | ||||
var type = lexical.type, closing = firstChar == type; | var type = lexical.type, closing = firstChar == type; | ||||
if (type == "vardef") return lexical.indented + 4; | if (type == "vardef") return lexical.indented + 4; | ||||
else if (type == "form" && firstChar == "{") return lexical.indented; | else if (type == "form" && firstChar == "{") return lexical.indented; | ||||
else if (type == "stat" || type == "form") return lexical.indented + indentUnit; | else if (type == "stat" || type == "form") return lexical.indented + indentUnit; | ||||
else if (lexical.info == "switch" && !closing) | else if (lexical.info == "switch" && !closing) | ||||
return lexical.indented + (/^(?:case|default)\b/.test(textAfter) ? indentUnit : 2 * indentUnit); | return lexical.indented + (/^(?:case|default)\b/.test(textAfter) ? indentUnit : 2 * indentUnit); | ||||
else if (lexical.align) return lexical.column + (closing ? 0 : 1); | else if (lexical.align) return lexical.column + (closing ? 0 : 1); | ||||
else return lexical.indented + (closing ? 0 : indentUnit); | else return lexical.indented + (closing ? 0 : indentUnit); | ||||
}, | }, | ||||
electricChars: ":{}" | electricChars: ":{}" | ||||
}; | }; | ||||
}); | }); | ||||
CodeMirror.defineMIME("text/javascript", "javascript"); | CodeMirror.defineMIME("text/javascript", "javascript"); | ||||
CodeMirror.defineMIME("application/json", {name: "javascript", json: true}); | CodeMirror.defineMIME("application/json", {name: "javascript", json: true}); |