Commit 6ce2b8e1 authored by yhirano's avatar yhirano Committed by Commit bot

Support Promise<T> syntax in the IDL parser.

The Web IDL spec specifies Promise<T> syntax. This CL makes the IDL parser
recognize the syntax.

BUG=421539

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

Cr-Commit-Position: refs/heads/master@{#300255}
parent 5f318980
...@@ -93,7 +93,8 @@ class IDLLexer(object): ...@@ -93,7 +93,8 @@ class IDLLexer(object):
'octet' : 'OCTET', 'octet' : 'OCTET',
'optional' : 'OPTIONAL', 'optional' : 'OPTIONAL',
'or' : 'OR', 'or' : 'OR',
'partial' : 'PARTIAL', 'partial' : 'PARTIAL',
'Promise' : 'PROMISE',
'readonly' : 'READONLY', 'readonly' : 'READONLY',
'RegExp' : 'REGEXP', 'RegExp' : 'REGEXP',
'sequence' : 'SEQUENCE', 'sequence' : 'SEQUENCE',
......
This diff is collapsed.
...@@ -59,8 +59,8 @@ class IDLPPAPILexer(IDLLexer): ...@@ -59,8 +59,8 @@ class IDLPPAPILexer(IDLLexer):
# Remove JS types # Remove JS types
self._DelKeywords(['boolean', 'byte', 'ByteString', 'Date', 'DOMString', self._DelKeywords(['boolean', 'byte', 'ByteString', 'Date', 'DOMString',
'double', 'float', 'long', 'object', 'octet', 'RegExp', 'double', 'float', 'long', 'object', 'octet', 'Promise',
'short', 'unsigned']) 'RegExp', 'short', 'unsigned'])
# If run by itself, attempt to build the lexer # If run by itself, attempt to build the lexer
......
...@@ -124,18 +124,15 @@ class IDLPPAPIParser(IDLParser): ...@@ -124,18 +124,15 @@ class IDLPPAPIParser(IDLParser):
"""StructMember : ExtendedAttributeList Type identifier ';'""" """StructMember : ExtendedAttributeList Type identifier ';'"""
p[0] = self.BuildNamed('Member', p, 3, ListFromConcat(p[1], p[2])) p[0] = self.BuildNamed('Member', p, 3, ListFromConcat(p[1], p[2]))
# [24]
def p_Typedef(self, p): def p_Typedef(self, p):
"""Typedef : TYPEDEF ExtendedAttributeListNoComments Type identifier ';'""" """Typedef : TYPEDEF ExtendedAttributeListNoComments Type identifier ';'"""
p[0] = self.BuildNamed('Typedef', p, 4, ListFromConcat(p[2], p[3])) p[0] = self.BuildNamed('Typedef', p, 4, ListFromConcat(p[2], p[3]))
# [24.1]
def p_TypedefFunc(self, p): def p_TypedefFunc(self, p):
"""Typedef : TYPEDEF ExtendedAttributeListNoComments ReturnType identifier '(' ArgumentList ')' ';'""" """Typedef : TYPEDEF ExtendedAttributeListNoComments ReturnType identifier '(' ArgumentList ')' ';'"""
args = self.BuildProduction('Arguments', p, 5, p[6]) args = self.BuildProduction('Arguments', p, 5, p[6])
p[0] = self.BuildNamed('Callback', p, 4, ListFromConcat(p[2], p[3], args)) p[0] = self.BuildNamed('Callback', p, 4, ListFromConcat(p[2], p[3], args))
# [27]
def p_ConstValue(self, p): def p_ConstValue(self, p):
"""ConstValue : integer """ConstValue : integer
| integer LSHIFT integer | integer LSHIFT integer
...@@ -157,12 +154,10 @@ class IDLPPAPIParser(IDLParser): ...@@ -157,12 +154,10 @@ class IDLPPAPIParser(IDLParser):
| BooleanLiteral """ | BooleanLiteral """
p[0] = p[1] p[0] = p[1]
# [21]
def p_EnumValueList(self, p): def p_EnumValueList(self, p):
"""EnumValueList : EnumValue EnumValues""" """EnumValueList : EnumValue EnumValues"""
p[0] = ListFromConcat(p[1], p[2]) p[0] = ListFromConcat(p[1], p[2])
# [22]
def p_EnumValues(self, p): def p_EnumValues(self, p):
"""EnumValues : ',' EnumValue EnumValues """EnumValues : ',' EnumValue EnumValues
|""" |"""
...@@ -176,6 +171,13 @@ class IDLPPAPIParser(IDLParser): ...@@ -176,6 +171,13 @@ class IDLPPAPIParser(IDLParser):
if len(p) > 3: if len(p) > 3:
p[0].AddChildren(p[4]) p[0].AddChildren(p[4])
# Omit PromiseType, as it is a JS type.
def p_NonAnyType(self, p):
"""NonAnyType : PrimitiveType TypeSuffix
| identifier TypeSuffix
| SEQUENCE '<' Type '>' Null"""
IDLParser.p_NonAnyType(self, p)
def p_PrimitiveType(self, p): def p_PrimitiveType(self, p):
"""PrimitiveType : IntegerType """PrimitiveType : IntegerType
| UnsignedIntegerType | UnsignedIntegerType
...@@ -200,13 +202,11 @@ class IDLPPAPIParser(IDLParser): ...@@ -200,13 +202,11 @@ class IDLPPAPIParser(IDLParser):
| PP_FILEHANDLE""" | PP_FILEHANDLE"""
p[0] = p[1] p[0] = p[1]
# [66]
def p_FloatType(self, p): def p_FloatType(self, p):
"""FloatType : FLOAT_T """FloatType : FLOAT_T
| DOUBLE_T""" | DOUBLE_T"""
p[0] = p[1] p[0] = p[1]
# [67]
def p_UnsignedIntegerType(self, p): def p_UnsignedIntegerType(self, p):
"""UnsignedIntegerType : UINT8_T """UnsignedIntegerType : UINT8_T
| UINT16_T | UINT16_T
...@@ -215,7 +215,6 @@ class IDLPPAPIParser(IDLParser): ...@@ -215,7 +215,6 @@ class IDLPPAPIParser(IDLParser):
p[0] = p[1] p[0] = p[1]
# [68]
def p_IntegerType(self, p): def p_IntegerType(self, p):
"""IntegerType : CHAR """IntegerType : CHAR
| INT8_T | INT8_T
...@@ -237,6 +236,10 @@ class IDLPPAPIParser(IDLParser): ...@@ -237,6 +236,10 @@ class IDLPPAPIParser(IDLParser):
""" """ """ """
pass pass
def p_PromiseType(self, p):
""" """
pass
# We only support: # We only support:
# [ identifier ] # [ identifier ]
# [ identifier ( ArgumentList )] # [ identifier ( ArgumentList )]
...@@ -272,7 +275,6 @@ class IDLPPAPIParser(IDLParser): ...@@ -272,7 +275,6 @@ class IDLPPAPIParser(IDLParser):
if len(p) > 1: if len(p) > 1:
p[0] = p[1] p[0] = p[1]
# [76]
def p_ExtendedAttributeIdentConst(self, p): def p_ExtendedAttributeIdentConst(self, p):
"""ExtendedAttributeIdentConst : identifier '=' ConstValue""" """ExtendedAttributeIdentConst : identifier '=' ConstValue"""
p[0] = self.BuildNamed('ExtAttribute', p, 1, p[3]) p[0] = self.BuildNamed('ExtAttribute', p, 1, p[3])
......
...@@ -181,3 +181,37 @@ interface MyIFaceStringifiers { ...@@ -181,3 +181,37 @@ interface MyIFaceStringifiers {
interface MyExtendedAttributeInterface { interface MyExtendedAttributeInterface {
[Attr, MethodIdentList=(Foo, Bar)] void method(); [Attr, MethodIdentList=(Foo, Bar)] void method();
}; };
/* TREE
*Interface(MyIfacePromise)
* Operation(method1)
* Arguments()
* Type()
* Promise(Promise)
* Type()
* PrimitiveType(void)
* Operation(method2)
* Arguments()
* Type()
* Promise(Promise)
* Type()
* PrimitiveType(long)
* Operation(method3)
* Arguments()
* Type()
* Promise(Promise)
* Type()
* Any()
* Operation(method4)
* Arguments()
* Type()
* Promise(Promise)
* Type()
* Any()
*/
interface MyIfacePromise {
Promise<void> method1();
Promise<long> method2();
Promise<any> method3();
Promise method4();
};
...@@ -42,6 +42,9 @@ symatics should exist. This is an exact match. ...@@ -42,6 +42,9 @@ symatics should exist. This is an exact match.
* ExtAttribute(fake_attribute) * ExtAttribute(fake_attribute)
* Type() * Type()
* PrimitiveType(str_t) * PrimitiveType(str_t)
* Member(z)
* Type()
* Typeref(Promise)
* ExtAttributes() * ExtAttributes()
* ExtAttribute(union) * ExtAttribute(union)
*/ */
...@@ -49,4 +52,5 @@ symatics should exist. This is an exact match. ...@@ -49,4 +52,5 @@ symatics should exist. This is an exact match.
uint32_t x; uint32_t x;
uint64_t y; uint64_t y;
[fake_attribute] str_t string; [fake_attribute] str_t string;
Promise z;
}; };
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