diff --git a/ablescript/src/ast.rs b/ablescript/src/ast.rs index e1fe244..05bf7ee 100644 --- a/ablescript/src/ast.rs +++ b/ablescript/src/ast.rs @@ -110,7 +110,7 @@ pub enum Stmt { Loop { body: Block, }, - Break, + Enough, HopBack, Dim { diff --git a/ablescript/src/error.rs b/ablescript/src/error.rs index 051a325..ad38ac7 100644 --- a/ablescript/src/error.rs +++ b/ablescript/src/error.rs @@ -13,7 +13,7 @@ pub enum ErrorKind { UnexpectedToken(Token), UnknownVariable(String), MeloVariable(String), - TopLevelBreak, + TopLevelEnough, MissingLhs, Brian(InterpretError), Io(io::Error), @@ -50,7 +50,7 @@ impl Display for ErrorKind { ErrorKind::UnexpectedToken(token) => write!(f, "unexpected token {:?}", token), ErrorKind::UnknownVariable(name) => write!(f, "unknown identifier \"{}\"", name), ErrorKind::MeloVariable(name) => write!(f, "banned variable \"{}\"", name), - ErrorKind::TopLevelBreak => write!(f, "can only `break` out of a loop"), + ErrorKind::TopLevelEnough => write!(f, "can only `enough` out of a loop"), ErrorKind::Brian(err) => write!(f, "brainfuck error: {}", err), // TODO: give concrete numbers here. ErrorKind::MissingLhs => write!(f, "missing expression before binary operation"), diff --git a/ablescript/src/interpret.rs b/ablescript/src/interpret.rs index ddf2986..9a75a0f 100644 --- a/ablescript/src/interpret.rs +++ b/ablescript/src/interpret.rs @@ -68,9 +68,9 @@ enum HaltStatus { /// We ran out of statements to execute. Finished, - /// A `break` statement occurred at the given span, and was not + /// An `enough` statement occurred at the given span, and was not /// caught by a `loop` statement up to this point. - Break(Range), + Enough(Range), /// A `hopback` statement occurred at the given span, and was not /// caught by a `loop` statement up to this point. @@ -105,20 +105,20 @@ 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 - /// `break` or `hopback` statement occurred at the top level. + /// `enough` or `hopback` 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::Break(span) | HaltStatus::Hopback(span) => Err(Error { - // It's an error to issue a `break` outside of a + HaltStatus::Enough(span) | HaltStatus::Hopback(span) => Err(Error { + // It's an error to issue a `enough` outside of a // `loop` statement. - kind: ErrorKind::TopLevelBreak, + kind: ErrorKind::TopLevelEnough, span, }), } } - /// The same as `eval_stmts`, but report "break" and "hopback" + /// The same as `eval_stmts`, but report "enough" and "hopback" /// exit codes as normal conditions in a HaltStatus enum, and /// create a new stack frame if `stackframe` is true. /// @@ -279,15 +279,15 @@ impl ExecEnv { let res = self.eval_stmts_hs(body, true)?; match res { HaltStatus::Finished => (), - HaltStatus::Break(_) => break, + HaltStatus::Enough(_) => break, HaltStatus::Hopback(_) => continue, } }, Stmt::Assign { assignable, value } => { self.assign(assignable, self.eval_expr(value)?)?; } - Stmt::Break => { - return Ok(HaltStatus::Break(stmt.span.clone())); + Stmt::Enough => { + return Ok(HaltStatus::Enough(stmt.span.clone())); } Stmt::HopBack => { return Ok(HaltStatus::Hopback(stmt.span.clone())); diff --git a/ablescript/src/lexer.rs b/ablescript/src/lexer.rs index df7ad25..74000a4 100644 --- a/ablescript/src/lexer.rs +++ b/ablescript/src/lexer.rs @@ -93,8 +93,9 @@ pub enum Token { #[token("loop")] Loop, - #[token("break")] - Break, + /// Break out of the loop + #[token("enough")] + Enough, /// HopBack hops on the back of loop - like `continue` #[token("hopback")] diff --git a/ablescript/src/parser.rs b/ablescript/src/parser.rs index 4100119..4cb0ee1 100644 --- a/ablescript/src/parser.rs +++ b/ablescript/src/parser.rs @@ -84,8 +84,8 @@ impl<'source> Parser<'source> { self.loop_flow()?, start..self.lexer.span().end, )), - Token::Break => Ok(Spanned::new( - self.semicolon_terminated(Stmt::Break)?, + Token::Enough => Ok(Spanned::new( + self.semicolon_terminated(Stmt::Enough)?, start..self.lexer.span().end, )), Token::HopBack => Ok(Spanned::new(