Skip to content

Commit

Permalink
implement q!
Browse files Browse the repository at this point in the history
  • Loading branch information
hgwr committed Jul 7, 2024
1 parent db7e8c9 commit c36e64f
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions src/ex/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -259,15 +259,15 @@ impl Parser {
}

fn simple_command(&mut self) -> Result<MyOption<Box<dyn Command>>, GenericError> {
let command_opt = self.q_command()? | self.wq_command()?;
let command_opt =
self.q_command()? | self.wq_command()? | self.q_exclamation_command()?;
if let MyOption::Some(command) = command_opt {
return Ok(MyOption::Some(command));
}
Ok(MyOption::None)
}

fn q_command(&mut self) -> Result<MyOption<Box<dyn Command>>, GenericError> {
// tokens が "q" は Ok(Some(Box::new(ExitCommand {}))) を返す。
if self.accept(TokenType::Command, "q") {
self.pop();
return Ok(MyOption::Some(Box::new(exit::ExitCommand {})));
Expand All @@ -276,8 +276,18 @@ impl Parser {
Ok(MyOption::None)
}

fn q_exclamation_command(&mut self) -> Result<MyOption<Box<dyn Command>>, GenericError> {
if self.accept(TokenType::Command, "q") {
self.pop();
if self.accept(TokenType::Command, "!") {
self.pop();
return Ok(MyOption::Some(Box::new(exit::ExitWithoutSaveCommand {})));
}
}
Ok(MyOption::None)
}

fn wq_command(&mut self) -> Result<MyOption<Box<dyn Command>>, GenericError> {
// tokens が "w", "q" は Ok(Some(Box::new(ExitWithSaveCommand {}))) を返す。
if self.accept(TokenType::Command, "w") {
self.pop();
if self.accept(TokenType::Command, "q") {
Expand Down

0 comments on commit c36e64f

Please sign in to comment.