Closed Cokemonkey11 closed 5 years ago
Use pom::parser::Parser
instead of pom::Parser
, there is lifetime parameter, e.g.
pub fn json<'a>() -> Parser<'a, u8, JsonValue> {
space() * value() - end()
}
I'm having some problems with seq(&' static str)
if I try that.
https://github.com/Cokemonkey11/wurstdoktor/tree/nostatic
error[E0495]: cannot infer an appropriate lifetime for lifetime parameter `'a` due to conflicting requirements
--> src\main.rs:92:7
|
92 | ).map(|(((d, (e, n)), p), r)| {
| ^^^
|
note: first, the lifetime cannot outlive the lifetime 'a as defined on the function body at 75:13...
--> src\main.rs:75:13
|
75 | fn class_fn<'a>() -> Parser<'a, u8, WurstFunction> {
| ^^
= note: ...so that the expression is assignable:
expected pom::parser::Parser<'a, _, _>
found pom::parser::Parser<'_, _, _>
= note: but, the lifetime must be valid for the static lifetime...
note: ...so that the type `&[u8]` will meet its required lifetime bounds
--> src\main.rs:79:13
|
79 | !seq(PRIVATE) *
| ^^^^^^^^^^^^^
error: aborting due to previous error
For more information about this error, try `rustc --explain E0495`.
error: Could not compile `wurstdoktor`.
I have no problem when doing this in examples/json.rs
static NULL: &[u8; 4] = b"null";
fn value<'a>() -> Parser<'a, u8, JsonValue> {
( seq(NULL).map(|_|JsonValue::Null)
You're right - I think the problem is actually related to !
operator:
@@ -52,7 +52,7 @@ fn object<'a>() -> Parser<'a, u8, HashMap<String, JsonValue>> {
}
fn value<'a>() -> Parser<'a, u8, JsonValue> {
- ( seq(b"null").map(|_|JsonValue::Null)
+ ( !seq(b"*") * seq(b"null").map(|_|JsonValue::Null)
error[E0495]: cannot infer an appropriate lifetime for lifetime parameter `'a` due to conflicting requirements
--> examples\json.rs:63:4
|
63 | ) - space()
| ^
|
note: first, the lifetime cannot outlive the lifetime 'a as defined on the function body at 55:10...
--> examples\json.rs:55:10
|
55 | fn value<'a>() -> Parser<'a, u8, JsonValue> {
| ^^
= note: ...so that the expression is assignable:
expected pom::parser::Parser<'a, _, _>
found pom::parser::Parser<'_, _, _>
= note: but, the lifetime must be valid for the static lifetime...
note: ...so that the type `&[u8]` will meet its required lifetime bounds
--> examples\json.rs:56:4
|
56 | ( !seq(b"*") * seq(b"null").map(|_|JsonValue::Null)
| ^^^^^^^^^^
Yes, fixed.
Means if you want to parse a string sourced from IO, you need to use lazy_static. Not very convenient