def testDeclarationSet2(self): '''Just tries to parse and sees that everything was parsed, doesn't predict the result''' parser = SPGenerator.buildParser("declarationset") result = TextTools.tag(declaration, parser) assert result[-1] == len( declaration ), '''Didn't complete parse of the simpleparse declaration, only got %s chars, should have %s''' % ( result[-1], len(declaration))
def doBasicTest( self, parserName, testValue, expected, ): parser = SPGenerator.buildParser(parserName) result = TextTools.tag(testValue, parser) assert result == expected, '''\nexpected:%s\n got:%s\n''' % ( pprint.pformat(expected), pprint.pformat(result))
declaration = r'''testparser := (a,b)* a := 'a' b := 'b' ''' testdata = 'aba' expectedResult = (1, [('a', 0, 1, []), ('b', 1, 2, [])], 2) from simpleparse.simpleparsegrammar import Parser from simpleparse.stt.TextTools import TextTools import pprint parser = Parser(declaration).generator.buildParser('testparser') result = TextTools.tag(testdata, parser) if result != expectedResult: print 'backup-on-subtable-test failed' print '\texpected', pprint.pprint(expectedResult) print '\tgot', pprint.pprint(result)
a := 'a' ''' testdata = 'aaaa' expectedResult = (1, [ ('as', 0, 4, [ ('a', 0, 1, NullResult), ('as', 1, 4, [ ('a', 1, 2, NullResult), ('as', 2, 4, [ ('a', 2, 3, NullResult), ('as', 3, 4, [ ('a', 3, 4, NullResult) ]) ]) ]) ]) ], 4) parser = Parser( declaration ).generator.buildParser( 'testparser' ) print "About to attempt the deep-nesting test" print "If python goes into an infinite loop, then the test failed ;) " print result = TextTools.tag( testdata, parser ) if result != expectedResult: print 'test-deep-nesting failed' print '\texpected', expectedResult print '\tgot', result else: print "test-deep-nesting succeeded!\nYou're probably using the non-recursive mx.TextTools rewrite"
def testDeclarationSet2( self ): '''Just tries to parse and sees that everything was parsed, doesn't predict the result''' parser = SPGenerator.buildParser( "declarationset" ) result = TextTools.tag( declaration, parser ) assert result[-1] == len(declaration), '''Didn't complete parse of the simpleparse declaration, only got %s chars, should have %s'''%(result[-1], len(declaration))
def doBasicTest(self, parserName, testValue, expected, ): parser = SPGenerator.buildParser( parserName ) result = TextTools.tag( testValue, parser ) assert result == expected, '''\nexpected:%s\n got:%s\n'''%( pprint.pformat(expected), pprint.pformat(result))
print (tag,start,stop,subtags), buffer def word( self, (tag,start,stop,subtags), buffer ): print (tag,start,stop,subtags), buffer def markup( self, (tag,start,stop,subtags), buffer ): print (tag,start,stop,subtags), buffer parser = Parser(grammar) for test in tests: success, children, nextcharacter = parser.parse( test, production="para", processor=Processor()) #print success, children, nextcharacter assert success and nextcharacter==len(test) print from simpleparse import generator from simpleparse.stt.TextTools import TextTools input = tests[0] parser = generator.buildParser(grammar).parserbyname("para") taglist = TextTools.tag(input, parser) for tag, beg, end, parts in taglist[1]: if tag == 'plain': stdout.write(input[beg:end]) elif tag == 'markup': markup = parts[0] mtag, mbeg, mend = markup[:3] start, stop = codes.get(mtag, ('<!-- unknown -->','<!-- / -->')) stdout.write(start + input[mbeg+1:mend-1] + stop) stderr.write('parsed %s chars of %s\n' % (taglist[-1], len(input)))