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

Unified Diff: filters/parse_interface.py

Issue 5636796054503424: Issue 1170 - [adblockplus.org Anwiki to CMS migration] Migrate content (Closed)
Patch Set: Brought in changes to website made over last few months. Created Jan. 19, 2015, 12:18 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') | filters/subscription_sort.py » ('J')
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..ecf78e37c05812937dd7d83bd08599497e7ac369
--- /dev/null
+++ b/filters/parse_interface.py
@@ -0,0 +1,52 @@
+import re, warnings
Sebastian Noack 2015/02/13 17:51:49 Licence disclaimer is missing, not only here but a
kzar 2015/02/20 14:55:18 Done.
+
+TYPE_REGEXP = r"(?:arrayof\s+)?\w+"
+
+def parse_interface(interface_items):
+ parsed = []
+ for key, value in interface_items.iteritems():
+ if "(" in key:
+ # Item is a method
+ match = re.match(r"^\s*(%s)\s+(\w+)\s*\(\s*([^\)]*)\s*\)\s*$" % TYPE_REGEXP, key)
Sebastian Noack 2015/02/13 17:51:49 Be aware that \w doesn't math dashes and non-ASCII
kzar 2015/02/20 14:55:18 Done.
+ if not match:
+ warnings.warn("Skipped malformed method: '%s'" % key)
+ continue
+ return_type, property_name, argument_string = match.groups()
+ arguments = []
+ if "version" in value:
+ property_version = value["version"]
+ else:
+ property_version = ""
+ if argument_string:
+ for argument in argument_string.split(","):
+ if argument.strip():
+ match = re.match(r"^\s*(%s)\s+(\w+)\s*$" % TYPE_REGEXP, argument)
+ if not match:
+ warnings.warn("Skipped malformed argument: '%s'" % argument)
+ continue
+ argument_type, argument_name = match.groups()
+ 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:
+ # Item is a property
+ match = re.match(r"^\s*(readonly\s+)?(%s)\s+(\w+)\s*$" % TYPE_REGEXP, key)
+ if not match:
+ warnings.warn("Skipped malformed property: '%s'" % key)
+ continue
+ property_modifier, property_type, property_name = match.groups()
+ parsed.append({
+ "type": property_type,
+ "name": property_name,
+ "modifier": property_modifier or ""
+ })
+ parsed.sort(key=lambda x: x["name"])
+ return parsed
« no previous file with comments | « no previous file | filters/subscription_sort.py » ('j') | filters/subscription_sort.py » ('J')

Powered by Google App Engine
This is Rietveld