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

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

Issue 66313005: Experimental parser: better escaping (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/regex_lexer.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 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 builder.set_character_classes(parser_state.character_classes) 81 builder.set_character_classes(parser_state.character_classes)
82 assert 'default' in parser_state.rules 82 assert 'default' in parser_state.rules
83 def process(k, v): 83 def process(k, v):
84 assert 'default' in v 84 assert 'default' in v
85 graphs = [] 85 graphs = []
86 for (graph, action) in v['regex']: 86 for (graph, action) in v['regex']:
87 (precedence, code, transition) = action 87 (precedence, code, transition) = action
88 if code: 88 if code:
89 graph = NfaBuilder.add_action(graph, (precedence, code, None)) 89 graph = NfaBuilder.add_action(graph, (precedence, code, None))
90 if transition == 'continue': 90 if transition == 'continue':
91 graph = NfaBuilder.add_continue(graph) 91 if not v['default'][1][2] == 'continue':
92 graph = NfaBuilder.add_continue(graph)
92 elif (transition == 'break' or 93 elif (transition == 'break' or
93 transition == 'terminate' or 94 transition == 'terminate' or
94 transition == 'terminate_illegal'): 95 transition == 'terminate_illegal'):
95 pass 96 NfaBuilder.add_action(graph, (-1, transition, None))
96 else: 97 else:
97 assert k == 'default' 98 assert k == 'default'
98 graph = NfaBuilder.join_subgraph(graph, transition, rule_map[transition] ) 99 graph = NfaBuilder.join_subgraph(graph, transition, rule_map[transition] )
99 graphs.append(graph) 100 graphs.append(graph)
100 graph = NfaBuilder.or_graphs(graphs) 101 graph = NfaBuilder.or_graphs(graphs)
101 # merge default action 102 # merge default action
102 (precedence, code, transition) = v['default'][1] 103 (precedence, code, transition) = v['default'][1]
103 assert transition == 'continue' or transition == 'break' 104 assert transition == 'continue' or transition == 'break'
105 if transition == 'continue':
106 assert k != 'default'
107 # graph = NfaBuilder.apply_modifier('*', graph)
104 if code: 108 if code:
105 graph = NfaBuilder.add_incoming_action(graph, (precedence, code, None)) 109 graph = NfaBuilder.add_incoming_action(graph, (precedence, code, None))
106 rule_map[k] = graph 110 rule_map[k] = graph
107 for k, v in parser_state.rules.items(): 111 for k, v in parser_state.rules.items():
108 if k == 'default': continue 112 if k == 'default': continue
109 process(k, v) 113 process(k, v)
110 process('default', parser_state.rules['default']) 114 process('default', parser_state.rules['default'])
111 html_data = [] 115 html_data = []
112 for rule_name, graph in rule_map.items(): 116 for rule_name, graph in rule_map.items():
113 nfa = builder.nfa(graph) 117 nfa = builder.nfa(graph)
(...skipping 15 matching lines...) Expand all
129 with open(re_file, 'r') as f: 133 with open(re_file, 'r') as f:
130 RuleParser.parse(f.read(), parser_state) 134 RuleParser.parse(f.read(), parser_state)
131 html_data = process_rules(parser_state) 135 html_data = process_rules(parser_state)
132 136
133 html_file = args.html 137 html_file = args.html
134 if html_file: 138 if html_file:
135 html = generate_html(html_data) 139 html = generate_html(html_data)
136 with open(args.html, 'w') as f: 140 with open(args.html, 'w') as f:
137 f.write(html) 141 f.write(html)
138 print "wrote html to %s" % html_file 142 print "wrote html to %s" % html_file
OLDNEW
« no previous file with comments | « no previous file | tools/lexer_generator/regex_lexer.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698