OLD | NEW |
---|---|
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 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
138 # string literals (K&R2: A.2.6) | 138 # string literals (K&R2: A.2.6) |
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+'))|[-+]?Inf|NaN)' |
viettrungluu
2014/08/14 22:32:25
Currently, for numbers, we use unary minus (and pl
| |
149 | 149 |
150 # Ordinals | 150 # Ordinals |
151 ordinal = r'@[0-9]+' | 151 ordinal = r'@[0-9]+' |
152 missing_ordinal_value = r'@' | 152 missing_ordinal_value = r'@' |
153 # Don't allow ordinal values in octal (even invalid octal, like 09) or | 153 # Don't allow ordinal values in octal (even invalid octal, like 09) or |
154 # hexadecimal. | 154 # hexadecimal. |
155 octal_or_hex_ordinal_disallowed = r'@((0[0-9]+)|('+hex_prefix+hex_digits+'))' | 155 octal_or_hex_ordinal_disallowed = r'@((0[0-9]+)|('+hex_prefix+hex_digits+'))' |
156 | 156 |
157 ## | 157 ## |
158 ## Rules for the normal state | 158 ## Rules for the normal state |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
241 return t | 241 return t |
242 | 242 |
243 # Ignore C and C++ style comments | 243 # Ignore C and C++ style comments |
244 def t_COMMENT(self, t): | 244 def t_COMMENT(self, t): |
245 r'(/\*(.|\n)*?\*/)|(//.*(\n[ \t]*//.*)*)' | 245 r'(/\*(.|\n)*?\*/)|(//.*(\n[ \t]*//.*)*)' |
246 t.lexer.lineno += t.value.count("\n") | 246 t.lexer.lineno += t.value.count("\n") |
247 | 247 |
248 def t_error(self, t): | 248 def t_error(self, t): |
249 msg = "Illegal character %s" % repr(t.value[0]) | 249 msg = "Illegal character %s" % repr(t.value[0]) |
250 self._error(msg, t) | 250 self._error(msg, t) |
OLD | NEW |