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

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

Issue 160443002: Experimental parser: remove match actions (Closed) Base URL: https://v8.googlecode.com/svn/branches/experimental/parser
Patch Set: Created 6 years, 10 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/code_generator.py ('k') | tools/lexer_generator/dfa_optimizer.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 26 matching lines...) Expand all
37 self.__transitions = transitions 37 self.__transitions = transitions
38 self.__action = action 38 self.__action = action
39 assert isinstance(action, Action) 39 assert isinstance(action, Action)
40 40
41 def name(self): 41 def name(self):
42 return self.__name 42 return self.__name
43 43
44 def action(self): 44 def action(self):
45 return self.__action 45 return self.__action
46 46
47 def transition_count(self):
48 return len(self.__transitions)
49
50 def omega_transition(self):
51 if TransitionKey.omega() in self.__transitions:
52 return self.__transitions[TransitionKey.omega()]
53 return None
54
47 def epsilon_closure_iter(self): 55 def epsilon_closure_iter(self):
48 return iter([]) 56 return iter([])
49 57
50 def transition_state_for_key(self, value): 58 def transition_state_for_key(self, value):
51 matches = list(self.transition_state_iter_for_key(value)) 59 matches = list(self.transition_state_iter_for_key(value))
52 assert len(matches) <= 1 60 assert len(matches) <= 1
53 return matches[0] if matches else None 61 return matches[0] if matches else None
54 62
55 def key_state_iter( 63 def key_state_iter(
56 self, 64 self,
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
178 def f(state, visitor_state): 186 def f(state, visitor_state):
179 state_id = len(id_to_state) 187 state_id = len(id_to_state)
180 id_to_state[state_id] = state 188 id_to_state[state_id] = state
181 action = state.action() 189 action = state.action()
182 all_keys.append(state.key_iter()) 190 all_keys.append(state.key_iter())
183 if state in terminal_set: 191 if state in terminal_set:
184 key = ("terminal set", action) 192 key = ("terminal set", action)
185 else: 193 else:
186 # Match actions are valid only if we have matched the whole token, not 194 # Match actions are valid only if we have matched the whole token, not
187 # just some sub-part of it. 195 # just some sub-part of it.
188 assert not action.match_action() 196 # TODO(dcarney): restore
197 # assert not action.is_match_action()
189 key = ("nonterminal set", action) 198 key = ("nonterminal set", action)
190 if not key in initial_partitions: 199 if not key in initial_partitions:
191 initial_partitions[key] = set() 200 initial_partitions[key] = set()
192 initial_partitions[key].add(state_id) 201 initial_partitions[key].add(state_id)
193 self.__dfa.visit_all_states(f) 202 self.__dfa.visit_all_states(f)
194 partitions = set() 203 partitions = set()
195 working_set = set() 204 working_set = set()
196 205
197 # Create StatePartition objects: 206 # Create StatePartition objects:
198 for k, p in initial_partitions.items(): 207 for k, p in initial_partitions.items():
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
375 elif len(intersection) <= len(difference): 384 elif len(intersection) <= len(difference):
376 working_set.add(intersection) 385 working_set.add(intersection)
377 else: 386 else:
378 working_set.add(difference) 387 working_set.add(difference)
379 if old_partitions: 388 if old_partitions:
380 partitions -= old_partitions 389 partitions -= old_partitions
381 if new_partitions: 390 if new_partitions:
382 partitions |= new_partitions 391 partitions |= new_partitions
383 (start_name, mapping) = self.__create_states_from_partitions(partitions) 392 (start_name, mapping) = self.__create_states_from_partitions(partitions)
384 return Dfa(self.__dfa.encoding(), start_name, mapping) 393 return Dfa(self.__dfa.encoding(), start_name, mapping)
OLDNEW
« no previous file with comments | « tools/lexer_generator/code_generator.py ('k') | tools/lexer_generator/dfa_optimizer.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698