Skip to content

Commit c606c06

Browse files
authored
Merge pull request #1640 from Mark-Simulacrum/shortcut-endles
Shortcut can terminate immediately
2 parents 25d6d25 + b56185c commit c606c06

File tree

1 file changed

+9
-26
lines changed

1 file changed

+9
-26
lines changed

parser/src/command/shortcut.rs

Lines changed: 9 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,13 @@ pub enum ShortcutCommand {
2121
}
2222

2323
#[derive(PartialEq, Eq, Debug)]
24-
pub enum ParseError {
25-
ExpectedEnd,
26-
}
24+
pub enum ParseError {}
2725

2826
impl std::error::Error for ParseError {}
2927

3028
impl fmt::Display for ParseError {
31-
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
32-
match self {
33-
ParseError::ExpectedEnd => write!(f, "expected end of command"),
34-
}
29+
fn fmt(&self, _: &mut fmt::Formatter) -> fmt::Result {
30+
match *self {}
3531
}
3632
}
3733

@@ -49,14 +45,9 @@ impl ShortcutCommand {
4945
return Ok(None);
5046
}
5147
toks.next_token()?;
52-
if let Some(Token::Dot) | Some(Token::EndOfLine) = toks.peek_token()? {
53-
toks.next_token()?;
54-
*input = toks;
55-
let command = shortcuts.get(word).unwrap();
56-
return Ok(Some(*command));
57-
} else {
58-
return Err(toks.error(ParseError::ExpectedEnd));
59-
}
48+
*input = toks;
49+
let command = shortcuts.get(word).unwrap();
50+
return Ok(Some(*command));
6051
}
6152
Ok(None)
6253
}
@@ -70,12 +61,12 @@ fn parse(input: &str) -> Result<Option<ShortcutCommand>, Error<'_>> {
7061

7162
#[test]
7263
fn test_1() {
73-
assert_eq!(parse("ready."), Ok(Some(ShortcutCommand::Ready)),);
64+
assert_eq!(parse("ready."), Ok(Some(ShortcutCommand::Ready)));
7465
}
7566

7667
#[test]
7768
fn test_2() {
78-
assert_eq!(parse("ready"), Ok(Some(ShortcutCommand::Ready)),);
69+
assert_eq!(parse("ready"), Ok(Some(ShortcutCommand::Ready)));
7970
}
8071

8172
#[test]
@@ -85,15 +76,7 @@ fn test_3() {
8576

8677
#[test]
8778
fn test_4() {
88-
use std::error::Error;
89-
assert_eq!(
90-
parse("ready word")
91-
.unwrap_err()
92-
.source()
93-
.unwrap()
94-
.downcast_ref(),
95-
Some(&ParseError::ExpectedEnd),
96-
);
79+
assert_eq!(parse("ready word"), Ok(Some(ShortcutCommand::Ready)));
9780
}
9881

9982
#[test]

0 commit comments

Comments
 (0)