diff options
| author | Anhgelus Morhtuuzh <william@herges.fr> | 2026-05-04 16:31:51 +0200 |
|---|---|---|
| committer | Anhgelus Morhtuuzh <william@herges.fr> | 2026-05-04 16:31:51 +0200 |
| commit | 308c8893d9706318e8e756069f40c1435a70df91 (patch) | |
| tree | 5dd53a179f3b76d5638d300a3a9713fa37a42275 /examples | |
| parent | 4d151a25403e734ab3724d3bda21e29c396cd147 (diff) | |
feat(lib): return multiple errors
Diffstat (limited to 'examples')
| -rw-r--r-- | examples/main.c | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/examples/main.c b/examples/main.c index 18393c6..d28af79 100644 --- a/examples/main.c +++ b/examples/main.c @@ -4,13 +4,20 @@ #include <typdown.h> void foo(char *v) { - uint8_t code; - void *doc = typdown_parse(v, &code); - if (code != 0) { - printf("cannot parse '%s', error: %s (%d)\n", v, typdown_getErrorString(code), code); + struct typdown_Document doc = typdown_parse(v); + if (doc.errors != NULL) { + for (int i = 0; i < doc.errors_len; i++) { + struct typdown_Error error = doc.errors[i]; + printf("cannot parse '%s', error: %s (%d)\n", v, typdown_getErrorString(error.code), error.code); + printf("%d to %d ", error.location.beg, error.location.end); + for (int j = error.location.beg; j < error.location.end; j++) + printf("%c", v[j]); + printf("\n"); + } typdown_free(doc); return; } + uint8_t code; char *res = typdown_renderHTML(doc, &code); if (code != 0) { printf("cannot render '%s', error: %s (%d)\n", v, typdown_getErrorString(code), code); @@ -31,6 +38,6 @@ int main() { // invalid foo("hello *world"); foo("hello world :::"); - foo("# hello :::"); + foo("# hello :::"); return 0; } |
