| 165 | |
| 166 | |
| 167 | def format_error(context=None, context_mark=None, problem=None, problem_mark=None, note=None, indent=0): |
| 168 | lines = [] |
| 169 | indentstr = ' ' * indent |
| 170 | if context is not None: |
| 171 | lines.append(indentstr + context) |
| 172 | if ( |
| 173 | context_mark is not None |
| 174 | and ( |
| 175 | problem is None or problem_mark is None |
| 176 | or context_mark != problem_mark |
| 177 | ) |
| 178 | ): |
| 179 | lines.append(context_mark.to_string(indent=indent)) |
| 180 | if problem is not None: |
| 181 | lines.append(indentstr + problem) |
| 182 | if problem_mark is not None: |
| 183 | lines.append(problem_mark.to_string(indent=indent)) |
| 184 | if note is not None: |
| 185 | lines.append(indentstr + note) |
| 186 | return '\n'.join(lines) |
| 187 | |
| 188 | |
| 189 | class MarkedError(Exception): |