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

Unified Diff: mojo/public/bindings/pylib/parse/mojo_lexer.py

Issue 217093002: Mojo: Mojom: Detect (lexically) bad or missing ordinals. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 9 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | mojo/public/bindings/pylib/parse/mojo_parser_unittest.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mojo/public/bindings/pylib/parse/mojo_lexer.py
diff --git a/mojo/public/bindings/pylib/parse/mojo_lexer.py b/mojo/public/bindings/pylib/parse/mojo_lexer.py
index ff39bd33af9bb579354434d18ba41f8f58e5bb7d..d0cbd6ad507a83c103c4364f24875097d89df1c1 100644
--- a/mojo/public/bindings/pylib/parse/mojo_lexer.py
+++ b/mojo/public/bindings/pylib/parse/mojo_lexer.py
@@ -161,6 +161,13 @@ class Lexer(object):
'('+hex_prefix+'('+hex_digits+'|'+hex_fractional_constant+')'+ \
binary_exponent_part+'[FfLl]?)'
+ # Ordinals
+ ordinal = r'@[0-9]+'
+ missing_ordinal_value = r'@'
+ # Don't allow ordinal values in octal (even invalid octal, like 09) or
+ # hexadecimal.
+ octal_or_hex_ordinal_disallowed = r'@((0[0-9]+)|('+hex_prefix+hex_digits+'))'
+
##
## Rules for the normal state
##
@@ -204,7 +211,6 @@ class Lexer(object):
t_SEMI = r';'
t_STRING_LITERAL = string_literal
- t_ORDINAL = r'@[0-9]*'
# The following floating and integer constants are defined as
# functions to impose a strict order (otherwise, decimal
@@ -260,6 +266,21 @@ class Lexer(object):
msg = "String contains invalid escape code"
self._error(msg, t)
+ # Handle ordinal-related tokens in the right order:
+ @TOKEN(octal_or_hex_ordinal_disallowed)
+ def t_OCTAL_OR_HEX_ORDINAL_DISALLOWED(self, t):
+ msg = "Octal and hexadecimal ordinal values not allowed"
+ self._error(msg, t)
+
+ @TOKEN(ordinal)
+ def t_ORDINAL(self, t):
+ return t
+
+ @TOKEN(missing_ordinal_value)
+ def t_BAD_ORDINAL(self, t):
+ msg = "Missing ordinal value"
+ self._error(msg, t)
+
@TOKEN(identifier)
def t_NAME(self, t):
t.type = self.keyword_map.get(t.value, "NAME")
« no previous file with comments | « no previous file | mojo/public/bindings/pylib/parse/mojo_parser_unittest.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698