Backed out changeset 06f41c22f3a6 (bug 1888460) for causing linux xpcshell failures...
[gecko.git] / accessible / mac / SelectorMapGen.py
blob1e406ade1f63a367041afaf830c7a15777715758
1 #!/usr/bin/env python
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/.
7 import re
10 def write_map(fd, name, text):
11 matches = re.findall(r"^//\s(AX\w+)\n-\s?\(.*?\)([\w:]+)", text, re.MULTILINE)
12 entries = [' @"%s" : @"%s"' % (a, s) for [a, s] in matches]
14 fd.write("NSDictionary* %s() {\n" % name)
15 fd.write(" // Create an autoreleased NSDictionary object once, and leak it.\n")
16 fd.write(" static NSDictionary* s%s = [@{\n" % name)
17 fd.write(",\n".join(entries))
18 fd.write("\n } retain];\n\n")
19 fd.write(" return s%s;\n" % name)
20 fd.write("}\n\n")
23 def gen_mm(fd, protocol_file):
24 protocol = open(protocol_file).read()
25 fd.write("/* THIS FILE IS AUTOGENERATED - DO NOT EDIT */\n\n")
26 fd.write("#import <Foundation/Foundation.h>\n\n")
27 fd.write("namespace mozilla {\nnamespace a11y {\nnamespace mac {\n\n")
29 sections = re.findall(
30 r"#pragma mark - (\w+)\n(.*?)(?=(?:#pragma mark|@end))", protocol, re.DOTALL
32 for name, text in sections:
33 write_map(fd, name, text)
35 fd.write("}\n}\n}\n")
38 def gen_h(fd, protocol_file):
39 protocol = open(protocol_file).read()
40 sections = re.findall(
41 r"#pragma mark - (\w+)\n(.*?)(?=(?:#pragma mark|@end))", protocol, re.DOTALL
44 fd.write("/* THIS FILE IS AUTOGENERATED - DO NOT EDIT */\n\n")
45 fd.write("#ifndef _MacSelectorMap_H_\n")
46 fd.write("#define _MacSelectorMap_H_\n")
47 fd.write("\n@class NSDictionary;\n")
48 fd.write("\nnamespace mozilla {\nnamespace a11y {\nnamespace mac {\n\n")
49 for name, _ in sections:
50 fd.write("NSDictionary* %s();\n\n" % name)
51 fd.write("}\n}\n}\n")
52 fd.write("\n#endif\n")
55 # For debugging
56 if __name__ == "__main__":
57 import sys
59 gen_mm(sys.stdout, "accessible/mac/MOXAccessibleProtocol.h")
61 gen_h(sys.stdout, "accessible/mac/MOXAccessibleProtocol.h")