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

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

Issue 135053003: Experimental parser: remove inline code from lexer rules (Closed) Base URL: https://v8.googlecode.com/svn/branches/experimental/parser
Patch Set: Created 6 years, 11 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/rule_parser.py ('k') | no next file » | 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 25 matching lines...) Expand all
36 self.state = RuleParserState(KeyEncoding.get('latin1')) 36 self.state = RuleParserState(KeyEncoding.get('latin1'))
37 37
38 def parse(self, string): 38 def parse(self, string):
39 return self.state.parse(string) 39 return self.state.parse(string)
40 40
41 def test_basic(self): 41 def test_basic(self):
42 self.parse(''' 42 self.parse('''
43 alias = /regex/; 43 alias = /regex/;
44 <<cond1>> /regex/ <||cond2> 44 <<cond1>> /regex/ <||cond2>
45 <<cond1>> alias <||cond2> 45 <<cond1>> alias <||cond2>
46 <<cond2>> /regex/ <|{body}|> 46 <<cond2>> /regex/ <|body|>
47 <<cond2>> alias <|{body}|> 47 <<cond2>> alias <|body|>
48 <<cond3>> /regex/ <{body}||> 48 <<cond3>> /regex/ <body||>
49 <<cond3>> alias <{body}||>''') 49 <<cond3>> alias <body||>''')
50 50
51 self.assertTrue(len(self.state.aliases), 1) 51 self.assertTrue(len(self.state.aliases), 1)
52 self.assertTrue('alias' in self.state.aliases) 52 self.assertTrue('alias' in self.state.aliases)
53 self.assertEquals(self.state.aliases['alias'], RegexParser.parse('regex')) 53 self.assertEquals(self.state.aliases['alias'], RegexParser.parse('regex'))
54 54
55 self.assertTrue(len(self.state.rules), 2) 55 self.assertTrue(len(self.state.rules), 2)
56 self.assertTrue('cond1' in self.state.rules) 56 self.assertTrue('cond1' in self.state.rules)
57 self.assertEquals(len(self.state.rules['cond1']['regex']), 2) 57 self.assertEquals(len(self.state.rules['cond1']['regex']), 2)
58 # self.assertTrue('regex2' in self.state.rules['cond1']) 58 # self.assertTrue('regex2' in self.state.rules['cond1'])
59 # self.assertEquals(self.state.rules['cond1']['regex2'], 59 # self.assertEquals(self.state.rules['cond1']['regex2'],
60 # ('condition', 'cond2')) 60 # ('condition', 'cond2'))
61 61
62 self.assertTrue('cond2' in self.state.rules) 62 self.assertTrue('cond2' in self.state.rules)
63 self.assertEquals(len(self.state.rules['cond2']['regex']), 2) 63 self.assertEquals(len(self.state.rules['cond2']['regex']), 2)
64 # self.assertTrue('regex3' in self.state.rules['cond2']) 64 # self.assertTrue('regex3' in self.state.rules['cond2'])
65 # self.assertEquals(self.state.rules['cond2']['regex3'], 65 # self.assertEquals(self.state.rules['cond2']['regex3'],
66 # ('body', 'body')) 66 # ('body', 'body'))
67 67
68 self.assertTrue('cond3' in self.state.rules) 68 self.assertTrue('cond3' in self.state.rules)
69 self.assertEquals(len(self.state.rules['cond3']['regex']), 2) 69 self.assertEquals(len(self.state.rules['cond3']['regex']), 2)
70 # self.assertTrue('regex4' in self.state.rules['cond3']) 70 # self.assertTrue('regex4' in self.state.rules['cond3'])
71 # self.assertEquals(self.state.rules['cond3']['regex4'], 71 # self.assertEquals(self.state.rules['cond3']['regex4'],
72 # ('condition_and_body', 'cond4', 'body')) 72 # ('condition_and_body', 'cond4', 'body'))
73 73
74 def test_more_complicated(self): 74 def test_more_complicated(self):
75 self.parse(''' 75 self.parse('''
76 alias = "regex;with;semicolon"; 76 alias = "regex;with;semicolon";
77 <<cond1>> "regex3}with}braces}" <|{body {with} braces }|> 77 <<cond1>> "regex3}with}braces}" <|body|>
78 <<cond1>> "regex4{with{braces}" <{body {with} braces }||>''') 78 <<cond1>> "regex4{with{braces}" <body||>''')
79 79
80 self.assertEquals(self.state.aliases['alias'], 80 self.assertEquals(self.state.aliases['alias'],
81 RegexParser.parse("regex;with;semicolon")) 81 RegexParser.parse("regex;with;semicolon"))
82 self.assertTrue('cond1' in self.state.rules) 82 self.assertTrue('cond1' in self.state.rules)
83 self.assertEquals(len(self.state.rules['cond1']['regex']), 2) 83 self.assertEquals(len(self.state.rules['cond1']['regex']), 2)
84 84
85 # self.assertEquals( 85 # self.assertEquals(
86 # self.parse['cond1']['regex4{with{braces}'], 86 # self.parse['cond1']['regex4{with{braces}'],
87 # ('body', 'body {with} braces }')) 87 # ('body', 'body {with} braces }'))
88
89 def test_body_with_if(self):
90 self.parse('<<cond>> "regex" <|{ if (foo) { bar } }|>')
91 # self.assertEquals(
92 # self.parse['cond']['regex'],
93 # ('body', 'if (foo) { bar }'))
94
95 def test_regexp_with_count(self):
96 self.parse('<<cond>> /regex{1,3}/ <|{ if (foo) { bar } }|>')
97 # self.assertEquals(
98 # self.parse['cond']['regex{1,3}'],
99 # ('body', 'if (foo) { bar }'))
OLDNEW
« no previous file with comments | « tools/lexer_generator/rule_parser.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698