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

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

Issue 62163003: Experimental parser: catch oom from asm when running viz (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 | 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 19 matching lines...) Expand all
30 from rule_parser import RuleParser, RuleParserState 30 from rule_parser import RuleParser, RuleParserState
31 31
32 file_template = ''' 32 file_template = '''
33 <html> 33 <html>
34 <head> 34 <head>
35 <script src="viz.js"></script> 35 <script src="viz.js"></script>
36 <script> 36 <script>
37 function draw(name, id) { 37 function draw(name, id) {
38 code = document.getElementById(id).innerHTML 38 code = document.getElementById(id).innerHTML
39 document.body.innerHTML += "<h1>" + name + "</h1>"; 39 document.body.innerHTML += "<h1>" + name + "</h1>";
40 document.body.innerHTML += Viz(code, 'svg'); 40 try {
41 document.body.innerHTML += Viz(code, 'svg');
42 } catch(e) {
43 document.body.innerHTML += "<h3>error</h3>";
44 }
41 } 45 }
42 </script> 46 </script>
43 </head> 47 </head>
44 <body> 48 <body>
45 %s 49 %s
46 </body> 50 </body>
47 </html>''' 51 </html>'''
48 52
49 script_template = ''' <script type="text/vnd.graphviz" id="%s"> 53 script_template = ''' <script type="text/vnd.graphviz" id="%s">
50 %s 54 %s
(...skipping 27 matching lines...) Expand all
78 graphs = [] 82 graphs = []
79 for (graph, code, action) in v['regex']: 83 for (graph, code, action) in v['regex']:
80 # graphs.append(NfaBuilder.add_action(graph, (action, identifier))) 84 # graphs.append(NfaBuilder.add_action(graph, (action, identifier)))
81 graphs.append(graph) 85 graphs.append(graph)
82 rule_map[k] = builder.nfa(NfaBuilder.or_graphs(graphs)) 86 rule_map[k] = builder.nfa(NfaBuilder.or_graphs(graphs))
83 html_data = [] 87 html_data = []
84 for rule_name, nfa in rule_map.items(): 88 for rule_name, nfa in rule_map.items():
85 (start, dfa_nodes) = nfa.compute_dfa() 89 (start, dfa_nodes) = nfa.compute_dfa()
86 dfa = Dfa(start, dfa_nodes) 90 dfa = Dfa(start, dfa_nodes)
87 html_data.append((rule_name, nfa, dfa)) 91 html_data.append((rule_name, nfa, dfa))
88 print generate_html(html_data) 92 html = generate_html(html_data)
93 # print html
89 94
90 def parse_file(file_name): 95 def parse_file(file_name):
91 parser_state = RuleParserState() 96 parser_state = RuleParserState()
92 with open(file_name, 'r') as f: 97 with open(file_name, 'r') as f:
93 RuleParser.parse(f.read(), parser_state) 98 RuleParser.parse(f.read(), parser_state)
94 process_rules(parser_state) 99 process_rules(parser_state)
95 100
96 if __name__ == '__main__': 101 if __name__ == '__main__':
97 parse_file('src/lexer/lexer_py.re') 102 parse_file('src/lexer/lexer_py.re')
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698