Пример #1
0
	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 )
Пример #2
0
	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 )
Пример #3
0
	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 )
Пример #4
0
	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 )
Пример #5
0
	def readPass( self ):
		return actions.Seq()
Пример #6
0
def test_flatten_simplify():
    s2 = actions.Seq(actions.Seq(), actions.Print())
    fs2 = s2.flatten()
    assert isinstance(fs2, actions.Print)
Пример #7
0
def test_flatten_noChange():
    s2 = actions.Seq(actions.Print(), actions.Print())
    fs2 = s2.flatten()
    assert s2._children == fs2._children