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

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

Issue 63943005: Experimental lexer generator: refactor(TransitionKey) += comments. (Closed) Base URL: https://v8.googlecode.com/svn/branches/experimental/parser
Patch Set: moar comments 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 | « tools/lexer_generator/dfa.py ('k') | tools/lexer_generator/transition_keys.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 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 self.__add_transition(TransitionKey.epsilon(), end) 98 self.__add_transition(TransitionKey.epsilon(), end)
99 99
100 def __matches(self, match_func, value): 100 def __matches(self, match_func, value):
101 f = lambda acc, (k, vs): acc | vs if match_func(k, value) else acc 101 f = lambda acc, (k, vs): acc | vs if match_func(k, value) else acc
102 return reduce(f, self.__transitions.items(), set()) 102 return reduce(f, self.__transitions.items(), set())
103 103
104 def char_matches(self, value): 104 def char_matches(self, value):
105 return self.__matches(lambda k, v : k.matches_char(v), value) 105 return self.__matches(lambda k, v : k.matches_char(v), value)
106 106
107 def key_matches(self, value): 107 def key_matches(self, value):
108 return self.__matches(lambda k, v : k.matches_key(v), value) 108 return self.__matches(lambda k, v : k.is_superset_of_key(v), value)
109 109
110 class Nfa(Automaton): 110 class Nfa(Automaton):
111 111
112 def __init__(self, start, end, nodes_created): 112 def __init__(self, start, end, nodes_created):
113 super(Nfa, self).__init__() 113 super(Nfa, self).__init__()
114 self.__start = start 114 self.__start = start
115 self.__end = end 115 self.__end = end
116 self.__verify(nodes_created) 116 self.__verify(nodes_created)
117 117
118 def start_set(self): 118 def start_set(self):
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
181 for state in reduce(f, nfa_state_set, set()): 181 for state in reduce(f, nfa_state_set, set()):
182 match_states.add(state) 182 match_states.add(state)
183 transition_state = Nfa.__to_dfa(match_states, dfa_nodes, end_node) 183 transition_state = Nfa.__to_dfa(match_states, dfa_nodes, end_node)
184 dfa_nodes[name]['transitions'][key] = transition_state 184 dfa_nodes[name]['transitions'][key] = transition_state
185 return name 185 return name
186 186
187 def compute_dfa(self): 187 def compute_dfa(self):
188 dfa_nodes = {} 188 dfa_nodes = {}
189 start_name = self.__to_dfa(set([self.__start]), dfa_nodes, self.__end) 189 start_name = self.__to_dfa(set([self.__start]), dfa_nodes, self.__end)
190 return (start_name, dfa_nodes) 190 return (start_name, dfa_nodes)
OLDNEW
« no previous file with comments | « tools/lexer_generator/dfa.py ('k') | tools/lexer_generator/transition_keys.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698