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

Side by Side Diff: mojo/public/tools/bindings/pylib/mojom/parse/lexer.py

Issue 474063002: Mojo: add support for {double,float}.{INFINITY,NEGATIVE_INFINITY,NAN} (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix test Created 6 years, 4 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
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 imp 5 import imp
6 import os.path 6 import os.path
7 import sys 7 import sys
8 8
9 def _GetDirAbove(dirname): 9 def _GetDirAbove(dirname):
10 """Returns the directory "above" this file containing |dirname| (which must 10 """Returns the directory "above" this file containing |dirname| (which must
(...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_HEX', 80 'INT_CONST_DEC', 'INT_CONST_HEX',
81 'FLOAT_CONST', 81 'FLOAT_CONST', 'FLOAT_BUILTIN',
82 82
83 # String literals 83 # String literals
84 'STRING_LITERAL', 84 'STRING_LITERAL',
85 85
86 # Operators 86 # Operators
87 'MINUS', 87 'MINUS',
88 'PLUS', 88 'PLUS',
89 'AMP', 89 'AMP',
90 'QSTN', 90 'QSTN',
91 91
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 string_char = r"""([^"\\\n]|"""+escape_sequence+')' 139 string_char = r"""([^"\\\n]|"""+escape_sequence+')'
140 string_literal = '"'+string_char+'*"' 140 string_literal = '"'+string_char+'*"'
141 bad_string_literal = '"'+string_char+'*'+bad_escape+string_char+'*"' 141 bad_string_literal = '"'+string_char+'*'+bad_escape+string_char+'*"'
142 142
143 # floating constants (K&R2: A.2.5.3) 143 # floating constants (K&R2: A.2.5.3)
144 exponent_part = r"""([eE][-+]?[0-9]+)""" 144 exponent_part = r"""([eE][-+]?[0-9]+)"""
145 fractional_constant = r"""([0-9]*\.[0-9]+)|([0-9]+\.)""" 145 fractional_constant = r"""([0-9]*\.[0-9]+)|([0-9]+\.)"""
146 floating_constant = \ 146 floating_constant = \
147 '(((('+fractional_constant+')'+ \ 147 '(((('+fractional_constant+')'+ \
148 exponent_part+'?)|([0-9]+'+exponent_part+')))' 148 exponent_part+'?)|([0-9]+'+exponent_part+')))'
149 floating_builtin = \
150 r"""(((double)|(float))\.((NAN)|((NEGATIVE_)?INFINITY)))"""
149 151
150 # Ordinals 152 # Ordinals
151 ordinal = r'@[0-9]+' 153 ordinal = r'@[0-9]+'
152 missing_ordinal_value = r'@' 154 missing_ordinal_value = r'@'
153 # Don't allow ordinal values in octal (even invalid octal, like 09) or 155 # Don't allow ordinal values in octal (even invalid octal, like 09) or
154 # hexadecimal. 156 # hexadecimal.
155 octal_or_hex_ordinal_disallowed = r'@((0[0-9]+)|('+hex_prefix+hex_digits+'))' 157 octal_or_hex_ordinal_disallowed = r'@((0[0-9]+)|('+hex_prefix+hex_digits+'))'
156 158
157 ## 159 ##
158 ## Rules for the normal state 160 ## Rules for the normal state
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
193 195
194 # The following floating and integer constants are defined as 196 # The following floating and integer constants are defined as
195 # functions to impose a strict order (otherwise, decimal 197 # functions to impose a strict order (otherwise, decimal
196 # is placed before the others because its regex is longer, 198 # is placed before the others because its regex is longer,
197 # and this is bad) 199 # and this is bad)
198 # 200 #
199 @TOKEN(floating_constant) 201 @TOKEN(floating_constant)
200 def t_FLOAT_CONST(self, t): 202 def t_FLOAT_CONST(self, t):
201 return t 203 return t
202 204
205 @TOKEN(floating_builtin)
206 def t_FLOAT_BUILTIN(self, t):
207 return t
208
203 @TOKEN(hex_constant) 209 @TOKEN(hex_constant)
204 def t_INT_CONST_HEX(self, t): 210 def t_INT_CONST_HEX(self, t):
205 return t 211 return t
206 212
207 @TOKEN(octal_constant_disallowed) 213 @TOKEN(octal_constant_disallowed)
208 def t_OCTAL_CONSTANT_DISALLOWED(self, t): 214 def t_OCTAL_CONSTANT_DISALLOWED(self, t):
209 msg = "Octal values not allowed" 215 msg = "Octal values not allowed"
210 self._error(msg, t) 216 self._error(msg, t)
211 217
212 @TOKEN(decimal_constant) 218 @TOKEN(decimal_constant)
(...skipping 28 matching lines...) Expand all
241 return t 247 return t
242 248
243 # Ignore C and C++ style comments 249 # Ignore C and C++ style comments
244 def t_COMMENT(self, t): 250 def t_COMMENT(self, t):
245 r'(/\*(.|\n)*?\*/)|(//.*(\n[ \t]*//.*)*)' 251 r'(/\*(.|\n)*?\*/)|(//.*(\n[ \t]*//.*)*)'
246 t.lexer.lineno += t.value.count("\n") 252 t.lexer.lineno += t.value.count("\n")
247 253
248 def t_error(self, t): 254 def t_error(self, t):
249 msg = "Illegal character %s" % repr(t.value[0]) 255 msg = "Illegal character %s" % repr(t.value[0])
250 self._error(msg, t) 256 self._error(msg, t)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698