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

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

Issue 69293005: Experimental parser: add catch all rule (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
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 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
46 <cond2> alias {body} 46 <cond2> alias {body}
47 <cond3> /regex/ {body} <<cond1>> 47 <cond3> /regex/ {body} <<cond1>>
48 <cond3> alias {body} <<cond1>>''') 48 <cond3> alias {body} <<cond1>>''')
49 49
50 self.assertTrue(len(self.state.aliases), 1) 50 self.assertTrue(len(self.state.aliases), 1)
51 self.assertTrue('alias' in self.state.aliases) 51 self.assertTrue('alias' in self.state.aliases)
52 self.assertEquals(self.state.aliases['alias'], RegexParser.parse('regex')) 52 self.assertEquals(self.state.aliases['alias'], RegexParser.parse('regex'))
53 53
54 self.assertTrue(len(self.state.rules), 2) 54 self.assertTrue(len(self.state.rules), 2)
55 self.assertTrue('cond1' in self.state.rules) 55 self.assertTrue('cond1' in self.state.rules)
56 self.assertEquals(len(self.state.rules['cond1']), 2) 56 self.assertEquals(len(self.state.rules['cond1']['regex']), 2)
57 # self.assertTrue('regex2' in self.state.rules['cond1']) 57 # self.assertTrue('regex2' in self.state.rules['cond1'])
58 # self.assertEquals(self.state.rules['cond1']['regex2'], 58 # self.assertEquals(self.state.rules['cond1']['regex2'],
59 # ('condition', 'cond2')) 59 # ('condition', 'cond2'))
60 60
61 self.assertTrue('cond2' in self.state.rules) 61 self.assertTrue('cond2' in self.state.rules)
62 self.assertEquals(len(self.state.rules['cond2']), 2) 62 self.assertEquals(len(self.state.rules['cond2']['regex']), 2)
63 # self.assertTrue('regex3' in self.state.rules['cond2']) 63 # self.assertTrue('regex3' in self.state.rules['cond2'])
64 # self.assertEquals(self.state.rules['cond2']['regex3'], 64 # self.assertEquals(self.state.rules['cond2']['regex3'],
65 # ('body', 'body')) 65 # ('body', 'body'))
66 66
67 self.assertTrue('cond3' in self.state.rules) 67 self.assertTrue('cond3' in self.state.rules)
68 self.assertEquals(len(self.state.rules['cond3']), 2) 68 self.assertEquals(len(self.state.rules['cond3']['regex']), 2)
69 # self.assertTrue('regex4' in self.state.rules['cond3']) 69 # self.assertTrue('regex4' in self.state.rules['cond3'])
70 # self.assertEquals(self.state.rules['cond3']['regex4'], 70 # self.assertEquals(self.state.rules['cond3']['regex4'],
71 # ('condition_and_body', 'cond4', 'body')) 71 # ('condition_and_body', 'cond4', 'body'))
72 72
73 def test_more_complicated(self): 73 def test_more_complicated(self):
74 self.parse(''' 74 self.parse('''
75 alias = "regex;with;semicolon"; 75 alias = "regex;with;semicolon";
76 <cond1> "regex3}with}braces}" {body {with} braces } 76 <cond1> "regex3}with}braces}" {body {with} braces }
77 <cond1> "regex4{with{braces}" {body {with} braces }''') 77 <cond1> "regex4{with{braces}" {body {with} braces }''')
78 78
79 self.assertEquals(self.state.aliases['alias'], 79 self.assertEquals(self.state.aliases['alias'],
80 RegexParser.parse("regex;with;semicolon")) 80 RegexParser.parse("regex;with;semicolon"))
81 self.assertTrue('cond1' in self.state.rules) 81 self.assertTrue('cond1' in self.state.rules)
82 self.assertEquals(len(self.state.rules['cond1']), 2) 82 self.assertEquals(len(self.state.rules['cond1']['regex']), 2)
83 83
84 # self.assertEquals( 84 # self.assertEquals(
85 # self.parse['cond1']['regex4{with{braces}'], 85 # self.parse['cond1']['regex4{with{braces}'],
86 # ('body', 'body {with} braces }')) 86 # ('body', 'body {with} braces }'))
87 87
88 def test_body_with_if(self): 88 def test_body_with_if(self):
89 self.parse('<cond> "regex" { if (foo) { bar } }') 89 self.parse('<cond> "regex" { if (foo) { bar } }')
90 # self.assertEquals( 90 # self.assertEquals(
91 # self.parse['cond']['regex'], 91 # self.parse['cond']['regex'],
92 # ('body', 'if (foo) { bar }')) 92 # ('body', 'if (foo) { bar }'))
93 93
94 def test_regexp_with_count(self): 94 def test_regexp_with_count(self):
95 self.parse('<cond> /regex{1,3}/ { if (foo) { bar } }') 95 self.parse('<cond> /regex{1,3}/ { if (foo) { bar } }')
96 # self.assertEquals( 96 # self.assertEquals(
97 # self.parse['cond']['regex{1,3}'], 97 # self.parse['cond']['regex{1,3}'],
98 # ('body', 'if (foo) { bar }')) 98 # ('body', 'if (foo) { bar }'))
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698