From c0a2857122b99db3cec716cb52859c5c67d6117c Mon Sep 17 00:00:00 2001 From: Erin Date: Tue, 17 May 2022 19:03:02 +0200 Subject: [PATCH] Changed `hopback` to `and again` (credits: Evrey#6086) --- ablescript/src/ast.rs | 2 +- ablescript/src/interpret.rs | 16 ++++++++-------- ablescript/src/lexer.rs | 7 ++++--- ablescript/src/parser.rs | 4 ++-- 4 files changed, 15 insertions(+), 14 deletions(-) diff --git a/ablescript/src/ast.rs b/ablescript/src/ast.rs index 05bf7ee..85c5b0c 100644 --- a/ablescript/src/ast.rs +++ b/ablescript/src/ast.rs @@ -111,7 +111,7 @@ pub enum Stmt { body: Block, }, Enough, - HopBack, + AndAgain, Dim { ident: Spanned, diff --git a/ablescript/src/interpret.rs b/ablescript/src/interpret.rs index 9a75a0f..f0cbfbe 100644 --- a/ablescript/src/interpret.rs +++ b/ablescript/src/interpret.rs @@ -72,9 +72,9 @@ enum HaltStatus { /// caught by a `loop` statement up to this point. Enough(Range), - /// A `hopback` statement occurred at the given span, and was not + /// A `and again` statement occurred at the given span, and was not /// caught by a `loop` statement up to this point. - Hopback(Range), + AndAgain(Range), } /// The number of bits the `read` statement reads at once from @@ -105,11 +105,11 @@ impl ExecEnv { /// Execute a set of Statements in the root stack frame. Return an /// error if one or more of the Stmts failed to evaluate, or if a - /// `enough` or `hopback` statement occurred at the top level. + /// `enough` or `and again` statement occurred at the top level. pub fn eval_stmts(&mut self, stmts: &[Spanned]) -> Result<(), Error> { match self.eval_stmts_hs(stmts, false)? { HaltStatus::Finished => Ok(()), - HaltStatus::Enough(span) | HaltStatus::Hopback(span) => Err(Error { + HaltStatus::Enough(span) | HaltStatus::AndAgain(span) => Err(Error { // It's an error to issue a `enough` outside of a // `loop` statement. kind: ErrorKind::TopLevelEnough, @@ -118,7 +118,7 @@ impl ExecEnv { } } - /// The same as `eval_stmts`, but report "enough" and "hopback" + /// The same as `eval_stmts`, but report "enough" and "and again" /// exit codes as normal conditions in a HaltStatus enum, and /// create a new stack frame if `stackframe` is true. /// @@ -280,7 +280,7 @@ impl ExecEnv { match res { HaltStatus::Finished => (), HaltStatus::Enough(_) => break, - HaltStatus::Hopback(_) => continue, + HaltStatus::AndAgain(_) => continue, } }, Stmt::Assign { assignable, value } => { @@ -289,8 +289,8 @@ impl ExecEnv { Stmt::Enough => { return Ok(HaltStatus::Enough(stmt.span.clone())); } - Stmt::HopBack => { - return Ok(HaltStatus::Hopback(stmt.span.clone())); + Stmt::AndAgain => { + return Ok(HaltStatus::AndAgain(stmt.span.clone())); } Stmt::Melo(ident) => match self.get_var_mut(ident)? { var @ Variable::Ref(_) => *var = Variable::Melo, diff --git a/ablescript/src/lexer.rs b/ablescript/src/lexer.rs index 74000a4..cb39439 100644 --- a/ablescript/src/lexer.rs +++ b/ablescript/src/lexer.rs @@ -97,9 +97,9 @@ pub enum Token { #[token("enough")] Enough, - /// HopBack hops on the back of loop - like `continue` - #[token("hopback")] - HopBack, + /// Jump at the start of the loop + #[token("and again")] + AndAgain, /// Crash with random error (see discussion #17) #[token("rlyeh")] @@ -123,6 +123,7 @@ pub enum Token { /// An identifier #[regex(r"\p{XID_Start}[\p{XID_Continue}]+", get_ident)] + #[token("and ", |_| "and".to_owned())] Identifier(String), #[regex(r"owo .*")] diff --git a/ablescript/src/parser.rs b/ablescript/src/parser.rs index 4cb0ee1..17726e5 100644 --- a/ablescript/src/parser.rs +++ b/ablescript/src/parser.rs @@ -88,8 +88,8 @@ impl<'source> Parser<'source> { self.semicolon_terminated(Stmt::Enough)?, start..self.lexer.span().end, )), - Token::HopBack => Ok(Spanned::new( - self.semicolon_terminated(Stmt::HopBack)?, + Token::AndAgain => Ok(Spanned::new( + self.semicolon_terminated(Stmt::AndAgain)?, start..self.lexer.span().end, )), Token::Rlyeh => Ok(Spanned::new(