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

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

Issue 144603003: Experimental parser: better eos 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « tools/lexer_generator/nfa_builder.py ('k') | tools/lexer_generator/rule_parser.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 13 matching lines...) Expand all
24 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 27
28 import ply.lex as lex 28 import ply.lex as lex
29 29
30 class RuleLexer: 30 class RuleLexer:
31 31
32 tokens = ( 32 tokens = (
33 'DEFAULT_ACTION', 33 'DEFAULT_ACTION',
34 'EOS',
34 'CATCH_ALL', 35 'CATCH_ALL',
35 36
36 'IDENTIFIER', 37 'IDENTIFIER',
37 'STRING', 38 'STRING',
38 'REGEX', 39 'REGEX',
39 'CHARACTER_CLASS_REGEX', 40 'CHARACTER_CLASS_REGEX',
40 41
41 'PLUS', 42 'PLUS',
42 'QUESTION_MARK', 43 'QUESTION_MARK',
43 'EQUALS', 44 'EQUALS',
(...skipping 10 matching lines...) Expand all
54 'COMMA', 55 'COMMA',
55 ) 56 )
56 57
57 t_ignore = " \t\n\r" 58 t_ignore = " \t\n\r"
58 59
59 def t_COMMENT(self, t): 60 def t_COMMENT(self, t):
60 r'\#.*[\n\r]+' 61 r'\#.*[\n\r]+'
61 pass 62 pass
62 63
63 __special_identifiers = set(map(lambda s: s.lower(), 64 __special_identifiers = set(map(lambda s: s.lower(),
64 ['DEFAULT_ACTION', 'CATCH_ALL'])) 65 ['DEFAULT_ACTION', 'CATCH_ALL', 'EOS']))
65 66
66 def t_IDENTIFIER(self, t): 67 def t_IDENTIFIER(self, t):
67 r'[a-zA-Z0-9_]+' 68 r'[a-zA-Z0-9_]+'
68 if t.value in self.__special_identifiers: 69 if t.value in self.__special_identifiers:
69 t.type = t.value.upper() 70 t.type = t.value.upper()
70 return t 71 return t
71 72
72 t_STRING = r'"((\\("|\w|\\))|[^\\"])+"' 73 t_STRING = r'"((\\("|\w|\\))|[^\\"])+"'
73 t_REGEX = r'/(\\/|[^/])+/' 74 t_REGEX = r'/(\\/|[^/])+/'
74 t_CHARACTER_CLASS_REGEX = r'\[([^\]]|\\\])+\]' 75 t_CHARACTER_CLASS_REGEX = r'\[([^\]]|\\\])+\]'
(...skipping 16 matching lines...) Expand all
91 r'{' 92 r'{'
92 self.lexer.push_state('code') 93 self.lexer.push_state('code')
93 self.nesting = 1 94 self.nesting = 1
94 return t 95 return t
95 96
96 def t_ANY_error(self, t): 97 def t_ANY_error(self, t):
97 raise Exception("Illegal character '%s'" % t.value[0]) 98 raise Exception("Illegal character '%s'" % t.value[0])
98 99
99 def build(self, **kwargs): 100 def build(self, **kwargs):
100 self.lexer = lex.lex(module=self, **kwargs) 101 self.lexer = lex.lex(module=self, **kwargs)
OLDNEW
« no previous file with comments | « tools/lexer_generator/nfa_builder.py ('k') | tools/lexer_generator/rule_parser.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698