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

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

Issue 59043005: Experimental rule generator: fix previous commit. (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 | « no previous file | no next file » | 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 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 'LITERAL', 51 'LITERAL',
52 52
53 'RANGE', 53 'RANGE',
54 'NOT', 54 'NOT',
55 'CLASS_LITERAL', 55 'CLASS_LITERAL',
56 'CHARACTER_CLASS', 56 'CHARACTER_CLASS',
57 ) 57 )
58 58
59 states = ( 59 states = (
60 ('class','exclusive'), 60 ('class','exclusive'),
61 ('repeat','exclusive'),
61 ) 62 )
62 63
63 def t_ESCAPED_LITERAL(self, t): 64 def t_ESCAPED_LITERAL(self, t):
64 r'\\\(|\\\)|\\\[|\\\]|\\\||\\\+|\\\*|\\\?|\\\.|\\\\' 65 r'\\\(|\\\)|\\\[|\\\]|\\\||\\\+|\\\*|\\\?|\\\.|\\\\|\\\{|\\\}'
65 t.type = 'LITERAL' 66 t.type = 'LITERAL'
66 t.value = t.value[1:] 67 t.value = t.value[1:]
67 return t 68 return t
68 69
69 t_GROUP_BEGIN = r'\(' 70 t_GROUP_BEGIN = r'\('
70 t_GROUP_END = r'\)' 71 t_GROUP_END = r'\)'
71 72
72 t_REPEAT_BEGIN = r'\{'
73 t_REPEAT_END = r'\}'
74
75 t_OR = r'\|' 73 t_OR = r'\|'
76 t_ONE_OR_MORE = r'\+' 74 t_ONE_OR_MORE = r'\+'
77 t_ZERO_OR_MORE = r'\*' 75 t_ZERO_OR_MORE = r'\*'
78 t_ZERO_OR_ONE = r'\?' 76 t_ZERO_OR_ONE = r'\?'
79 77
80 t_NUMBER = r'[0-9]+'
81 t_COMMA = r','
82
83 t_ANY = r'\.' 78 t_ANY = r'\.'
84 79
85 t_LITERAL = r'.' 80 t_LITERAL = r'.'
86 81
87 def t_CLASS_BEGIN(self, t): 82 def t_CLASS_BEGIN(self, t):
88 r'\[' 83 r'\['
89 self.lexer.push_state('class') 84 self.lexer.push_state('class')
90 return t 85 return t
91 86
92 def t_class_CLASS_END(self, t): 87 def t_class_CLASS_END(self, t):
93 r'\]' 88 r'\]'
94 self.lexer.pop_state() 89 self.lexer.pop_state()
95 return t 90 return t
96 91
97 t_class_RANGE = '-' 92 t_class_RANGE = '-'
98 t_class_NOT = '\^' 93 t_class_NOT = '\^'
99 t_class_CHARACTER_CLASS = r':\w+:' 94 t_class_CHARACTER_CLASS = r':\w+:'
100 95
101 def t_class_ESCAPED_CLASS_LITERAL(self, t): 96 def t_class_ESCAPED_CLASS_LITERAL(self, t):
102 r'\\\^|\\-|\\\[|\\\]|\\\:|\\\w' 97 r'\\\^|\\-|\\\[|\\\]|\\\:|\\\w'
103 t.type = 'CLASS_LITERAL' 98 t.type = 'CLASS_LITERAL'
104 t.value = t.value[1:] 99 t.value = t.value[1:]
105 return t 100 return t
106 101
107 t_class_CLASS_LITERAL = r'[\w $_+]' # fix this 102 t_class_CLASS_LITERAL = r'[\w $_+]' # fix this
108 103
104 def t_REPEAT_BEGIN(self, t):
105 r'\{'
106 self.lexer.push_state('repeat')
107 return t
108
109 def t_repeat_REPEAT_END(self, t):
110 r'\}'
111 self.lexer.pop_state()
112 return t
113
114 t_repeat_NUMBER = r'[0-9]+'
115 t_repeat_COMMA = r','
116
109 t_ANY_ignore = '\n' 117 t_ANY_ignore = '\n'
110 118
111 def t_ANY_error(self, t): 119 def t_ANY_error(self, t):
112 raise Exception("Illegal character '%s'" % t.value[0]) 120 raise Exception("Illegal character '%s'" % t.value[0])
113 121
114 def build(self, **kwargs): 122 def build(self, **kwargs):
115 self.lexer = lex.lex(module=self, **kwargs) 123 self.lexer = lex.lex(module=self, **kwargs)
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698