Reviewers: marja,
Message:
Committed patchset #1 manually as r17543 (presubmit successful).
Description:
Experimental parser: fixup unit tests
[email protected]
BUG=
Committed: https://code.google.com/p/v8/source/detail?r=17543
Please review this at https://codereview.chromium.org/64053002/
SVN Base: https://v8.googlecode.com/svn/branches/experimental/parser
Affected files (+20, -11 lines):
M tools/lexer_generator/regex_parser.py
M tools/lexer_generator/rule_parser.py
M tools/lexer_generator/rule_parser_test.py
Index: tools/lexer_generator/regex_parser.py
diff --git a/tools/lexer_generator/regex_parser.py
b/tools/lexer_generator/regex_parser.py
index
1d2ff388670e35273700daf53151cf583124bc94..c508cb35f5ab636ac23ee97c9adb10306c9e8fa9
100644
--- a/tools/lexer_generator/regex_parser.py
+++ b/tools/lexer_generator/regex_parser.py
@@ -135,7 +135,7 @@ class RegexParser:
'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 @@ class RegexParser:
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
Index: tools/lexer_generator/rule_parser.py
diff --git a/tools/lexer_generator/rule_parser.py
b/tools/lexer_generator/rule_parser.py
index
9dc0b4e9672f14e89e71e797c3c075c80e517361..a616fec33d1c2faa49c833e85cf83b94b11f5003
100644
--- a/tools/lexer_generator/rule_parser.py
+++ b/tools/lexer_generator/rule_parser.py
@@ -179,7 +179,7 @@ class RuleParser:
'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 @@ class RuleParser:
__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
Index: tools/lexer_generator/rule_parser_test.py
diff --git a/tools/lexer_generator/rule_parser_test.py
b/tools/lexer_generator/rule_parser_test.py
index
b20427b0c383386163d9e2d6d000f36a717a418f..f0bf6df1d355544f7be24b571a140c6f9b9845b9
100644
--- a/tools/lexer_generator/rule_parser_test.py
+++ b/tools/lexer_generator/rule_parser_test.py
@@ -40,12 +40,12 @@ class RuleParserTestCase(unittest.TestCase):
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.