Bug 1025183 P1 Add ScalarValueString to webidl parser. r=bz

This commit is contained in:
Ben Kelly 2014-07-31 19:40:11 -04:00
Родитель a2acb5b3e5
Коммит 3e5f087f4e
4 изменённых файлов: 85 добавлений и 3 удалений

Просмотреть файл

@ -1379,6 +1379,7 @@ class IDLType(IDLObject):
'any',
'domstring',
'bytestring',
'scalarvaluestring',
'object',
'date',
'void',
@ -1431,6 +1432,9 @@ class IDLType(IDLObject):
def isDOMString(self):
return False
def isScalarValueString(self):
return False
def isVoid(self):
return self.name == "Void"
@ -1604,6 +1608,9 @@ class IDLNullableType(IDLType):
def isDOMString(self):
return self.inner.isDOMString()
def isScalarValueString(self):
return self.inner.isScalarValueString()
def isFloat(self):
return self.inner.isFloat()
@ -1725,6 +1732,9 @@ class IDLSequenceType(IDLType):
def isDOMString(self):
return False
def isScalarValueString(self):
return False
def isVoid(self):
return False
@ -1979,6 +1989,9 @@ class IDLArrayType(IDLType):
def isDOMString(self):
return False
def isScalarValueString(self):
return False
def isVoid(self):
return False
@ -2074,6 +2087,9 @@ class IDLTypedefType(IDLType, IDLObjectWithIdentifier):
def isDOMString(self):
return self.inner.isDOMString()
def isScalarValueString(self):
return self.inner.isScalarValueString()
def isVoid(self):
return self.inner.isVoid()
@ -2170,6 +2186,9 @@ class IDLWrapperType(IDLType):
def isDOMString(self):
return False
def isScalarValueString(self):
return False
def isVoid(self):
return False
@ -2306,6 +2325,7 @@ class IDLBuiltinType(IDLType):
'any',
'domstring',
'bytestring',
'scalarvaluestring',
'object',
'date',
'void',
@ -2340,6 +2360,7 @@ class IDLBuiltinType(IDLType):
Types.any: IDLType.Tags.any,
Types.domstring: IDLType.Tags.domstring,
Types.bytestring: IDLType.Tags.bytestring,
Types.scalarvaluestring: IDLType.Tags.scalarvaluestring,
Types.object: IDLType.Tags.object,
Types.date: IDLType.Tags.date,
Types.void: IDLType.Tags.void,
@ -2372,7 +2393,8 @@ class IDLBuiltinType(IDLType):
def isString(self):
return self._typeTag == IDLBuiltinType.Types.domstring or \
self._typeTag == IDLBuiltinType.Types.bytestring
self._typeTag == IDLBuiltinType.Types.bytestring or \
self._typeTag == IDLBuiltinType.Types.scalarvaluestring
def isByteString(self):
return self._typeTag == IDLBuiltinType.Types.bytestring
@ -2380,6 +2402,9 @@ class IDLBuiltinType(IDLType):
def isDOMString(self):
return self._typeTag == IDLBuiltinType.Types.domstring
def isScalarValueString(self):
return self._typeTag == IDLBuiltinType.Types.scalarvaluestring
def isInteger(self):
return self._typeTag <= IDLBuiltinType.Types.unsigned_long_long
@ -2532,6 +2557,9 @@ BuiltinTypes = {
IDLBuiltinType.Types.bytestring:
IDLBuiltinType(BuiltinLocation("<builtin type>"), "ByteString",
IDLBuiltinType.Types.bytestring),
IDLBuiltinType.Types.scalarvaluestring:
IDLBuiltinType(BuiltinLocation("<builtin type>"), "ScalarValueString",
IDLBuiltinType.Types.scalarvaluestring),
IDLBuiltinType.Types.object:
IDLBuiltinType(BuiltinLocation("<builtin type>"), "Object",
IDLBuiltinType.Types.object),
@ -2666,6 +2694,13 @@ class IDLValue(IDLObject):
raise WebIDLError("Trying to convert unrestricted value %s to non-unrestricted"
% self.value, [location]);
return self
elif self.type.isString() and type.isScalarValueString():
# Allow ScalarValueStrings to use default value just like
# DOMString. No coercion is required in this case as Codegen.py
# treats ScalarValueString just like DOMString, but with an
# extra normalization step.
assert self.type.isDOMString()
return self
raise WebIDLError("Cannot coerce type %s to type %s." %
(self.type, type), [location])
@ -3828,6 +3863,7 @@ class Tokenizer(object):
"Date": "DATE",
"DOMString": "DOMSTRING",
"ByteString": "BYTESTRING",
"ScalarValueString": "SCALARVALUESTRING",
"any": "ANY",
"boolean": "BOOLEAN",
"byte": "BYTE",
@ -4723,6 +4759,7 @@ class Parser(Tokenizer):
| DATE
| DOMSTRING
| BYTESTRING
| SCALARVALUESTRING
| ANY
| ATTRIBUTE
| BOOLEAN
@ -4976,6 +5013,12 @@ class Parser(Tokenizer):
"""
p[0] = IDLBuiltinType.Types.bytestring
def p_PrimitiveOrStringTypeScalarValueString(self, p):
"""
PrimitiveOrStringType : SCALARVALUESTRING
"""
p[0] = IDLBuiltinType.Types.scalarvaluestring
def p_UnsignedIntegerTypeUnsigned(self, p):
"""
UnsignedIntegerType : UNSIGNED IntegerType

Просмотреть файл

@ -159,7 +159,8 @@ def WebIDLTest(parser, harness):
"object", "Callback", "Callback2", "optional Dict",
"optional Dict2", "sequence<long>", "sequence<short>",
"MozMap<object>", "MozMap<Dict>", "MozMap<long>",
"long[]", "short[]", "Date", "Date?", "any" ]
"long[]", "short[]", "Date", "Date?", "any",
"ScalarValueString" ]
# When we can parse Date and RegExp, we need to add them here.
# Try to categorize things a bit to keep list lengths down
@ -170,7 +171,7 @@ def WebIDLTest(parser, harness):
primitives = numerics + booleans
nonNumerics = allBut(argTypes, numerics)
nonBooleans = allBut(argTypes, booleans)
strings = [ "DOMString", "ByteString", "Enum", "Enum2" ]
strings = [ "DOMString", "ByteString", "Enum", "Enum2", "ScalarValueString" ]
nonStrings = allBut(argTypes, strings)
nonObjects = primitives + strings
objects = allBut(argTypes, nonObjects )
@ -204,6 +205,7 @@ def WebIDLTest(parser, harness):
setDistinguishable("boolean?", allBut(nonBooleans, nullables))
setDistinguishable("DOMString", nonStrings)
setDistinguishable("ByteString", nonStrings)
setDistinguishable("ScalarValueString", nonStrings)
setDistinguishable("Enum", nonStrings)
setDistinguishable("Enum2", nonStrings)
setDistinguishable("Interface", notRelatedInterfaces)

