Commit c8dadb3d authored by Daan Sprenkels's avatar Daan Sprenkels
Browse files

parser: fix parse_ass_stmt

parent 4fa86cd7
Pipeline #1161 passed with stage
......@@ -374,17 +374,12 @@ impl Parser {
pub fn parse_ass_stmt(&mut self, mut offset: usize) -> ParseResult<AssStmt> {
let (ass_ident, mut offset) = try_parse!(self.parse_ident(offset));
let (ass_opt_field, mut offset) = {
let &TokenAndSpan(ref kind_token, ref span) = peek_token!(self.input, offset);
match kind_token {
&Token::Dot => {
let (field, offset) = try_parse!(self.parse_field(offset));
(Some(field), offset)
},
_ => (None, offset)
}
let (ass_opt_field, mut offset) = match self.parse_field(offset) {
Ok((field, offset)) => (Some(field), offset),
Err(_) => (None, offset)
};
let &TokenAndSpan(_, ref eqspan) = expect_token!("=", self.input, offset, Token::Eq);
expect_token!("=", self.input, offset, Token::Eq);
let (ass_exp, mut offset) = try_parse!(self.parse_exp(offset));
let &TokenAndSpan(_, ref scspan) = expect_token!(";", self.input, offset, Token::Semicolon);
......
......@@ -247,6 +247,17 @@ fn test_parse_field_exp() {
} });
}
#[test]
fn test_parse_ass_stmt() {
assert_parse_ok!(parse_ass_stmt, vec!(Token::Ident(String::from("a")), Token::Eq,
Token::LiteralInt(3), Token::Semicolon),
ast::AssStmt { span: _, var_name: _, field: None, value: _ });
assert_parse_ok!(parse_ass_stmt, vec!(Token::Ident(String::from("a")), Token::Dot,
Token::Hd, Token::Eq, Token::LiteralInt(3),
Token::Semicolon),
ast::AssStmt { span: _, var_name: _, field: Some(_), value: _ });
}
#[test]
fn test_parse_return_stmt() {
assert_parse_ok!(parse_return_stmt, vec!(Token::Return, Token::Semicolon),
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment