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

Side by Side Diff: filters/parse_interface.py

Issue 5636796054503424: Issue 1170 - [adblockplus.org Anwiki to CMS migration] Migrate content (Closed)
Patch Set: Created Sept. 17, 2014, 8:33 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | filters/subscription_sort.py » ('j') | filters/unescape.py » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 import re
2
3 def parse_interface(interfaces):
Wladimir Palant 2014/09/18 20:33:04 Nit: I think what it gets as parameter isn't inter
kzar 2014/09/19 11:28:06 Done.
4 parsed = []
5 for property_key, property in interfaces.iteritems():
Wladimir Palant 2014/09/18 20:33:04 Nit: I think that simple key, value as names would
kzar 2014/09/19 11:28:06 Done.
6 if property_key.find("(") > -1:
Wladimir Palant 2014/09/18 20:33:04 Nit: this can be written as simply |"(" in propert
kzar 2014/09/19 11:28:06 Done.
7 match = re.match("^(arrayof\W+\w+|\w+)\W+(\w+)[\W\(]+([^\)]*)[\W\)]+$", pr operty_key)
Wladimir Palant 2014/09/18 20:33:04 You generally want to use r"foo" rather than "foo"
kzar 2014/09/19 11:28:06 Done.
8 if not match:
9 continue
Wladimir Palant 2014/09/18 20:33:04 Just dropping the line without any message is a gr
kzar 2014/09/19 11:28:06 Done.
10 return_type, property_name, argument_string = match.groups()
11 arguments = []
12 if "version" in property:
13 property_version = property["version"]
14 else:
15 property_version = ""
Wladimir Palant 2014/09/18 20:33:04 Nit: Use None instead of empty string here?
kzar 2014/09/19 11:28:06 I think empty strings are more useful for template
16 if argument_string:
17 for i, argument in enumerate(argument_string.split(",")):
Wladimir Palant 2014/09/18 20:33:04 Nit: Why use enumerate() here? Doesn't seem to be
kzar 2014/09/19 11:28:06 Done.
18 parts = argument.split(" ")
Wladimir Palant 2014/09/18 20:33:04 How about: match = re.match(r"^\s*(%s)\s+(\w+)\
kzar 2014/09/19 11:28:06 Done.
19 argument_name = parts[-1]
20 argument_type = " ".join(parts[:-1])
21 arguments.append({
22 "name": argument_name,
23 "type": argument_type
24 })
25 parsed.append({
26 "type": "method",
27 "name": property_name,
28 "version": property_version,
29 "return_type": return_type,
30 "arguments": arguments,
31 })
32 else:
33 parts = property_key.split()
Wladimir Palant 2014/09/18 20:33:04 I'd prefer: match = re.match(r"^\s*(readonly\s+
kzar 2014/09/19 11:28:06 Done.
34 property = { }
Wladimir Palant 2014/09/18 20:33:04 Nit: no space between the brackets.
kzar 2014/09/19 11:28:06 Done.
35 property["type"], property["name"] = parts[-2:]
36 if len(parts) == 3:
37 property["modifier"] = parts[0]
Wladimir Palant 2014/09/18 20:33:04 I think using temporary variables like you've done
kzar 2014/09/19 11:28:06 Done.
38 parsed.append(property)
39 parsed = sorted(parsed, key=lambda x: x["name"])
Wladimir Palant 2014/09/18 20:33:04 Please use parse.sort() that will sort the list in
kzar 2014/09/19 11:28:06 Done.
40 return parsed
OLDNEW
« no previous file with comments | « no previous file | filters/subscription_sort.py » ('j') | filters/unescape.py » ('J')

Powered by Google App Engine
This is Rietveld