MCPcopy Create free account
hub / github.com/diasurgical/DevilutionX / ParseRow

Function ParseRow

tools/cpp_format_struct_table.py:189–263  ·  view source on GitHub ↗
(line: str, column_state: ColumnsState)

Source from the content-addressed store, hash-verified

187
188
189def ParseRow(line: str, column_state: ColumnsState) -> Row:
190 if line.endswith("// clang-format off"):
191 return Row(header=False, leading_comment=False, columns=[])
192 if not column_state.has_header and _HEADER_COMMENT_RE.match(line):
193 header_columns = ParseHeader(_HEADER_CONTENTS_RE.match(line).group(1))
194 if len(header_columns) > 1:
195 column_state.has_header = True
196 return Row(header=True, leading_comment=False, columns=header_columns)
197
198 if _SKIP_LINE_RE.match(line):
199 return Row(header=False, leading_comment=False, columns=[])
200
201 state = CharState()
202 leading_comment = False
203 column_begin = 0
204 column_end = 0
205 leading_spaces = True
206 columns = []
207 for i in range(len(line)):
208 c = line[i]
209 try:
210 UpdateCharState(c, state)
211 except RuntimeError as e:
212 raise RuntimeError(f" in:\n{line}") from e
213 if (state.parentheses and state.parentheses != ["{"]) or state.quotes:
214 if leading_spaces:
215 leading_spaces = False
216 column_begin = column_end = i
217 else:
218 column_end = i
219 continue
220
221 # Top-level "{":
222 if state.pushed_paren == "{" and state.parentheses == ["{"]:
223 column = line[column_begin:column_end]
224 if column:
225 if column.startswith("/*"):
226 leading_comment = True
227 columns.append(column)
228 column_begin = column_end + 2
229 column_end = column_begin
230 leading_spaces = True
231 continue
232
233 # Top-level "}":
234 if (
235 c == "}"
236 and not state.in_comment
237 and not state.quotes
238 and not state.parentheses
239 ):
240 columns.append(line[column_begin:column_end])
241 break
242
243 if state.in_comment:
244 if leading_spaces:
245 leading_spaces = False
246 column_begin = i

Callers 2

ProcessLineFunction · 0.85
FormatLineFunction · 0.85

Calls 4

RowClass · 0.85
ParseHeaderFunction · 0.85
CharStateClass · 0.85
UpdateCharStateFunction · 0.85

Tested by

no test coverage detected