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

Unified Diff: tools/lexer_generator/dfa_minimizer.py

Issue 169523003: Experimental parser: split and rename some files (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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « tools/lexer_generator/dfa.py ('k') | tools/lexer_generator/dfa_optimizer.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/lexer_generator/dfa_minimizer.py
diff --git a/tools/lexer_generator/dfa.py b/tools/lexer_generator/dfa_minimizer.py
similarity index 81%
copy from tools/lexer_generator/dfa.py
copy to tools/lexer_generator/dfa_minimizer.py
index 5a3dd5e4b364588ef2e1eb893056661d41af8cb0..9b42f604ff11cb3b34fd7a710f0dd8dac29de4ea 100644
--- a/tools/lexer_generator/dfa.py
+++ b/tools/lexer_generator/dfa_minimizer.py
@@ -1,4 +1,4 @@
-# Copyright 2013 the V8 project authors. All rights reserved.
+# Copyright 2014 the V8 project authors. All rights reserved.
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are
# met:
@@ -26,99 +26,8 @@
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
from itertools import chain
-from automaton import *
-from transition_keys import TransitionKey
-
-class DfaState(AutomatonState):
-
- def __init__(self, name, action, transitions):
- super(DfaState, self).__init__()
- self.__name = name
- self.__transitions = transitions
- self.__action = action
- assert isinstance(action, Action)
-
- def name(self):
- return self.__name
-
- def action(self):
- return self.__action
-
- def transition_count(self):
- return len(self.__transitions)
-
- def omega_transition(self):
- if TransitionKey.omega() in self.__transitions:
- return self.__transitions[TransitionKey.omega()]
- return None
-
- def epsilon_closure_iter(self):
- return iter([])
-
- def transition_state_for_key(self, value):
- matches = list(self.transition_state_iter_for_key(value))
- assert len(matches) <= 1
- return matches[0] if matches else None
-
- def key_state_iter(
- self,
- key_filter = lambda x: True,
- state_filter = lambda x: True,
- match_func = lambda x, y: True,
- yield_func = lambda x, y: (x, y)):
- for key, state in self.__transitions.items():
- if key_filter(key) and state_filter(state) and match_func(key, state):
- yield yield_func(key, state)
-
-class Dfa(Automaton):
-
- @staticmethod
- def __add_transition(transitions, key, state):
- assert key != None
- assert not key == TransitionKey.epsilon()
- assert not transitions.has_key(key)
- transitions[key] = state
-
- def __init__(self, encoding, start_name, mapping):
- super(Dfa, self).__init__(encoding)
- self.__terminal_set = set()
- name_map = {}
- for name, node_data in mapping.items():
- transitions = {}
- node = DfaState(name, node_data['action'], transitions)
- name_map[name] = (node, transitions)
- if node_data['terminal']:
- self.__terminal_set.add(node)
- for name, node_data in mapping.items():
- (node, transitions) = name_map[name]
- inversion = {}
- for key, state in node_data['transitions'].items():
- if not state in inversion:
- inversion[state] = []
- inversion[state].append(key)
- for state, keys in inversion.items():
- merged_key = TransitionKey.merged_key(encoding, keys)
- self.__add_transition(transitions, merged_key, name_map[state][0])
- self.__start = name_map[start_name][0]
- self.__node_count = len(mapping)
- self.__verify()
-
- def __verify(self):
- assert self.__terminal_set
- state_count = self.visit_all_states(lambda state, count: count + 1, 0)
- assert self.__node_count == state_count
-
- def node_count(self):
- return self.__node_count
-
- def start_state(self):
- return self.__start
-
- def terminal_set(self):
- return set(self.__terminal_set)
-
- def minimize(self):
- return DfaMinimizer(self).minimize()
+from dfa import Dfa
+from transition_key import TransitionKey
class StatePartition(object):
« no previous file with comments | « tools/lexer_generator/dfa.py ('k') | tools/lexer_generator/dfa_optimizer.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698