Commit 5885b696 authored by jl@opera.com's avatar jl@opera.com

IDL parser: align with current Web IDL specification

Mostly renumbered and restructured grammar productions.  Notable changes:

- add support for static attributes via StaticMember
- add support for built-in types ByteString and RegExp
- allow trailing comma in enum declarations

Depends on:
IDL parser: drop AttributeOrOperation and StaticAttribute overrides
https://codereview.chromium.org/336733002/
...or else breaks Blink compile.

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@278365 0039d316-1c4b-4281-b951-d872f2087c98
parent cb7f3e39
...@@ -67,6 +67,7 @@ class IDLLexer(object): ...@@ -67,6 +67,7 @@ class IDLLexer(object):
'attribute' : 'ATTRIBUTE', 'attribute' : 'ATTRIBUTE',
'boolean' : 'BOOLEAN', 'boolean' : 'BOOLEAN',
'byte' : 'BYTE', 'byte' : 'BYTE',
'ByteString' : 'BYTESTRING',
'callback' : 'CALLBACK', 'callback' : 'CALLBACK',
'const' : 'CONST', 'const' : 'CONST',
'creator' : 'CREATOR', 'creator' : 'CREATOR',
...@@ -94,7 +95,9 @@ class IDLLexer(object): ...@@ -94,7 +95,9 @@ class IDLLexer(object):
'or' : 'OR', 'or' : 'OR',
'partial' : 'PARTIAL', 'partial' : 'PARTIAL',
'readonly' : 'READONLY', 'readonly' : 'READONLY',
'RegExp' : 'REGEXP',
'sequence' : 'SEQUENCE', 'sequence' : 'SEQUENCE',
'serializer' : 'SERIALIZER',
'setter': 'SETTER', 'setter': 'SETTER',
'short' : 'SHORT', 'short' : 'SHORT',
'static' : 'STATIC', 'static' : 'STATIC',
......
...@@ -201,7 +201,7 @@ class IDLNode(object): ...@@ -201,7 +201,7 @@ class IDLNode(object):
child._parent = self child._parent = self
self._children.append(child) self._children.append(child)
continue continue
raise RuntimeError('Adding child of type .\n' % type(child).__name__) raise RuntimeError('Adding child of type %s.\n' % type(child).__name__)
# #
......
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
# on WebIDL. # on WebIDL.
# #
# WebIDL, and WebIDL grammar can be found at: # 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: # PLY can be found at:
# http://www.dabeaz.com/ply/ # http://www.dabeaz.com/ply/
# #
...@@ -144,7 +144,7 @@ def TokenTypeName(t): ...@@ -144,7 +144,7 @@ def TokenTypeName(t):
# http://www.dabeaz.com/ply/ # http://www.dabeaz.com/ply/
# #
# The parser is based on the WebIDL standard. See: # 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 # The various productions are annotated so that the WHOLE number greater than
# zero in the comment denotes the matching WebIDL grammar definition. # zero in the comment denotes the matching WebIDL grammar definition.
...@@ -183,7 +183,7 @@ class IDLParser(object): ...@@ -183,7 +183,7 @@ class IDLParser(object):
# #
#The parser is based on the WebIDL standard. See: #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] # [1]
def p_Definitions(self, p): def p_Definitions(self, p):
...@@ -193,7 +193,7 @@ class IDLParser(object): ...@@ -193,7 +193,7 @@ class IDLParser(object):
p[2].AddChildren(p[1]) p[2].AddChildren(p[1])
p[0] = ListFromConcat(p[2], p[3]) p[0] = ListFromConcat(p[2], p[3])
# [2] Add INLINE definition # [2]
def p_Definition(self, p): def p_Definition(self, p):
"""Definition : CallbackOrInterface """Definition : CallbackOrInterface
| Partial | Partial
...@@ -229,13 +229,13 @@ class IDLParser(object): ...@@ -229,13 +229,13 @@ class IDLParser(object):
"""Interface : INTERFACE identifier Inheritance '{' InterfaceMembers '}' ';'""" """Interface : INTERFACE identifier Inheritance '{' InterfaceMembers '}' ';'"""
p[0] = self.BuildNamed('Interface', p, 2, ListFromConcat(p[3], p[5])) p[0] = self.BuildNamed('Interface', p, 2, ListFromConcat(p[3], p[5]))
# [6] Error recovery for PARTIAL # [6]
def p_Partial(self, p): def p_Partial(self, p):
"""Partial : PARTIAL PartialDefinition""" """Partial : PARTIAL PartialDefinition"""
p[2].AddChildren(self.BuildTrue('Partial')) p[2].AddChildren(self.BuildTrue('Partial'))
p[0] = p[2] p[0] = p[2]
# [6.1] Error recovery for Enums # [6.1] Error recovery for Partial
def p_PartialError(self, p): def p_PartialError(self, p):
"""Partial : PARTIAL error""" """Partial : PARTIAL error"""
p[0] = self.BuildError(p, 'Partial') p[0] = self.BuildError(p, 'Partial')
...@@ -262,7 +262,7 @@ class IDLParser(object): ...@@ -262,7 +262,7 @@ class IDLParser(object):
# [10] # [10]
def p_InterfaceMember(self, p): def p_InterfaceMember(self, p):
"""InterfaceMember : Const """InterfaceMember : Const
| AttributeOrOperation""" | AttributeOrOperationOrIterator"""
p[0] = p[1] p[0] = p[1]
# [11] # [11]
...@@ -353,47 +353,54 @@ class IDLParser(object): ...@@ -353,47 +353,54 @@ class IDLParser(object):
# [21] # [21]
def p_EnumValueList(self, p): def p_EnumValueList(self, p):
"""EnumValueList : ExtendedAttributeList string EnumValues""" """EnumValueList : ExtendedAttributeList string EnumValueListComma"""
enum = self.BuildNamed('EnumItem', p, 2, p[1]) enum = self.BuildNamed('EnumItem', p, 2, p[1])
p[0] = ListFromConcat(enum, p[3]) p[0] = ListFromConcat(enum, p[3])
# [22] # [22]
def p_EnumValues(self, p): def p_EnumValueListComma(self, p):
"""EnumValues : ',' ExtendedAttributeList string EnumValues """EnumValueListComma : ',' EnumValueListString
|""" |"""
if len(p) > 1: if len(p) > 1:
enum = self.BuildNamed('EnumItem', p, 3, p[2]) p[0] = p[2]
p[0] = ListFromConcat(enum, p[4])
# [23] # [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): def p_CallbackRest(self, p):
"""CallbackRest : identifier '=' ReturnType '(' ArgumentList ')' ';'""" """CallbackRest : identifier '=' ReturnType '(' ArgumentList ')' ';'"""
arguments = self.BuildProduction('Arguments', p, 4, p[5]) arguments = self.BuildProduction('Arguments', p, 4, p[5])
p[0] = self.BuildNamed('Callback', p, 1, ListFromConcat(p[3], arguments)) p[0] = self.BuildNamed('Callback', p, 1, ListFromConcat(p[3], arguments))
# [24] # [25]
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] Error recovery for Typedefs # [25.1] Error recovery for Typedefs
def p_TypedefError(self, p): def p_TypedefError(self, p):
"""Typedef : TYPEDEF error ';'""" """Typedef : TYPEDEF error ';'"""
p[0] = self.BuildError(p, 'Typedef') p[0] = self.BuildError(p, 'Typedef')
# [25] # [26]
def p_ImplementsStatement(self, p): def p_ImplementsStatement(self, p):
"""ImplementsStatement : identifier IMPLEMENTS identifier ';'""" """ImplementsStatement : identifier IMPLEMENTS identifier ';'"""
name = self.BuildAttribute('REFERENCE', p[3]) name = self.BuildAttribute('REFERENCE', p[3])
p[0] = self.BuildNamed('Implements', p, 1, name) p[0] = self.BuildNamed('Implements', p, 1, name)
# [26] # [27]
def p_Const(self, p): def p_Const(self, p):
"""Const : CONST ConstType identifier '=' ConstValue ';'""" """Const : CONST ConstType identifier '=' ConstValue ';'"""
value = self.BuildProduction('Value', p, 5, p[5]) value = self.BuildProduction('Value', p, 5, p[5])
p[0] = self.BuildNamed('Const', p, 3, ListFromConcat(p[2], value)) p[0] = self.BuildNamed('Const', p, 3, ListFromConcat(p[2], value))
# [27] # [28]
def p_ConstValue(self, p): def p_ConstValue(self, p):
"""ConstValue : BooleanLiteral """ConstValue : BooleanLiteral
| FloatLiteral | FloatLiteral
...@@ -405,20 +412,20 @@ class IDLParser(object): ...@@ -405,20 +412,20 @@ class IDLParser(object):
else: else:
p[0] = p[1] p[0] = p[1]
# [27.1] Add definition for NULL # [28.1] Add definition for NULL
def p_null(self, p): def p_null(self, p):
"""null : NULL""" """null : NULL"""
p[0] = ListFromConcat(self.BuildAttribute('TYPE', 'NULL'), p[0] = ListFromConcat(self.BuildAttribute('TYPE', 'NULL'),
self.BuildAttribute('NAME', 'NULL')) self.BuildAttribute('NAME', 'NULL'))
# [28] # [29]
def p_BooleanLiteral(self, p): def p_BooleanLiteral(self, p):
"""BooleanLiteral : TRUE """BooleanLiteral : TRUE
| FALSE""" | FALSE"""
value = self.BuildAttribute('VALUE', Boolean(p[1] == 'true')) value = self.BuildAttribute('VALUE', Boolean(p[1] == 'true'))
p[0] = ListFromConcat(self.BuildAttribute('TYPE', 'boolean'), value) p[0] = ListFromConcat(self.BuildAttribute('TYPE', 'boolean'), value)
# [29] # [30]
def p_FloatLiteral(self, p): def p_FloatLiteral(self, p):
"""FloatLiteral : float """FloatLiteral : float
| '-' INFINITY | '-' INFINITY
...@@ -431,77 +438,82 @@ class IDLParser(object): ...@@ -431,77 +438,82 @@ class IDLParser(object):
p[0] = ListFromConcat(self.BuildAttribute('TYPE', 'float'), p[0] = ListFromConcat(self.BuildAttribute('TYPE', 'float'),
self.BuildAttribute('VALUE', val)) self.BuildAttribute('VALUE', val))
# [30] # [31] Removed unsupported: Serializer, Stringifier
def p_AttributeOrOperation(self, p): def p_AttributeOrOperationOrIterator(self, p):
"""AttributeOrOperation : STRINGIFIER StringifierAttributeOrOperation """AttributeOrOperationOrIterator : StaticMember
| StaticAttribute
| Attribute | Attribute
| Operation""" | OperationOrIterator"""
if len(p) > 2:
p[0] = p[2]
else:
p[0] = p[1] p[0] = p[1]
# [31] # [32-37] NOT IMPLEMENTED (Serializer)
def p_StringifierAttributeOrOperation(self, p): # [38-39] FIXME: NOT IMPLEMENTED (Stringifier) http://crbug.com/306606
"""StringifierAttributeOrOperation : Attribute
| OperationRest
| ';'"""
if p[1] == ';':
p[0] = self.BuildAttribute('STRINGIFIER', Boolean(True))
else:
p[0] = ListFromConcat(self.BuildAttribute('STRINGIFIER', p[1]), p[1])
# [31.1] FIXME: temporary production as part of moving |static| into # [40]
# base parser def p_StaticMember(self, p):
def p_StaticAttribute(self, p): """StaticMember : STATIC StaticMemberRest"""
"""StaticAttribute : STATIC Attribute"""
p[2].AddChildren(self.BuildTrue('STATIC')) p[2].AddChildren(self.BuildTrue('STATIC'))
p[0] = p[2] p[0] = p[2]
# [32] # [41]
def p_StaticMemberRest(self, p):
"""StaticMemberRest : AttributeRest
| ReturnType OperationRest"""
if len(p) == 2:
p[0] = p[1]
else:
p[2].AddChildren(p[1])
p[0] = p[2]
# [42]
def p_Attribute(self, p): def p_Attribute(self, p):
"""Attribute : Inherit ReadOnly ATTRIBUTE Type identifier ';'""" """Attribute : Inherit AttributeRest"""
p[0] = self.BuildNamed('Attribute', p, 5, p[2].AddChildren(ListFromConcat(p[1]))
ListFromConcat(p[1], p[2], p[4])) p[0] = p[2]
# [43]
def p_AttributeRest(self, p):
"""AttributeRest : ReadOnly ATTRIBUTE Type identifier ';'"""
p[0] = self.BuildNamed('Attribute', p, 4,
ListFromConcat(p[1], p[3]))
# [33] # [44]
def p_Inherit(self, p): def p_Inherit(self, p):
"""Inherit : INHERIT """Inherit : INHERIT
|""" |"""
if len(p) > 1: if len(p) > 1:
p[0] = self.BuildTrue('INHERIT') p[0] = self.BuildTrue('INHERIT')
# [34] # [45]
def p_ReadOnly(self, p): def p_ReadOnly(self, p):
"""ReadOnly : READONLY """ReadOnly : READONLY
|""" |"""
if len(p) > 1: if len(p) > 1:
p[0] = self.BuildTrue('READONLY') p[0] = self.BuildTrue('READONLY')
# [35] # [46]
def p_Operation(self, p): def p_OperationOrIterator(self, p):
"""Operation : Qualifiers OperationRest""" """OperationOrIterator : ReturnType OperationOrIteratorRest
| SpecialOperation"""
if len(p) == 3:
p[2].AddChildren(p[1]) p[2].AddChildren(p[1])
p[0] = p[2] p[0] = p[2]
# [36]
def p_Qualifiers(self, p):
"""Qualifiers : STATIC
| Specials"""
if p[1] == 'static':
p[0] = self.BuildTrue('STATIC')
else: else:
p[0] = p[1] 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): def p_Specials(self, p):
"""Specials : Special Specials """Specials : Special Specials
| """ | """
if len(p) > 1: if len(p) > 1:
p[0] = ListFromConcat(p[1], p[2]) p[0] = ListFromConcat(p[1], p[2])
# [38] # [49]
def p_Special(self, p): def p_Special(self, p):
"""Special : GETTER """Special : GETTER
| SETTER | SETTER
...@@ -510,14 +522,20 @@ class IDLParser(object): ...@@ -510,14 +522,20 @@ class IDLParser(object):
| LEGACYCALLER""" | LEGACYCALLER"""
p[0] = self.BuildTrue(p[1].upper()) 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 (IteratorRest)
# [39] # [54]
def p_OperationRest(self, p): def p_OperationRest(self, p):
"""OperationRest : ReturnType OptionalIdentifier '(' ArgumentList ')' ';'""" """OperationRest : OptionalIdentifier '(' ArgumentList ')' ';'"""
arguments = self.BuildProduction('Arguments', p, 3, p[4]) arguments = self.BuildProduction('Arguments', p, 2, p[3])
p[0] = self.BuildNamed('Operation', p, 2, ListFromConcat(p[1], arguments)) p[0] = self.BuildNamed('Operation', p, 1, arguments)
# [40] # [55]
def p_OptionalIdentifier(self, p): def p_OptionalIdentifier(self, p):
"""OptionalIdentifier : identifier """OptionalIdentifier : identifier
|""" |"""
...@@ -526,33 +544,32 @@ class IDLParser(object): ...@@ -526,33 +544,32 @@ class IDLParser(object):
else: else:
p[0] = '_unnamed_' p[0] = '_unnamed_'
# [41] # [56]
def p_ArgumentList(self, p): def p_ArgumentList(self, p):
"""ArgumentList : Argument Arguments """ArgumentList : Argument Arguments
|""" |"""
if len(p) > 1: if len(p) > 1:
p[0] = ListFromConcat(p[1], p[2]) p[0] = ListFromConcat(p[1], p[2])
# [41.1] ArgumentList error recovery # [56.1] ArgumentList error recovery
def p_ArgumentListError(self, p): def p_ArgumentListError(self, p):
"""ArgumentList : error """ """ArgumentList : error """
p[0] = self.BuildError(p, 'ArgumentList') p[0] = self.BuildError(p, 'ArgumentList')
# [42] # [57]
def p_Arguments(self, p): def p_Arguments(self, p):
"""Arguments : ',' Argument Arguments """Arguments : ',' Argument Arguments
|""" |"""
if len(p) > 1: if len(p) > 1:
p[0] = ListFromConcat(p[2], p[3]) p[0] = ListFromConcat(p[2], p[3])
# [43] # [58]
def p_Argument(self, p): def p_Argument(self, p):
"""Argument : ExtendedAttributeList OptionalOrRequiredArgument""" """Argument : ExtendedAttributeList OptionalOrRequiredArgument"""
p[2].AddChildren(p[1]) p[2].AddChildren(p[1])
p[0] = p[2] p[0] = p[2]
# [59]
# [44]
def p_OptionalOrRequiredArgument(self, p): def p_OptionalOrRequiredArgument(self, p):
"""OptionalOrRequiredArgument : OPTIONAL Type ArgumentName Default """OptionalOrRequiredArgument : OPTIONAL Type ArgumentName Default
| Type Ellipsis ArgumentName""" | Type Ellipsis ArgumentName"""
...@@ -563,13 +580,13 @@ class IDLParser(object): ...@@ -563,13 +580,13 @@ class IDLParser(object):
arg = self.BuildNamed('Argument', p, 3, ListFromConcat(p[1], p[2])) arg = self.BuildNamed('Argument', p, 3, ListFromConcat(p[1], p[2]))
p[0] = arg p[0] = arg
# [45] # [60]
def p_ArgumentName(self, p): def p_ArgumentName(self, p):
"""ArgumentName : ArgumentNameKeyword """ArgumentName : ArgumentNameKeyword
| identifier""" | identifier"""
p[0] = p[1] p[0] = p[1]
# [46] # [61]
def p_Ellipsis(self, p): def p_Ellipsis(self, p):
"""Ellipsis : ELLIPSIS """Ellipsis : ELLIPSIS
|""" |"""
...@@ -577,23 +594,23 @@ class IDLParser(object): ...@@ -577,23 +594,23 @@ class IDLParser(object):
p[0] = self.BuildNamed('Argument', p, 1) p[0] = self.BuildNamed('Argument', p, 1)
p[0].AddChildren(self.BuildTrue('ELLIPSIS')) p[0].AddChildren(self.BuildTrue('ELLIPSIS'))
# [47] # [62]
def p_ExceptionMember(self, p): def p_ExceptionMember(self, p):
"""ExceptionMember : Const """ExceptionMember : Const
| ExceptionField""" | ExceptionField"""
p[0] = p[1] p[0] = p[1]
# [48] # [63]
def p_ExceptionField(self, p): def p_ExceptionField(self, p):
"""ExceptionField : Type identifier ';'""" """ExceptionField : Type identifier ';'"""
p[0] = self.BuildNamed('ExceptionField', p, 2, p[1]) 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): def p_ExceptionFieldError(self, p):
"""ExceptionField : error""" """ExceptionField : error"""
p[0] = self.BuildError(p, 'ExceptionField') 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): def p_ExtendedAttributeListNoComments(self, p):
"""ExtendedAttributeListNoComments : '[' ExtendedAttribute ExtendedAttributes ']' """ExtendedAttributeListNoComments : '[' ExtendedAttribute ExtendedAttributes ']'
| """ | """
...@@ -601,7 +618,7 @@ class IDLParser(object): ...@@ -601,7 +618,7 @@ class IDLParser(object):
items = ListFromConcat(p[2], p[3]) items = ListFromConcat(p[2], p[3])
p[0] = self.BuildProduction('ExtAttributes', p, 1, items) 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): def p_ExtendedAttributeList(self, p):
"""ExtendedAttributeList : Comments '[' ExtendedAttribute ExtendedAttributes ']' """ExtendedAttributeList : Comments '[' ExtendedAttribute ExtendedAttributes ']'
| Comments """ | Comments """
...@@ -612,7 +629,7 @@ class IDLParser(object): ...@@ -612,7 +629,7 @@ class IDLParser(object):
else: else:
p[0] = p[1] p[0] = p[1]
# [50] # [65]
def p_ExtendedAttributes(self, p): def p_ExtendedAttributes(self, p):
"""ExtendedAttributes : ',' ExtendedAttribute ExtendedAttributes """ExtendedAttributes : ',' ExtendedAttribute ExtendedAttributes
|""" |"""
...@@ -624,8 +641,8 @@ class IDLParser(object): ...@@ -624,8 +641,8 @@ class IDLParser(object):
# [ identifier = identifier ] # [ identifier = identifier ]
# [ identifier ( ArgumentList )] # [ identifier ( ArgumentList )]
# [ identifier = identifier ( ArgumentList )] # [ identifier = identifier ( ArgumentList )]
# [51] map directly to 74-77 # [66] map directly to [91-93, 95]
# [52-54, 56] are unsupported # [67-69, 71] are unsupported
def p_ExtendedAttribute(self, p): def p_ExtendedAttribute(self, p):
"""ExtendedAttribute : ExtendedAttributeNoArgs """ExtendedAttribute : ExtendedAttributeNoArgs
| ExtendedAttributeArgList | ExtendedAttributeArgList
...@@ -633,7 +650,7 @@ class IDLParser(object): ...@@ -633,7 +650,7 @@ class IDLParser(object):
| ExtendedAttributeNamedArgList""" | ExtendedAttributeNamedArgList"""
p[0] = p[1] p[0] = p[1]
# [55] # [70]
def p_ArgumentNameKeyword(self, p): def p_ArgumentNameKeyword(self, p):
"""ArgumentNameKeyword : ATTRIBUTE """ArgumentNameKeyword : ATTRIBUTE
| CALLBACK | CALLBACK
...@@ -648,6 +665,7 @@ class IDLParser(object): ...@@ -648,6 +665,7 @@ class IDLParser(object):
| INHERIT | INHERIT
| LEGACYCALLER | LEGACYCALLER
| PARTIAL | PARTIAL
| SERIALIZER
| SETTER | SETTER
| STATIC | STATIC
| STRINGIFIER | STRINGIFIER
...@@ -655,7 +673,7 @@ class IDLParser(object): ...@@ -655,7 +673,7 @@ class IDLParser(object):
| UNRESTRICTED""" | UNRESTRICTED"""
p[0] = p[1] p[0] = p[1]
# [57] # [72]
def p_Type(self, p): def p_Type(self, p):
"""Type : SingleType """Type : SingleType
| UnionType TypeSuffix""" | UnionType TypeSuffix"""
...@@ -664,7 +682,7 @@ class IDLParser(object): ...@@ -664,7 +682,7 @@ class IDLParser(object):
else: else:
p[0] = self.BuildProduction('Type', p, 1, ListFromConcat(p[1], p[2])) p[0] = self.BuildProduction('Type', p, 1, ListFromConcat(p[1], p[2]))
# [58] # [73]
def p_SingleType(self, p): def p_SingleType(self, p):
"""SingleType : NonAnyType """SingleType : NonAnyType
| ANY TypeSuffixStartingWithArray""" | ANY TypeSuffixStartingWithArray"""
...@@ -673,21 +691,24 @@ class IDLParser(object): ...@@ -673,21 +691,24 @@ class IDLParser(object):
else: else:
p[0] = ListFromConcat(self.BuildProduction('Any', p, 1), p[2]) p[0] = ListFromConcat(self.BuildProduction('Any', p, 1), p[2])
# [59] # [74]
def p_UnionType(self, p): def p_UnionType(self, p):
"""UnionType : '(' UnionMemberType OR UnionMemberType UnionMemberTypes ')'""" """UnionType : '(' UnionMemberType OR UnionMemberType UnionMemberTypes ')'"""
# [60] # [75]
def p_UnionMemberType(self, p): def p_UnionMemberType(self, p):
"""UnionMemberType : NonAnyType """UnionMemberType : NonAnyType
| UnionType TypeSuffix | UnionType TypeSuffix
| ANY '[' ']' TypeSuffix""" | ANY '[' ']' TypeSuffix"""
# [61] # [76]
def p_UnionMemberTypes(self, p): def p_UnionMemberTypes(self, p):
"""UnionMemberTypes : OR UnionMemberType UnionMemberTypes """UnionMemberTypes : OR UnionMemberType UnionMemberTypes
|""" |"""
# [62] Moved DATE, DOMSTRING, OBJECT to PrimitiveType # [77] Moved BYTESTRING, DOMSTRING, OBJECT, DATE, REGEXP to PrimitiveType
# Moving all built-in types into PrimitiveType makes it easier to
# differentiate between them and 'identifier', since p[1] would be a string in
# both cases.
def p_NonAnyType(self, p): def p_NonAnyType(self, p):
"""NonAnyType : PrimitiveType TypeSuffix """NonAnyType : PrimitiveType TypeSuffix
| identifier TypeSuffix | identifier TypeSuffix
...@@ -703,7 +724,7 @@ class IDLParser(object): ...@@ -703,7 +724,7 @@ class IDLParser(object):
p[0] = self.BuildProduction('Sequence', p, 1, ListFromConcat(p[3], p[5])) p[0] = self.BuildProduction('Sequence', p, 1, ListFromConcat(p[3], p[5]))
# [63] # [78]
def p_ConstType(self, p): def p_ConstType(self, p):
"""ConstType : PrimitiveType Null """ConstType : PrimitiveType Null
| identifier Null""" | identifier Null"""
...@@ -714,23 +735,25 @@ class IDLParser(object): ...@@ -714,23 +735,25 @@ class IDLParser(object):
p[0] = p[1] p[0] = p[1]
# [64] # [79] Added BYTESTRING, DOMSTRING, OBJECT, DATE, REGEXP
def p_PrimitiveType(self, p): def p_PrimitiveType(self, p):
"""PrimitiveType : UnsignedIntegerType """PrimitiveType : UnsignedIntegerType
| UnrestrictedFloatType | UnrestrictedFloatType
| BOOLEAN | BOOLEAN
| BYTE | BYTE
| OCTET | OCTET
| BYTESTRING
| DOMSTRING | DOMSTRING
| OBJECT
| DATE | DATE
| OBJECT""" | REGEXP"""
if type(p[1]) == str: if type(p[1]) == str:
p[0] = self.BuildNamed('PrimitiveType', p, 1) p[0] = self.BuildNamed('PrimitiveType', p, 1)
else: else:
p[0] = p[1] p[0] = p[1]
# [65] # [80]
def p_UnrestrictedFloatType(self, p): def p_UnrestrictedFloatType(self, p):
"""UnrestrictedFloatType : UNRESTRICTED FloatType """UnrestrictedFloatType : UNRESTRICTED FloatType
| FloatType""" | FloatType"""
...@@ -742,13 +765,13 @@ class IDLParser(object): ...@@ -742,13 +765,13 @@ class IDLParser(object):
p[0] = typeref p[0] = typeref
# [66] # [81]
def p_FloatType(self, p): def p_FloatType(self, p):
"""FloatType : FLOAT """FloatType : FLOAT
| DOUBLE""" | DOUBLE"""
p[0] = p[1] p[0] = p[1]
# [67] # [82]
def p_UnsignedIntegerType(self, p): def p_UnsignedIntegerType(self, p):
"""UnsignedIntegerType : UNSIGNED IntegerType """UnsignedIntegerType : UNSIGNED IntegerType
| IntegerType""" | IntegerType"""
...@@ -757,7 +780,7 @@ class IDLParser(object): ...@@ -757,7 +780,7 @@ class IDLParser(object):
else: else:
p[0] = 'unsigned ' + p[2] p[0] = 'unsigned ' + p[2]
# [68] # [83]
def p_IntegerType(self, p): def p_IntegerType(self, p):
"""IntegerType : SHORT """IntegerType : SHORT
| LONG OptionalLong""" | LONG OptionalLong"""
...@@ -766,7 +789,7 @@ class IDLParser(object): ...@@ -766,7 +789,7 @@ class IDLParser(object):
else: else:
p[0] = p[1] + p[2] p[0] = p[1] + p[2]
# [69] # [84]
def p_OptionalLong(self, p): def p_OptionalLong(self, p):
"""OptionalLong : LONG """OptionalLong : LONG
| """ | """
...@@ -776,7 +799,7 @@ class IDLParser(object): ...@@ -776,7 +799,7 @@ class IDLParser(object):
p[0] = '' p[0] = ''
# [70] Add support for sized array # [85] Add support for sized array
def p_TypeSuffix(self, p): def p_TypeSuffix(self, p):
"""TypeSuffix : '[' integer ']' TypeSuffix """TypeSuffix : '[' integer ']' TypeSuffix
| '[' ']' TypeSuffix | '[' ']' TypeSuffix
...@@ -792,21 +815,21 @@ class IDLParser(object): ...@@ -792,21 +815,21 @@ class IDLParser(object):
p[0] = ListFromConcat(self.BuildTrue('NULLABLE'), p[2]) p[0] = ListFromConcat(self.BuildTrue('NULLABLE'), p[2])
# [71] # [86]
def p_TypeSuffixStartingWithArray(self, p): def p_TypeSuffixStartingWithArray(self, p):
"""TypeSuffixStartingWithArray : '[' ']' TypeSuffix """TypeSuffixStartingWithArray : '[' ']' TypeSuffix
| """ | """
if len(p) > 1: if len(p) > 1:
p[0] = self.BuildProduction('Array', p, 0, p[3]) p[0] = self.BuildProduction('Array', p, 0, p[3])
# [72] # [87]
def p_Null(self, p): def p_Null(self, p):
"""Null : '?' """Null : '?'
|""" |"""
if len(p) > 1: if len(p) > 1:
p[0] = self.BuildTrue('NULLABLE') p[0] = self.BuildTrue('NULLABLE')
# [73] # [88]
def p_ReturnType(self, p): def p_ReturnType(self, p):
"""ReturnType : Type """ReturnType : Type
| VOID""" | VOID"""
...@@ -816,30 +839,36 @@ class IDLParser(object): ...@@ -816,30 +839,36 @@ class IDLParser(object):
else: else:
p[0] = p[1] p[0] = p[1]
# [74] # [89-90] NOT IMPLEMENTED (IdentifierList)
# [91]
def p_ExtendedAttributeNoArgs(self, p): def p_ExtendedAttributeNoArgs(self, p):
"""ExtendedAttributeNoArgs : identifier""" """ExtendedAttributeNoArgs : identifier"""
p[0] = self.BuildNamed('ExtAttribute', p, 1) p[0] = self.BuildNamed('ExtAttribute', p, 1)
# [75] # [92]
def p_ExtendedAttributeArgList(self, p): def p_ExtendedAttributeArgList(self, p):
"""ExtendedAttributeArgList : identifier '(' ArgumentList ')'""" """ExtendedAttributeArgList : identifier '(' ArgumentList ')'"""
arguments = self.BuildProduction('Arguments', p, 2, p[3]) arguments = self.BuildProduction('Arguments', p, 2, p[3])
p[0] = self.BuildNamed('ExtAttribute', p, 1, arguments) p[0] = self.BuildNamed('ExtAttribute', p, 1, arguments)
# [76] # [93]
def p_ExtendedAttributeIdent(self, p): def p_ExtendedAttributeIdent(self, p):
"""ExtendedAttributeIdent : identifier '=' identifier""" """ExtendedAttributeIdent : identifier '=' identifier"""
value = self.BuildAttribute('VALUE', p[3]) value = self.BuildAttribute('VALUE', p[3])
p[0] = self.BuildNamed('ExtAttribute', p, 1, value) p[0] = self.BuildNamed('ExtAttribute', p, 1, value)
# [77] # [94] NOT IMPLEMENTED (ExtendedAttributeIdentList)
# [95]
def p_ExtendedAttributeNamedArgList(self, p): def p_ExtendedAttributeNamedArgList(self, p):
"""ExtendedAttributeNamedArgList : identifier '=' identifier '(' ArgumentList ')'""" """ExtendedAttributeNamedArgList : identifier '=' identifier '(' ArgumentList ')'"""
args = self.BuildProduction('Arguments', p, 4, p[5]) args = self.BuildProduction('Arguments', p, 4, p[5])
value = self.BuildNamed('Call', p, 3, args) value = self.BuildNamed('Call', p, 3, args)
p[0] = self.BuildNamed('ExtAttribute', p, 1, value) p[0] = self.BuildNamed('ExtAttribute', p, 1, value)
# [96] NOT IMPLEMENTED (ExtendedAttributeTypePair)
# #
# Parser Errors # Parser Errors
# #
......
...@@ -58,8 +58,9 @@ class IDLPPAPILexer(IDLLexer): ...@@ -58,8 +58,9 @@ class IDLPPAPILexer(IDLLexer):
self._AddKeywords(['mem_t', 'str_t', 'cstr_t', 'interface_t']) self._AddKeywords(['mem_t', 'str_t', 'cstr_t', 'interface_t'])
# Remove JS types # Remove JS types
self._DelKeywords(['boolean', 'byte', 'Date', 'DOMString', 'double', self._DelKeywords(['boolean', 'byte', 'ByteString', 'Date', 'DOMString',
'float', 'long', 'object', 'octet', 'short', 'unsigned']) 'double', 'float', 'long', 'object', 'octet', 'RegExp',
'short', 'unsigned'])
# If run by itself, attempt to build the lexer # If run by itself, attempt to build the lexer
......
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
# on WebIDL. # on WebIDL.
# #
# WebIDL, and WebIDL grammar can be found at: # 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: # PLY can be found at:
# http://www.dabeaz.com/ply/ # http://www.dabeaz.com/ply/
# #
...@@ -50,7 +50,7 @@ class IDLPPAPIParser(IDLParser): ...@@ -50,7 +50,7 @@ class IDLPPAPIParser(IDLParser):
# #
#The parser is based on the WebIDL standard. See: #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] # [1]
def p_Definitions(self, p): def p_Definitions(self, p):
......
ANY any ANY any
ATTRIBUTE attribute ATTRIBUTE attribute
BOOLEAN boolean BOOLEAN boolean
BYTESTRING ByteString
BYTE byte BYTE byte
CALLBACK callback CALLBACK callback
CONST const CONST const
...@@ -26,6 +27,8 @@ OPTIONAL optional ...@@ -26,6 +27,8 @@ OPTIONAL optional
OR or OR or
PARTIAL partial PARTIAL partial
READONLY readonly READONLY readonly
REGEXP RegExp
SERIALIZER serializer
SETTER setter SETTER setter
SHORT short SHORT short
STATIC static STATIC static
......
...@@ -67,6 +67,18 @@ enum MealType2 { ...@@ -67,6 +67,18 @@ enum MealType2 {
"other" "other"
}; };
/* TREE
*Enum(TrailingComma)
* EnumItem(rice)
* EnumItem(noodles)
* EnumItem(other)
*/
enum TrailingComma {
"rice",
"noodles",
"other",
};
/* BUILD Error(Unexpected string "noodles" after string "rice".) */ /* BUILD Error(Unexpected string "noodles" after string "rice".) */
/* ERROR Unexpected string "noodles" after string "rice". */ /* ERROR Unexpected string "noodles" after string "rice". */
enum MissingComma { enum MissingComma {
...@@ -75,14 +87,6 @@ enum MissingComma { ...@@ -75,14 +87,6 @@ enum MissingComma {
"other" "other"
}; };
/* BUILD Error(Trailing comma in block.) */
/* ERROR Trailing comma in block. */
enum TrailingComma {
"rice",
"noodles",
"other",
};
/* BUILD Error(Unexpected "," after ",".) */ /* BUILD Error(Unexpected "," after ",".) */
/* ERROR Unexpected "," after ",". */ /* ERROR Unexpected "," after ",". */
enum ExtraComma { enum ExtraComma {
......
...@@ -76,13 +76,23 @@ interface MyIFaceBig { ...@@ -76,13 +76,23 @@ interface MyIFaceBig {
* Attribute(readOnlyString) * Attribute(readOnlyString)
* Type() * Type()
* PrimitiveType(DOMString) * PrimitiveType(DOMString)
* Attribute(staticString)
* Type()
* PrimitiveType(DOMString)
* Operation(myFunction) * Operation(myFunction)
* Arguments()
* Argument(myLong)
* Type()
* PrimitiveType(long long)
* Type() * Type()
* PrimitiveType(void) * PrimitiveType(void)
* Operation(staticFunction)
* Arguments() * Arguments()
* Argument(myLong) * Argument(myLong)
* Type() * Type()
* PrimitiveType(long long) * PrimitiveType(long long)
* Type()
* PrimitiveType(void)
*/ */
interface MyIFaceBig2 { interface MyIFaceBig2 {
const DOMString? nullValue = null; const DOMString? nullValue = null;
...@@ -90,35 +100,37 @@ interface MyIFaceBig2 { ...@@ -90,35 +100,37 @@ interface MyIFaceBig2 {
const long long longValue2 = 123; const long long longValue2 = 123;
attribute DOMString myString; attribute DOMString myString;
readonly attribute DOMString readOnlyString; readonly attribute DOMString readOnlyString;
static attribute DOMString staticString;
void myFunction(long long myLong); void myFunction(long long myLong);
static void staticFunction(long long myLong);
}; };
/* TREE /* TREE
*Interface(MyIFaceSpecials) *Interface(MyIFaceSpecials)
* Operation(set) * Operation(set)
* Type()
* PrimitiveType(void)
* Arguments() * Arguments()
* Argument(property) * Argument(property)
* Type() * Type()
* PrimitiveType(DOMString) * PrimitiveType(DOMString)
* Operation(_unnamed_)
* Type() * Type()
* PrimitiveType(double) * PrimitiveType(void)
* Operation(_unnamed_)
* Arguments() * Arguments()
* Argument(property) * Argument(property)
* Type() * Type()
* PrimitiveType(DOMString) * PrimitiveType(DOMString)
* Operation(GetFiveSix)
* Type() * Type()
* PrimitiveType(long long) * PrimitiveType(double)
* Array(5) * Operation(GetFiveSix)
* Array(6)
* Arguments() * Arguments()
* Argument(arg) * Argument(arg)
* Type() * Type()
* Typeref(SomeType) * Typeref(SomeType)
* Type()
* PrimitiveType(long long)
* Array(5)
* Array(6)
*/ */
interface MyIFaceSpecials { interface MyIFaceSpecials {
setter creator void set(DOMString property); setter creator void set(DOMString property);
......
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