Skip to content

Commit 4a1d681

Browse files
albertjanmeredydd
authored andcommitted
fix single quoted continuated strings
1 parent cba703b commit 4a1d681

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

src/tokenize.js

+9-4
Original file line numberDiff line numberDiff line change
@@ -142,14 +142,19 @@ function _all_string_prefixes() {
142142
// StringPrefix can be the empty string (making it optional).
143143
var StringPrefix = group.apply(null, _all_string_prefixes())
144144

145+
// these regexes differ from python because .exec doesn't do the
146+
// same thing as .match in python. It's more like .search.
147+
// .match matches from the start of the string.
148+
// to get the same behaviour we can add a ^ to the start of the
149+
// regex
145150
// Tail end of ' string.
146-
var Single = "[^'\\\\]*(?:\\\\.[^'\\\\]*)*'";
151+
var Single = "^[^'\\\\]*(?:\\\\.[^'\\\\]*)*'";
147152
// Tail end of " string.
148-
var Double = '[^"\\\\]*(?:\\\\.[^"\\\\]*)*"';
153+
var Double = '^[^"\\\\]*(?:\\\\.[^"\\\\]*)*"';
149154
// Tail end of ''' string.
150-
var Single3 = "[^'\\\\]*(?:(?:\\\\.|'(?!''))[^'\\\\]*)*'''";
155+
var Single3 = "^[^'\\\\]*(?:(?:\\\\.|'(?!''))[^'\\\\]*)*'''";
151156
// Tail end of """ string.
152-
var Double3 = '[^"\\\\]*(?:(?:\\\\.|"(?!""))[^"\\\\]*)*"""';
157+
var Double3 = '^[^"\\\\]*(?:(?:\\\\.|"(?!""))[^"\\\\]*)*"""';
153158
var Triple = group(StringPrefix + "'''", StringPrefix + '"""');
154159
// Single-line ' or " string.
155160
var String_ = group(StringPrefix + "'[^\\n'\\\\]*(?:\\\\.[^\\n'\\\\]*)*'",

tok_test.py

Whitespace-only changes.

0 commit comments

Comments
 (0)