From c36e64f1e2346ec8e0938d7570ece6dcd12e7011 Mon Sep 17 00:00:00 2001 From: Shigeru Hagiwara Date: Sun, 7 Jul 2024 09:53:04 +0900 Subject: [PATCH] implement q! --- src/ex/parser.rs | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/ex/parser.rs b/src/ex/parser.rs index 54a709e..825c578 100644 --- a/src/ex/parser.rs +++ b/src/ex/parser.rs @@ -259,7 +259,8 @@ impl Parser { } fn simple_command(&mut self) -> Result>, 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)); } @@ -267,7 +268,6 @@ impl Parser { } fn q_command(&mut self) -> Result>, GenericError> { - // tokens が "q" は Ok(Some(Box::new(ExitCommand {}))) を返す。 if self.accept(TokenType::Command, "q") { self.pop(); return Ok(MyOption::Some(Box::new(exit::ExitCommand {}))); @@ -276,8 +276,18 @@ impl Parser { Ok(MyOption::None) } + fn q_exclamation_command(&mut self) -> Result>, 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>, GenericError> { - // tokens が "w", "q" は Ok(Some(Box::new(ExitWithSaveCommand {}))) を返す。 if self.accept(TokenType::Command, "w") { self.pop(); if self.accept(TokenType::Command, "q") {