Implemented read in Parser
This commit is contained in:
parent
4b6c3528da
commit
2ec416db97
|
@ -73,6 +73,7 @@ pub enum StmtKind {
|
||||||
args: Vec<Expr>,
|
args: Vec<Expr>,
|
||||||
},
|
},
|
||||||
Print(Expr),
|
Print(Expr),
|
||||||
|
Read(Iden),
|
||||||
Melo(Iden),
|
Melo(Iden),
|
||||||
Rlyeh,
|
Rlyeh,
|
||||||
Rickroll,
|
Rickroll,
|
||||||
|
|
|
@ -280,6 +280,7 @@ impl ExecEnv {
|
||||||
.write_all(include_str!("rickroll").as_bytes())
|
.write_all(include_str!("rickroll").as_bytes())
|
||||||
.expect("Failed to write to stdout");
|
.expect("Failed to write to stdout");
|
||||||
}
|
}
|
||||||
|
StmtKind::Read(_) => todo!(),
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(HaltStatus::Finished)
|
Ok(HaltStatus::Finished)
|
||||||
|
|
|
@ -86,6 +86,10 @@ pub enum Token {
|
||||||
#[token("print")]
|
#[token("print")]
|
||||||
Print,
|
Print,
|
||||||
|
|
||||||
|
/// Read input into preceding variable
|
||||||
|
#[token("read")]
|
||||||
|
Read,
|
||||||
|
|
||||||
/// Ban the following variable from ever being used again
|
/// Ban the following variable from ever being used again
|
||||||
#[token("melo")]
|
#[token("melo")]
|
||||||
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)?),
|
t => buf = Some(self.parse_expr(t, &mut buf)?),
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue