Left: | ||
Right: |
LEFT | RIGHT |
---|---|
1 # This file is part of the Adblock Plus website, | |
2 # Copyright (C) 2006-2015 Eyeo GmbH | |
3 # | |
4 # Adblock Plus is free software: you can redistribute it and/or modify | |
5 # it under the terms of the GNU General Public License version 3 as | |
6 # published by the Free Software Foundation. | |
7 # | |
8 # Adblock Plus is distributed in the hope that it will be useful, | |
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
11 # GNU General Public License for more details. | |
12 # | |
13 # You should have received a copy of the GNU General Public License | |
14 # along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. | |
15 | |
1 import re, warnings | 16 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.
| |
2 | 17 |
3 TYPE_REGEXP = r"(?:arrayof\s+)?\w+" | 18 TYPE_REGEXP = r"(?:arrayof\s+)?\w+" |
4 | 19 |
5 def parse_interface(interface_items): | 20 def parse_interface(interface_items): |
6 parsed = [] | 21 parsed = [] |
7 for key, value in interface_items.iteritems(): | 22 for key, value in interface_items.iteritems(): |
8 if "(" in key: | 23 if "(" in key: |
9 # Item is a method | 24 # Item is a method |
10 match = re.match(r"^\s*(%s)\s+(\w+)\s*\(\s*([^\)]*)\s*\)\s*$" % TYPE_REGEX P, key) | 25 match = re.match(r"^\s*(%s)\s+(\S+)\s*\(\s*([^\)]*)\s*\)\s*$" % TYPE_REGEX P, 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.
| |
11 if not match: | 26 if not match: |
12 warnings.warn("Skipped malformed method: '%s'" % key) | 27 warnings.warn("Skipped malformed method: '%s'" % key) |
13 continue | 28 continue |
14 return_type, property_name, argument_string = match.groups() | 29 return_type, property_name, argument_string = match.groups() |
15 arguments = [] | 30 arguments = [] |
16 if "version" in value: | |
17 property_version = value["version"] | |
18 else: | |
19 property_version = "" | |
20 if argument_string: | 31 if argument_string: |
21 for argument in argument_string.split(","): | 32 for argument in argument_string.split(","): |
22 if argument.strip(): | 33 if argument.strip(): |
23 match = re.match(r"^\s*(%s)\s+(\w+)\s*$" % TYPE_REGEXP, argument) | 34 match = re.match(r"^\s*(%s)\s+(\S+)\s*$" % TYPE_REGEXP, argument) |
24 if not match: | 35 if not match: |
25 warnings.warn("Skipped malformed argument: '%s'" % argument) | 36 warnings.warn("Skipped malformed argument: '%s'" % argument) |
26 continue | 37 continue |
27 argument_type, argument_name = match.groups() | 38 argument_type, argument_name = match.groups() |
28 arguments.append({ | 39 arguments.append({ |
29 "name": argument_name, | 40 "name": argument_name, |
30 "type": argument_type | 41 "type": argument_type |
31 }) | 42 }) |
32 parsed.append({ | 43 value.update({ |
33 "type": "method", | 44 "type": "method", |
34 "name": property_name, | 45 "name": property_name, |
35 "version": property_version, | |
36 "return_type": return_type, | 46 "return_type": return_type, |
37 "arguments": arguments | 47 "arguments": arguments |
38 }) | 48 }) |
49 parsed.append(value) | |
39 else: | 50 else: |
40 # Item is a property | 51 # Item is a property |
41 match = re.match(r"^\s*(readonly\s+)?(%s)\s+(\w+)\s*$" % TYPE_REGEXP, key) | 52 match = re.match(r"^\s*(readonly\s+)?(%s)\s+(\S+)\s*$" % TYPE_REGEXP, key) |
42 if not match: | 53 if not match: |
43 warnings.warn("Skipped malformed property: '%s'" % key) | 54 warnings.warn("Skipped malformed property: '%s'" % key) |
44 continue | 55 continue |
45 property_modifier, property_type, property_name = match.groups() | 56 property_modifier, property_type, property_name = match.groups() |
46 parsed.append({ | 57 value.update({ |
47 "type": property_type, | 58 "type": property_type, |
48 "name": property_name, | 59 "name": property_name, |
49 "modifier": property_modifier or "" | 60 "modifier": property_modifier or "" |
50 }) | 61 }) |
62 parsed.append(value) | |
51 parsed.sort(key=lambda x: x["name"]) | 63 parsed.sort(key=lambda x: x["name"]) |
52 return parsed | 64 return parsed |
LEFT | RIGHT |