BF code is now Vec<u8>

This commit is contained in:
Erin 2021-06-11 18:10:11 +02:00 committed by ondra05
parent 711ad27e00
commit 3bcef28843
2 changed files with 18 additions and 20 deletions

View file

@ -66,7 +66,7 @@ pub enum StmtKind {
BfFunctio {
iden: Iden,
tape_len: Option<Expr>,
code: String,
code: Vec<u8>,
},
Call {
iden: Iden,

View file

@ -402,26 +402,24 @@ impl<'source> Parser<'source> {
_ => todo!(),
};
let mut code = String::new();
let mut code: Vec<u8> = vec![];
loop {
code.push_str(
match self
.lexer
.next()
.ok_or(Error::unexpected_eof(self.lexer.span().start))?
{
Token::Plus
| Token::Minus
| Token::Dot
| Token::Comma
| Token::LeftBracket
| Token::RightBracket
| Token::LessThan
| Token::GreaterThan => self.lexer.slice(),
Token::RightCurly => break,
_ => "",
},
);
match self
.lexer
.next()
.ok_or(Error::unexpected_eof(self.lexer.span().start))?
{
Token::Plus
| Token::Minus
| Token::Dot
| Token::Comma
| Token::LeftBracket
| Token::RightBracket
| Token::LessThan
| Token::GreaterThan => code.push(self.lexer.slice().as_bytes()[0]),
Token::RightCurly => break,
_ => (),
}
}
Ok(StmtKind::BfFunctio {