Show More
@@ -545,9 +545,9 b' class IPythonInputSplitter(InputSplitter):' | |||||
545 | def transforms_in_use(self): |
|
545 | def transforms_in_use(self): | |
546 | """Transformers, excluding logical line transformers if we're in a |
|
546 | """Transformers, excluding logical line transformers if we're in a | |
547 | Python line.""" |
|
547 | Python line.""" | |
548 |
t = self.physical_line_transforms |
|
548 | t = self.physical_line_transforms[:] | |
549 | if not self.within_python_line: |
|
549 | if not self.within_python_line: | |
550 | t += self.logical_line_transforms |
|
550 | t += [self.assemble_logical_lines] + self.logical_line_transforms | |
551 | return t + [self.assemble_python_lines] + self.python_line_transforms |
|
551 | return t + [self.assemble_python_lines] + self.python_line_transforms | |
552 |
|
552 | |||
553 | def reset(self): |
|
553 | def reset(self): | |
@@ -556,6 +556,7 b' class IPythonInputSplitter(InputSplitter):' | |||||
556 | self._buffer_raw[:] = [] |
|
556 | self._buffer_raw[:] = [] | |
557 | self.source_raw = '' |
|
557 | self.source_raw = '' | |
558 | self.transformer_accumulating = False |
|
558 | self.transformer_accumulating = False | |
|
559 | self.within_python_line = False | |||
559 | for t in self.transforms: |
|
560 | for t in self.transforms: | |
560 | t.reset() |
|
561 | t.reset() | |
561 |
|
562 | |||
@@ -685,11 +686,11 b' class IPythonInputSplitter(InputSplitter):' | |||||
685 | if line is None: |
|
686 | if line is None: | |
686 | return _accumulating(transformer) |
|
687 | return _accumulating(transformer) | |
687 |
|
688 | |||
|
689 | if not self.within_python_line: | |||
688 | line = self.assemble_logical_lines.push(line) |
|
690 | line = self.assemble_logical_lines.push(line) | |
689 | if line is None: |
|
691 | if line is None: | |
690 | return _accumulating('acc logical line') |
|
692 | return _accumulating('acc logical line') | |
691 |
|
693 | |||
692 | if not self.within_python_line: |
|
|||
693 | for transformer in self.logical_line_transforms: |
|
694 | for transformer in self.logical_line_transforms: | |
694 | line = transformer.push(line) |
|
695 | line = transformer.push(line) | |
695 | if line is None: |
|
696 | if line is None: |
@@ -180,10 +180,12 b' def assemble_logical_lines():' | |||||
180 |
|
180 | |||
181 | parts = [] |
|
181 | parts = [] | |
182 | while line is not None: |
|
182 | while line is not None: | |
183 | parts.append(line.rstrip('\\')) |
|
183 | if line.endswith('\\') and (not has_comment(line)): | |
184 | if not line.endswith('\\'): |
|
184 | parts.append(line[:-1]) | |
|
185 | line = (yield None) # Get another line | |||
|
186 | else: | |||
|
187 | parts.append(line) | |||
185 | break |
|
188 | break | |
186 | line = (yield None) |
|
|||
187 |
|
189 | |||
188 | # Output |
|
190 | # Output | |
189 |
line = ' |
|
191 | line = ''.join(parts) |
@@ -190,12 +190,19 b' syntax_ml = \\' | |||||
190 | ], |
|
190 | ], | |
191 | ], |
|
191 | ], | |
192 |
|
192 | |||
193 | multiline_datastructure = |
|
193 | multiline_datastructure_prompt = | |
194 | [ [('>>> a = [1,','a = [1,'), |
|
194 | [ [('>>> a = [1,','a = [1,'), | |
195 | ('... 2]','2]'), |
|
195 | ('... 2]','2]'), | |
196 | ], |
|
196 | ], | |
197 | ], |
|
197 | ], | |
198 |
|
198 | |||
|
199 | multiline_datastructure = | |||
|
200 | [ [('b = ("%s"', None), | |||
|
201 | ('# comment', None), | |||
|
202 | ('%foo )', 'b = ("%s"\n# comment\n%foo )'), | |||
|
203 | ], | |||
|
204 | ], | |||
|
205 | ||||
199 | leading_indent = |
|
206 | leading_indent = | |
200 | [ [(' print "hi"','print "hi"'), |
|
207 | [ [(' print "hi"','print "hi"'), | |
201 | ], |
|
208 | ], | |
@@ -262,7 +269,7 b' def test_classic_prompt():' | |||||
262 | tt.check_pairs(transform_and_reset(ipt.classic_prompt), syntax['classic_prompt']) |
|
269 | tt.check_pairs(transform_and_reset(ipt.classic_prompt), syntax['classic_prompt']) | |
263 | for example in syntax_ml['classic_prompt']: |
|
270 | for example in syntax_ml['classic_prompt']: | |
264 | transform_checker(example, ipt.classic_prompt) |
|
271 | transform_checker(example, ipt.classic_prompt) | |
265 | for example in syntax_ml['multiline_datastructure']: |
|
272 | for example in syntax_ml['multiline_datastructure_prompt']: | |
266 | transform_checker(example, ipt.classic_prompt) |
|
273 | transform_checker(example, ipt.classic_prompt) | |
267 |
|
274 | |||
268 |
|
275 | |||
@@ -280,6 +287,8 b' def test_assemble_logical_lines():' | |||||
280 | (u"12 *\\", None), |
|
287 | (u"12 *\\", None), | |
281 |
(None, u"a = |
|
288 | (None, u"a = 12 *"), | |
282 | ], |
|
289 | ], | |
|
290 | [(u"# foo\\", u"# foo\\"), # Comments can't be continued like this | |||
|
291 | ], | |||
283 | ] |
|
292 | ] | |
284 | for example in tests: |
|
293 | for example in tests: | |
285 | transform_checker(example, ipt.assemble_logical_lines) |
|
294 | transform_checker(example, ipt.assemble_logical_lines) | |
@@ -300,7 +309,7 b' def test_assemble_python_lines():' | |||||
300 | (u"2,", None), |
|
309 | (u"2,", None), | |
301 | (None, u"a = [1,\n2,"), |
|
310 | (None, u"a = [1,\n2,"), | |
302 | ], |
|
311 | ], | |
303 | ] |
|
312 | ] + syntax_ml['multiline_datastructure'] | |
304 | for example in tests: |
|
313 | for example in tests: | |
305 | transform_checker(example, ipt.assemble_python_lines) |
|
314 | transform_checker(example, ipt.assemble_python_lines) | |
306 |
|
315 |
General Comments 0
You need to be logged in to leave comments.
Login now