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

Side by Side Diff: mojo/public/bindings/pylib/parse/mojo_lexer.py

Issue 221953005: Mojo: Mojom: Add basic lexer tests, and remove hex float constants. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 8 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 | « no previous file | mojo/public/bindings/pylib/parse/mojo_lexer_unittest.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 2014 The Chromium Authors. All rights reserved. 1 # Copyright 2014 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 import re 5 import re
6 import sys 6 import sys
7 import os.path 7 import os.path
8 8
9 # Try to load the ply module, if not, then assume it is in the third_party 9 # Try to load the ply module, if not, then assume it is in the third_party
10 # directory. 10 # directory.
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 ## 71 ##
72 ## All the tokens recognized by the lexer 72 ## All the tokens recognized by the lexer
73 ## 73 ##
74 tokens = keywords + ( 74 tokens = keywords + (
75 # Identifiers 75 # Identifiers
76 'NAME', 76 'NAME',
77 77
78 # Constants 78 # Constants
79 'ORDINAL', 79 'ORDINAL',
80 'INT_CONST_DEC', 'INT_CONST_OCT', 'INT_CONST_HEX', 80 'INT_CONST_DEC', 'INT_CONST_OCT', 'INT_CONST_HEX',
81 'FLOAT_CONST', 'HEX_FLOAT_CONST', 81 'FLOAT_CONST',
82 'CHAR_CONST', 82 'CHAR_CONST',
83 83
84 # String literals 84 # String literals
85 'STRING_LITERAL', 85 'STRING_LITERAL',
86 86
87 # Operators 87 # Operators
88 'PLUS', 'MINUS', 'TIMES', 'DIVIDE', 'MOD', 88 'PLUS', 'MINUS', 'TIMES', 'DIVIDE', 'MOD',
89 'OR', 'AND', 'NOT', 'XOR', 'LSHIFT', 'RSHIFT', 89 'OR', 'AND', 'NOT', 'XOR', 'LSHIFT', 'RSHIFT',
90 90
91 # Assignment 91 # Assignment
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 # string literals (K&R2: A.2.6) 147 # string literals (K&R2: A.2.6)
148 string_char = r"""([^"\\\n]|"""+escape_sequence+')' 148 string_char = r"""([^"\\\n]|"""+escape_sequence+')'
149 string_literal = '"'+string_char+'*"' 149 string_literal = '"'+string_char+'*"'
150 bad_string_literal = '"'+string_char+'*'+bad_escape+string_char+'*"' 150 bad_string_literal = '"'+string_char+'*'+bad_escape+string_char+'*"'
151 151
152 # floating constants (K&R2: A.2.5.3) 152 # floating constants (K&R2: A.2.5.3)
153 exponent_part = r"""([eE][-+]?[0-9]+)""" 153 exponent_part = r"""([eE][-+]?[0-9]+)"""
154 fractional_constant = r"""([0-9]*\.[0-9]+)|([0-9]+\.)""" 154 fractional_constant = r"""([0-9]*\.[0-9]+)|([0-9]+\.)"""
155 floating_constant = \ 155 floating_constant = \
156 '(((('+fractional_constant+')'+ \ 156 '(((('+fractional_constant+')'+ \
157 exponent_part+'?)|([0-9]+'+exponent_part+'))[FfLl]?)' 157 exponent_part+'?)|([0-9]+'+exponent_part+')))'
158 binary_exponent_part = r'''([pP][+-]?[0-9]+)'''
159 hex_fractional_constant = \
160 '((('+hex_digits+r""")?\."""+hex_digits+')|('+hex_digits+r"""\.))"""
161 hex_floating_constant = \
162 '('+hex_prefix+'('+hex_digits+'|'+hex_fractional_constant+')'+ \
163 binary_exponent_part+'[FfLl]?)'
164 158
165 # Ordinals 159 # Ordinals
166 ordinal = r'@[0-9]+' 160 ordinal = r'@[0-9]+'
167 missing_ordinal_value = r'@' 161 missing_ordinal_value = r'@'
168 # Don't allow ordinal values in octal (even invalid octal, like 09) or 162 # Don't allow ordinal values in octal (even invalid octal, like 09) or
169 # hexadecimal. 163 # hexadecimal.
170 octal_or_hex_ordinal_disallowed = r'@((0[0-9]+)|('+hex_prefix+hex_digits+'))' 164 octal_or_hex_ordinal_disallowed = r'@((0[0-9]+)|('+hex_prefix+hex_digits+'))'
171 165
172 ## 166 ##
173 ## Rules for the normal state 167 ## Rules for the normal state
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
215 209
216 # The following floating and integer constants are defined as 210 # The following floating and integer constants are defined as
217 # functions to impose a strict order (otherwise, decimal 211 # functions to impose a strict order (otherwise, decimal
218 # is placed before the others because its regex is longer, 212 # is placed before the others because its regex is longer,
219 # and this is bad) 213 # and this is bad)
220 # 214 #
221 @TOKEN(floating_constant) 215 @TOKEN(floating_constant)
222 def t_FLOAT_CONST(self, t): 216 def t_FLOAT_CONST(self, t):
223 return t 217 return t
224 218
225 @TOKEN(hex_floating_constant)
226 def t_HEX_FLOAT_CONST(self, t):
227 return t
228
229 @TOKEN(hex_constant) 219 @TOKEN(hex_constant)
230 def t_INT_CONST_HEX(self, t): 220 def t_INT_CONST_HEX(self, t):
231 return t 221 return t
232 222
233 @TOKEN(bad_octal_constant) 223 @TOKEN(bad_octal_constant)
234 def t_BAD_CONST_OCT(self, t): 224 def t_BAD_CONST_OCT(self, t):
235 msg = "Invalid octal constant" 225 msg = "Invalid octal constant"
236 self._error(msg, t) 226 self._error(msg, t)
237 227
238 @TOKEN(octal_constant) 228 @TOKEN(octal_constant)
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
288 return t 278 return t
289 279
290 # Ignore C and C++ style comments 280 # Ignore C and C++ style comments
291 def t_COMMENT(self, t): 281 def t_COMMENT(self, t):
292 r'(/\*(.|\n)*?\*/)|(//.*(\n[ \t]*//.*)*)' 282 r'(/\*(.|\n)*?\*/)|(//.*(\n[ \t]*//.*)*)'
293 pass 283 pass
294 284
295 def t_error(self, t): 285 def t_error(self, t):
296 msg = 'Illegal character %s' % repr(t.value[0]) 286 msg = 'Illegal character %s' % repr(t.value[0])
297 self._error(msg, t) 287 self._error(msg, t)
OLDNEW
« no previous file with comments | « no previous file | mojo/public/bindings/pylib/parse/mojo_lexer_unittest.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698