##// 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 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 + [self.assemble_logical_lines]
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
688 line = self.assemble_logical_lines.push(line)
689 if line is None:
690 return _accumulating('acc logical line')
691
692 if not self.within_python_line:
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 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,13 +180,15 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 = ' '.join(parts)
191 line = ''.join(parts)
190
192
191 # Utilities
193 # Utilities
192 def _make_help_call(target, esc, lspace, next_input=None):
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 [ [('>>> a = [1,','a = [1,'),
194 [ [('>>> a = [1,','a = [1,'),
195 ('... 2]','2]'),
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 leading_indent =
206 leading_indent =
200 [ [(' print "hi"','print "hi"'),
207 [ [(' print "hi"','print "hi"'),
@@ -222,31 +229,31 b' syntax_ml = \\'
222
229
223 escaped =
230 escaped =
224 [ [('%abc def \\', None),
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 [('%abc def \\', None),
234 [('%abc def \\', None),
228 ('ghi\\', None),
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 assign_magic =
240 assign_magic =
234 [ [(u'a = %bc de \\', None),
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 [(u'a = %bc de \\', None),
244 [(u'a = %bc de \\', None),
238 (u'fg\\', None),
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 assign_system =
250 assign_system =
244 [ [(u'a = !bc de \\', None),
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 [(u'a = !bc de \\', None),
254 [(u'a = !bc de \\', None),
248 (u'fg\\', None),
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 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
@@ -274,11 +281,13 b' def test_ipy_prompt():'
274 def test_assemble_logical_lines():
281 def test_assemble_logical_lines():
275 tests = \
282 tests = \
276 [ [(u"a = \\", None),
283 [ [(u"a = \\", None),
277 (u"123", u"a = 123"),
284 (u"123", u"a = 123"),
278 ],
285 ],
279 [(u"a = \\", None), # Test resetting when within a multi-line string
286 [(u"a = \\", None), # Test resetting when within a multi-line string
280 (u"12 *\\", None),
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 for example in tests:
293 for example in tests:
@@ -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