diff options
| author | Teddy Wing | 2018-10-01 03:18:34 +0200 | 
|---|---|---|
| committer | Teddy Wing | 2018-10-01 03:18:34 +0200 | 
| commit | 5ef2443642a2d8b223afdf169200a725d2809b76 (patch) | |
| tree | a666db63c165db76c6016cbf084743f2df60dacf /src/parser.rs | |
| parent | 45e173176a0d4b44c9b1bf3cc7a880929d1360a6 (diff) | |
| download | dome-key-map-5ef2443642a2d8b223afdf169200a725d2809b76.tar.bz2 | |
Add <Bslash> and <lt> escapes for action (WIP)
Trying to add new escape special keys for '\' and '<' but having a bit
of trouble.
Looks like I'm not using `and` `satisfy` correctly, as I'm getting this
error:
    error[E0271]: type mismatch resolving `<(impl combine::Parser, combine::combinator::Satisfy<_, [closure@src/parser.rs:263:56: 263:68]>) as combine::Parser>::Output == char`
       --> src/parser.rs:260:18
        |
    260 |                   (choice!(
        |  __________________^
    261 | |                     try(string_case_insensitive("Bslash")).map(|_| '\\'),
    262 | |                     try(string_case_insensitive("lt")).map(|_| '<'),
    263 | |                     try(action_character().and(satisfy(|c| c != '>')))
    264 | |                 ).map(|c|
        | |_________________^ expected tuple, found char
        |
        = note: expected type `(char, _)`
                   found type `char`
        = note: required because of the requirements on the impl of `combine::Parser` for `combine::combinator::Try<(impl combine::Parser, combine::combinator::Satisfy<_, [closure@src/parser.rs:263:56: 263:68]>)>`
        = note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
I had added the `satisfy` not '>' after getting this test failure
without it:
    ---- parser::tests::action_parses_map_with_bslash_and_lt_special_keys stdout ----
    thread 'parser::tests::action_parses_map_with_bslash_and_lt_special_keys' panicked at 'assertion failed: `(left == right)`
      left: `Err(Errors { position: PointerOffset(4332007031), errors: [Unexpected(Token('l')), Expected(Token('>'))] })`,
     right: `Ok(Map([KeyboardKeyWithModifiers { key: Character(Character(Character('a'))), flags: None }, KeyboardKeyWithModifiers { key: Character(Character(Character('\\'))), flags: None }, KeyboardKeyWithModifiers { key: Character(Character(Character('A'))), flags: None }, KeyboardKeyWithModifiers { key: Character(Character(Character('N'))), flags: None }, KeyboardKeyWithModifiers { key: Character(Character(Character('D'))), flags: None }, KeyboardKeyWithModifiers { key: Character(Character(Character('<'))), flags: None }, KeyboardKeyWithModifiers { key: Character(Character(Character('>'))), flags: None }, KeyboardKeyWithModifiers { key: Character(Character(Character('\\'))), flags: Some([Control]) }, KeyboardKeyWithModifiers { key: Character(Character(Character('<'))), flags: Some([Meta, Shift]) }]))`', src/parser.rs:928:9
as I suspected this was a problem with `<lt>`. But now that I think
about it, it could just as easily have been a problem with `<Bslash>`.
Not sure.
Anyway, I'm thinking of dropping these escapes because they're redundant
(we already have '\' escaping) and because I'm tired of these errors.
Diffstat (limited to 'src/parser.rs')
| -rw-r--r-- | src/parser.rs | 56 | 
1 files changed, 55 insertions, 1 deletions
| diff --git a/src/parser.rs b/src/parser.rs index a84aba1..4b1f83e 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -257,7 +257,11 @@ where              )),              try((                  many1(key_modifier()), -                action_character().map(|c| +                choice!( +                    try(string_case_insensitive("Bslash")).map(|_| '\\'), +                    try(string_case_insensitive("lt")).map(|_| '<'), +                    try(action_character().and(satisfy(|c| c != '>'))) +                ).map(|c|                      KeyboardKey::Character(Character::new(c))                  ),              )) @@ -875,6 +879,56 @@ mod tests {      }      #[test] +    fn action_parses_map_with_bslash_and_lt_special_keys() { +        let text = "a<Bslash>AND<lt>><C-Bslash><D-S-lt>"; + +        let expected = Action::Map(vec![ +            KeyboardKeyWithModifiers::new( +                KeyboardKey::Character(Character::new('a')), +                None, +            ), +            KeyboardKeyWithModifiers::new( +                KeyboardKey::Character(Character::new('\\')), +                None, +            ), +            KeyboardKeyWithModifiers::new( +                KeyboardKey::Character(Character::new('A')), +                None, +            ), +            KeyboardKeyWithModifiers::new( +                KeyboardKey::Character(Character::new('N')), +                None, +            ), +            KeyboardKeyWithModifiers::new( +                KeyboardKey::Character(Character::new('D')), +                None, +            ), +            KeyboardKeyWithModifiers::new( +                KeyboardKey::Character(Character::new('<')), +                None, +            ), +            KeyboardKeyWithModifiers::new( +                KeyboardKey::Character(Character::new('>')), +                None, +            ), +            KeyboardKeyWithModifiers::new( +                KeyboardKey::Character(Character::new('\\')), +                Some(vec![Flag::Control]), +            ), +            KeyboardKeyWithModifiers::new( +                KeyboardKey::Character(Character::new('<')), +                Some(vec![ +                    Flag::Meta, +                    Flag::Shift, +                ]), +            ), +        ]); +        let result = action_map().easy_parse(text).map(|t| t.0); + +        assert_eq!(result, Ok(expected)); +    } + +    #[test]      fn action_parses_command_to_vec_of_words() {          let text = "/usr/bin/say 'hello'";      } | 
