예제 #1
0
파일: dsl.py 프로젝트: vhb/pyrser
def add_mod(self, seq, mod):
    """Create a tree.{Complement, LookAhead, Neg, Until}"""
    modstr = self.value(mod)
    if modstr == '~':
        seq.parser_tree = parsing.Complement(seq.parser_tree)
    elif modstr == '!!':
        seq.parser_tree = parsing.LookAhead(seq.parser_tree)
    elif modstr == '!':
        seq.parser_tree = parsing.Neg(seq.parser_tree)
    elif modstr == '->':
        seq.parser_tree = parsing.Until(seq.parser_tree)
    return True
예제 #2
0
 def test_18_Complement(self):
     """
     Basic test for complement ~R
     """
     parser = parsing.Parser()
     parser.parsed_stream("==")
     parseTree = parsing.Seq(
         parsing.Call(parsing.Parser.read_char, '='),
         parsing.Complement(parsing.Call(parsing.Parser.read_char, '=')))
     res = parseTree(parser)
     self.assertEqual(res, False, "failed to get the correct final value")
     self.assertEqual(parser._stream._cursor._index, 0,
                      "failed to get the correct index after a lookahead")
     parser.parsed_stream("=+")
     res = parseTree(parser)
     self.assertEqual(res, True, "failed to get the correct final value")
     self.assertEqual(parser._stream._cursor._index, 2,
                      "failed to get the correct index after a lookahead")
예제 #3
0
 def test_it_is_true_when_clause_is_false(self):
     clause = mock.Mock(return_value=False)
     comp = parsing.Complement(clause)
     parser = mock.Mock(**{'read_eof.return_value': False})
     self.assertTrue(comp(parser))