Added flags to language specifiction. Added optional expect string to language specification. Added some exaple grammars for testing and demos
This commit is contained in:
@@ -13,7 +13,7 @@ void test_ident(void) {
|
||||
|
||||
/* ^[a-zA-Z_][a-zA-Z0-9_]*$ */
|
||||
|
||||
mpc_parser_t* Ident = mpc_enclose(
|
||||
mpc_parser_t* Ident = mpc_whole(
|
||||
mpc_and(2, mpcf_strfold,
|
||||
mpc_or(2, mpc_alpha(), mpc_underscore()),
|
||||
mpc_many1(mpcf_strfold, mpc_or(3, mpc_alpha(), mpc_underscore(), mpc_digit())),
|
||||
@@ -62,7 +62,7 @@ void test_maths(void) {
|
||||
mpc_parens(Expr, free)
|
||||
));
|
||||
|
||||
mpc_define(Maths, mpc_enclose(Expr, free));
|
||||
mpc_define(Maths, mpc_whole(Expr, free));
|
||||
|
||||
PT_ASSERT(mpc_match(Maths, "1", &r0, int_eq, free, int_print));
|
||||
PT_ASSERT(mpc_match(Maths, "(5)", &r1, int_eq, free, int_print));
|
||||
|
@@ -11,9 +11,9 @@ void test_grammar(void) {
|
||||
Value = mpc_new("value");
|
||||
Maths = mpc_new("maths");
|
||||
|
||||
mpc_define(Expr, mpca_grammar(" <product> (('+' | '-') <product>)* ", Prod));
|
||||
mpc_define(Prod, mpca_grammar(" <value> (('*' | '/') <value>)* ", Value));
|
||||
mpc_define(Value, mpca_grammar(" /[0-9]+/ | '(' <expression> ')' ", Expr));
|
||||
mpc_define(Expr, mpca_grammar(MPC_LANG_DEFAULT, " <product> (('+' | '-') <product>)* ", Prod));
|
||||
mpc_define(Prod, mpca_grammar(MPC_LANG_DEFAULT, " <value> (('*' | '/') <value>)* ", Value));
|
||||
mpc_define(Value, mpca_grammar(MPC_LANG_DEFAULT, " /[0-9]+/ | '(' <expression> ')' ", Expr));
|
||||
mpc_define(Maths, mpca_total(Expr));
|
||||
|
||||
t0 = mpc_ast_new("product|value|regex", "24");
|
||||
@@ -66,7 +66,7 @@ void test_language(void) {
|
||||
Value = mpc_new("value");
|
||||
Maths = mpc_new("maths");
|
||||
|
||||
mpca_lang(
|
||||
mpca_lang(MPC_LANG_DEFAULT,
|
||||
" \
|
||||
expression : <product> (('+' | '-') <product>)*; \
|
||||
product : <value> (('*' | '/') <value>)*; \
|
||||
@@ -87,7 +87,7 @@ void test_language_file(void) {
|
||||
Value = mpc_new("value");
|
||||
Maths = mpc_new("maths");
|
||||
|
||||
mpca_lang_contents("./tests/maths.grammar", Expr, Prod, Value, Maths);
|
||||
mpca_lang_contents(MPC_LANG_DEFAULT,"./tests/maths.grammar", Expr, Prod, Value, Maths);
|
||||
|
||||
mpc_cleanup(4, Expr, Prod, Value, Maths);
|
||||
|
||||
|
Reference in New Issue
Block a user