Improve webidl precision

Allow enum variants staring with digit
This commit is contained in:
Kunal Mohan 2020-06-01 19:19:41 +05:30
parent e0f3e9b980
commit d9db350df5

View file

@ -4328,7 +4328,7 @@ def getEnumValueName(value):
if re.match("[^\x20-\x7E]", value): if re.match("[^\x20-\x7E]", value):
raise SyntaxError('Enum value "' + value + '" contains non-ASCII characters') raise SyntaxError('Enum value "' + value + '" contains non-ASCII characters')
if re.match("^[0-9]", value): if re.match("^[0-9]", value):
raise SyntaxError('Enum value "' + value + '" starts with a digit') value = '_' + value
value = re.sub(r'[^0-9A-Za-z_]', '_', value) value = re.sub(r'[^0-9A-Za-z_]', '_', value)
if re.match("^_[A-Z]|__", value): if re.match("^_[A-Z]|__", value):
raise SyntaxError('Enum value "' + value + '" is reserved by the C++ spec') raise SyntaxError('Enum value "' + value + '" is reserved by the C++ spec')
@ -4650,20 +4650,24 @@ class CGUnionConversionStruct(CGThing):
# "object" is not distinguishable from other types # "object" is not distinguishable from other types
assert not object or not (interfaceObject or arrayObject or callbackObject or mozMapObject) assert not object or not (interfaceObject or arrayObject or callbackObject or mozMapObject)
templateBody = CGList([], "\n") templateBody = CGList([], "\n")
if object: if arrayObject or callbackObject:
templateBody.append(object) # An object can be both an sequence object and a callback or
# dictionary, but we shouldn't have both in the union's members
# because they are not distinguishable.
assert not (arrayObject and callbackObject)
templateBody.append(arrayObject if arrayObject else callbackObject)
if interfaceObject: if interfaceObject:
assert not object
templateBody.append(interfaceObject) templateBody.append(interfaceObject)
if arrayObject: elif object:
templateBody.append(arrayObject) templateBody.append(object)
if callbackObject:
templateBody.append(callbackObject)
if mozMapObject: if mozMapObject:
templateBody.append(mozMapObject) templateBody.append(mozMapObject)
conversions.append(CGIfWrapper("value.get().is_object()", templateBody)) conversions.append(CGIfWrapper("value.get().is_object()", templateBody))
if dictionaryObject: if dictionaryObject:
assert not hasObjectTypes assert not object
conversions.append(dictionaryObject) conversions.append(dictionaryObject)
stringTypes = [t for t in memberTypes if t.isString() or t.isEnum()] stringTypes = [t for t in memberTypes if t.isString() or t.isEnum()]