##// END OF EJS Templates
New ast_nodes method, and change push_accepts_more to use it.
Thomas Kluyver -
Show More
@@ -445,8 +445,12 class InputSplitter(object):
445 if not self._full_dedent:
445 if not self._full_dedent:
446 return False
446 return False
447 else:
447 else:
448 nblocks = len(split_blocks(''.join(self._buffer)))
448 try:
449 if nblocks==1:
449 nodes = self.ast_nodes()
450 except Exception:
451 return False
452 else:
453 if len(nodes) == 1:
450 return False
454 return False
451
455
452 # When input is complete, then termination is marked by an extra blank
456 # When input is complete, then termination is marked by an extra blank
@@ -536,6 +540,23 class InputSplitter(object):
536 # splitter, which is more accurate than ours.
540 # splitter, which is more accurate than ours.
537 return split_blocks(''.join(blocks))
541 return split_blocks(''.join(blocks))
538
542
543 def ast_nodes(self, lines=None):
544 """Turn the lines into a list of AST nodes.
545
546 Parameters
547 ----------
548 lines : str
549 A (possibly multiline) string of Python code. If None (default), it
550 will use the InputSplitter's current code buffer.
551
552 Returns
553 -------
554 A list of AST (abstract syntax tree) nodes representing the code.
555 """
556 if lines is None:
557 lines = u"".join(self._buffer)
558 return ast.parse(lines).body
559
539 #------------------------------------------------------------------------
560 #------------------------------------------------------------------------
540 # Private interface
561 # Private interface
541 #------------------------------------------------------------------------
562 #------------------------------------------------------------------------
General Comments 0
You need to be logged in to leave comments. Login now