Skip to content

fix incomplete list handling #18

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 11 additions & 9 deletions src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,13 @@ fn parse_list(tokens: &mut Vec<Token>) -> Result<Object, ParseError> {
}

let mut list: Vec<Object> = Vec::new();
while !tokens.is_empty() {
let token = tokens.pop();
if token == None {
loop {
let Some(token) = tokens.pop() else {
return Err(ParseError {
err: format!("Did not find enough tokens"),
err: format!("Expected RParen or next list element, but ran out of tokens!"),
});
}
let t = token.unwrap();
match t {
};
match token {
Token::Keyword(k) => list.push(Object::Keyword(k)),
Token::If => list.push(Object::If),
Token::BinaryOp(b) => list.push(Object::BinaryOp(b)),
Expand All @@ -65,14 +63,18 @@ fn parse_list(tokens: &mut Vec<Token>) -> Result<Object, ParseError> {
}
}
}

Ok(Object::List(Rc::new(list)))
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn incomplete_list() {
parse_list(&mut vec![Token::LParen, Token::Integer(5)])
.expect_err("List is missing RParen");
}

#[test]
fn test_add() {
let list = parse("(+ 1 2)").unwrap();
Expand Down