@ -1,10 +1,10 @@
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 ( "^((==)|(!=)|(<=)|(>=)|(<>)|(<<)|(>>)|(//)|(\\*\\*))" ) ;
@ -65,15 +65,15 @@ CodeMirror.defineMode("python", function(conf, parserConf) {
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 ;
@ -109,13 +109,13 @@ CodeMirror.defineMode("python", function(conf, parserConf) {
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 ;
@ -128,31 +128,31 @@ CodeMirror.defineMode("python", function(conf, parserConf) {
if ( stream . match ( singleDelimiters ) ) {
return null ;
}
if ( stream . match ( types ) ) {
return 'builtin' ;
}
if ( stream . match ( keywords ) ) {
return 'keyword' ;
}
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' ;
return function tokenString ( stream , state ) {
while ( ! stream . eol ( ) ) {
stream . eatWhile ( /[^'"\\]/ ) ;
@ -178,7 +178,7 @@ CodeMirror.defineMode("python", function(conf, parserConf) {
return OUTCLASS ;
} ;
}
function indent ( stream , state , type ) {
type = type || 'py' ;
var indentUnit = 0 ;
@ -197,7 +197,7 @@ CodeMirror.defineMode("python", function(conf, parserConf) {
type : type
} ) ;
}
function dedent ( stream , state ) {
if ( state . scopes . length == 1 ) return ;
if ( state . scopes [ 0 ] . type === 'py' ) {
@ -237,7 +237,7 @@ CodeMirror.defineMode("python", function(conf, parserConf) {
return ERRORCLASS ;
}
}
// Handle decorators
if ( current === '@' ) {
style = state . tokenize ( stream , state ) ;
@ -250,7 +250,7 @@ CodeMirror.defineMode("python", function(conf, parserConf) {
return ERRORCLASS ;
}
}
// Handle scope changes.
if ( current === 'pass' || current === 'return' ) {
state . dedent += 1 ;
@ -278,7 +278,7 @@ CodeMirror.defineMode("python", function(conf, parserConf) {
if ( state . scopes . length > 1 ) state . scopes . shift ( ) ;
state . dedent -= 1 ;
}
return style ;
}
@ -292,27 +292,27 @@ CodeMirror.defineMode("python", function(conf, parserConf) {
dedent : 0
} ;
} ,
token : function ( stream , state ) {
var style = tokenLexer ( stream , state ) ;
state . lastToken = { style : style , content : stream . current ( ) } ;
if ( stream . eol ( ) && stream . lambda ) {
state . lambda = false ;
}
return style ;
} ,
indent : function ( state , textAfter ) {
if ( state . tokenize != tokenBase ) {
return 0 ;
}
return state . scopes [ 0 ] . offset ;
}
} ;
return external ;
} ) ;