From f3c459f26ed131d2d114d002cde25f1c8bc6ce89 Mon Sep 17 00:00:00 2001 From: Erin Date: Fri, 11 Jun 2021 18:10:11 +0200 Subject: [PATCH] BF code is now Vec --- src/ast.rs | 2 +- src/parser.rs | 36 +++++++++++++++++------------------- 2 files changed, 18 insertions(+), 20 deletions(-) diff --git a/src/ast.rs b/src/ast.rs index d599c86..95df472 100644 --- a/src/ast.rs +++ b/src/ast.rs @@ -66,7 +66,7 @@ pub enum StmtKind { BfFunctio { iden: Iden, tape_len: Option, - code: String, + code: Vec, }, Call { iden: Iden, diff --git a/src/parser.rs b/src/parser.rs index 15190df..0ee4c4f 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -402,26 +402,24 @@ impl<'source> Parser<'source> { _ => todo!(), }; - let mut code = String::new(); + let mut code: Vec = 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 {