Index: filters/parse_interface.py |
diff --git a/filters/parse_interface.py b/filters/parse_interface.py |
new file mode 100644 |
index 0000000000000000000000000000000000000000..3b3e8192c3315f424d5fe7af44ab325bcf6e7b31 |
--- /dev/null |
+++ b/filters/parse_interface.py |
@@ -0,0 +1,45 @@ |
+import re |
+from jinja2 import environmentfilter |
+# readonly PRInt32 subscriptionCount |
+# void removePatterns ( arrayof wstring patterns ) |
+# wstring updateExternalSubscription ( AString id, AUTF8String title, arrayof wstring patterns ) |
+ |
+@environmentfilter |
+def parse_interface(environment, interfaces): |
+ parsed = [] |
+ for property_key, property in interfaces.iteritems(): |
+ if property_key.find("(") > -1: |
+ match = re.match("^(arrayof\W+\w+|\w+)\W+(\w+)[\W\(]+([^\)]*)[\W\)]+$", property_key) |
+ if not match: |
+ continue |
+ return_type, property_name, argument_string = match.groups() |
+ arguments = [] |
+ if "version" in property: |
+ property_version = property["version"] |
+ else: |
+ property_version = "" |
+ if argument_string: |
+ for i, argument in enumerate(argument_string.split(",")): |
+ parts = argument.split(" ") |
+ argument_name = parts[-1] |
+ argument_type = " ".join(parts[:-1]) |
+ arguments.append({ |
+ "name": argument_name, |
+ "type": argument_type |
+ }) |
+ parsed.append({ |
+ "type": "method", |
+ "name": property_name, |
+ "version": property_version, |
+ "return_type": return_type, |
+ "arguments": arguments, |
+ }) |
+ else: |
+ parts = property_key.split() |
+ property = { } |
+ property["type"], property["name"] = parts[-2:] |
+ if len(parts) == 3: |
+ property["modifier"] = parts[0] |
+ parsed.append(property) |
+ parsed = sorted(parsed, key=lambda x: x["name"]) |
+ return parsed |