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

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

Issue 73143002: Experimental parser: cleanup after grammar refactor (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 | « tools/lexer_generator/automata_test.py ('k') | tools/lexer_generator/code_generator_test.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 13 matching lines...) Expand all
24 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 27
28 from types import TupleType, ListType 28 from types import TupleType, ListType
29 from itertools import chain 29 from itertools import chain
30 from transition_keys import TransitionKey 30 from transition_keys import TransitionKey
31 31
32 class Action(object): 32 class Action(object):
33 33
34 def __init__(self, entry_action, match_action = None, precedence = -1): 34 def __init__(self, entry_action, match_action, precedence = -1):
35 assert type 35 for action in [entry_action, match_action]:
36 if action == None:
37 continue
38 assert type(action) == TupleType and len(action)
39 assert action[0] != None
36 self.__entry_action = entry_action 40 self.__entry_action = entry_action
37 self.__match_action = match_action 41 self.__match_action = match_action
38 self.__precedence = precedence 42 self.__precedence = precedence
39 43
40 def entry_action(self): 44 def entry_action(self):
41 return self.__entry_action 45 return self.__entry_action
42 46
43 def match_action(self): 47 def match_action(self):
44 return self.__match_action 48 return self.__match_action
45 49
46 def precedence(self): 50 def precedence(self):
47 return self.__precedence 51 return self.__precedence
48 52
49 def __hash__(self): 53 def __hash__(self):
50 return hash((self.__entry_action, self.__match_action)) 54 return hash((self.__entry_action, self.__match_action))
51 55
52 def __eq__(self, other): 56 def __eq__(self, other):
53 return (isinstance(other, self.__class__) and 57 return (isinstance(other, self.__class__) and
54 self.__entry_action == other.__entry_action and 58 self.__entry_action == other.__entry_action and
55 self.__match_action == other.__match_action) 59 self.__match_action == other.__match_action)
56 60
57 def __str__(self): 61 def __str__(self):
58 return "action<%s, %s>" % (self.__entry_action, self.__match_action) 62 parts = []
63 for action in [self.__entry_action, self.__match_action]:
64 part = ""
65 if action:
66 part += action[0]
67 if action[1]:
68 part += "(%s)" % action[1]
69 parts.append(part)
70 return "action< %s >" % " | ".join(parts)
59 71
60 class AutomatonState(object): 72 class AutomatonState(object):
61 73
62 __node_number_counter = 0 74 __node_number_counter = 0
63 75
64 def __init__(self): 76 def __init__(self):
65 self.__node_number = AutomatonState.__node_number_counter 77 self.__node_number = AutomatonState.__node_number_counter
66 AutomatonState.__node_number_counter += 1 78 AutomatonState.__node_number_counter += 1
67 79
68 def __hash__(self): 80 def __hash__(self):
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
165 node [shape = doublecircle, style=unfilled]; %s 177 node [shape = doublecircle, style=unfilled]; %s
166 node [shape = circle]; 178 node [shape = circle];
167 %s 179 %s
168 %s 180 %s
169 } 181 }
170 ''' % (start_shape, 182 ''' % (start_shape,
171 start_number, 183 start_number,
172 " ".join(terminals), 184 " ".join(terminals),
173 "\n".join(edge_content), 185 "\n".join(edge_content),
174 "\n".join(node_content)) 186 "\n".join(node_content))
OLDNEW
« no previous file with comments | « tools/lexer_generator/automata_test.py ('k') | tools/lexer_generator/code_generator_test.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698