-
Notifications
You must be signed in to change notification settings - Fork 293
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
parser for """long string""" ? #157
Comments
I would assume you'd have to have it be the first rule in your grammar so that it will always take precedence, and then it'd be, more or less |
Thanks for the hint. Not as straightforward as I thought, here's what I've tried: mpc_re_mode("{{{.+}}}", MPC_RE_MULTILINE | MPC_RE_DOTALL); the mpc_re_mode("{{{[^}]+}}}", MPC_RE_MULTILINE | MPC_RE_DOTALL); this one works better, but not for contents that include
With combinators, I've tried the following mpc_parser_t *no3b = mpc_not(mpc_string("}}}"), free);
mpc_parser_t *item = mpc_or(2,
mpc_many1(mpcf_strfold, mpc_noneof("}")),
mpc_and(2,
mpcf_strfold,
no3b,
mpc_or(2, mpc_string("}}"), mpc_string("}")),
free
));
mpc_parser_t *block = mpc_and(3, mpcf_strfold,
mpc_string("{{{"),
mpc_many(mpcf_strfold, item),
mpc_string("}}}"),
free, free); I was expecting this to be a solution, but it only works if there's no Now, the following grammar-based mpc_parser_t *no3b = mpc_new("no3b");
mpc_parser_t *item = mpc_new("item");
mpc_parser_t *block = mpc_new("block");
mpc_define(no3b, mpc_not(mpc_string("}}}"), free));
mpc_define(item,
mpca_grammar(MPCA_LANG_WHITESPACE_SENSITIVE,
" /[^}]+/ | ( <no3b> (\"}}\" | \"}\" ) ) ",
no3b, NULL));
mpc_define(block,
mpca_grammar(MPCA_LANG_WHITESPACE_SENSITIVE,
" \"{{{\" <item>* \"}}}\" ",
item, NULL)); I'll do more testing with this one and eventually go with it.
To summarize the exercise (and happy to enter other tickets as convenient):
Thanks. |
Question: how to define a parser for arbitrary contents delimited by multi-char indicators? As a concrete case, consider python long strings, eg:
My case is actually with
{{{
and}}}
as delimiters, but any hints are appreciated.The text was updated successfully, but these errors were encountered: