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>
void test_str(cleri_grammar_t * grammar, const char * str)
{
cleri_parse_t * pr = cleri_parse(grammar, str);
printf("Test string '%s': %s\n", str, pr->is_valid ? "true" : "false");
cleri_parse_free(pr);
}
int main(void)
{
/* define grammar */
cleri_t * k_hi = cleri_keyword(0, "hi", 0);
cleri_t * r_name = cleri_regex(0, "^(?:\"(?:[^\"]*)\")+");
cleri_t * start = cleri_sequence(0, 2, k_hi, r_name);
/* compile grammar */
cleri_grammar_t * my_grammar = cleri_grammar(start, NULL);
/* test some strings */
test_str(my_grammar, "hi \"Iris\""); // true
test_str(my_grammar, "bye \"Iris\""); // false
/* cleanup grammar */
cleri_grammar_free(my_grammar);
return 0;
}
|