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

Side by Side Diff: tools/lexer_generator/action_test.py

Issue 61003003: Experimental parser: cleanup rule processing result (Closed) Base URL: https://v8.googlecode.com/svn/branches/experimental/parser
Patch Set: Created 7 years, 1 month 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 | « no previous file | tools/lexer_generator/code_generator_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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 self.assertEqual(actions[-1], Action('TERMINATE')) 44 self.assertEqual(actions[-1], Action('TERMINATE'))
45 self.assertEqual(actions[-2].data(), expected_code) 45 self.assertEqual(actions[-2].data(), expected_code)
46 46
47 def test_action_precedence(self): 47 def test_action_precedence(self):
48 rules = '''<default> 48 rules = '''<default>
49 "key" { KEYWORD } <<break>> 49 "key" { KEYWORD } <<break>>
50 /[a-z]+/ { ID } <<break>>''' 50 /[a-z]+/ { ID } <<break>>'''
51 automata_for_conditions = process_rules(rules) 51 automata_for_conditions = process_rules(rules)
52 self.assertEqual(len(automata_for_conditions), 1) 52 self.assertEqual(len(automata_for_conditions), 1)
53 self.assertTrue('default' in automata_for_conditions) 53 self.assertTrue('default' in automata_for_conditions)
54 (nfa, dfa) = automata_for_conditions['default'] 54 dfa = automata_for_conditions['default'].dfa()
55 55
56 self.__verify_last_action(dfa, 'foo', 'ID') 56 self.__verify_last_action(dfa, 'foo', 'ID')
57 self.__verify_last_action(dfa, 'key', 'KEYWORD') 57 self.__verify_last_action(dfa, 'key', 'KEYWORD')
58 self.__verify_last_action(dfa, 'k', 'ID') 58 self.__verify_last_action(dfa, 'k', 'ID')
59 self.__verify_last_action(dfa, 'ke', 'ID') 59 self.__verify_last_action(dfa, 'ke', 'ID')
60 self.__verify_last_action(dfa, 'keys', 'ID') 60 self.__verify_last_action(dfa, 'keys', 'ID')
61 61
62 def test_wrong_action_precedence(self): 62 def test_wrong_action_precedence(self):
63 rules = '''<default> 63 rules = '''<default>
64 /[a-z]+/ { ID } <<break>> 64 /[a-z]+/ { ID } <<break>>
65 "key" { KEYWORD } <<break>>''' 65 "key" { KEYWORD } <<break>>'''
66 automata_for_conditions = process_rules(rules) 66 automata_for_conditions = process_rules(rules)
67 self.assertEqual(len(automata_for_conditions), 1) 67 self.assertEqual(len(automata_for_conditions), 1)
68 self.assertTrue('default' in automata_for_conditions) 68 self.assertTrue('default' in automata_for_conditions)
69 (nfa, dfa) = automata_for_conditions['default'] 69 dfa = automata_for_conditions['default'].dfa()
70 70
71 # The keyword is not recognized because of the rule preference order (ID 71 # The keyword is not recognized because of the rule preference order (ID
72 # is preferred over KEYWORD). 72 # is preferred over KEYWORD).
73 self.__verify_last_action(dfa, 'foo', 'ID') 73 self.__verify_last_action(dfa, 'foo', 'ID')
74 self.__verify_last_action(dfa, 'key', 'ID') 74 self.__verify_last_action(dfa, 'key', 'ID')
OLDNEW
« no previous file with comments | « no previous file | tools/lexer_generator/code_generator_test.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698