Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3)

Side by Side Diff: tools/lexer_generator/test/automata_test.py

Issue 169523003: Experimental parser: split and rename some files (Closed) Base URL: https://v8.googlecode.com/svn/branches/experimental/parser
Patch Set: Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « tools/lexer_generator/term.py ('k') | tools/lexer_generator/test/rule_parser_test.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 11 matching lines...) Expand all
22 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 27
28 import unittest 28 import unittest
29 from lexer_generator.dot_utilities import * 29 from lexer_generator.dot_utilities import *
30 from lexer_generator.automaton import Action 30 from lexer_generator.automaton import Action
31 from lexer_generator.regex_parser import RegexParser 31 from lexer_generator.regex_parser import RegexParser
32 from lexer_generator.transition_keys import TransitionKey, KeyEncoding 32 from lexer_generator.transition_key import TransitionKey, KeyEncoding
33 from lexer_generator.nfa_builder import NfaBuilder 33 from lexer_generator.nfa_builder import NfaBuilder
34 from lexer_generator.dfa import Dfa 34 from lexer_generator.dfa import Dfa
35 from lexer_generator.dfa_minimizer import DfaMinimizer
35 36
36 class AutomataTestCase(unittest.TestCase): 37 class AutomataTestCase(unittest.TestCase):
37 38
38 __encoding = KeyEncoding.get('latin1') 39 __encoding = KeyEncoding.get('latin1')
39 40
40 @staticmethod 41 @staticmethod
41 def __build_automata(string): 42 def __build_automata(string):
42 encoding = AutomataTestCase.__encoding 43 encoding = AutomataTestCase.__encoding
43 trees = {'main' : RegexParser.parse(string)} 44 trees = {'main' : RegexParser.parse(string)}
44 nfa = NfaBuilder.nfa(encoding, {}, trees, 'main') 45 nfa = NfaBuilder.nfa(encoding, {}, trees, 'main')
45 (start_name, dfa_nodes) = nfa.compute_dfa() 46 (start_name, dfa_nodes) = nfa.compute_dfa()
46 dfa = Dfa(encoding, start_name, dfa_nodes) 47 dfa = Dfa(encoding, start_name, dfa_nodes)
47 return (nfa, dfa, dfa.minimize()) 48 return (nfa, dfa, DfaMinimizer(dfa).minimize())
48 49
49 # (pattern, should match, should not match) 50 # (pattern, should match, should not match)
50 __test_data = [ 51 __test_data = [
51 ("a", ["a"], ["b", ""]), 52 ("a", ["a"], ["b", ""]),
52 ("ab", ["ab"], ["bb", ""]), 53 ("ab", ["ab"], ["bb", ""]),
53 ("a+b", ["ab", "aab", "aaab"], ["a", "b", ""]), 54 ("a+b", ["ab", "aab", "aaab"], ["a", "b", ""]),
54 ("a?b", ["ab", "b"], ["a", "c", ""]), 55 ("a?b", ["ab", "b"], ["a", "c", ""]),
55 ("a*b", ["ab", "aaab", "b"], ["a", "c", ""]), 56 ("a*b", ["ab", "aaab", "b"], ["a", "c", ""]),
56 ("a|b", ["a", "b"], ["ab", "c", ""]), 57 ("a|b", ["a", "b"], ["ab", "c", ""]),
57 (".", ["a", "b"], ["", "aa"]), 58 (".", ["a", "b"], ["", "aa"]),
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 key_a = TransitionKey.single_char(encoding, ord('a')) 96 key_a = TransitionKey.single_char(encoding, ord('a'))
96 key_b = TransitionKey.single_char(encoding, ord('b')) 97 key_b = TransitionKey.single_char(encoding, ord('b'))
97 key_c = TransitionKey.single_char(encoding, ord('c')) 98 key_c = TransitionKey.single_char(encoding, ord('c'))
98 99
99 mapping['S_0']['transitions'][key_a] = 'S_1' 100 mapping['S_0']['transitions'][key_a] = 'S_1'
100 mapping['S_0']['transitions'][key_b] = 'S_2' 101 mapping['S_0']['transitions'][key_b] = 'S_2'
101 mapping['S_1']['transitions'][key_c] = 'S_3' 102 mapping['S_1']['transitions'][key_c] = 'S_3'
102 mapping['S_2']['transitions'][key_c] = 'S_3' 103 mapping['S_2']['transitions'][key_c] = 'S_3'
103 mapping['S_3']['terminal'] = True 104 mapping['S_3']['terminal'] = True
104 105
105 mdfa = Dfa(encoding, 'S_0', mapping).minimize() 106 mdfa = DfaMinimizer(Dfa(encoding, 'S_0', mapping)).minimize()
106 self.assertEqual(3, mdfa.node_count()) 107 self.assertEqual(3, mdfa.node_count())
OLDNEW
« no previous file with comments | « tools/lexer_generator/term.py ('k') | tools/lexer_generator/test/rule_parser_test.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698