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

Side by Side Diff: tools/lexer_generator/dfa.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 | « no previous file | tools/lexer_generator/nfa.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 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 matches = reduce(f, self.__transitions.items(), set()) 59 matches = reduce(f, self.__transitions.items(), set())
60 if not matches: 60 if not matches:
61 return None 61 return None
62 assert len(matches) == 1 62 assert len(matches) == 1
63 return iter(matches).next() 63 return iter(matches).next()
64 64
65 def char_matches(self, value): 65 def char_matches(self, value):
66 return self.__matches(lambda k, v : k.matches_char(v), value) 66 return self.__matches(lambda k, v : k.matches_char(v), value)
67 67
68 def key_matches(self, value): 68 def key_matches(self, value):
69 return self.__matches(lambda k, v : k.matches_key(v), value) 69 return self.__matches(lambda k, v : k.is_superset_of_key(v), value)
70 70
71 class Dfa(Automaton): 71 class Dfa(Automaton):
72 72
73 def __init__(self, start_name, mapping): 73 def __init__(self, start_name, mapping):
74 super(Dfa, self).__init__() 74 super(Dfa, self).__init__()
75 self.__terminal_set = set() 75 self.__terminal_set = set()
76 name_map = {} 76 name_map = {}
77 for name, node_data in mapping.items(): 77 for name, node_data in mapping.items():
78 node = DfaState(name, node_data['action']) 78 node = DfaState(name, node_data['action'])
79 name_map[name] = node 79 name_map[name] = node
(...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after
361 elif len(intersection) <= len(difference): 361 elif len(intersection) <= len(difference):
362 working_set.add(intersection) 362 working_set.add(intersection)
363 else: 363 else:
364 working_set.add(difference) 364 working_set.add(difference)
365 if old_partitions: 365 if old_partitions:
366 partitions -= old_partitions 366 partitions -= old_partitions
367 if new_partitions: 367 if new_partitions:
368 partitions |= new_partitions 368 partitions |= new_partitions
369 (start_name, mapping) = self.__merge_partitions(partitions) 369 (start_name, mapping) = self.__merge_partitions(partitions)
370 return Dfa(start_name, mapping) 370 return Dfa(start_name, mapping)
OLDNEW
« no previous file with comments | « no previous file | tools/lexer_generator/nfa.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698