vendor/assets/javascripts/codemirror/modes/python.js in codemirror-rails-3.02 vs vendor/assets/javascripts/codemirror/modes/python.js in codemirror-rails-3.12

- old
+ new

@@ -1,19 +1,19 @@ CodeMirror.defineMode("python", function(conf, parserConf) { var ERRORCLASS = 'error'; - + function wordRegexp(words) { return new RegExp("^((" + words.join(")|(") + "))\\b"); } - - var singleOperators = new RegExp("^[\\+\\-\\*/%&|\\^~<>!]"); - var singleDelimiters = new RegExp('^[\\(\\)\\[\\]\\{\\}@,:`=;\\.]'); - var doubleOperators = new RegExp("^((==)|(!=)|(<=)|(>=)|(<>)|(<<)|(>>)|(//)|(\\*\\*))"); - var doubleDelimiters = new RegExp("^((\\+=)|(\\-=)|(\\*=)|(%=)|(/=)|(&=)|(\\|=)|(\\^=))"); - var tripleDelimiters = new RegExp("^((//=)|(>>=)|(<<=)|(\\*\\*=))"); - var identifiers = new RegExp("^[_A-Za-z][_A-Za-z0-9]*"); + var singleOperators = parserConf.singleOperators || new RegExp("^[\\+\\-\\*/%&|\\^~<>!]"); + var singleDelimiters = parserConf.singleDelimiters || new RegExp('^[\\(\\)\\[\\]\\{\\}@,:`=;\\.]'); + var doubleOperators = parserConf.doubleOperators || new RegExp("^((==)|(!=)|(<=)|(>=)|(<>)|(<<)|(>>)|(//)|(\\*\\*))"); + var doubleDelimiters = parserConf.doubleDelimiters || new RegExp("^((\\+=)|(\\-=)|(\\*=)|(%=)|(/=)|(&=)|(\\|=)|(\\^=))"); + var tripleDelimiters = parserConf.tripleDelimiters || new RegExp("^((//=)|(>>=)|(<<=)|(\\*\\*=))"); + var identifiers = parserConf.identifiers|| new RegExp("^[_A-Za-z][_A-Za-z0-9]*"); + var wordOperators = wordRegexp(['and', 'or', 'not', 'is', 'in']); var commonkeywords = ['as', 'assert', 'break', 'class', 'continue', 'def', 'del', 'elif', 'else', 'except', 'finally', 'for', 'from', 'global', 'if', 'import', 'lambda', 'pass', 'raise', 'return', @@ -70,19 +70,19 @@ } } if (stream.eatSpace()) { return null; } - + var ch = stream.peek(); - + // Handle Comments if (ch === '#') { stream.skipToEnd(); return 'comment'; } - + // Handle Number Literals if (stream.match(/^[0-9\.]/, false)) { var floatLiteral = false; // Floats if (stream.match(/^\d*\.\d+(e[\+\-]?\d+)?/i)) { floatLiteral = true; } @@ -114,17 +114,17 @@ // Integer literals may be "long" stream.eat(/L/i); return 'number'; } } - + // Handle Strings if (stream.match(stringPrefixes)) { state.tokenize = tokenStringFactory(stream.current()); return state.tokenize(stream, state); } - + // Handle operators and Delimiters if (stream.match(tripleDelimiters) || stream.match(doubleDelimiters)) { return null; } if (stream.match(doubleOperators) @@ -133,35 +133,35 @@ return 'operator'; } if (stream.match(singleDelimiters)) { return null; } - + if (stream.match(keywords)) { return 'keyword'; } - + if (stream.match(builtins)) { return 'builtin'; } - + if (stream.match(identifiers)) { return 'variable'; } - + // Handle non-detected items stream.next(); return ERRORCLASS; } - + function tokenStringFactory(delimiter) { while ('rub'.indexOf(delimiter.charAt(0).toLowerCase()) >= 0) { delimiter = delimiter.substr(1); } var singleline = delimiter.length == 1; var OUTCLASS = 'string'; - + function tokenString(stream, state) { while (!stream.eol()) { stream.eatWhile(/[^'"\\]/); if (stream.eat('\\')) { stream.next(); @@ -185,11 +185,11 @@ return OUTCLASS; } tokenString.isString = true; return tokenString; } - + function indent(stream, state, type) { type = type || 'py'; var indentUnit = 0; if (type === 'py') { if (state.scopes[0].type !== 'py') { @@ -208,11 +208,11 @@ state.scopes.unshift({ offset: indentUnit, type: type }); } - + function dedent(stream, state, type) { type = type || 'py'; if (state.scopes.length == 1) return; if (state.scopes[0].type === 'py') { var _indent = stream.indentation(); @@ -257,21 +257,21 @@ // appropriate. style = 'meta'; } return style; } - + // Handle decorators if (current === '@') { return stream.match(identifiers, false) ? 'meta' : ERRORCLASS; } if ((style === 'variable' || style === 'builtin') && state.lastToken === 'meta') { style = 'meta'; } - + // Handle scope changes. if (current === 'pass' || current === 'return') { state.dedent += 1; } if (current === 'lambda') state.lambda = true; @@ -296,11 +296,11 @@ } if (state.dedent > 0 && stream.eol() && state.scopes[0].type == 'py') { if (state.scopes.length > 1) state.scopes.shift(); state.dedent -= 1; } - + return style; } var external = { startState: function(basecolumn) { @@ -310,30 +310,30 @@ lastToken: null, lambda: false, dedent: 0 }; }, - + token: function(stream, state) { var style = tokenLexer(stream, state); - + state.lastToken = style; - + if (stream.eol() && stream.lambda) { state.lambda = false; } - + return style; }, - + indent: function(state) { if (state.tokenize != tokenBase) { return state.tokenize.isString ? CodeMirror.Pass : 0; } - + return state.scopes[0].offset; } - + }; return external; }); CodeMirror.defineMIME("text/x-python", "python");