mirror of
https://github.com/servo/servo.git
synced 2025-08-13 17:35:36 +01:00
Use ascii_case_insensitive_phf_map! in PropertyId::parse
This commit is contained in:
parent
33ef6f78e5
commit
2f996e34f5
7 changed files with 21 additions and 69 deletions
|
@ -33,7 +33,6 @@ def main():
|
|||
rust = render(template, product=product, data=properties, __file__=template)
|
||||
if output == "style-crate":
|
||||
write(os.environ["OUT_DIR"], "properties.rs", rust)
|
||||
write(os.environ["OUT_DIR"], "static_ids.txt", static_ids(properties))
|
||||
if product == "gecko":
|
||||
template = os.path.join(BASE, "gecko.mako.rs")
|
||||
rust = render(template, data=properties)
|
||||
|
@ -72,19 +71,6 @@ def write(directory, filename, content):
|
|||
open(os.path.join(directory, filename), "wb").write(content)
|
||||
|
||||
|
||||
def static_id_generator(properties):
|
||||
for kind, props in [("Longhand", properties.longhands),
|
||||
("Shorthand", properties.shorthands)]:
|
||||
for p in props:
|
||||
yield "%s\tStaticId::%s(%sId::%s)" % (p.name, kind, kind, p.camel_case)
|
||||
for alias in p.alias:
|
||||
yield "%s\tStaticId::%s(%sId::%s)" % (alias, kind, kind, p.camel_case)
|
||||
|
||||
|
||||
def static_ids(properties):
|
||||
return '\n'.join(static_id_generator(properties))
|
||||
|
||||
|
||||
def write_html(properties):
|
||||
properties = dict(
|
||||
(p.name, {
|
||||
|
|
|
@ -731,24 +731,33 @@ impl ToCss for PropertyId {
|
|||
}
|
||||
}
|
||||
|
||||
// FIXME(https://github.com/rust-lang/rust/issues/33156): remove this enum and use PropertyId
|
||||
// when stable Rust allows destructors in statics.
|
||||
enum StaticId {
|
||||
Longhand(LonghandId),
|
||||
Shorthand(ShorthandId),
|
||||
}
|
||||
include!(concat!(env!("OUT_DIR"), "/static_ids.rs"));
|
||||
impl PropertyId {
|
||||
/// Returns a given property from the string `s`.
|
||||
///
|
||||
/// Returns Err(()) for unknown non-custom properties
|
||||
pub fn parse(s: Cow<str>) -> Result<Self, ()> {
|
||||
if let Ok(name) = ::custom_properties::parse_name(&s) {
|
||||
pub fn parse(property_name: Cow<str>) -> Result<Self, ()> {
|
||||
if let Ok(name) = ::custom_properties::parse_name(&property_name) {
|
||||
return Ok(PropertyId::Custom(::custom_properties::Name::from(name)))
|
||||
}
|
||||
|
||||
let lower_case = ::str::cow_into_ascii_lowercase(s);
|
||||
match STATIC_IDS.get(&*lower_case) {
|
||||
// FIXME(https://github.com/rust-lang/rust/issues/33156): remove this enum and use PropertyId
|
||||
// when stable Rust allows destructors in statics.
|
||||
enum StaticId {
|
||||
Longhand(LonghandId),
|
||||
Shorthand(ShorthandId),
|
||||
}
|
||||
ascii_case_insensitive_phf_map! {
|
||||
StaticIds: Map<StaticId> = {
|
||||
% for (kind, properties) in [("Longhand", data.longhands), ("Shorthand", data.shorthands)]:
|
||||
% for property in properties:
|
||||
% for name in [property.name] + property.alias:
|
||||
"${name}" => "StaticId::${kind}(${kind}Id::${property.camel_case})",
|
||||
% endfor
|
||||
% endfor
|
||||
% endfor
|
||||
}
|
||||
}
|
||||
match StaticIds::get(&property_name) {
|
||||
Some(&StaticId::Longhand(id)) => Ok(PropertyId::Longhand(id)),
|
||||
Some(&StaticId::Shorthand(id)) => Ok(PropertyId::Shorthand(id)),
|
||||
None => Err(()),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue