(line: str, source_directory: str)
| 79 | current_section = None |
| 80 | in_multi_line_comment = False |
| 81 | def parse_line(line: str, source_directory: str): |
| 82 | nonlocal current_section, in_multi_line_comment |
| 83 | line = line.strip() |
| 84 | if line == "" or line.startswith(";") or line.startswith("//") or line.startswith("#") or line.startswith("%"): |
| 85 | pass # skip comments and empty lines |
| 86 | elif line.startswith("/*"): |
| 87 | in_multi_line_comment = True |
| 88 | elif line.endswith("*/"): |
| 89 | in_multi_line_comment = False |
| 90 | elif in_multi_line_comment: |
| 91 | pass |
| 92 | elif line.startswith(r"\{"): # follow include |
| 93 | include_path = self._parse_include_directive(line) |
| 94 | include_path = self._expand_cm(include_path) |
| 95 | if not os.path.isabs(include_path): |
| 96 | include_path = os.path.join(source_directory, include_path) |
| 97 | source_directory = os.path.split(os.path.abspath(include_path))[0] |
| 98 | if os.path.exists(include_path): |
| 99 | with open(include_path, encoding="latin-1") as f: |
| 100 | for line in f.readlines(): |
| 101 | parse_line(line, source_directory) |
| 102 | else: |
| 103 | print("Warning: included file {} not found.".format(include_path)) |
| 104 | elif line.startswith("["): |
| 105 | section = self._parse_section_header(line) |
| 106 | if section.name in self.sections.keys(): |
| 107 | current_section = self.sections[section.name] |
| 108 | else: |
| 109 | self.sections[section.name] = section |
| 110 | current_section = section |
| 111 | else: |
| 112 | property_name, property_value = self._parse_property(line) |
| 113 | if current_section is None: |
| 114 | raise ValueError("Missing section header") |
| 115 | current_section.properties[property_name] = property_value |
| 116 | source_directory = os.path.split(os.path.abspath(path))[0] |
| 117 | with open(path, encoding="latin-1") as f: |
| 118 | for line in f: |
nothing calls this directly
no test coverage detected