diff options
| author | Teddy Wing | 2018-08-20 11:26:57 +0200 | 
|---|---|---|
| committer | Teddy Wing | 2018-08-20 11:26:57 +0200 | 
| commit | b58c082c39e77da664703c34c45d832a59974554 (patch) | |
| tree | c2e8ef2053111dfa0250d6ee954d8a8cc9774773 /src/lib.rs | |
| parent | 135d09cc04a874a36c5973d52412cf4f276f6226 (diff) | |
| download | dome-key-map-b58c082c39e77da664703c34c45d832a59974554.tar.bz2 | |
Parse whole map file strings
Very important: file must be terminated by a newline in order to parse
correctly because of the way `Action`s are parsed. Will need to correct
this to work for EOF also.
We can now parse a whole file of map and mode definitions!
Diffstat (limited to 'src/lib.rs')
| -rw-r--r-- | src/lib.rs | 49 | 
1 files changed, 31 insertions, 18 deletions
| @@ -204,24 +204,36 @@ where      I: Stream<Item = char>,      I::Error: ParseError<I::Item, I::Range, I::Position>,  { -    ( -        many::<Vec<Mode>, _>(mode()), -        map_collection(), -    ).map(|(modes, maps)| { -        let mut modes_hash = HashMap::new(); - -        for mode in modes { -            modes_hash.insert( -                mode.trigger, -                mode.maps, -            ); -        } +    definitions() +        .map(|definitions| { +            let mut maps = HashMap::new(); +            let mut modes = HashMap::new(); + +            for definition in definitions { +                match definition { +                    Definition::Map(map) => { +                        maps.insert( +                            map.trigger, +                            MapAction { +                                action: map.action, +                                kind: map.kind, +                            } +                        ); +                    }, +                    Definition::Mode(mode) => { +                        modes.insert( +                            mode.trigger, +                            mode.maps, +                        ); +                    }, +                } +            } -        MapGroup { -            maps: maps, -            modes: modes_hash, -        } -    }) +            MapGroup { +                maps: maps, +                modes: modes, +            } +        })  }  fn comment<I>() -> impl Parser<Input = I> @@ -459,7 +471,8 @@ mode <down><up> {      map <play> p  } -cmd <play> /usr/bin/say hello"; +cmd <play> /usr/bin/say hello +";          let result = map_group().easy_parse(text).map(|t| t.0);          let mut maps: MapCollection = HashMap::new(); | 
