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

Unified Diff: tools/lexer_generator/lexer_test.py

Issue 68343004: Experimental parser: better actions (Closed) Base URL: https://v8.googlecode.com/svn/branches/experimental/parser
Patch Set: 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « tools/lexer_generator/generator.py ('k') | tools/lexer_generator/nfa.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/lexer_generator/lexer_test.py
diff --git a/tools/lexer_generator/lexer_test.py b/tools/lexer_generator/lexer_test.py
index 0596c84a14b43f66a0bc80248be74f5affb3a628..a165349547c72b5a7c81886c76bb0ea9593b002c 100644
--- a/tools/lexer_generator/lexer_test.py
+++ b/tools/lexer_generator/lexer_test.py
@@ -30,60 +30,44 @@ from generator import Generator
class LexerTestCase(unittest.TestCase):
- def __verify_action_stream(self, stream, expected_stream):
- for (ix, item) in enumerate(expected_stream):
- self.assertEquals(stream[ix][0], item[0])
- self.assertEquals(stream[ix][4], item[1])
+ def __verify_action_stream(self, rules, string, expected_stream):
+ expected_stream.append(('terminate', '\0'))
+ for i, (action, start, stop) in enumerate(Generator(rules).lex(string)):
+ self.assertEquals(expected_stream[i][0], action)
+ self.assertEquals(expected_stream[i][1], string[start : stop])
def test_simple(self):
rules = '''
<default>
- "(" { LBRACE } <<continue>>
- ")" { RBRACE } <<continue>>
+ "(" { LBRACE }
+ ")" { RBRACE }
- "foo" { FOO } <<continue>>
- eof <<terminate>>
- default <<break>>'''
-
- generator = Generator(rules)
+ "foo" { FOO }
+ eof <<terminate>>'''
string = 'foo()\0'
- self.__verify_action_stream(
- generator.lex(string),
+ self.__verify_action_stream(rules, string,
[('FOO', 'foo'), ('LBRACE', '('), ('RBRACE', ')')])
def test_maximal_matching(self):
rules = '''
<default>
- "<" { LT } <<continue>>
- "<<" { SHL } <<continue>>
- " " { SPACE } <<continue>>
- eof <<terminate>>
- default <<break>>'''
-
- generator = Generator(rules)
+ "<" { LT }
+ "<<" { SHL }
+ " " { SPACE }
+ eof <<terminate>>'''
string = '<< <\0'
- self.__verify_action_stream(
- generator.lex(string),
+ self.__verify_action_stream(rules, string,
[('SHL', '<<'), ('SPACE', ' '), ('LT', '<')])
-
def test_consecutive_epsilon_transitions(self):
- # This rule set will create a NFA where we first have an epsilon transition,
- # then following that, an epsilon transition with an action. This will test
- # that the action is correctly pulled forward when creating the dfa.
rules = '''
digit = [0-9];
number = (digit+ ("." digit+)?);
<default>
- number { NUMBER } <<continue>>
- eof <<terminate>>
- default <<break>>'''
-
- generator = Generator(rules)
+ number { NUMBER }
+ eof <<terminate>>'''
string = '555\0'
- self.__verify_action_stream(
- generator.lex(string),
- [('NUMBER', '555')])
+ self.__verify_action_stream(rules, string, [('NUMBER', '555')])
« no previous file with comments | « tools/lexer_generator/generator.py ('k') | tools/lexer_generator/nfa.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698