Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: filters/parse_interface.py

Issue 6265373108207616: Issue #1170 adblockplus.org migration from Anwiki to our CMS. (Closed)
Patch Set: Created Sept. 17, 2014, 8:22 a.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | filters/subscription_sort.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
« no previous file with comments | « no previous file | filters/subscription_sort.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld