Revision: 17543
Author:   [email protected]
Date:     Thu Nov  7 08:57:51 2013 UTC
Log:      Experimental parser: fixup unit tests

[email protected]

BUG=

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

Modified:
 /branches/experimental/parser/tools/lexer_generator/regex_parser.py
 /branches/experimental/parser/tools/lexer_generator/rule_parser.py
 /branches/experimental/parser/tools/lexer_generator/rule_parser_test.py

=======================================
--- /branches/experimental/parser/tools/lexer_generator/regex_parser.py Wed Nov 6 08:50:55 2013 UTC +++ /branches/experimental/parser/tools/lexer_generator/regex_parser.py Thu Nov 7 08:57:51 2013 UTC
@@ -135,7 +135,7 @@
     'empty :'

   def p_error(self, p):
-    raise Exception("Syntax error in input '%s'" % p)
+    raise Exception("Syntax error in input '%s'" % str(p))

   @staticmethod
   def __cat(left, right):
@@ -156,4 +156,8 @@
       parser = RegexParser()
       parser.build()
       RegexParser.__static_instance = parser
-    return parser.parser.parse(data, lexer=parser.lexer.lexer)
+    try:
+      return parser.parser.parse(data, lexer=parser.lexer.lexer)
+    except Exception as e:
+      RegexParser.__static_instance = None
+      raise e
=======================================
--- /branches/experimental/parser/tools/lexer_generator/rule_parser.py Thu Nov 7 08:25:59 2013 UTC +++ /branches/experimental/parser/tools/lexer_generator/rule_parser.py Thu Nov 7 08:57:51 2013 UTC
@@ -179,7 +179,7 @@
     'empty :'

   def p_error(self, p):
-    raise Exception("Syntax error in input '%s'" % p)
+    raise Exception("Syntax error in input '%s'" % str(p))

   def build(self, **kwargs):
     self.parser = yacc.yacc(module=self, debug=0, write_tables=0, **kwargs)
@@ -189,10 +189,15 @@
   __static_instance = None
   @staticmethod
   def parse(data, parser_state):
-    if not RuleParser.__static_instance:
-      RuleParser.__static_instance = RuleParser()
-      RuleParser.__static_instance.build()
     parser = RuleParser.__static_instance
+    if not parser:
+      parser = RuleParser()
+      parser.build()
+      RuleParser.__static_instance = parser
     parser.__state = parser_state
-    parser.parser.parse(data, lexer=parser.lexer.lexer)
+    try:
+      parser.parser.parse(data, lexer=parser.lexer.lexer)
+    except Exception as e:
+      RuleParser.__static_instance = None
+      raise e
     parser.__state = None
=======================================
--- /branches/experimental/parser/tools/lexer_generator/rule_parser_test.py Wed Nov 6 09:14:29 2013 UTC +++ /branches/experimental/parser/tools/lexer_generator/rule_parser_test.py Thu Nov 7 08:57:51 2013 UTC
@@ -40,12 +40,12 @@
    def test_basic(self):
      self.parse('''
 alias = /regex/;
-<cond1> /regex/ :=> cond2
-<cond1> alias :=> cond2
+<cond1> /regex/ <<cond2>>
+<cond1> alias <<cond2>>
 <cond2> /regex/ {body}
 <cond2> alias {body}
-<cond3> /regex/ => cond4 {body}
-<cond3> alias => cond4 {body}''')
+<cond3> /regex/ {body} <<cond4>>
+<cond3> alias {body} <<cond4>>''')

      self.assertTrue(len(self.state.aliases), 1)
      self.assertTrue('alias' in self.state.aliases)

--
--
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