From 44d6a88faa55daa0ff7db2bea486a8a7574b4c40 Mon Sep 17 00:00:00 2001 From: Jeff Date: Thu, 15 Aug 2024 21:22:24 -0400 Subject: [PATCH] Pass tests --- dust-lang/src/parser.rs | 56 +++++++++++++++++++++++------------------ dust-lang/src/token.rs | 3 +-- 2 files changed, 32 insertions(+), 27 deletions(-) diff --git a/dust-lang/src/parser.rs b/dust-lang/src/parser.rs index 0bd9a4a..bb589a8 100644 --- a/dust-lang/src/parser.rs +++ b/dust-lang/src/parser.rs @@ -1024,22 +1024,28 @@ mod tests { Ok(AbstractSyntaxTree { statements: [Statement::Expression(Expression::block( Block::Async(vec![ - Statement::Expression(Expression::operator( - OperatorExpression::Assignment { - assignee: Expression::identifier(Identifier::new("x"), (0, 0)), - value: Expression::literal(LiteralExpression::Integer(42), (0, 0)), - }, - (0, 0) + Statement::ExpressionNullified(Node::new( + Expression::operator( + OperatorExpression::Assignment { + assignee: Expression::identifier(Identifier::new("x"), (8, 9)), + value: Expression::literal( + LiteralExpression::Integer(42), + (12, 14) + ), + }, + (8, 14) + ), + (8, 15) )), Statement::Expression(Expression::operator( OperatorExpression::Assignment { - assignee: Expression::identifier(Identifier::new("y"), (0, 0)), - value: Expression::literal(LiteralExpression::Float(4.0), (0, 0)), + assignee: Expression::identifier(Identifier::new("y"), (16, 17)), + value: Expression::literal(LiteralExpression::Float(4.0), (20, 23)), }, - (0, 0) + (16, 23) )) ]), - (0, 0) + (0, 25) ),)] .into() }) @@ -1560,45 +1566,45 @@ mod tests { OperatorExpression::Assignment { assignee: Expression::identifier( Identifier::new("foo"), - (0, 0) + (2, 5) ), value: Expression::literal( LiteralExpression::Integer(42), - (0, 0) + (8, 10) ), }, - (0, 0) + (2, 10) ), - (0, 0) + (2, 11) ),), Statement::ExpressionNullified(Node::new( Expression::operator( OperatorExpression::Assignment { assignee: Expression::identifier( Identifier::new("bar"), - (0, 0) + (12, 15) ), value: Expression::literal( LiteralExpression::Integer(42), - (0, 0) + (18, 20) ), }, - (0, 0) + (12, 20) ), - (0, 0) + (12, 21) ),), Statement::Expression(Expression::operator( OperatorExpression::Assignment { - assignee: Expression::identifier(Identifier::new("baz"), (0, 0)), + assignee: Expression::identifier(Identifier::new("baz"), (22, 25)), value: Expression::literal( LiteralExpression::String("42".to_string()), - (0, 0) + (28, 32) ), }, - (0, 0) + (22, 32) )), ]), - (0, 0) + (0, 34) )) ])) ) @@ -1612,10 +1618,10 @@ mod tests { parse(source), Ok(AbstractSyntaxTree::with_statements([ Statement::Expression(Expression::operator( - OperatorExpression::Math { + OperatorExpression::Comparison { left: Expression::literal(LiteralExpression::Integer(42), (0, 2)), - operator: Node::new(MathOperator::Divide, (3, 5)), - right: Expression::literal(LiteralExpression::Integer(2), (6, 8)), + operator: Node::new(ComparisonOperator::Equal, (3, 5)), + right: Expression::literal(LiteralExpression::Integer(42), (6, 8)), }, (0, 8), )) diff --git a/dust-lang/src/token.rs b/dust-lang/src/token.rs index 64a679a..a4fdd10 100644 --- a/dust-lang/src/token.rs +++ b/dust-lang/src/token.rs @@ -238,9 +238,8 @@ impl<'src> Token<'src> { pub fn precedence(&self) -> u8 { match self { - Token::Identifier(_) => 10, Token::Dot => 9, - Token::LeftCurlyBrace | Token::LeftParenthesis | Token::LeftSquareBrace => 8, + Token::LeftParenthesis | Token::LeftSquareBrace => 8, Token::Star | Token::Slash | Token::Percent => 7, Token::Minus | Token::Plus => 6, Token::DoubleEqual