RoleHGen.py (1219B)
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(roleH, roleIdl): 11 input = open(roleIdl).read() 12 roles = re.findall(r"const unsigned long ROLE_([A-Z_]+) = (\d+);", input) 13 14 roleH.write( 15 "/* THIS FILE IS AUTOGENERATED - DO NOT EDIT */\n" 16 "/* Roles are defined in accessible/interfaces/nsIAccessibleRole.idl */\n\n" 17 "#ifndef _role_h_\n" 18 "#define _role_h_\n\n" 19 "namespace mozilla {\n" 20 "namespace a11y {\n" 21 "namespace roles {\n\n" 22 "enum Role {\n" 23 ) 24 for name, num in roles: 25 roleH.write(f" {name} = {num},\n") 26 lastName = roles[-1][0] 27 roleH.write( 28 f" LAST_ROLE = {lastName}\n" 29 "};\n\n" 30 "} // namespace roles\n\n" 31 "typedef enum mozilla::a11y::roles::Role role;\n\n" 32 "} // namespace a11y\n" 33 "} // namespace mozilla\n\n" 34 "#endif\n" 35 ) 36 37 38 # For debugging 39 if __name__ == "__main__": 40 import sys 41 42 generate(sys.stdout, "accessible/interfaces/nsIAccessibleRole.idl")