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

Unified Diff: tools/lexer_generator/lexer_test.py

Issue 143643005: Experimental parser: add tests for subgraph handling. (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 | « tools/lexer_generator/automaton.py ('k') | no next file » | 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 f0b7fbca491bef136e5a298da074de85db464870..3c76270fca768d950e697a710b997275f23b479e 100644
--- a/tools/lexer_generator/lexer_test.py
+++ b/tools/lexer_generator/lexer_test.py
@@ -32,10 +32,13 @@ from rule_parser import RuleProcessor
class LexerTestCase(unittest.TestCase):
def __verify_action_stream(self, rules, string, expected):
- expected = map(lambda (action, s) : (Action(None, (action, None)), s), expected)
- automata = RuleProcessor.parse(rules, 'latin1').default_automata()
+ expected = map(lambda (action, s) : (Action(None, (action, None)), s),
+ expected)
+ rule_processor = RuleProcessor.parse(rules, 'latin1')
+ automata = rule_processor.default_automata()
for automaton in [automata.nfa(), automata.dfa(), automata.minimal_dfa()]:
- for i, (action, start, stop) in enumerate(automaton.lex(string)):
+ for i, (action, start, stop) in enumerate(
+ automaton.lex(string, rule_processor.default_action)):
self.assertEquals(expected[i][0], action)
self.assertEquals(expected[i][1], string[start : stop])
@@ -102,3 +105,45 @@ class LexerTestCase(unittest.TestCase):
self.__verify_action_stream(rules, 'ke', [('ID', 'ke')])
self.__verify_action_stream(rules, 'key', [('ID', 'key')])
self.__verify_action_stream(rules, 'keys', [('ID', 'keys')])
+
+ def test_simple_subgraph(self):
+ rules = '''
+ <<default>>
+ /[a-z]/ <|ID|Identifier>
+ " " <|SPACE|>
+ <<Identifier>>
+ /[a-z]/ <|ID|continue>
+ '''
+ self.__verify_action_stream(rules, 'a bc def',
+ [('ID', 'a'), ('SPACE', ' '), ('ID', 'bc'),
+ ('SPACE', ' '), ('ID', 'def')])
+
+ def test_entering_subgraph_without_match_action(self):
+ # Note: there is no match action for entering the subgraph. It means that
+ # one char identifiers are not accepted.
+ rules = '''
+ <<default>>
+ /[a-z]/ <||Identifier>
+ " " <|SPACE|>
+ default_action <ILLEGAL>
+ <<Identifier>>
+ /[a-z]/ <|ID|continue>
+ '''
+ self.__verify_action_stream(rules, 'bc a def',
+ [('ID', 'bc'), ('SPACE', ' '), ('ILLEGAL', 'a'),
+ ('SPACE', ' '), ('ID', 'def')])
+
+ def test_subgraph_with_noncontinue(self):
+ # In the "Identifier" subgraph, we have rules which don't have "continue".
+ rules = '''
+ <<default>>
+ /[b-z]/ <|ID|Identifier>
+ " " <|SPACE|>
+ <<Identifier>>
+ /[b-z]/ <|ID|continue>
+ /[a]/ <|INVALID|>
+ '''
+ self.__verify_action_stream(rules, 'bc ba de',
+ [('ID', 'bc'), ('SPACE', ' '),
+ ('INVALID', 'ba'), ('SPACE', ' '),
+ ('ID', 'de')])
« no previous file with comments | « tools/lexer_generator/automaton.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698