forked from AbleScript/ablescript
Implemented read in Parser
This commit is contained in:
parent
430f0c2b90
commit
3edbca51d5
|
@ -73,6 +73,7 @@ pub enum StmtKind {
|
|||
args: Vec<Expr>,
|
||||
},
|
||||
Print(Expr),
|
||||
Read(Iden),
|
||||
Melo(Iden),
|
||||
Rlyeh,
|
||||
Rickroll,
|
||||
|
|
|
@ -280,6 +280,7 @@ impl ExecEnv {
|
|||
.write_all(include_str!("rickroll").as_bytes())
|
||||
.expect("Failed to write to stdout");
|
||||
}
|
||||
StmtKind::Read(_) => todo!(),
|
||||
}
|
||||
|
||||
Ok(HaltStatus::Finished)
|
||||
|
|
|
@ -86,6 +86,10 @@ pub enum Token {
|
|||
#[token("print")]
|
||||
Print,
|
||||
|
||||
/// Read input into preceding variable
|
||||
#[token("read")]
|
||||
Read,
|
||||
|
||||
/// Ban the following variable from ever being used again
|
||||
#[token("melo")]
|
||||
Melo,
|
||||
|
|
|
@ -318,6 +318,18 @@ impl<'source> Parser<'source> {
|
|||
};
|
||||
}
|
||||
}
|
||||
|
||||
// Read input
|
||||
Token::Read => {
|
||||
if let Some(Expr {
|
||||
kind: ExprKind::Variable(iden),
|
||||
span,
|
||||
}) = buf
|
||||
{
|
||||
break self.semi_terminated(StmtKind::Read(Iden::new(iden, span)))?;
|
||||
}
|
||||
}
|
||||
|
||||
t => buf = Some(self.parse_expr(t, &mut buf)?),
|
||||
}
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue