OLD | NEW |
(Empty) | |
| 1 import re, warnings |
| 2 |
| 3 TYPE_REGEXP = r"(?:arrayof\s+)?\w+" |
| 4 |
| 5 def parse_interface(interface_items): |
| 6 parsed = [] |
| 7 for key, value in interface_items.iteritems(): |
| 8 if "(" in key: |
| 9 # Item is a method |
| 10 match = re.match(r"^\s*(%s)\s+(\w+)\s*\(\s*([^\)]*)\s*\)\s*$" % TYPE_REGEX
P, key) |
| 11 if not match: |
| 12 warnings.warn("Skipped malformed method: '%s'" % key) |
| 13 continue |
| 14 return_type, property_name, argument_string = match.groups() |
| 15 arguments = [] |
| 16 if "version" in value: |
| 17 property_version = value["version"] |
| 18 else: |
| 19 property_version = "" |
| 20 if argument_string: |
| 21 for argument in argument_string.split(","): |
| 22 if argument.strip(): |
| 23 match = re.match(r"^\s*(%s)\s+(\w+)\s*$" % TYPE_REGEXP, argument) |
| 24 if not match: |
| 25 warnings.warn("Skipped malformed argument: '%s'" % argument) |
| 26 continue |
| 27 argument_type, argument_name = match.groups() |
| 28 arguments.append({ |
| 29 "name": argument_name, |
| 30 "type": argument_type |
| 31 }) |
| 32 parsed.append({ |
| 33 "type": "method", |
| 34 "name": property_name, |
| 35 "version": property_version, |
| 36 "return_type": return_type, |
| 37 "arguments": arguments |
| 38 }) |
| 39 else: |
| 40 # Item is a property |
| 41 match = re.match(r"^\s*(readonly\s+)?(%s)\s+(\w+)\s*$" % TYPE_REGEXP, key) |
| 42 if not match: |
| 43 warnings.warn("Skipped malformed property: '%s'" % key) |
| 44 continue |
| 45 property_modifier, property_type, property_name = match.groups() |
| 46 parsed.append({ |
| 47 "type": property_type, |
| 48 "name": property_name, |
| 49 "modifier": property_modifier or "" |
| 50 }) |
| 51 parsed.sort(key=lambda x: x["name"]) |
| 52 return parsed |
OLD | NEW |