Mojo: Mojom: Don't allow $ in identifiers.

R=darin@chromium.org

Review URL: https://codereview.chromium.org/290113004

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@271110 0039d316-1c4b-4281-b951-d872f2087c98
parent ae91a681
......@@ -113,8 +113,8 @@ class Lexer(object):
## Regexes for use in tokens
##
# valid C identifiers (K&R2: A.2.3), plus '$' (supported by some compilers)
identifier = r'[a-zA-Z_$][0-9a-zA-Z_$]*'
# valid C identifiers (K&R2: A.2.3)
identifier = r'[a-zA-Z_][0-9a-zA-Z_]*'
hex_prefix = '0[xX]'
hex_digits = '[0-9a-fA-F]+'
......
......@@ -63,6 +63,25 @@ class LexerTest(unittest.TestCase):
# Clone all lexer instances from this one, since making a lexer is slow.
self._zygote_lexer = lex.lex(mojom.parse.lexer.Lexer("my_file.mojom"))
def testValidIdentifiers(self):
"""Tests identifiers."""
self.assertEquals(self._SingleTokenForInput("abcd"),
_MakeLexToken("NAME", "abcd"))
self.assertEquals(self._SingleTokenForInput("AbC_d012_"),
_MakeLexToken("NAME", "AbC_d012_"))
self.assertEquals(self._SingleTokenForInput("_0123"),
_MakeLexToken("NAME", "_0123"))
def testInvalidIdentifiers(self):
with self.assertRaisesRegexp(
mojom.parse.lexer.LexError,
r"^my_file\.mojom:1: Error: Illegal character '\$'$"):
self._TokensForInput("$abc")
with self.assertRaisesRegexp(
mojom.parse.lexer.LexError,
r"^my_file\.mojom:1: Error: Illegal character '\$'$"):
self._TokensForInput("a$bc")
def testValidSingleKeywords(self):
"""Tests valid, single keywords."""
self.assertEquals(self._SingleTokenForInput("handle"),
......@@ -86,8 +105,7 @@ class LexerTest(unittest.TestCase):
def testValidSingleTokens(self):
"""Tests valid, single (non-keyword) tokens."""
self.assertEquals(self._SingleTokenForInput("asdf"),
_MakeLexToken("NAME", "asdf"))
# NAME tested in |testValidIdentifiers|.
self.assertEquals(self._SingleTokenForInput("@123"),
_MakeLexToken("ORDINAL", "@123"))
self.assertEquals(self._SingleTokenForInput("456"),
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment