예제 #1
0
    def do_test(self, pattern, target, dfa_result, nfa_result, parser_factory):
        alphabet = LineAwareAlphabet(UnicodeAlphabet.instance(), parser_factory)
        compiler = Compiler.single(alphabet, pattern)
        str(compiler.expression)
#        text = str(compiler.expression)
#        assert text == format('(?P<label>{0!s})', pattern), text
        
        factory = LineAwareStreamFactory(alphabet)
        target = factory.from_string(target)
        
        dfa = compiler.dfa()
        result = dfa.match(target)
        if result:
            (a, b, c) = result
            (p, q, r) = dfa_result
            assert a == p, result
            assert b == q, result
            assert_str(repr(c), r)
        else:
            assert dfa_result == None, dfa_result

        nfa = compiler.nfa()
        result = list(nfa.match(target))
        assert len(result) == len(nfa_result), result
        for ((a,b,c), (p,q,r)) in zip(result, nfa_result):
            assert a == p, result
            assert b == q, result
            assert_str(repr(c), r)
예제 #2
0
    def do_test(self, pattern, target, dfa_result, nfa_result, parser_factory):
        alphabet = LineAwareAlphabet(UnicodeAlphabet.instance(),
                                     parser_factory)
        compiler = Compiler.single(alphabet, pattern)
        str(compiler.expression)
        #        text = str(compiler.expression)
        #        assert text == format('(?P<label>{0!s})', pattern), text

        factory = LineAwareStreamFactory(alphabet)
        target = factory.from_string(target)

        dfa = compiler.dfa()
        result = dfa.match(target)
        if result:
            (a, b, c) = result
            (p, q, r) = dfa_result
            assert a == p, result
            assert b == q, result
            assert_str(repr(c), r)
        else:
            assert dfa_result == None, dfa_result

        nfa = compiler.nfa()
        result = list(nfa.match(target))
        assert len(result) == len(nfa_result), result
        for ((a, b, c), (p, q, r)) in zip(result, nfa_result):
            assert a == p, result
            assert b == q, result
            assert_str(repr(c), r)
예제 #3
0
 def do_test(self, pattern, target, dfa_result, nfa_result):
     alphabet = UnicodeAlphabet.instance()
     compiler = Compiler.single(alphabet, pattern)
     text = str(compiler.expression)
     assert text == format('(?P<label>{0!s})', pattern), text
     nfa = compiler.nfa()
     result = list(nfa.match(target))
     assert result == nfa_result, result
     dfa = compiler.dfa()
     result = dfa.match(target)
     assert result == dfa_result, result
예제 #4
0
파일: core.py 프로젝트: cajus/python-lepl
 def do_test(self, pattern, target, dfa_result, nfa_result):
     alphabet = UnicodeAlphabet.instance()
     compiler = Compiler.single(alphabet, pattern)
     text = str(compiler.expression)
     assert text == fmt('(?P<label>{0!s})', pattern), text
     nfa = compiler.nfa()
     result = list(nfa.match((0, StringHelper(target))))
     assert result == nfa_result, result
     dfa = compiler.dfa()
     result = dfa.match((0, StringHelper(target)))
     assert result == dfa_result, result