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

Unified Diff: ppapi/generators/idl_parser.py

Issue 9388002: Add support for Chrome Apps to IDL lexer/parser (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fixed reduce conflicts and allowed use of callback as identifier Created 8 years, 10 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
« ppapi/generators/idl_lexer.py ('K') | « ppapi/generators/idl_option.py ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ppapi/generators/idl_parser.py
diff --git a/ppapi/generators/idl_parser.py b/ppapi/generators/idl_parser.py
index 45f10210a70a1b220599c67382dd46550900157a..c2757277be72e09320346fe14253279af31bc0cf 100755
--- a/ppapi/generators/idl_parser.py
+++ b/ppapi/generators/idl_parser.py
@@ -213,23 +213,55 @@ class IDLParser(IDLLexer):
# present. The extended attributes and the top_list become siblings which
# in turn are children of the file object created from the results of top.
def p_top(self, p):
- """top : COMMENT COMMENT ext_attr_block top_list"""
+ """top : top_list
+ | namespace"""
noelallen1 2012/02/28 22:31:33 I would encourage us to use the copyright notice c
asargent_no_longer_on_chrome 2012/03/03 01:12:02 I fell back to leaving this as-is for now, and wil
+ # TODO(noelallen) - push the expectation of copyright/filedoc comments out
+ # of the parser and into the PPAPI-specific codegen.
+ if len(p[1]) > 0 and p[1][0].cls != 'Namespace':
+ # Hack to pull out the first two comments from the children of |top_list|
noelallen1 2012/02/28 22:31:33 Lets find a better solution for this hack.
asargent_no_longer_on_chrome 2012/03/03 01:12:02 Removed it per above comment.
+ # and insert them into the top-level list we return in p[0]
+ assert len(p[1][0].children) >= 2
+ for i in (0, 1):
+ assert p[1][0].children[i].cls == 'Comment'
+ copyright_comment = p[1][0].children.pop(0)
+ copyright_comment.cls = 'Copyright'
+ filedoc_comment = p[1][0].children.pop(0)
+ p[0] = ListFromConcat(copyright_comment, filedoc_comment, p[1])
+ else:
+ p[0] = ListFromConcat(p[1])
+ if self.parse_debug: DumpReduction('top', p)
- Copyright = self.BuildComment('Copyright', p, 1)
- Filedoc = self.BuildComment('Comment', p, 2)
+ def p_namespace(self, p):
+ """namespace : modifiers NAMESPACE namespace_name '{' top_list '}' ';'"""
+ children = ListFromConcat(p[1], p[5])
+ p[0] = self.BuildNamed('Namespace', p, 3, children)
- p[0] = ListFromConcat(Copyright, Filedoc, p[3], p[4])
- if self.parse_debug: DumpReduction('top', p)
+ # We allow namespace names of the form foo.bar.baz.
+ def p_namespace_name(self, p):
+ """namespace_name : SYMBOL
+ | SYMBOL '.' namespace_name"""
+ p[0] = "".join(p[1:])
+
+ def p_dictionary_block(self, p):
+ """dictionary_block : modifiers DICTIONARY SYMBOL '{' struct_list '}' ';'"""
+ p[0] = self.BuildNamed('Dictionary', p, 3, ListFromConcat(p[5]))
+
+ def p_callback_decl(self, p):
+ """callback_decl : modifiers CALLBACK SYMBOL '=' SYMBOL param_list ';'"""
+ children = ListFromConcat(p[1], p[6])
+ p[0] = self.BuildNamed('Callback', p, 3, children)
# Build a list of top level items.
def p_top_list(self, p):
- """top_list : describe_block top_list
+ """top_list : dictionary_block top_list
+ | describe_block top_list
| enum_block top_list
| inline top_list
| interface_block top_list
| label_block top_list
| struct_block top_list
| typedef_decl top_list
+ | callback_decl top_list
| """
if len(p) > 2:
p[0] = ListFromConcat(p[1], p[2])
@@ -482,6 +514,13 @@ class IDLParser(IDLLexer):
elif len(p) == 1: return
if self.parse_debug: DumpReduction('arrays', p)
+
+# An identifier is a legal value for a parameter or attribute name.
+ def p_identifier(self, p):
+ """identifier : SYMBOL
+ | CALLBACK"""
+ p[0] = p[1]
+
#
# Parameter List
#
@@ -499,12 +538,19 @@ class IDLParser(IDLLexer):
if self.parse_debug: DumpReduction('param_list', p)
def p_param_item(self, p):
- """param_item : modifiers SYMBOL arrays SYMBOL"""
- typeref = self.BuildAttribute('TYPEREF', p[2])
- children = ListFromConcat(p[1],typeref, p[3])
- p[0] = self.BuildNamed('Param', p, 4, children)
+ """param_item : modifiers optional SYMBOL arrays identifier"""
+ typeref = self.BuildAttribute('TYPEREF', p[3])
+ children = ListFromConcat(p[1],p[2], typeref, p[4])
+ p[0] = self.BuildNamed('Param', p, 5, children)
if self.parse_debug: DumpReduction('param_item', p)
+ def p_optional(self, p):
+ """optional : OPTIONAL
+ | """
+ if len(p) == 2:
+ p[0] = self.BuildAttribute('OPTIONAL', True)
+
+
def p_param_cont(self, p):
"""param_cont : ',' param_item param_cont
| """
@@ -520,7 +566,7 @@ class IDLParser(IDLLexer):
#
# Typedef
#
-# A typedef creates a new referencable type. The tyepdef can specify an array
+# A typedef creates a new referencable type. The typedef can specify an array
# definition as well as a function declaration.
#
def p_typedef_data(self, p):
@@ -615,26 +661,31 @@ class IDLParser(IDLLexer):
# A member attribute or function of a struct or interface.
#
def p_member_attribute(self, p):
- """member_attribute : modifiers SYMBOL SYMBOL """
- typeref = self.BuildAttribute('TYPEREF', p[2])
- children = ListFromConcat(p[1], typeref)
- p[0] = self.BuildNamed('Member', p, 3, children)
- if self.parse_debug: DumpReduction('attribute', p)
-
- def p_member_attribute_array(self, p):
- """member_attribute : modifiers SYMBOL arrays SYMBOL """
+ """member_attribute : modifiers SYMBOL arrays questionmark identifier"""
typeref = self.BuildAttribute('TYPEREF', p[2])
- children = ListFromConcat(p[1], typeref, p[3])
- p[0] = self.BuildNamed('Member', p, 4, children)
+ children = ListFromConcat(p[1], typeref, p[3], p[4])
+ p[0] = self.BuildNamed('Member', p, 5, children)
if self.parse_debug: DumpReduction('attribute', p)
def p_member_function(self, p):
- """member_function : modifiers SYMBOL SYMBOL param_list"""
- typeref = self.BuildAttribute('TYPEREF', p[2])
- children = ListFromConcat(p[1], typeref, p[4])
- p[0] = self.BuildNamed('Member', p, 3, children)
+ """member_function : modifiers static SYMBOL SYMBOL param_list"""
+ typeref = self.BuildAttribute('TYPEREF', p[3])
+ children = ListFromConcat(p[1], p[2], typeref, p[5])
+ p[0] = self.BuildNamed('Member', p, 4, children)
if self.parse_debug: DumpReduction('function', p)
+ def p_static(self, p):
+ """static : STATIC
+ | """
+ if len(p) == 2:
+ p[0] = self.BuildAttribute('STATIC', True)
+
+ def p_questionmark(self, p):
+ """questionmark : '?'
+ | """
+ if len(p) == 2:
+ p[0] = self.BuildAttribute('OPTIONAL', True)
+
#
# Interface
#
« ppapi/generators/idl_lexer.py ('K') | « ppapi/generators/idl_option.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698