Revision: 17436
Author:   [email protected]
Date:     Wed Oct 30 16:36:45 2013 UTC
Log:      Experimental parser generator: Saner rule parsing.

BUG=

[email protected]

Review URL: https://codereview.chromium.org/47493004
http://code.google.com/p/v8/source/detail?r=17436

Modified:
 /branches/experimental/parser/tools/lexer_generator/rule_lexer.py
 /branches/experimental/parser/tools/lexer_generator/rule_parser.py

=======================================
--- /branches/experimental/parser/tools/lexer_generator/rule_lexer.py Wed Oct 30 14:06:48 2013 UTC +++ /branches/experimental/parser/tools/lexer_generator/rule_lexer.py Wed Oct 30 16:36:45 2013 UTC
@@ -31,22 +31,62 @@

   tokens = (
       'ALIAS',
-      'CONDITION_TRANSITION',
-      'CONDITION'
+      'EQUALS',
+      'REGEX',
+      'CONDITION',
+      'CONDITION_BEGIN',
+      'CONDITION_END',
+      'REGEX_AND_TRANSITION',
+      'REGEX_AND_BODY',
       )

-  t_ignore = " \t\n"
+  t_ANY_ignore = " \t\n"
+
+  states = (
+    ('afterAlias', 'exclusive'),
+    ('afterAliasEquals', 'exclusive'),
+    ('inCondition', 'exclusive'),
+    ('seenCondition', 'exclusive'),
+    ('afterCondition', 'exclusive'))

   def t_ALIAS(self, t):
-    r'\s*(?P<name>[a-zA-Z0-9_]+)\s*=\s*(?P<regex>.+)\s*;\s*'
+    r'[a-zA-Z0-9_]+'
+    self.lexer.begin('afterAlias')
     return t

-  def t_CONDITION_TRANSITION(self, t):
-    r'\s*<(?P<old>[a-zA-Z]+)>\s*(?P<regex>.+)\s*:=>\s*(?P<new>.+)\s*'
+  def t_afterAlias_EQUALS(self, t):
+    r'='
+    self.lexer.begin('afterAliasEquals')
     return t

-  def t_CONDITION(self, t):
-    r'\s*<(?P<old>[a-zA-Z]+)>\s*(?P<regex>.+)\s*{(?P<body>.+)}\s*'
+  def t_afterAliasEquals_REGEX(self, t):
+    r'(?P<regex>.+)\s*;'
+    self.lexer.begin('INITIAL')
+    return t
+
+  def t_CONDITION_BEGIN(self, t):
+    r'<'
+    self.lexer.begin('inCondition')
+    return t
+
+  def t_inCondition_CONDITION(self, t):
+    r'[a-zA-Z0-9_]+'
+    self.lexer.begin('seenCondition')
+    return t
+
+  def t_seenCondition_CONDITION_END(self, t):
+    r'>'
+    self.lexer.begin('afterCondition')
+    return t
+
+  def t_afterCondition_REGEX_AND_TRANSITION(self, t):
+    r'(?P<regex>.+)\s*:=>\s*(?P<new>.+)\s*'
+    self.lexer.begin('INITIAL')
+    return t
+
+  def t_afterCondition_REGEX_AND_BODY(self, t):
+    r'(?P<regex>.+)\s*{\s*(?P<body>.+)\s*}\s*'
+    self.lexer.begin('INITIAL')
     return t

   def t_error(self, t):
=======================================
--- /branches/experimental/parser/tools/lexer_generator/rule_parser.py Wed Oct 30 14:06:48 2013 UTC +++ /branches/experimental/parser/tools/lexer_generator/rule_parser.py Wed Oct 30 16:36:45 2013 UTC
@@ -36,23 +36,22 @@
   transitions = dict()

   def p_statement_alias(self, p):
-    'statement : ALIAS'
-    name = self.lexer.lexer.lexmatch.group('name')
+    'statement : ALIAS EQUALS REGEX'
     regex = self.lexer.lexer.lexmatch.group('regex')
-    self.aliases[name] = regex
+    self.aliases[p[1]] = regex

   def p_statement_condition_transition(self, p):
-    'statement : CONDITION_TRANSITION'
-    old_condition = self.lexer.lexer.lexmatch.group('old')
+ 'statement : CONDITION_BEGIN CONDITION CONDITION_END REGEX_AND_TRANSITION'
+    old_condition = p[2]
     regex = self.lexer.lexer.lexmatch.group('regex')
     new_condition = self.lexer.lexer.lexmatch.group('new')
     if old_condition not in self.transitions:
       self.transitions[old_condition] = []
     self.transitions[old_condition].append((regex, new_condition))

-  def p_statement_condition(self, p):
-    'statement : CONDITION'
-    old_condition = self.lexer.lexer.lexmatch.group('old')
+  def p_statement_condition_body(self, p):
+    'statement : CONDITION_BEGIN CONDITION CONDITION_END REGEX_AND_BODY'
+    old_condition = p[2]
     regex = self.lexer.lexer.lexmatch.group('regex')
     body = self.lexer.lexer.lexmatch.group('body')
     if old_condition not in self.transitions:

--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
--- You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to