Skip to content

Commit 95e9edf

Browse files
committed
[python mode] Handle continued lines better
Closes codemirror#5256
1 parent 5b8e5ab commit 95e9edf

File tree

1 file changed

+5
-9
lines changed

1 file changed

+5
-9
lines changed

mode/python/python.js

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
CodeMirror.defineMode("python", function(conf, parserConf) {
4242
var ERRORCLASS = "error";
4343

44-
var delimiters = parserConf.delimiters || parserConf.singleDelimiters || /^[\(\)\[\]\{\}@,:`=;\.]/;
44+
var delimiters = parserConf.delimiters || parserConf.singleDelimiters || /^[\(\)\[\]\{\}@,:`=;\.\\]/;
4545
// (Backwards-compatiblity with old, cumbersome config system)
4646
var operators = [parserConf.singleOperators, parserConf.doubleOperators, parserConf.doubleDelimiters, parserConf.tripleDelimiters,
4747
parserConf.operators || /^([-+*/%\/&|^]=?|[<>=]+|\/\/=?|\*\*=?|!=|[~!@])/]
@@ -76,9 +76,10 @@
7676

7777
// tokenizers
7878
function tokenBase(stream, state) {
79-
if (stream.sol()) state.indent = stream.indentation()
79+
var sol = stream.sol() && state.lastToken != "\\"
80+
if (sol) state.indent = stream.indentation()
8081
// Handle scope changes
81-
if (stream.sol() && top(state).type == "py") {
82+
if (sol && top(state).type == "py") {
8283
var scopeOffset = top(state).offset;
8384
if (stream.eatSpace()) {
8485
var lineOffset = stream.indentation();
@@ -100,13 +101,8 @@
100101
function tokenBaseInner(stream, state) {
101102
if (stream.eatSpace()) return null;
102103

103-
var ch = stream.peek();
104-
105104
// Handle Comments
106-
if (ch == "#") {
107-
stream.skipToEnd();
108-
return "comment";
109-
}
105+
if (stream.match(/^#.*/)) return "comment";
110106

111107
// Handle Number Literals
112108
if (stream.match(/^[0-9\.]/, false)) {

0 commit comments

Comments
 (0)