aboutsummaryrefslogtreecommitdiff
path: root/examples/main.c
blob: 5dd3a4b56f4cb0d95681a06c2ef4fd55f140b6d3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#include <stdlib.h>
#include <stdio.h>
#include <stdint.h>
#include "typdown.h"

void foo(char *v) {
    uint8_t code;
    char *res = typdown_parse(v, &code);
    if (code == 0) {
        printf("%s\n", res);
        free(res);
    } else printf("cannot parse '%s', error: %s (%d)\n", v, typdown_getErrorString(code), code);
}

int main() {
    // valid
    foo("hello world");
    foo("he*ll*o world");
    foo("# he*ll*o world");

    // invalid
    foo("hello *world");
    foo("hello world :::");
    foo("# hello :::");
    return 0;
}