summaryrefslogtreecommitdiffstats
path: root/mojo
diff options
context:
space:
mode:
authorviettrungluu@chromium.org <viettrungluu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-05-20 00:03:08 +0000
committerviettrungluu@chromium.org <viettrungluu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-05-20 00:03:08 +0000
commit1fd97c225503aed3d2cf889f2f20ba96479dc6db (patch)
tree576b5c0f28385886292669b5222dc27286d7f10f /mojo
parent4f2a759713bba0701b43d5408d7d17c8342cabe7 (diff)
downloadchromium_src-1fd97c225503aed3d2cf889f2f20ba96479dc6db.zip
chromium_src-1fd97c225503aed3d2cf889f2f20ba96479dc6db.tar.gz
chromium_src-1fd97c225503aed3d2cf889f2f20ba96479dc6db.tar.bz2
Mojo: Mojom: Make specialized handle types (e.g., message_pipe) not keywords.
Other types (e.g., int32) aren't keywords, so it's a bit anomalous that the specialized handle types are. (Insisting that they be keywords makes adding future handle types more difficult, since doing so could break existing .mojom files.) R=darin@chromium.org Review URL: https://codereview.chromium.org/295773002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@271519 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'mojo')
-rw-r--r--mojo/public/tools/bindings/pylib/mojom/parse/lexer.py4
-rw-r--r--mojo/public/tools/bindings/pylib/mojom/parse/parser.py29
-rw-r--r--mojo/public/tools/bindings/pylib/mojom_tests/parse/lexer_unittest.py6
-rw-r--r--mojo/public/tools/bindings/pylib/mojom_tests/parse/parser_unittest.py43
4 files changed, 59 insertions, 23 deletions
diff --git a/mojo/public/tools/bindings/pylib/mojom/parse/lexer.py b/mojo/public/tools/bindings/pylib/mojom/parse/lexer.py
index eff1bde..28e86ec 100644
--- a/mojo/public/tools/bindings/pylib/mojom/parse/lexer.py
+++ b/mojo/public/tools/bindings/pylib/mojom/parse/lexer.py
@@ -57,10 +57,6 @@ class Lexer(object):
##
keywords = (
'HANDLE',
- 'DATA_PIPE_CONSUMER',
- 'DATA_PIPE_PRODUCER',
- 'MESSAGE_PIPE',
- 'SHARED_BUFFER',
'IMPORT',
'MODULE',
diff --git a/mojo/public/tools/bindings/pylib/mojom/parse/parser.py b/mojo/public/tools/bindings/pylib/mojom/parse/parser.py
index be75fc7..a72f6d8 100644
--- a/mojo/public/tools/bindings/pylib/mojom/parse/parser.py
+++ b/mojo/public/tools/bindings/pylib/mojom/parse/parser.py
@@ -193,20 +193,25 @@ class Parser(object):
def p_basictypename(self, p):
"""basictypename : identifier
- | HANDLE
- | specializedhandle"""
+ | handletype"""
p[0] = p[1]
- def p_specializedhandle(self, p):
- """specializedhandle : HANDLE LANGLE specializedhandlename RANGLE"""
- p[0] = "handle<" + p[3] + ">"
-
- def p_specializedhandlename(self, p):
- """specializedhandlename : DATA_PIPE_CONSUMER
- | DATA_PIPE_PRODUCER
- | MESSAGE_PIPE
- | SHARED_BUFFER"""
- p[0] = p[1]
+ def p_handletype(self, p):
+ """handletype : HANDLE
+ | HANDLE LANGLE identifier RANGLE"""
+ if len(p) == 2:
+ p[0] = p[1]
+ else:
+ if p[3] not in ('data_pipe_consumer',
+ 'data_pipe_producer',
+ 'message_pipe',
+ 'shared_buffer'):
+ # Note: We don't enable tracking of line numbers for everything, so we
+ # can't use |p.lineno(3)|.
+ raise ParseError(self.filename, "Invalid handle type %r:" % p[3],
+ lineno=p.lineno(1),
+ snippet=self._GetSnippet(p.lineno(1)))
+ p[0] = "handle<" + p[3] + ">"
def p_array(self, p):
"""array : typename LBRACKET RBRACKET"""
diff --git a/mojo/public/tools/bindings/pylib/mojom_tests/parse/lexer_unittest.py b/mojo/public/tools/bindings/pylib/mojom_tests/parse/lexer_unittest.py
index 9f40dd6..ce553c3 100644
--- a/mojo/public/tools/bindings/pylib/mojom_tests/parse/lexer_unittest.py
+++ b/mojo/public/tools/bindings/pylib/mojom_tests/parse/lexer_unittest.py
@@ -67,12 +67,6 @@ class LexerTest(unittest.TestCase):
"""Tests valid keywords."""
self.assertEquals(self._SingleTokenForInput("handle"),
_MakeLexTokenForKeyword("handle"))
- self.assertEquals(self._SingleTokenForInput("data_pipe_consumer"),
- _MakeLexTokenForKeyword("data_pipe_consumer"))
- self.assertEquals(self._SingleTokenForInput("data_pipe_producer"),
- _MakeLexTokenForKeyword("data_pipe_producer"))
- self.assertEquals(self._SingleTokenForInput("message_pipe"),
- _MakeLexTokenForKeyword("message_pipe"))
self.assertEquals(self._SingleTokenForInput("import"),
_MakeLexTokenForKeyword("import"))
self.assertEquals(self._SingleTokenForInput("module"),
diff --git a/mojo/public/tools/bindings/pylib/mojom_tests/parse/parser_unittest.py b/mojo/public/tools/bindings/pylib/mojom_tests/parse/parser_unittest.py
index 99a41e2..5ef995b 100644
--- a/mojo/public/tools/bindings/pylib/mojom_tests/parse/parser_unittest.py
+++ b/mojo/public/tools/bindings/pylib/mojom_tests/parse/parser_unittest.py
@@ -311,7 +311,7 @@ struct MyStruct {
parser.Parse(source6, "my_file.mojom")
def testNestedNamespace(self):
- """Tests nested namespaces work."""
+ """Tests that "nested" namespaces work."""
source = """\
module my.mod {
@@ -331,6 +331,47 @@ struct MyStruct {
[('FIELD', 'int32', 'a', ast.Ordinal(None), None)])])]
self.assertEquals(parser.Parse(source, "my_file.mojom"), expected)
+ def testValidHandleTypes(self):
+ """Tests (valid) handle types."""
+ source = """\
+struct MyStruct {
+ handle a;
+ handle<data_pipe_consumer> b;
+ handle <data_pipe_producer> c;
+ handle < message_pipe > d;
+ handle
+ < shared_buffer
+ > e;
+};
+"""
+ expected = \
+[('MODULE',
+ '',
+ None,
+ [('STRUCT',
+ 'MyStruct',
+ None,
+ [('FIELD', 'handle', 'a', ast.Ordinal(None), None),
+ ('FIELD', 'handle<data_pipe_consumer>', 'b', ast.Ordinal(None), None),
+ ('FIELD', 'handle<data_pipe_producer>', 'c', ast.Ordinal(None), None),
+ ('FIELD', 'handle<message_pipe>', 'd', ast.Ordinal(None), None),
+ ('FIELD', 'handle<shared_buffer>', 'e', ast.Ordinal(None), None)])])]
+ self.assertEquals(parser.Parse(source, "my_file.mojom"), expected)
+
+ def testInvalidHandleType(self):
+ """Tests an invalid (unknown) handle type."""
+ source = """\
+struct MyStruct {
+ handle<wtf_is_this> foo;
+};
+"""
+ with self.assertRaisesRegexp(
+ parser.ParseError,
+ r"^my_file\.mojom:2: Error: "
+ r"Invalid handle type 'wtf_is_this':\n"
+ r" handle<wtf_is_this> foo;$"):
+ parser.Parse(source, "my_file.mojom")
+
if __name__ == "__main__":
unittest.main()