def readRepeat( self, with_print=False ): regex = self.readRegexLiteral() if self.tryReadIndent(): body = self.readStatements().withPrint( with_print ) self.mustReadOutdent() return actions.Repeat( regex, body ) else: body = actions.Seq().withPrint( with_print ) return actions.Repeat( regex, body )
def readStatements( self ): # print( 'READ STMNT' ) sofar = [] while True: e = self.readCommand() # print( 'Command', e ) if not e: break sofar.append( e ) return actions.Seq( *sofar )
def readRequire( self, with_print = False ): # print( 'READ REQUIRE' ) regex = self.readRegexLiteral() if self.tryReadIndent(): # print( 'INDENT' ) stmnts = self.readStatements().withPrint( with_print ) self.mustReadOutdent() return actions.Require( regex, stmnts ) else: # print( 'NO INDENT', with_print ) body = actions.Seq().withPrint( with_print ) # print( 'BODY', body._children ) return actions.Require( regex, body )
def readUntil( self ): regex = self.readRegexLiteral() break_at_end = False if self.tryReadKeyword( ':' ): key = self.readToken() if key.isSymbol( value="At-End" ): self.mustReadKeyword( '=' ) val = self.readToken() if val.isSymbol( value="Break" ): break_at_end = True else: raise Exception( 'Not implemented yet' ) else: raise Exception( 'Until: unrecognised key: {}'.format( key.lexemeValue() ) ) if self.tryReadIndent(): stmnts = self.readStatements() self.mustReadOutdent() return actions.Until( regex, stmnts, break_at_end=break_at_end ) else: return actions.Until( regex, actions.Seq(), break_at_end=break_at_end )
def readPass( self ): return actions.Seq()
def test_flatten_simplify(): s2 = actions.Seq(actions.Seq(), actions.Print()) fs2 = s2.flatten() assert isinstance(fs2, actions.Print)
def test_flatten_noChange(): s2 = actions.Seq(actions.Print(), actions.Print()) fs2 = s2.flatten() assert s2._children == fs2._children