Changed hopback to and again (credits: Evrey#6086)

This commit is contained in:
Erin 2022-05-17 19:03:02 +02:00 committed by ondra05
parent 6473ce8f1e
commit a292b1abc1
4 changed files with 15 additions and 14 deletions

View file

@ -111,7 +111,7 @@ pub enum Stmt {
body: Block,
},
Enough,
HopBack,
AndAgain,
Dim {
ident: Spanned<String>,

View file

@ -72,9 +72,9 @@ enum HaltStatus {
/// caught by a `loop` statement up to this point.
Enough(Range<usize>),
/// 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<usize>),
AndAgain(Range<usize>),
}
/// 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<Stmt>]) -> 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,

View file

@ -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 .*")]

View file

@ -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(