summaryrefslogtreecommitdiff
path: root/public/vendor/codemirror/mode/python/python.js
diff options
context:
space:
mode:
Diffstat (limited to 'public/vendor/codemirror/mode/python/python.js')
-rw-r--r--public/vendor/codemirror/mode/python/python.js63
1 files changed, 32 insertions, 31 deletions
diff --git a/public/vendor/codemirror/mode/python/python.js b/public/vendor/codemirror/mode/python/python.js
index 553f2d6f..196b026c 100644
--- a/public/vendor/codemirror/mode/python/python.js
+++ b/public/vendor/codemirror/mode/python/python.js
@@ -53,7 +53,7 @@
var doubleDelimiters = parserConf.doubleDelimiters || /^(\+=|\-=|\*=|%=|\/=|&=|\|=|\^=)/;
var tripleDelimiters = parserConf.tripleDelimiters || /^(\/\/=|>>=|<<=|\*\*=)/;
- if (parserConf.version && parseInt(parserConf.version, 10) == 3){
+ if (parserConf.version && parseInt(parserConf.version, 10) == 3) {
// since http://legacy.python.org/dev/peps/pep-0465/ @ is also an operator
var singleOperators = parserConf.singleOperators || /^[\+\-\*\/%&|\^~<>!@]/;
var identifiers = parserConf.identifiers|| /^[_A-Za-z\u00A1-\uFFFF][_A-Za-z0-9\u00A1-\uFFFF]*/;
@@ -65,12 +65,12 @@
var hangingIndent = parserConf.hangingIndent || conf.indentUnit;
var myKeywords = commonKeywords, myBuiltins = commonBuiltins;
- if(parserConf.extra_keywords != undefined){
+ if (parserConf.extra_keywords != undefined)
myKeywords = myKeywords.concat(parserConf.extra_keywords);
- }
- if(parserConf.extra_builtins != undefined){
+
+ if (parserConf.extra_builtins != undefined)
myBuiltins = myBuiltins.concat(parserConf.extra_builtins);
- }
+
if (parserConf.version && parseInt(parserConf.version, 10) == 3) {
myKeywords = myKeywords.concat(py3.keywords);
myBuiltins = myBuiltins.concat(py3.builtins);
@@ -85,13 +85,14 @@
// tokenizers
function tokenBase(stream, state) {
+ if (stream.sol()) state.indent = stream.indentation()
// Handle scope changes
if (stream.sol() && top(state).type == "py") {
var scopeOffset = top(state).offset;
if (stream.eatSpace()) {
var lineOffset = stream.indentation();
if (lineOffset > scopeOffset)
- pushScope(stream, state, "py");
+ pushPyScope(state);
else if (lineOffset < scopeOffset && dedent(stream, state))
state.errorToken = true;
return null;
@@ -224,16 +225,18 @@
return tokenString;
}
- function pushScope(stream, state, type) {
- var offset = 0, align = null;
- if (type == "py") {
- while (top(state).type != "py")
- state.scopes.pop();
- }
- offset = top(state).offset + (type == "py" ? conf.indentUnit : hangingIndent);
- if (type != "py" && !stream.match(/^(\s|#.*)*$/, false))
- align = stream.column() + 1;
- state.scopes.push({offset: offset, type: type, align: align});
+ function pushPyScope(state) {
+ while (top(state).type != "py") state.scopes.pop()
+ state.scopes.push({offset: top(state).offset + conf.indentUnit,
+ type: "py",
+ align: null})
+ }
+
+ function pushBracketScope(stream, state, type) {
+ var align = stream.match(/^([\s\[\{\(]|#.*)*$/, false) ? null : stream.column() + 1
+ state.scopes.push({offset: state.indent + hangingIndent,
+ type: type,
+ align: align})
}
function dedent(stream, state) {
@@ -250,12 +253,11 @@
var current = stream.current();
// Handle decorators
- if (current == "@"){
- if(parserConf.version && parseInt(parserConf.version, 10) == 3){
- return stream.match(identifiers, false) ? "meta" : "operator";
- } else {
- return stream.match(identifiers, false) ? "meta" : ERRORCLASS;
- }
+ if (current == "@") {
+ if (parserConf.version && parseInt(parserConf.version, 10) == 3)
+ return stream.match(identifiers, false) ? "meta" : "operator";
+ else
+ return stream.match(identifiers, false) ? "meta" : ERRORCLASS;
}
if ((style == "variable" || style == "builtin")
@@ -268,15 +270,15 @@
if (current == "lambda") state.lambda = true;
if (current == ":" && !state.lambda && top(state).type == "py")
- pushScope(stream, state, "py");
+ pushPyScope(state);
var delimiter_index = current.length == 1 ? "[({".indexOf(current) : -1;
if (delimiter_index != -1)
- pushScope(stream, state, "])}".slice(delimiter_index, delimiter_index+1));
+ pushBracketScope(stream, state, "])}".slice(delimiter_index, delimiter_index+1));
delimiter_index = "])}".indexOf(current);
if (delimiter_index != -1) {
- if (top(state).type == current) state.scopes.pop();
+ if (top(state).type == current) state.indent = state.scopes.pop().offset - hangingIndent
else return ERRORCLASS;
}
if (state.dedent > 0 && stream.eol() && top(state).type == "py") {
@@ -292,6 +294,7 @@
return {
tokenize: tokenBase,
scopes: [{offset: basecolumn || 0, type: "py", align: null}],
+ indent: basecolumn || 0,
lastToken: null,
lambda: false,
dedent: 0
@@ -316,16 +319,14 @@
if (state.tokenize != tokenBase)
return state.tokenize.isString ? CodeMirror.Pass : 0;
- var scope = top(state);
- var closing = textAfter && textAfter.charAt(0) == scope.type;
+ var scope = top(state), closing = scope.type == textAfter.charAt(0)
if (scope.align != null)
- return scope.align - (closing ? 1 : 0);
- else if (closing && state.scopes.length > 1)
- return state.scopes[state.scopes.length - 2].offset;
+ return scope.align - (closing ? 1 : 0)
else
- return scope.offset;
+ return scope.offset - (closing ? hangingIndent : 0)
},
+ electricInput: /^\s*[\}\]\)]$/,
closeBrackets: {triples: "'\""},
lineComment: "#",
fold: "indent"