##// END OF EJS Templates
Fix for \ at end of comment, and add tests
Thomas Kluyver -
Show More
@@ -545,9 +545,9 b' class IPythonInputSplitter(InputSplitter):'
545 545 def transforms_in_use(self):
546 546 """Transformers, excluding logical line transformers if we're in a
547 547 Python line."""
548 t = self.physical_line_transforms + [self.assemble_logical_lines]
548 t = self.physical_line_transforms[:]
549 549 if not self.within_python_line:
550 t += self.logical_line_transforms
550 t += [self.assemble_logical_lines] + self.logical_line_transforms
551 551 return t + [self.assemble_python_lines] + self.python_line_transforms
552 552
553 553 def reset(self):
@@ -556,6 +556,7 b' class IPythonInputSplitter(InputSplitter):'
556 556 self._buffer_raw[:] = []
557 557 self.source_raw = ''
558 558 self.transformer_accumulating = False
559 self.within_python_line = False
559 560 for t in self.transforms:
560 561 t.reset()
561 562
@@ -685,11 +686,11 b' class IPythonInputSplitter(InputSplitter):'
685 686 if line is None:
686 687 return _accumulating(transformer)
687 688
688 line = self.assemble_logical_lines.push(line)
689 if line is None:
690 return _accumulating('acc logical line')
691
692 689 if not self.within_python_line:
690 line = self.assemble_logical_lines.push(line)
691 if line is None:
692 return _accumulating('acc logical line')
693
693 694 for transformer in self.logical_line_transforms:
694 695 line = transformer.push(line)
695 696 if line is None:
@@ -180,13 +180,15 b' def assemble_logical_lines():'
180 180
181 181 parts = []
182 182 while line is not None:
183 parts.append(line.rstrip('\\'))
184 if not line.endswith('\\'):
183 if line.endswith('\\') and (not has_comment(line)):
184 parts.append(line[:-1])
185 line = (yield None) # Get another line
186 else:
187 parts.append(line)
185 188 break
186 line = (yield None)
187 189
188 190 # Output
189 line = ' '.join(parts)
191 line = ''.join(parts)
190 192
191 193 # Utilities
192 194 def _make_help_call(target, esc, lspace, next_input=None):
@@ -190,11 +190,18 b' syntax_ml = \\'
190 190 ],
191 191 ],
192 192
193 multiline_datastructure =
193 multiline_datastructure_prompt =
194 194 [ [('>>> a = [1,','a = [1,'),
195 195 ('... 2]','2]'),
196 196 ],
197 197 ],
198
199 multiline_datastructure =
200 [ [('b = ("%s"', None),
201 ('# comment', None),
202 ('%foo )', 'b = ("%s"\n# comment\n%foo )'),
203 ],
204 ],
198 205
199 206 leading_indent =
200 207 [ [(' print "hi"','print "hi"'),
@@ -222,31 +229,31 b' syntax_ml = \\'
222 229
223 230 escaped =
224 231 [ [('%abc def \\', None),
225 ('ghi', u_fmt("get_ipython().magic({u}'abc def ghi')")),
232 ('ghi', u_fmt("get_ipython().magic({u}'abc def ghi')")),
226 233 ],
227 234 [('%abc def \\', None),
228 235 ('ghi\\', None),
229 (None, u_fmt("get_ipython().magic({u}'abc def ghi')")),
236 (None, u_fmt("get_ipython().magic({u}'abc def ghi')")),
230 237 ],
231 238 ],
232 239
233 240 assign_magic =
234 241 [ [(u'a = %bc de \\', None),
235 (u'fg', u_fmt("a = get_ipython().magic({u}'bc de fg')")),
242 (u'fg', u_fmt("a = get_ipython().magic({u}'bc de fg')")),
236 243 ],
237 244 [(u'a = %bc de \\', None),
238 245 (u'fg\\', None),
239 (None, u_fmt("a = get_ipython().magic({u}'bc de fg')")),
246 (None, u_fmt("a = get_ipython().magic({u}'bc de fg')")),
240 247 ],
241 248 ],
242 249
243 250 assign_system =
244 251 [ [(u'a = !bc de \\', None),
245 (u'fg', u_fmt("a = get_ipython().getoutput({u}'bc de fg')")),
252 (u'fg', u_fmt("a = get_ipython().getoutput({u}'bc de fg')")),
246 253 ],
247 254 [(u'a = !bc de \\', None),
248 255 (u'fg\\', None),
249 (None, u_fmt("a = get_ipython().getoutput({u}'bc de fg')")),
256 (None, u_fmt("a = get_ipython().getoutput({u}'bc de fg')")),
250 257 ],
251 258 ],
252 259 )
@@ -262,7 +269,7 b' def test_classic_prompt():'
262 269 tt.check_pairs(transform_and_reset(ipt.classic_prompt), syntax['classic_prompt'])
263 270 for example in syntax_ml['classic_prompt']:
264 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 273 transform_checker(example, ipt.classic_prompt)
267 274
268 275
@@ -274,11 +281,13 b' def test_ipy_prompt():'
274 281 def test_assemble_logical_lines():
275 282 tests = \
276 283 [ [(u"a = \\", None),
277 (u"123", u"a = 123"),
284 (u"123", u"a = 123"),
278 285 ],
279 286 [(u"a = \\", None), # Test resetting when within a multi-line string
280 287 (u"12 *\\", None),
281 (None, u"a = 12 *"),
288 (None, u"a = 12 *"),
289 ],
290 [(u"# foo\\", u"# foo\\"), # Comments can't be continued like this
282 291 ],
283 292 ]
284 293 for example in tests:
@@ -300,7 +309,7 b' def test_assemble_python_lines():'
300 309 (u"2,", None),
301 310 (None, u"a = [1,\n2,"),
302 311 ],
303 ]
312 ] + syntax_ml['multiline_datastructure']
304 313 for example in tests:
305 314 transform_checker(example, ipt.assemble_python_lines)
306 315
General Comments 0
You need to be logged in to leave comments. Login now