RelationTypeGen.py (1185B)
1 #!/usr/bin/env python 2 # 3 # This Source Code Form is subject to the terms of the Mozilla Public 4 # License, v. 2.0. If a copy of the MPL was not distributed with this 5 # file, You can obtain one at http://mozilla.org/MPL/2.0/. 6 7 import re 8 9 10 def generate(relH, relIdl): 11 input = open(relIdl).read() 12 relations = re.findall( 13 r"const unsigned long RELATION_([A-Z_]+) = ([x0-9a-f]+);", input 14 ) 15 16 relH.write( 17 "/* THIS FILE IS AUTOGENERATED - DO NOT EDIT */\n" 18 "/* Relations are defined in accessible/interfaces/nsIAccessibleRelation.idl */\n\n" 19 "#ifndef mozilla_a11y_relationtype_h_\n" 20 "#define mozilla_a11y_relationtype_h_\n\n" 21 "namespace mozilla {\n" 22 "namespace a11y {\n\n" 23 "enum class RelationType {\n" 24 ) 25 for name, num in relations: 26 relH.write(f" {name} = {num},\n") 27 lastName = relations[-1][0] 28 relH.write( 29 f" LAST = {lastName}\n" 30 "};\n\n" 31 "} // namespace a11y\n" 32 "} // namespace mozilla\n\n" 33 "#endif\n" 34 ) 35 36 37 # For debugging 38 if __name__ == "__main__": 39 import sys 40 41 generate(sys.stdout, "accessible/interfaces/nsIAccessibleRelation.idl")