(data: str, file_name: str, map_binary_to_string: bool = False)
| 57 | |
| 58 | |
| 59 | def parse(data: str, file_name: str, map_binary_to_string: bool = False) -> OrderedDict[str, Any]: |
| 60 | protocol = OrderedDict() |
| 61 | protocol["version"] = OrderedDict() |
| 62 | protocol["domains"] = [] |
| 63 | domain = None |
| 64 | item = None |
| 65 | subitems = None |
| 66 | nukeDescription = False |
| 67 | global description |
| 68 | lines = data.split("\n") |
| 69 | for i in range(0, len(lines)): |
| 70 | if nukeDescription: |
| 71 | description = "" |
| 72 | nukeDescription = False |
| 73 | line = lines[i] |
| 74 | trimLine = line.strip() |
| 75 | |
| 76 | if trimLine.startswith("#"): |
| 77 | if len(description): |
| 78 | description += "\n" |
| 79 | description += trimLine[2:] |
| 80 | continue |
| 81 | else: |
| 82 | nukeDescription = True |
| 83 | |
| 84 | if len(trimLine) == 0: |
| 85 | continue |
| 86 | |
| 87 | match = re.compile(r"^(experimental )?(deprecated )?domain (.*)").match(line) |
| 88 | if match: |
| 89 | domain = createItem({"domain": match.group(3)}, match.group(1), match.group(2)) |
| 90 | protocol["domains"].append(domain) |
| 91 | continue |
| 92 | |
| 93 | match = re.compile(r"^ depends on ([^\s]+)").match(line) |
| 94 | if match: |
| 95 | if "dependencies" not in domain: |
| 96 | domain["dependencies"] = [] |
| 97 | domain["dependencies"].append(match.group(1)) |
| 98 | continue |
| 99 | |
| 100 | match = re.compile( |
| 101 | r"^ (experimental )?(deprecated )?type (.*) " |
| 102 | r"extends (array of )?([^\s]+)" |
| 103 | ).match(line) |
| 104 | if match: |
| 105 | if "types" not in domain: |
| 106 | domain["types"] = [] |
| 107 | item = createItem({"id": match.group(3)}, match.group(1), match.group(2)) |
| 108 | assignType(item, match.group(5), match.group(4), map_binary_to_string) |
| 109 | domain["types"].append(item) |
| 110 | continue |
| 111 | |
| 112 | match = re.compile(r"^ (experimental )?(deprecated )?(command|event) (.*)").match(line) |
| 113 | if match: |
| 114 | list = [] |
| 115 | if match.group(3) == "command": |
| 116 | if "commands" in domain: |
no test coverage detected