| 145 | |
| 146 | |
| 147 | def ParseHeader(line: str) -> list[str]: |
| 148 | parens = [] |
| 149 | columns = [] |
| 150 | begin = end = 0 |
| 151 | leading_spaces = True |
| 152 | for i in range(len(line)): |
| 153 | c = line[i] |
| 154 | if c == "{": |
| 155 | if not parens: |
| 156 | if end > begin: |
| 157 | columns.append(line[begin:end]) |
| 158 | begin = end = i |
| 159 | parens.append(c) |
| 160 | continue |
| 161 | elif c == "}": |
| 162 | if not parens or parens[-1] != "{": |
| 163 | raise RuntimeError("Mismatched paretheses") |
| 164 | parens.pop() |
| 165 | if not parens: |
| 166 | if i >= begin: |
| 167 | columns.append(line[begin : i + 1]) |
| 168 | begin = end = i |
| 169 | elif parens: |
| 170 | end = i + 1 |
| 171 | else: |
| 172 | if c == " ": |
| 173 | if not leading_spaces: |
| 174 | if end > begin: |
| 175 | columns.append(line[begin:end]) |
| 176 | leading_spaces = True |
| 177 | begin = end = i |
| 178 | else: |
| 179 | if leading_spaces: |
| 180 | begin = i |
| 181 | leading_spaces = False |
| 182 | else: |
| 183 | end = i + 1 |
| 184 | if end > begin: |
| 185 | columns.append(line[begin:end]) |
| 186 | return columns |
| 187 | |
| 188 | |
| 189 | def ParseRow(line: str, column_state: ColumnsState) -> Row: |