OLD | NEW |
1 # Copyright 2013 the V8 project authors. All rights reserved. | 1 # Copyright 2013 the V8 project authors. All rights reserved. |
2 # Redistribution and use in source and binary forms, with or without | 2 # Redistribution and use in source and binary forms, with or without |
3 # modification, are permitted provided that the following conditions are | 3 # modification, are permitted provided that the following conditions are |
4 # met: | 4 # met: |
5 # | 5 # |
6 # * Redistributions of source code must retain the above copyright | 6 # * Redistributions of source code must retain the above copyright |
7 # notice, this list of conditions and the following disclaimer. | 7 # notice, this list of conditions and the following disclaimer. |
8 # * Redistributions in binary form must reproduce the above | 8 # * Redistributions in binary form must reproduce the above |
9 # copyright notice, this list of conditions and the following | 9 # copyright notice, this list of conditions and the following |
10 # disclaimer in the documentation and/or other materials provided | 10 # disclaimer in the documentation and/or other materials provided |
(...skipping 24 matching lines...) Expand all Loading... |
35 expected = map(lambda (action, s) : (Action(None, (action, None)), s), expec
ted) | 35 expected = map(lambda (action, s) : (Action(None, (action, None)), s), expec
ted) |
36 expected.append((Action(None, ('terminate', None)), '\0')) | 36 expected.append((Action(None, ('terminate', None)), '\0')) |
37 automata = RuleProcessor.parse(rules).default_automata() | 37 automata = RuleProcessor.parse(rules).default_automata() |
38 for automaton in [automata.dfa(), automata.minimal_dfa()]: | 38 for automaton in [automata.dfa(), automata.minimal_dfa()]: |
39 for i, (action, start, stop) in enumerate(automaton.lex(string)): | 39 for i, (action, start, stop) in enumerate(automaton.lex(string)): |
40 self.assertEquals(expected[i][0], action) | 40 self.assertEquals(expected[i][0], action) |
41 self.assertEquals(expected[i][1], string[start : stop]) | 41 self.assertEquals(expected[i][1], string[start : stop]) |
42 | 42 |
43 def test_simple(self): | 43 def test_simple(self): |
44 rules = ''' | 44 rules = ''' |
| 45 eos = [:eos:]; |
45 <<default>> | 46 <<default>> |
46 "(" <|LBRACE|> | 47 "(" <|LBRACE|> |
47 ")" <|RBRACE|> | 48 ")" <|RBRACE|> |
48 | 49 |
49 "foo" <|FOO|> | 50 "foo" <|FOO|> |
50 eof <|terminate|>''' | 51 eos <|terminate|>''' |
51 | 52 |
52 string = 'foo()\0' | 53 string = 'foo()' |
53 self.__verify_action_stream(rules, string, | 54 self.__verify_action_stream(rules, string, |
54 [('FOO', 'foo'), ('LBRACE', '('), ('RBRACE', ')')]) | 55 [('FOO', 'foo'), ('LBRACE', '('), ('RBRACE', ')')]) |
55 | 56 |
56 def test_maximal_matching(self): | 57 def test_maximal_matching(self): |
57 rules = ''' | 58 rules = ''' |
| 59 eos = [:eos:]; |
58 <<default>> | 60 <<default>> |
59 "<" <|LT|> | 61 "<" <|LT|> |
60 "<<" <|SHL|> | 62 "<<" <|SHL|> |
61 " " <|SPACE|> | 63 " " <|SPACE|> |
62 eof <|terminate|>''' | 64 eos <|terminate|>''' |
63 | 65 |
64 string = '<< <\0' | 66 string = '<< <' |
65 self.__verify_action_stream(rules, string, | 67 self.__verify_action_stream(rules, string, |
66 [('SHL', '<<'), ('SPACE', ' '), ('LT', '<')]) | 68 [('SHL', '<<'), ('SPACE', ' '), ('LT', '<')]) |
67 | 69 |
68 def test_consecutive_epsilon_transitions(self): | 70 def test_consecutive_epsilon_transitions(self): |
69 rules = ''' | 71 rules = ''' |
| 72 eos = [:eos:]; |
70 digit = [0-9]; | 73 digit = [0-9]; |
71 number = (digit+ ("." digit+)?); | 74 number = (digit+ ("." digit+)?); |
72 <<default>> | 75 <<default>> |
73 number <|NUMBER|> | 76 number <|NUMBER|> |
74 eof <|terminate|>''' | 77 eos <|terminate|>''' |
75 | 78 |
76 string = '555\0' | 79 string = '555' |
77 self.__verify_action_stream(rules, string, [('NUMBER', '555')]) | 80 self.__verify_action_stream(rules, string, [('NUMBER', '555')]) |
OLD | NEW |