Replies: 5 comments 2 replies
-
rust-peg/tests/run-pass/custom_expr.rs Lines 9 to 17 in 4317fbd But, I'd suggest writing three separate rules, especially if they'll handle escaping differently. If you really want to take the delimiter as a parameter, I'd suggest taking a rule delim_string(delim: rule<()>) -> String
= delim() chars:(!delim() [c] { c } / escape_char())* delim() { chars.into_iter().collect() }
rule use_it() = delim_string(<"\"">) |
Beta Was this translation helpful? Give feedback.
-
Thanks a lot! it works and making it getting a rule with the delimiter also works even better |
Beta Was this translation helpful? Give feedback.
-
Another small question that troubled me and couldn't get how to do it - in conditional blocks how to return a custom "dynamic" error. I want to have an "interpreted string". peg::parser! {
rule delim_interp_string(delim: rule<()>) -> String
= "$" s:delim_string(delim) { ?
json_serde::from_str::<String>(&format!(r#""{}""#, s))
.map_err(|err| format!("Invalid interpreted string: {}", err))
}
} |
Beta Was this translation helpful? Give feedback.
-
How can I do that? |
Beta Was this translation helpful? Give feedback.
-
Hope I don't bother too much. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I am trying to have a query parser allowing strings with single/double/triple quotes.
I thought to do it with a rule
delim_string
getting the delimiter as a parameter and then using it but there something with it I seem to not get right...I'd mention I'm still new to rust and looking at peg just lately.
I tried several things looking into the examples trying to use
##parse_string_literal(delim)
ordelim()
or different code blocks but didn't help.The following compiles but doesn't work as expected -
Help will be very much appreciated thanks!
Beta Was this translation helpful? Give feedback.
All reactions