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

Side by Side Diff: tools/lexer_generator/lexer_test.py

Issue 77153005: Experimental parser: abstract lexing (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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « tools/lexer_generator/dfa.py ('k') | tools/lexer_generator/nfa.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Copyright 2013 the V8 project authors. All rights reserved. 1 # Copyright 2013 the V8 project authors. All rights reserved.
2 # Redistribution and use in source and binary forms, with or without 2 # Redistribution and use in source and binary forms, with or without
3 # modification, are permitted provided that the following conditions are 3 # modification, are permitted provided that the following conditions are
4 # met: 4 # met:
5 # 5 #
6 # * Redistributions of source code must retain the above copyright 6 # * Redistributions of source code must retain the above copyright
7 # notice, this list of conditions and the following disclaimer. 7 # notice, this list of conditions and the following disclaimer.
8 # * Redistributions in binary form must reproduce the above 8 # * Redistributions in binary form must reproduce the above
9 # copyright notice, this list of conditions and the following 9 # copyright notice, this list of conditions and the following
10 # disclaimer in the documentation and/or other materials provided 10 # disclaimer in the documentation and/or other materials provided
(...skipping 17 matching lines...) Expand all
28 import unittest 28 import unittest
29 from automaton import Action 29 from automaton import Action
30 from rule_parser import RuleProcessor 30 from rule_parser import RuleProcessor
31 31
32 class LexerTestCase(unittest.TestCase): 32 class LexerTestCase(unittest.TestCase):
33 33
34 def __verify_action_stream(self, rules, string, expected): 34 def __verify_action_stream(self, rules, string, expected):
35 expected = map(lambda (action, s) : (Action(None, (action, None)), s), expec ted) 35 expected = map(lambda (action, s) : (Action(None, (action, None)), s), expec ted)
36 expected.append((Action(None, ('terminate', None)), '\0')) 36 expected.append((Action(None, ('terminate', None)), '\0'))
37 automata = RuleProcessor.parse(rules).default_automata() 37 automata = RuleProcessor.parse(rules).default_automata()
38 for automaton in [automata.dfa(), automata.minimal_dfa()]: 38 for automaton in [automata.nfa(), automata.dfa(), automata.minimal_dfa()]:
39 for i, (action, start, stop) in enumerate(automaton.lex(string)): 39 for i, (action, start, stop) in enumerate(automaton.lex(string)):
40 self.assertEquals(expected[i][0], action) 40 self.assertEquals(expected[i][0], action)
41 self.assertEquals(expected[i][1], string[start : stop]) 41 self.assertEquals(expected[i][1], string[start : stop])
42 42
43 def test_simple(self): 43 def test_simple(self):
44 rules = ''' 44 rules = '''
45 eos = [:eos:]; 45 eos = [:eos:];
46 <<default>> 46 <<default>>
47 "(" <|LBRACE|> 47 "(" <|LBRACE|>
48 ")" <|RBRACE|> 48 ")" <|RBRACE|>
(...skipping 22 matching lines...) Expand all
71 rules = ''' 71 rules = '''
72 eos = [:eos:]; 72 eos = [:eos:];
73 digit = [0-9]; 73 digit = [0-9];
74 number = (digit+ ("." digit+)?); 74 number = (digit+ ("." digit+)?);
75 <<default>> 75 <<default>>
76 number <|NUMBER|> 76 number <|NUMBER|>
77 eos <|terminate|>''' 77 eos <|terminate|>'''
78 78
79 string = '555' 79 string = '555'
80 self.__verify_action_stream(rules, string, [('NUMBER', '555')]) 80 self.__verify_action_stream(rules, string, [('NUMBER', '555')])
OLDNEW
« no previous file with comments | « tools/lexer_generator/dfa.py ('k') | tools/lexer_generator/nfa.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698