File: main.c

package info (click to toggle)
libcleri 1.0.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 560 kB
  • sloc: ansic: 4,572; makefile: 51; sh: 40
file content (29 lines) | stat: -rw-r--r-- 843 bytes parent folder | download | duplicates (3)
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
27
28
29
#include <stdio.h>
#include <cleri/cleri.h>

const char * TestChoice = "goodbye";

int main(void)
{
    /* define grammar */
    cleri_t * k_hello = cleri_keyword(0, "hello", 0);
    cleri_t * k_goodbye = cleri_keyword(0, "goodbye", 0);
    cleri_t * choice = cleri_choice(
        0,                      // gid, not used in this example
        0,                      // stop at first match
        2,                      // number of elements
        k_hello, k_goodbye);    // elements

    /* create grammar */
    cleri_grammar_t * grammar = cleri_grammar(choice, NULL);

    /* parse some test string */
    cleri_parse_t * pr = cleri_parse(grammar, TestChoice);
    printf("Test: %s, '%s'\n", pr->is_valid ? "true" : "false", TestChoice);

    /* cleanup */
    cleri_parse_free(pr);
    cleri_grammar_free(grammar);

    return 0;
}