aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorTeddy Wing2018-09-27 21:55:12 +0200
committerTeddy Wing2018-09-28 12:38:32 +0200
commit76ab45d4a5890c4c348b33c32775e45a7c320c58 (patch)
treecb8a825cd478e7ba9470c56c20e72863f981450e /src
parentd7786b89766e607018953ea15d19dbe46802cc85 (diff)
downloaddome-key-map-76ab45d4a5890c4c348b33c32775e45a7c320c58.tar.bz2
parser::map(): Try to parse Action with a dependency on MapKind
Some non-working code where I was trying to get an `Action2` to parse correctly, with a dependency on the result of the `map_kind()` parser. Couldn't figure out how to get this to work though, as I couldn't escape errors like this one: error[E0271]: type mismatch resolving `<[closure@src/parser.rs:157:36: 186:6] as std::ops::FnOnce<(_,)>>::Output == std::result::Result<parser::Map, <I as combine::StreamOnce>::Error>` --> src/parser.rs:137:16 | 137 | fn map<I>() -> impl Parser<Input = I, Output = Map> | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected enum `std::result::Result`, found struct `parser::Map` | = note: expected type `std::result::Result<std::result::Result<(parser::Map, _), _>, _>` found type `std::result::Result<parser::Map, _>` = note: required because of the requirements on the impl of `combine::Parser` for `combine::combinator::FlatMap<combine::combinator::TakeUntil<_, combine::char::Newline<I>>, [closure@src/parser.rs:157:36: 186:6]>` = note: the return type of a function must have a statically known size error: aborting due to previous error For more information about this error, try `rustc --explain E0271`. Feeling like I've spent way too long stuck on this, so I'm just going to parse actions into new action type (`Action2` for now) by doing a second parsing pass. It's not going to be as performant, but at least I'm confident that will work. We can always come back to this later. I'll be reverting this commit.
Diffstat (limited to 'src')
-rw-r--r--src/parser.rs66
1 files changed, 53 insertions, 13 deletions
diff --git a/src/parser.rs b/src/parser.rs
index 57abbbb..f034784 100644
--- a/src/parser.rs
+++ b/src/parser.rs
@@ -138,21 +138,61 @@ where
I: Stream<Item = char>,
I::Error: ParseError<I::Item, I::Range, I::Position>,
{
- (
- map_kind(),
- whitespace_separator(),
- trigger(),
- whitespace_separator(),
- action()
- ).map(|(kind, _, trigger, _, action)|
- Map {
- trigger: trigger,
- action: action,
- kind: kind,
- }
- )
+ // (
+ // map_kind(),
+ // whitespace_separator(),
+ // trigger(),
+ // whitespace_separator(),
+ // action()
+ // ).map(|(kind, _, trigger, _, action)|
+ // Map {
+ // trigger: trigger,
+ // action: action,
+ // kind: kind,
+ // }
+ // )
+
+ // ---
+ take_until(newline()).flat_map(|line| {
+ map_kind().parse(line).map(|t| {
+ let map_kind = t.0;
+ let rest = t.1;
+
+ (
+ whitespace_separator(),
+ trigger(),
+ whitespace_separator(),
+ action()
+ )
+ .map(|(_, trigger, _, action)|
+ Map {
+ trigger: trigger,
+ action: action,
+ kind: map_kind,
+ }
+ )
+ .parse(rest)
+
+ // map_kind
+
+ // match map_kind {
+ // MapKind::Map => {
+ // },
+ // MapKind::Command => {
+ // },
+ // }
+ })
+ })
}
+
+// fn real_action<I>(input: I) -> impl Parser<Input = I, Output = Action2>
+// where
+// I: Stream<Item = char>,
+// I::Error: ParseError<I::Item, I::Range, I::Position>,
+// {
+// }
+
fn map_collection<I>() -> impl Parser<Input = I, Output = MapCollection>
where
I: Stream<Item = char>,