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

Unified Diff: tools/lexer_generator/automaton.py

Issue 152513004: Experimental parser: some tuple removal (Closed) Base URL: https://v8.googlecode.com/svn/branches/experimental/parser
Patch Set: Created 6 years, 11 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 | « no previous file | tools/lexer_generator/code_generator.jinja » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/lexer_generator/automaton.py
diff --git a/tools/lexer_generator/automaton.py b/tools/lexer_generator/automaton.py
index a911a1bb0f3ae61158ad847927ba261317265eaa..90213cbb3f88138643adb762f4aec8256fb863bd 100644
--- a/tools/lexer_generator/automaton.py
+++ b/tools/lexer_generator/automaton.py
@@ -25,10 +25,48 @@
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-from types import TupleType, ListType
+from types import TupleType, ListType, StringType
from itertools import chain
from transition_keys import TransitionKey
+class Term(object):
+ '''A class representing a function and its arguments.
+ f(a,b,c) would be represented as ('f', a, b, c) where
+ a, b, and c are strings or Terms.'''
+
+ @staticmethod
+ def __verify_string(v):
+ assert (not ',' in v) and (not '(' in v)
+
+ def __init__(self, name, *args):
+ assert type(name) == StringType
+ self.__verify_string(name)
+ for v in args:
+ if type(v) == StringType:
+ self.__verify_string(v)
+ else:
+ assert isinstance(v, self.__class__)
+ self.__tuple = tuple([name] + list(args))
+ self.__str = None
+
+ def name(self):
+ return self.__tuple[0]
+
+ def args(self):
+ return self.__tuple[1:]
+
+ def __hash__(self):
+ return hash(self.__tuple)
+
+ def __eq__(self, other):
+ return (isinstance(other, self.__class__) and
+ self.__tuple == other.__tuple)
+
+ def __str__(self):
+ if self.__str == None:
+ self.__str = '(%s)' % ','.join(map(str, self.__tuple))
+ return self.__str
+
class Action(object):
@staticmethod
@@ -50,8 +88,7 @@ class Action(object):
for action in [entry_action, match_action]:
if action == None:
continue
- assert type(action) == TupleType and len(action)
- assert action[0] != None
+ assert isinstance(action, Term)
assert entry_action or match_action
self.__entry_action = entry_action
self.__match_action = match_action
@@ -79,9 +116,7 @@ class Action(object):
for action in [self.__entry_action, self.__match_action]:
part = ""
if action:
- part += action[0]
- if action[1]:
- part += "(%s)" % str(action[1])
+ part += str(action)
parts.append(part)
return "action< %s >" % " | ".join(parts)
« no previous file with comments | « no previous file | tools/lexer_generator/code_generator.jinja » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698