Example #1
0
 def test_it_is_true_when_clause_is_false(self):
     clause = mock.Mock(return_value=False)
     looka = parsing.LookAhead(clause)
     parser = mock.Mock(**{'read_eof.return_value': False})
     self.assertTrue(looka(parser))
     parser._stream.save_context.assert_called_once_with()
     parser._stream.restore_context.assert_called_once_with()
Example #2
0
File: dsl.py Project: 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
Example #3
0
 def test_17_Lookahead(self):
     """
     Basic test for lookahead !!R
     """
     parser = parsing.Parser()
     parser.parsed_stream("==")
     parseTree = \
         parsing.Seq(parsing.Call(parsing.Parser.read_char, '='),
                     parsing.LookAhead(parsing.Call(
                         parsing.Parser.read_char,
                         '=')),
                     )
     res = parseTree(parser)
     self.assertEqual(res, True, "failed to get the correct final value")
     self.assertEqual(parser._stream._cursor._index, 1,
                      "failed to get the correct index after a lookahead")