| 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 17 matching lines...) Expand all Loading... |
| 28 import unittest | 28 import unittest |
| 29 from automaton import Action | 29 from automaton import Action |
| 30 from rule_parser import RuleProcessor | 30 from rule_parser import RuleProcessor |
| 31 | 31 |
| 32 class LexerTestCase(unittest.TestCase): | 32 class LexerTestCase(unittest.TestCase): |
| 33 | 33 |
| 34 def __verify_action_stream(self, rules, string, expected): | 34 def __verify_action_stream(self, rules, string, expected): |
| 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.nfa(), 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 eos = [:eos:]; |
| 46 <<default>> | 46 <<default>> |
| 47 "(" <|LBRACE|> | 47 "(" <|LBRACE|> |
| 48 ")" <|RBRACE|> | 48 ")" <|RBRACE|> |
| (...skipping 22 matching lines...) Expand all Loading... |
| 71 rules = ''' | 71 rules = ''' |
| 72 eos = [:eos:]; | 72 eos = [:eos:]; |
| 73 digit = [0-9]; | 73 digit = [0-9]; |
| 74 number = (digit+ ("." digit+)?); | 74 number = (digit+ ("." digit+)?); |
| 75 <<default>> | 75 <<default>> |
| 76 number <|NUMBER|> | 76 number <|NUMBER|> |
| 77 eos <|terminate|>''' | 77 eos <|terminate|>''' |
| 78 | 78 |
| 79 string = '555' | 79 string = '555' |
| 80 self.__verify_action_stream(rules, string, [('NUMBER', '555')]) | 80 self.__verify_action_stream(rules, string, [('NUMBER', '555')]) |
| OLD | NEW |