GenerateCSSPropertyID.py (1404B)
1 # This Source Code Form is subject to the terms of the Mozilla Public 2 # License, v. 2.0. If a copy of the MPL was not distributed with this 3 # file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 5 import runpy 6 import string 7 8 9 def generate(output, template, dataFile): 10 with open(template, "r") as f: 11 template = string.Template(f.read()) 12 data = runpy.run_path(dataFile)["data"] 13 14 longhand_count = 0 15 shorthand_count = 0 16 alias_count = 0 17 property_ids = [] 18 for prop in data.values(): 19 if prop.type() != "alias": 20 if prop.type() == "longhand": 21 assert shorthand_count == 0 22 longhand_count += 1 23 else: 24 assert alias_count == 0 25 shorthand_count += 1 26 property_ids.append("eCSSProperty_{}".format(prop.id)) 27 else: 28 alias_count += 1 29 property_ids.append("eCSSPropertyAlias_{}".format(prop.alias_id)) 30 31 output.write("/* THIS IS AN AUTOGENERATED FILE. DO NOT EDIT */\n\n") 32 output.write( 33 template.substitute( 34 { 35 "property_ids": "\n".join(" {},".format(p) for p in property_ids), 36 "longhand_first": property_ids[0], 37 "longhand_count": property_ids[longhand_count], 38 "shorthand_count": property_ids[longhand_count + shorthand_count], 39 } 40 ) 41 )