Commit a50b4ecb authored by Kenichi Ishibashi's avatar Kenichi Ishibashi Committed by Commit Bot

IDL parser: Merge custom rules to the base parser

Upstream some rules in blink_idl_parser to idl_parser.

BUG=617899

Change-Id: Ib9c0e68b1e81ab41147e01c5281e3e7f8366999d
Reviewed-on: https://chromium-review.googlesource.com/544724Reviewed-by: default avatarKentaro Hara <haraken@chromium.org>
Reviewed-by: default avatarHitoshi Yoshida <peria@chromium.org>
Commit-Queue: Kenichi Ishibashi <bashi@chromium.org>
Cr-Commit-Position: refs/heads/master@{#481790}
parent 7bd2df28
...@@ -207,35 +207,6 @@ class BlinkIDLParser(IDLParser): ...@@ -207,35 +207,6 @@ class BlinkIDLParser(IDLParser):
# Numbers are as per Candidate Recommendation 19 April 2012: # Numbers are as per Candidate Recommendation 19 April 2012:
# http://www.w3.org/TR/2012/CR-WebIDL-20120419/ # http://www.w3.org/TR/2012/CR-WebIDL-20120419/
# [b47]
def p_ExceptionMember(self, p):
"""ExceptionMember : Const
| ExceptionField
| Attribute
| ExceptionOperation"""
# Standard is (no Attribute, no ExceptionOperation):
# ExceptionMember : Const
# | ExceptionField
# FIXME: In DOMException.idl, Attributes should be changed to
# ExceptionFields, and Attribute removed from this rule.
p[0] = p[1]
# [b47.1] FIXME: rename to ExceptionAttribute
def p_Attribute(self, p):
"""Attribute : ReadOnly ATTRIBUTE Type identifier ';'"""
p[0] = self.BuildNamed('Attribute', p, 4,
ListFromConcat(p[1], p[3]))
# [b47.2]
def p_ExceptionOperation(self, p):
"""ExceptionOperation : Type identifier '(' ')' ';'"""
# Needed to handle one case in DOMException.idl:
# // Override in a Mozilla compatible format
# [NotEnumerable] DOMString toString();
# Limited form of Operation to prevent others from being added.
# FIXME: Should be a stringifier instead.
p[0] = self.BuildNamed('ExceptionOperation', p, 2, p[1])
# Extended attributes # Extended attributes
# [b49] Override base parser: remove comment field, since comments stripped # [b49] Override base parser: remove comment field, since comments stripped
# FIXME: Upstream # FIXME: Upstream
...@@ -262,52 +233,6 @@ class BlinkIDLParser(IDLParser): ...@@ -262,52 +233,6 @@ class BlinkIDLParser(IDLParser):
elif len(p) == 2: elif len(p) == 2:
p[0] = self.BuildError(p, 'ExtendedAttributes') p[0] = self.BuildError(p, 'ExtendedAttributes')
# [b51] Add ExtendedAttributeStringLiteral and ExtendedAttributeStringLiteralList
def p_ExtendedAttribute(self, p):
"""ExtendedAttribute : ExtendedAttributeNoArgs
| ExtendedAttributeArgList
| ExtendedAttributeIdent
| ExtendedAttributeIdentList
| ExtendedAttributeNamedArgList
| ExtendedAttributeStringLiteral
| ExtendedAttributeStringLiteralList"""
p[0] = p[1]
# Blink extension: Add support for string literal Extended Attribute values
def p_ExtendedAttributeStringLiteral(self, p):
"""ExtendedAttributeStringLiteral : identifier '=' StringLiteral """
def unwrap_string(ls):
"""Reach in and grab the string literal's "NAME"."""
return ls[1].value
value = self.BuildAttribute('VALUE', unwrap_string(p[3]))
p[0] = self.BuildNamed('ExtAttribute', p, 1, value)
# Blink extension: Add support for compound Extended Attribute values over string literals ("A","B")
def p_ExtendedAttributeStringLiteralList(self, p):
"""ExtendedAttributeStringLiteralList : identifier '=' '(' StringLiteralList ')' """
value = self.BuildAttribute('VALUE', p[4])
p[0] = self.BuildNamed('ExtAttribute', p, 1, value)
# Blink extension: one or more string literals. The values aren't propagated as literals,
# but their by their value only.
def p_StringLiteralList(self, p):
"""StringLiteralList : StringLiteral ',' StringLiteralList
| StringLiteral"""
def unwrap_string(ls):
"""Reach in and grab the string literal's "NAME"."""
return ls[1].value
if len(p) > 3:
p[0] = ListFromConcat(unwrap_string(p[1]), p[3])
else:
p[0] = ListFromConcat(unwrap_string(p[1]))
def p_StringLiteral(self, p):
"""StringLiteral : string"""
p[0] = ListFromConcat(self.BuildAttribute('TYPE', 'DOMString'),
self.BuildAttribute('NAME', p[1]))
def __init__(self, def __init__(self,
# common parameters # common parameters
debug=False, debug=False,
......
...@@ -718,22 +718,39 @@ class IDLParser(object): ...@@ -718,22 +718,39 @@ 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'))
# [] Unspecified # Not specified
def p_ExceptionMember(self, p): def p_ExceptionMember(self, p):
"""ExceptionMember : Const """ExceptionMember : Const
| ExceptionField""" | ExceptionField
| ExceptionAttribute
| ExceptionOperation"""
p[0] = p[1] p[0] = p[1]
# [] Unspecified # Not specified
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])
# [] Error recovery for ExceptionMembers - Unspecified # Error recovery for ExceptionMembers - Not specified
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')
# Not specified
def p_ExceptionAttribute(self, p):
"""ExceptionAttribute : ReadOnly ATTRIBUTE Type identifier ';'"""
p[0] = self.BuildNamed('Attribute', p, 4,
ListFromConcat(p[1], p[3]))
# Not specified
def p_ExceptionOperation(self, p):
"""ExceptionOperation : Type identifier '(' ')' ';'"""
# Needed to handle one case in DOMException.idl:
# // Override in a Mozilla compatible format
# [NotEnumerable] DOMString toString();
# Limited form of Operation to prevent others from being added.
p[0] = self.BuildNamed('ExceptionOperation', p, 2, p[1])
# [59] # [59]
def p_Iterable(self, p): def p_Iterable(self, p):
"""Iterable : ITERABLE '<' Type OptionalType '>' ';'""" """Iterable : ITERABLE '<' Type OptionalType '>' ';'"""
...@@ -794,20 +811,25 @@ class IDLParser(object): ...@@ -794,20 +811,25 @@ class IDLParser(object):
if len(p) > 1: if len(p) > 1:
p[0] = ListFromConcat(p[2], p[3]) p[0] = ListFromConcat(p[2], p[3])
# We only support: # https://heycam.github.io/webidl/#idl-extended-attributes
# The ExtendedAttribute symbol in Web IDL grammar is very flexible but we
# only support following patterns:
# [ identifier ] # [ identifier ]
# [ identifier ( ArgumentList ) ] # [ identifier ( ArgumentList ) ]
# [ identifier = identifier ] # [ identifier = identifier ]
# [ identifier = ( IdentifierList ) ] # [ identifier = ( IdentifierList ) ]
# [ identifier = identifier ( ArgumentList ) ] # [ identifier = identifier ( ArgumentList ) ]
# [66] map directly to [91-93, 95] # [ identifier = ( StringList ) ]
# [67-69, 71] are unsupported # The first five patterns are specified in the Web IDL spec and the last
# pattern is Blink's custom extension to support [ReflectOnly].
def p_ExtendedAttribute(self, p): def p_ExtendedAttribute(self, p):
"""ExtendedAttribute : ExtendedAttributeNoArgs """ExtendedAttribute : ExtendedAttributeNoArgs
| ExtendedAttributeArgList | ExtendedAttributeArgList
| ExtendedAttributeIdent | ExtendedAttributeIdent
| ExtendedAttributeIdentList | ExtendedAttributeIdentList
| ExtendedAttributeNamedArgList""" | ExtendedAttributeNamedArgList
| ExtendedAttributeStringLiteral
| ExtendedAttributeStringLiteralList"""
p[0] = p[1] p[0] = p[1]
# [71] # [71]
...@@ -1072,6 +1094,44 @@ class IDLParser(object): ...@@ -1072,6 +1094,44 @@ class IDLParser(object):
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)
# Blink extension: Add support for string literal Extended Attribute values
def p_ExtendedAttributeStringLiteral(self, p):
"""ExtendedAttributeStringLiteral : identifier '=' StringLiteral"""
def UnwrapString(ls):
"""Reach in and grab the string literal's "NAME"."""
return ls[1].value
value = self.BuildAttribute('VALUE', UnwrapString(p[3]))
p[0] = self.BuildNamed('ExtAttribute', p, 1, value)
# Blink extension: Add support for compound Extended Attribute values over
# string literals ("A","B")
def p_ExtendedAttributeStringLiteralList(self, p):
"""ExtendedAttributeStringLiteralList : identifier '=' '(' StringLiteralList ')'"""
value = self.BuildAttribute('VALUE', p[4])
p[0] = self.BuildNamed('ExtAttribute', p, 1, value)
# Blink extension: One or more string literals. The values aren't propagated
# as literals, but their by their value only.
def p_StringLiteralList(self, p):
"""StringLiteralList : StringLiteral ',' StringLiteralList
| StringLiteral"""
def UnwrapString(ls):
"""Reach in and grab the string literal's "NAME"."""
return ls[1].value
if len(p) > 3:
p[0] = ListFromConcat(UnwrapString(p[1]), p[3])
else:
p[0] = ListFromConcat(UnwrapString(p[1]))
# Blink extension: Wrap string literal.
def p_StringLiteral(self, p):
"""StringLiteral : string"""
p[0] = ListFromConcat(self.BuildAttribute('TYPE', 'DOMString'),
self.BuildAttribute('NAME', p[1]))
# [99] # [99]
def p_StringType(self, p): def p_StringType(self, p):
"""StringType : BYTESTRING """StringType : BYTESTRING
......
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