diff --git a/README.md b/README.md index ffe9c0f..b017582 100644 --- a/README.md +++ b/README.md @@ -703,7 +703,7 @@ String literals are surrounded in double quotes `"`. Character literals in singl Parts specified one after another are parsed in order (like `mpc_and`), while parts separated by a pipe `|` are alternatives (like `mpc_or`). Parenthesis `()` are used to specify precedence. `*` can be used to mean zero or more of. `+` for one or more of. `?` for zero or one of. `!` for negation. And a number inside braces `{5}` to means so many counts of. -Rules are specified by rule name, optionally followed by an _expected_ string, followed by a colon `:`, followed by the definition, and ending in a semicolon `;`. The flags variable is a set of flags `MPC_LANG_DEFAULT`, `MPC_LANG_PREDICTIVE`, or `MPC_LANG_WHITESPACE_SENSITIVE`. For specifying if the language is predictive or whitespace sensitive. +Rules are specified by rule name, optionally followed by an _expected_ string, followed by a colon `:`, followed by the definition, and ending in a semicolon `;`. The flags variable is a set of flags `MPCA_LANG_DEFAULT`, `MPCA_LANG_PREDICTIVE`, or `MPCA_LANG_WHITESPACE_SENSITIVE`. For specifying if the language is predictive or whitespace sensitive. Like with the regular expressions, this user input is parsed by existing parts of the _mpc_ library. It provides one of the more powerful features of the library. diff --git a/examples/doge.c b/examples/doge.c index 5b15556..b6c1e7a 100644 --- a/examples/doge.c +++ b/examples/doge.c @@ -7,7 +7,7 @@ int main(int argc, char **argv) { mpc_parser_t* Phrase = mpc_new("phrase"); mpc_parser_t* Doge = mpc_new("doge"); - mpca_lang(MPC_LANG_DEFAULT, + mpca_lang(MPCA_LANG_DEFAULT, " \ adjective : \"wow\" | \"many\" | \"so\" | \"such\"; \ noun : \"lisp\" | \"language\" | \"c\" | \"book\" | \"build\"; \ diff --git a/examples/lispy.c b/examples/lispy.c index ae185d4..940876c 100644 --- a/examples/lispy.c +++ b/examples/lispy.c @@ -11,7 +11,7 @@ int main(int argc, char **argv) { mpc_parser_t* Expr = mpc_new("expr"); mpc_parser_t* Lispy = mpc_new("lispy"); - mpca_lang(MPC_LANG_PREDICTIVE, + mpca_lang(MPCA_LANG_PREDICTIVE, " \ number \"number\" : /[0-9]+/ ; \ symbol \"symbol\" : /[a-zA-Z0-9_+\\-*\\/\\\\=<>!&]+/ ; \ diff --git a/examples/maths.c b/examples/maths.c index 18199cc..e08d91f 100644 --- a/examples/maths.c +++ b/examples/maths.c @@ -7,7 +7,7 @@ int main(int argc, char **argv) { mpc_parser_t *Value = mpc_new("value"); mpc_parser_t *Maths = mpc_new("maths"); - mpca_lang(MPC_LANG_PREDICTIVE, + mpca_lang(MPCA_LANG_PREDICTIVE, " \ expression : (('+' | '-') )*; \ product : (('*' | '/') )*; \ diff --git a/examples/smallc.c b/examples/smallc.c index 2836051..174d073 100644 --- a/examples/smallc.c +++ b/examples/smallc.c @@ -20,7 +20,7 @@ int main(int argc, char **argv) { mpc_parser_t* Includes = mpc_new("includes"); mpc_parser_t* Smallc = mpc_new("smallc"); - mpc_err_t* err = mpca_lang(MPC_LANG_DEFAULT, + mpc_err_t* err = mpca_lang(MPCA_LANG_DEFAULT, " \n\ ident : /[a-zA-Z_][a-zA-Z0-9_]*/ ; \n\ number : /[0-9]+/ ; \n\ diff --git a/mpc.c b/mpc.c index 8a40104..d240d7d 100644 --- a/mpc.c +++ b/mpc.c @@ -2781,7 +2781,7 @@ static mpc_val_t *mpcaf_grammar_repeat(int n, mpc_val_t **xs) { static mpc_val_t *mpcaf_grammar_string(mpc_val_t *x, void *s) { mpca_grammar_st_t *st = s; char *y = mpcf_unescape(x); - mpc_parser_t *p = (st->flags & MPC_LANG_WHITESPACE_SENSITIVE) ? mpc_string(y) : mpc_tok(mpc_string(y)); + mpc_parser_t *p = (st->flags & MPCA_LANG_WHITESPACE_SENSITIVE) ? mpc_string(y) : mpc_tok(mpc_string(y)); free(y); return mpca_state(mpca_tag(mpc_apply(p, mpcf_str_ast), "string")); } @@ -2789,7 +2789,7 @@ static mpc_val_t *mpcaf_grammar_string(mpc_val_t *x, void *s) { static mpc_val_t *mpcaf_grammar_char(mpc_val_t *x, void *s) { mpca_grammar_st_t *st = s; char *y = mpcf_unescape(x); - mpc_parser_t *p = (st->flags & MPC_LANG_WHITESPACE_SENSITIVE) ? mpc_char(y[0]) : mpc_tok(mpc_char(y[0])); + mpc_parser_t *p = (st->flags & MPCA_LANG_WHITESPACE_SENSITIVE) ? mpc_char(y[0]) : mpc_tok(mpc_char(y[0])); free(y); return mpca_state(mpca_tag(mpc_apply(p, mpcf_str_ast), "char")); } @@ -2797,7 +2797,7 @@ static mpc_val_t *mpcaf_grammar_char(mpc_val_t *x, void *s) { static mpc_val_t *mpcaf_grammar_regex(mpc_val_t *x, void *s) { mpca_grammar_st_t *st = s; char *y = mpcf_unescape_regex(x); - mpc_parser_t *p = (st->flags & MPC_LANG_WHITESPACE_SENSITIVE) ? mpc_re(y) : mpc_tok(mpc_re(y)); + mpc_parser_t *p = (st->flags & MPCA_LANG_WHITESPACE_SENSITIVE) ? mpc_re(y) : mpc_tok(mpc_re(y)); free(y); return mpca_state(mpca_tag(mpc_apply(p, mpcf_str_ast), "regex")); } @@ -2927,7 +2927,7 @@ mpc_parser_t *mpca_grammar_st(const char *grammar, mpca_grammar_st_t *st) { mpc_cleanup(5, GrammarTotal, Grammar, Term, Factor, Base); - return (st->flags & MPC_LANG_PREDICTIVE) ? mpc_predictive(r.output) : r.output; + return (st->flags & MPCA_LANG_PREDICTIVE) ? mpc_predictive(r.output) : r.output; } @@ -3006,7 +3006,7 @@ static mpc_val_t *mpca_stmt_list_apply_to(mpc_val_t *x, void *s) { while(*stmts) { stmt = *stmts; left = mpca_grammar_find_parser(stmt->ident, st); - if (st->flags & MPC_LANG_PREDICTIVE) { stmt->grammar = mpc_predictive(stmt->grammar); } + if (st->flags & MPCA_LANG_PREDICTIVE) { stmt->grammar = mpc_predictive(stmt->grammar); } if (stmt->name) { stmt->grammar = mpc_expect(stmt->grammar, stmt->name); } mpc_define(left, stmt->grammar); free(stmt->ident); diff --git a/mpc.h b/mpc.h index 4e43ef6..79b0254 100644 --- a/mpc.h +++ b/mpc.h @@ -285,9 +285,9 @@ mpc_parser_t *mpca_or(int n, ...); mpc_parser_t *mpca_and(int n, ...); enum { - MPC_LANG_DEFAULT = 0, - MPC_LANG_PREDICTIVE = 1, - MPC_LANG_WHITESPACE_SENSITIVE = 2 + MPCA_LANG_DEFAULT = 0, + MPCA_LANG_PREDICTIVE = 1, + MPCA_LANG_WHITESPACE_SENSITIVE = 2 }; mpc_parser_t *mpca_grammar(int flags, const char *grammar, ...); diff --git a/tests/grammar.c b/tests/grammar.c index 1a06d4f..c37a6f3 100644 --- a/tests/grammar.c +++ b/tests/grammar.c @@ -11,9 +11,9 @@ void test_grammar(void) { Value = mpc_new("value"); Maths = mpc_new("maths"); - mpc_define(Expr, mpca_grammar(MPC_LANG_DEFAULT, " (('+' | '-') )* ", Prod)); - mpc_define(Prod, mpca_grammar(MPC_LANG_DEFAULT, " (('*' | '/') )* ", Value)); - mpc_define(Value, mpca_grammar(MPC_LANG_DEFAULT, " /[0-9]+/ | '(' ')' ", Expr)); + mpc_define(Expr, mpca_grammar(MPCA_LANG_DEFAULT, " (('+' | '-') )* ", Prod)); + mpc_define(Prod, mpca_grammar(MPCA_LANG_DEFAULT, " (('*' | '/') )* ", Value)); + mpc_define(Value, mpca_grammar(MPCA_LANG_DEFAULT, " /[0-9]+/ | '(' ')' ", 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(MPC_LANG_DEFAULT, + mpca_lang(MPCA_LANG_DEFAULT, " \ expression : (('+' | '-') )*; \ product : (('*' | '/') )*; \ @@ -87,7 +87,7 @@ void test_language_file(void) { Value = mpc_new("value"); Maths = mpc_new("maths"); - mpca_lang_contents(MPC_LANG_DEFAULT,"./tests/maths.grammar", Expr, Prod, Value, Maths); + mpca_lang_contents(MPCA_LANG_DEFAULT,"./tests/maths.grammar", Expr, Prod, Value, Maths); mpc_cleanup(4, Expr, Prod, Value, Maths);