Index: tools/idl_parser/idl_parser.py |
diff --git a/tools/idl_parser/idl_parser.py b/tools/idl_parser/idl_parser.py |
index 8a682ea688b6821d8993f8c52c8e9dcf6b78cc44..7a5202c50397049f0ef267b733d6a4c60deb7db9 100755 |
--- a/tools/idl_parser/idl_parser.py |
+++ b/tools/idl_parser/idl_parser.py |
@@ -12,7 +12,7 @@ |
# on WebIDL. |
# |
# WebIDL, and WebIDL grammar can be found at: |
-# http://dev.w3.org/2006/webapi/WebIDL/ |
+# http://heycam.github.io/webidl/ |
# PLY can be found at: |
# http://www.dabeaz.com/ply/ |
# |
@@ -144,7 +144,7 @@ def TokenTypeName(t): |
# http://www.dabeaz.com/ply/ |
# |
# The parser is based on the WebIDL standard. See: |
-# http://www.w3.org/TR/WebIDL/#idl-grammar |
+# http://heycam.github.io/webidl/#idl-grammar |
# |
# The various productions are annotated so that the WHOLE number greater than |
# zero in the comment denotes the matching WebIDL grammar definition. |
@@ -183,7 +183,7 @@ class IDLParser(object): |
# |
#The parser is based on the WebIDL standard. See: |
-# http://www.w3.org/TR/WebIDL/#idl-grammar |
+# http://heycam.github.io/webidl/#idl-grammar |
# |
# [1] |
def p_Definitions(self, p): |
@@ -193,7 +193,7 @@ class IDLParser(object): |
p[2].AddChildren(p[1]) |
p[0] = ListFromConcat(p[2], p[3]) |
- # [2] Add INLINE definition |
+ # [2] |
def p_Definition(self, p): |
"""Definition : CallbackOrInterface |
| Partial |
@@ -229,13 +229,13 @@ class IDLParser(object): |
"""Interface : INTERFACE identifier Inheritance '{' InterfaceMembers '}' ';'""" |
p[0] = self.BuildNamed('Interface', p, 2, ListFromConcat(p[3], p[5])) |
- # [6] Error recovery for PARTIAL |
+ # [6] |
def p_Partial(self, p): |
"""Partial : PARTIAL PartialDefinition""" |
p[2].AddChildren(self.BuildTrue('Partial')) |
p[0] = p[2] |
- # [6.1] Error recovery for Enums |
+ # [6.1] Error recovery for Partial |
def p_PartialError(self, p): |
"""Partial : PARTIAL error""" |
p[0] = self.BuildError(p, 'Partial') |
@@ -262,7 +262,7 @@ class IDLParser(object): |
# [10] |
def p_InterfaceMember(self, p): |
"""InterfaceMember : Const |
- | AttributeOrOperation""" |
+ | AttributeOrOperationOrIterator""" |
p[0] = p[1] |
# [11] |
@@ -353,47 +353,54 @@ class IDLParser(object): |
# [21] |
def p_EnumValueList(self, p): |
- """EnumValueList : ExtendedAttributeList string EnumValues""" |
+ """EnumValueList : ExtendedAttributeList string EnumValueListComma""" |
enum = self.BuildNamed('EnumItem', p, 2, p[1]) |
p[0] = ListFromConcat(enum, p[3]) |
# [22] |
- def p_EnumValues(self, p): |
- """EnumValues : ',' ExtendedAttributeList string EnumValues |
- |""" |
+ def p_EnumValueListComma(self, p): |
+ """EnumValueListComma : ',' EnumValueListString |
+ |""" |
if len(p) > 1: |
- enum = self.BuildNamed('EnumItem', p, 3, p[2]) |
- p[0] = ListFromConcat(enum, p[4]) |
+ p[0] = p[2] |
# [23] |
+ def p_EnumValueListString(self, p): |
+ """EnumValueListString : ExtendedAttributeList string EnumValueListComma |
+ |""" |
+ if len(p) > 1: |
+ enum = self.BuildNamed('EnumItem', p, 2, p[1]) |
+ p[0] = ListFromConcat(enum, p[3]) |
+ |
+ # [24] |
def p_CallbackRest(self, p): |
"""CallbackRest : identifier '=' ReturnType '(' ArgumentList ')' ';'""" |
arguments = self.BuildProduction('Arguments', p, 4, p[5]) |
p[0] = self.BuildNamed('Callback', p, 1, ListFromConcat(p[3], arguments)) |
- # [24] |
+ # [25] |
def p_Typedef(self, p): |
"""Typedef : TYPEDEF ExtendedAttributeListNoComments Type identifier ';'""" |
p[0] = self.BuildNamed('Typedef', p, 4, ListFromConcat(p[2], p[3])) |
- # [24.1] Error recovery for Typedefs |
+ # [25.1] Error recovery for Typedefs |
def p_TypedefError(self, p): |
"""Typedef : TYPEDEF error ';'""" |
p[0] = self.BuildError(p, 'Typedef') |
- # [25] |
+ # [26] |
def p_ImplementsStatement(self, p): |
"""ImplementsStatement : identifier IMPLEMENTS identifier ';'""" |
name = self.BuildAttribute('REFERENCE', p[3]) |
p[0] = self.BuildNamed('Implements', p, 1, name) |
- # [26] |
+ # [27] |
def p_Const(self, p): |
"""Const : CONST ConstType identifier '=' ConstValue ';'""" |
value = self.BuildProduction('Value', p, 5, p[5]) |
p[0] = self.BuildNamed('Const', p, 3, ListFromConcat(p[2], value)) |
- # [27] |
+ # [28] |
def p_ConstValue(self, p): |
"""ConstValue : BooleanLiteral |
| FloatLiteral |
@@ -405,20 +412,20 @@ class IDLParser(object): |
else: |
p[0] = p[1] |
- # [27.1] Add definition for NULL |
+ # [28.1] Add definition for NULL |
def p_null(self, p): |
"""null : NULL""" |
p[0] = ListFromConcat(self.BuildAttribute('TYPE', 'NULL'), |
self.BuildAttribute('NAME', 'NULL')) |
- # [28] |
+ # [29] |
def p_BooleanLiteral(self, p): |
"""BooleanLiteral : TRUE |
| FALSE""" |
value = self.BuildAttribute('VALUE', Boolean(p[1] == 'true')) |
p[0] = ListFromConcat(self.BuildAttribute('TYPE', 'boolean'), value) |
- # [29] |
+ # [30] |
def p_FloatLiteral(self, p): |
"""FloatLiteral : float |
| '-' INFINITY |
@@ -431,69 +438,81 @@ class IDLParser(object): |
p[0] = ListFromConcat(self.BuildAttribute('TYPE', 'float'), |
self.BuildAttribute('VALUE', val)) |
- # [30] |
- def p_AttributeOrOperation(self, p): |
- """AttributeOrOperation : STRINGIFIER StringifierAttributeOrOperation |
- | Attribute |
- | Operation""" |
- if len(p) > 2: |
- p[0] = p[2] |
- else: |
- p[0] = p[1] |
+ # [31] Removed unsupported: Serializer, Stringifier |
+ def p_AttributeOrOperationOrIterator(self, p): |
+ """AttributeOrOperationOrIterator : StaticMember |
+ | Attribute |
+ | OperationOrIterator""" |
+ p[0] = p[1] |
- # [31] |
- def p_StringifierAttributeOrOperation(self, p): |
- """StringifierAttributeOrOperation : Attribute |
- | OperationRest |
- | ';'""" |
- if p[1] == ';': |
- p[0] = self.BuildAttribute('STRINGIFIER', Boolean(True)) |
+ # [32-39] NOT IMPLEMENTED |
Nils Barth (inactive)
2014/06/16 06:50:48
Could you link to the stringifier bug?
// FIXME: N
|
+ |
+ # [40] |
+ def p_StaticMember(self, p): |
+ """StaticMember : STATIC StaticMemberRest""" |
+ p[2].AddChildren(self.BuildTrue('STATIC')) |
+ p[0] = p[2] |
+ |
+ # [41] |
+ def p_StaticMemberRest(self, p): |
+ """StaticMemberRest : AttributeRest |
+ | ReturnType OperationRest""" |
+ if len(p) == 2: |
+ p[0] = p[1] |
else: |
- p[0] = ListFromConcat(self.BuildAttribute('STRINGIFIER', p[1]), p[1]) |
+ p[2].AddChildren(p[1]) |
+ p[0] = p[2] |
- # [32] |
+ # [42] |
def p_Attribute(self, p): |
- """Attribute : Inherit ReadOnly ATTRIBUTE Type identifier ';'""" |
- p[0] = self.BuildNamed('Attribute', p, 5, |
- ListFromConcat(p[1], p[2], p[4])) |
+ """Attribute : Inherit AttributeRest""" |
+ p[2].AddChildren(ListFromConcat(p[1])) |
+ p[0] = p[2] |
- # [33] |
+ # [43] |
+ def p_AttributeRest(self, p): |
+ """AttributeRest : ReadOnly ATTRIBUTE Type identifier ';'""" |
+ p[0] = self.BuildNamed('Attribute', p, 4, |
+ ListFromConcat(p[1], p[3])) |
+ |
+ # [44] |
def p_Inherit(self, p): |
"""Inherit : INHERIT |
|""" |
if len(p) > 1: |
p[0] = self.BuildTrue('INHERIT') |
- # [34] |
+ # [45] |
def p_ReadOnly(self, p): |
"""ReadOnly : READONLY |
- |""" |
+ |""" |
if len(p) > 1: |
p[0] = self.BuildTrue('READONLY') |
- # [35] |
- def p_Operation(self, p): |
- """Operation : Qualifiers OperationRest""" |
- p[2].AddChildren(p[1]) |
- p[0] = p[2] |
- |
- # [36] |
- def p_Qualifiers(self, p): |
- """Qualifiers : STATIC |
- | Specials""" |
- if p[1] == 'static': |
- p[0] = self.BuildTrue('STATIC') |
+ # [46] |
+ def p_OperationOrIterator(self, p): |
+ """OperationOrIterator : ReturnType OperationOrIteratorRest |
+ | SpecialOperation""" |
+ if len(p) == 3: |
+ p[2].AddChildren(p[1]) |
+ p[0] = p[2] |
else: |
p[0] = p[1] |
- # [37] |
+ # [47] |
+ def p_SpecialOperation(self, p): |
+ """SpecialOperation : Special Specials ReturnType OperationRest""" |
+ p[4].AddChildren(ListFromConcat(p[1], p[2], p[3])) |
+ p[0] = p[4] |
+ |
+ # [48] |
def p_Specials(self, p): |
"""Specials : Special Specials |
| """ |
if len(p) > 1: |
p[0] = ListFromConcat(p[1], p[2]) |
- # [38] |
+ # [49] |
def p_Special(self, p): |
"""Special : GETTER |
| SETTER |
@@ -502,14 +521,20 @@ class IDLParser(object): |
| LEGACYCALLER""" |
p[0] = self.BuildTrue(p[1].upper()) |
+ # [50] Removed unsupported: IteratorRest |
+ def p_OperationOrIteratorRest(self, p): |
+ """OperationOrIteratorRest : OperationRest""" |
+ p[0] = p[1] |
+ |
+ # [51-53] NOT IMPLEMENTED |
Nils Barth (inactive)
2014/06/16 06:50:48
Could you elab as "NOT IMPLEMENTED (iterator)"
Do
Jens Widell
2014/06/16 10:39:49
I had no plans right now, at least. Implementing s
Nils Barth (inactive)
2014/06/17 05:08:18
Got it; as a rule we don't add support for anythin
|
- # [39] |
+ # [54] |
def p_OperationRest(self, p): |
- """OperationRest : ReturnType OptionalIdentifier '(' ArgumentList ')' ';'""" |
- arguments = self.BuildProduction('Arguments', p, 3, p[4]) |
- p[0] = self.BuildNamed('Operation', p, 2, ListFromConcat(p[1], arguments)) |
+ """OperationRest : OptionalIdentifier '(' ArgumentList ')' ';'""" |
+ arguments = self.BuildProduction('Arguments', p, 2, p[3]) |
+ p[0] = self.BuildNamed('Operation', p, 1, arguments) |
- # [40] |
+ # [55] |
def p_OptionalIdentifier(self, p): |
"""OptionalIdentifier : identifier |
|""" |
@@ -518,33 +543,32 @@ class IDLParser(object): |
else: |
p[0] = '_unnamed_' |
- # [41] |
+ # [56] |
def p_ArgumentList(self, p): |
"""ArgumentList : Argument Arguments |
|""" |
if len(p) > 1: |
p[0] = ListFromConcat(p[1], p[2]) |
- # [41.1] ArgumentList error recovery |
+ # [56.1] ArgumentList error recovery |
def p_ArgumentListError(self, p): |
"""ArgumentList : error """ |
p[0] = self.BuildError(p, 'ArgumentList') |
- # [42] |
+ # [57] |
def p_Arguments(self, p): |
"""Arguments : ',' Argument Arguments |
|""" |
if len(p) > 1: |
p[0] = ListFromConcat(p[2], p[3]) |
- # [43] |
+ # [58] |
def p_Argument(self, p): |
"""Argument : ExtendedAttributeList OptionalOrRequiredArgument""" |
p[2].AddChildren(p[1]) |
p[0] = p[2] |
- |
- # [44] |
+ # [59] |
def p_OptionalOrRequiredArgument(self, p): |
"""OptionalOrRequiredArgument : OPTIONAL Type ArgumentName Default |
| Type Ellipsis ArgumentName""" |
@@ -555,13 +579,13 @@ class IDLParser(object): |
arg = self.BuildNamed('Argument', p, 3, ListFromConcat(p[1], p[2])) |
p[0] = arg |
- # [45] |
+ # [60] |
def p_ArgumentName(self, p): |
"""ArgumentName : ArgumentNameKeyword |
| identifier""" |
p[0] = p[1] |
- # [46] |
+ # [61] |
def p_Ellipsis(self, p): |
"""Ellipsis : ELLIPSIS |
|""" |
@@ -569,23 +593,23 @@ class IDLParser(object): |
p[0] = self.BuildNamed('Argument', p, 1) |
p[0].AddChildren(self.BuildTrue('ELLIPSIS')) |
- # [47] |
+ # [62] |
def p_ExceptionMember(self, p): |
"""ExceptionMember : Const |
| ExceptionField""" |
p[0] = p[1] |
- # [48] |
+ # [63] |
def p_ExceptionField(self, p): |
"""ExceptionField : Type identifier ';'""" |
p[0] = self.BuildNamed('ExceptionField', p, 2, p[1]) |
- # [48.1] Error recovery for ExceptionMembers |
+ # [63.1] Error recovery for ExceptionMembers |
def p_ExceptionFieldError(self, p): |
"""ExceptionField : error""" |
p[0] = self.BuildError(p, 'ExceptionField') |
- # [49] No comment version for mid statement attributes. |
+ # [64] No comment version for mid statement attributes. |
def p_ExtendedAttributeListNoComments(self, p): |
"""ExtendedAttributeListNoComments : '[' ExtendedAttribute ExtendedAttributes ']' |
| """ |
@@ -593,7 +617,7 @@ class IDLParser(object): |
items = ListFromConcat(p[2], p[3]) |
p[0] = self.BuildProduction('ExtAttributes', p, 1, items) |
- # [49.1] Add optional comment field for start of statements. |
+ # [64.1] Add optional comment field for start of statements. |
def p_ExtendedAttributeList(self, p): |
"""ExtendedAttributeList : Comments '[' ExtendedAttribute ExtendedAttributes ']' |
| Comments """ |
@@ -604,7 +628,7 @@ class IDLParser(object): |
else: |
p[0] = p[1] |
- # [50] |
+ # [65] |
def p_ExtendedAttributes(self, p): |
"""ExtendedAttributes : ',' ExtendedAttribute ExtendedAttributes |
|""" |
@@ -616,8 +640,8 @@ class IDLParser(object): |
# [ identifier = identifier ] |
# [ identifier ( ArgumentList )] |
# [ identifier = identifier ( ArgumentList )] |
- # [51] map directly to 74-77 |
- # [52-54, 56] are unsupported |
+ # [66] map directly to [91-93, 95] |
+ # [67-69, 71] are unsupported |
def p_ExtendedAttribute(self, p): |
"""ExtendedAttribute : ExtendedAttributeNoArgs |
| ExtendedAttributeArgList |
@@ -625,7 +649,7 @@ class IDLParser(object): |
| ExtendedAttributeNamedArgList""" |
p[0] = p[1] |
- # [55] |
+ # [70] |
def p_ArgumentNameKeyword(self, p): |
"""ArgumentNameKeyword : ATTRIBUTE |
| CALLBACK |
@@ -640,6 +664,7 @@ class IDLParser(object): |
| INHERIT |
| LEGACYCALLER |
| PARTIAL |
+ | SERIALIZER |
| SETTER |
| STATIC |
| STRINGIFIER |
@@ -647,7 +672,7 @@ class IDLParser(object): |
| UNRESTRICTED""" |
p[0] = p[1] |
- # [57] |
+ # [72] |
def p_Type(self, p): |
"""Type : SingleType |
| UnionType TypeSuffix""" |
@@ -656,7 +681,7 @@ class IDLParser(object): |
else: |
p[0] = self.BuildProduction('Type', p, 1, ListFromConcat(p[1], p[2])) |
- # [58] |
+ # [73] |
def p_SingleType(self, p): |
"""SingleType : NonAnyType |
| ANY TypeSuffixStartingWithArray""" |
@@ -665,21 +690,21 @@ class IDLParser(object): |
else: |
p[0] = ListFromConcat(self.BuildProduction('Any', p, 1), p[2]) |
- # [59] |
+ # [74] |
def p_UnionType(self, p): |
"""UnionType : '(' UnionMemberType OR UnionMemberType UnionMemberTypes ')'""" |
- # [60] |
+ # [75] |
def p_UnionMemberType(self, p): |
"""UnionMemberType : NonAnyType |
| UnionType TypeSuffix |
| ANY '[' ']' TypeSuffix""" |
- # [61] |
+ # [76] |
def p_UnionMemberTypes(self, p): |
"""UnionMemberTypes : OR UnionMemberType UnionMemberTypes |
|""" |
- # [62] Moved DATE, DOMSTRING, OBJECT to PrimitiveType |
+ # [77] Moved BYTESTRING, DOMSTRING, OBJECT, DATE, REGEXP to PrimitiveType |
def p_NonAnyType(self, p): |
"""NonAnyType : PrimitiveType TypeSuffix |
| identifier TypeSuffix |
@@ -695,7 +720,7 @@ class IDLParser(object): |
p[0] = self.BuildProduction('Sequence', p, 1, ListFromConcat(p[3], p[5])) |
- # [63] |
+ # [78] |
def p_ConstType(self, p): |
"""ConstType : PrimitiveType Null |
| identifier Null""" |
@@ -706,23 +731,25 @@ class IDLParser(object): |
p[0] = p[1] |
- # [64] |
+ # [79] |
Nils Barth (inactive)
2014/06/16 06:50:47
Could you note that we've added BYTESTRING etc.?
|
def p_PrimitiveType(self, p): |
"""PrimitiveType : UnsignedIntegerType |
| UnrestrictedFloatType |
| BOOLEAN |
| BYTE |
| OCTET |
+ | BYTESTRING |
| DOMSTRING |
+ | OBJECT |
| DATE |
- | OBJECT""" |
+ | REGEXP""" |
if type(p[1]) == str: |
p[0] = self.BuildNamed('PrimitiveType', p, 1) |
else: |
p[0] = p[1] |
- # [65] |
+ # [80] |
def p_UnrestrictedFloatType(self, p): |
"""UnrestrictedFloatType : UNRESTRICTED FloatType |
| FloatType""" |
@@ -734,13 +761,13 @@ class IDLParser(object): |
p[0] = typeref |
- # [66] |
+ # [81] |
def p_FloatType(self, p): |
"""FloatType : FLOAT |
| DOUBLE""" |
p[0] = p[1] |
- # [67] |
+ # [82] |
def p_UnsignedIntegerType(self, p): |
"""UnsignedIntegerType : UNSIGNED IntegerType |
| IntegerType""" |
@@ -749,7 +776,7 @@ class IDLParser(object): |
else: |
p[0] = 'unsigned ' + p[2] |
- # [68] |
+ # [83] |
def p_IntegerType(self, p): |
"""IntegerType : SHORT |
| LONG OptionalLong""" |
@@ -758,7 +785,7 @@ class IDLParser(object): |
else: |
p[0] = p[1] + p[2] |
- # [69] |
+ # [84] |
def p_OptionalLong(self, p): |
"""OptionalLong : LONG |
| """ |
@@ -768,7 +795,7 @@ class IDLParser(object): |
p[0] = '' |
- # [70] Add support for sized array |
+ # [85] Add support for sized array |
def p_TypeSuffix(self, p): |
"""TypeSuffix : '[' integer ']' TypeSuffix |
| '[' ']' TypeSuffix |
@@ -784,21 +811,21 @@ class IDLParser(object): |
p[0] = ListFromConcat(self.BuildTrue('NULLABLE'), p[2]) |
- # [71] |
+ # [86] |
def p_TypeSuffixStartingWithArray(self, p): |
"""TypeSuffixStartingWithArray : '[' ']' TypeSuffix |
| """ |
if len(p) > 1: |
p[0] = self.BuildProduction('Array', p, 0, p[3]) |
- # [72] |
+ # [87] |
def p_Null(self, p): |
"""Null : '?' |
|""" |
if len(p) > 1: |
p[0] = self.BuildTrue('NULLABLE') |
- # [73] |
+ # [88] |
def p_ReturnType(self, p): |
"""ReturnType : Type |
| VOID""" |
@@ -808,24 +835,26 @@ class IDLParser(object): |
else: |
p[0] = p[1] |
- # [74] |
+ # [89-90] NOT IMPLEMENTED |
Nils Barth (inactive)
2014/06/16 06:50:48
Gloss: (IdentifierList)
|
+ |
+ # [91] |
def p_ExtendedAttributeNoArgs(self, p): |
"""ExtendedAttributeNoArgs : identifier""" |
p[0] = self.BuildNamed('ExtAttribute', p, 1) |
- # [75] |
+ # [92] |
def p_ExtendedAttributeArgList(self, p): |
"""ExtendedAttributeArgList : identifier '(' ArgumentList ')'""" |
arguments = self.BuildProduction('Arguments', p, 2, p[3]) |
p[0] = self.BuildNamed('ExtAttribute', p, 1, arguments) |
- # [76] |
+ # [93] |
def p_ExtendedAttributeIdent(self, p): |
"""ExtendedAttributeIdent : identifier '=' identifier""" |
value = self.BuildAttribute('VALUE', p[3]) |
p[0] = self.BuildNamed('ExtAttribute', p, 1, value) |
- # [77] |
+ # [95] |
Nils Barth (inactive)
2014/06/16 06:50:48
# [94] NOT IMPLEMENTED (ExtendedAttributeIdentList
|
def p_ExtendedAttributeNamedArgList(self, p): |
"""ExtendedAttributeNamedArgList : identifier '=' identifier '(' ArgumentList ')'""" |
args = self.BuildProduction('Arguments', p, 4, p[5]) |