Просмотреть файл

@ -0,0 +1,36 @@
# -*- coding: UTF-8 -*-
import WebIDL
def WebIDLTest(parser, harness):
parser.parse("""
interface TestScalarValueString {
attribute ScalarValueString svs;
};
""")
results = parser.finish();
harness.check(len(results), 1, "Should be one production")
harness.ok(isinstance(results[0], WebIDL.IDLInterface),
"Should be an IDLInterface")
iface = results[0]
harness.check(iface.identifier.QName(), "::TestScalarValueString",
"Interface has the right QName")
harness.check(iface.identifier.name, "TestScalarValueString",
"Interface has the right name")
harness.check(iface.parent, None, "Interface has no parent")
members = iface.members
harness.check(len(members), 1, "Should be one member")
attr = members[0]
harness.ok(isinstance(attr, WebIDL.IDLAttribute), "Should be an IDLAttribute")
harness.check(attr.identifier.QName(), "::TestScalarValueString::svs",
"Attr has correct QName")
harness.check(attr.identifier.name, "svs", "Attr has correct name")
harness.check(str(attr.type), "ScalarValueString",
"Attr type is the correct name")
harness.ok(attr.type.isScalarValueString(), "Should be ScalarValueString type")
harness.ok(attr.type.isString(), "Should be String collective type")
harness.ok(not attr.type.isDOMString(), "Should be not be DOMString type")

Просмотреть файл

@ -63,6 +63,7 @@ def WebIDLTest(parser, harness):
"octet",
"DOMString",
"ByteString",
"ScalarValueString",
#"sequence<float>",
"object",
"ArrayBuffer",