mirror of
https://github.com/servo/servo.git
synced 2025-08-03 12:40:06 +01:00
Keyword argument for custom constant mapping
This commit is contained in:
parent
1c34162220
commit
12f429e23b
2 changed files with 8 additions and 3 deletions
|
@ -18,7 +18,7 @@ def to_camel_case(ident):
|
|||
|
||||
class Keyword(object):
|
||||
def __init__(self, name, values, gecko_constant_prefix=None,
|
||||
gecko_enum_prefix=None,
|
||||
gecko_enum_prefix=None, custom_consts=None,
|
||||
extra_gecko_values=None, extra_servo_values=None):
|
||||
self.name = name
|
||||
self.values = values.split()
|
||||
|
@ -29,6 +29,7 @@ class Keyword(object):
|
|||
self.gecko_enum_prefix = gecko_enum_prefix
|
||||
self.extra_gecko_values = (extra_gecko_values or "").split()
|
||||
self.extra_servo_values = (extra_servo_values or "").split()
|
||||
self.consts_map = {} if custom_consts is None else custom_consts
|
||||
|
||||
def gecko_values(self):
|
||||
return self.values + self.extra_gecko_values
|
||||
|
@ -45,12 +46,15 @@ class Keyword(object):
|
|||
raise Exception("Bad product: " + product)
|
||||
|
||||
def gecko_constant(self, value):
|
||||
moz_stripped = value.replace("-moz-", '')
|
||||
parts = moz_stripped.split('-')
|
||||
if self.gecko_enum_prefix:
|
||||
parts = value.replace("-moz-", "").split("-")
|
||||
parts = [p.title() for p in parts]
|
||||
return self.gecko_enum_prefix + "::" + "".join(parts)
|
||||
else:
|
||||
return self.gecko_constant_prefix + "_" + value.replace("-moz-", "").replace("-", "_").upper()
|
||||
mapped = self.consts_map.get(value)
|
||||
suffix = mapped if mapped else moz_stripped.replace("-", "_")
|
||||
return self.gecko_constant_prefix + "_" + suffix.upper()
|
||||
|
||||
def needs_cast(self):
|
||||
return self.gecko_enum_prefix is None
|
||||
|
|
|
@ -312,6 +312,7 @@
|
|||
keyword_kwargs = {a: kwargs.pop(a, None) for a in [
|
||||
'gecko_constant_prefix', 'gecko_enum_prefix',
|
||||
'extra_gecko_values', 'extra_servo_values',
|
||||
'custom_consts',
|
||||
]}
|
||||
%>
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue