return result;
}
-/* TODO: there is no way to create a pretty report from ParseResult in case of an error */
+void print_parse_error(FILE *stream,
+ const char *str,
+ struct ParseResult result)
+{
+ if (!result.is_error) {
+ return;
+ }
+
+ /* TODO: print_parse_error doesn't support colors */
+ /* TODO: print_parse_error doesn't support multiple lines */
+
+ fprintf(stream, "%s\n", str);
+ for (size_t i = 0; i < result.error_cursor; ++i) {
+ fprintf(stream, " ")
+ }
+ fprintf(stream, "^\n");
+ fprintf(stream, "%s\n", result.error);
+}
struct ParseResult result = create_expr_from_str(code, &cursor, n);
if (result.is_error) {
- fprintf(stderr, "[ERROR] %s on character %ld", result.error, result.error_cursor);
+ print_parse_error(stderr, code, result);
} else {
print_expr_as_sexpr(result.expr);
}