Implemented read in Parser

This commit is contained in:
Erin 2021-06-18 20:28:53 +02:00 committed by ondra05
parent 430f0c2b90
commit 3edbca51d5
4 changed files with 18 additions and 0 deletions

View file

@ -73,6 +73,7 @@ pub enum StmtKind {
args: Vec<Expr>,
},
Print(Expr),
Read(Iden),
Melo(Iden),
Rlyeh,
Rickroll,

View file

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

View file

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

View file

@ -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)?),
}
};