Skip to content
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

Support Int/Float operators in guard expressions #92

Merged
merged 2 commits into from
Jul 19, 2024

Conversation

rawhat
Copy link
Contributor

@rawhat rawhat commented Jul 19, 2024

Closes #90

Copy link
Member

@lpil lpil left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yooo that was fast! Thank you

@gleam-lang/tree-sitter-team this look good to you?

Copy link
Member

@the-mikedavis the-mikedavis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just one thing about precedence, otherwise this looks good 👍

grammar.js Outdated
Comment on lines 463 to 466
binaryExpr(prec.left, 5, "*", $._case_clause_guard_expression),
binaryExpr(prec.left, 5, "*.", $._case_clause_guard_expression),
binaryExpr(prec.left, 5, "/", $._case_clause_guard_expression),
binaryExpr(prec.left, 5, "/.", $._case_clause_guard_expression)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
binaryExpr(prec.left, 5, "*", $._case_clause_guard_expression),
binaryExpr(prec.left, 5, "*.", $._case_clause_guard_expression),
binaryExpr(prec.left, 5, "/", $._case_clause_guard_expression),
binaryExpr(prec.left, 5, "/.", $._case_clause_guard_expression)
binaryExpr(prec.left, 6, "*", $._case_clause_guard_expression),
binaryExpr(prec.left, 6, "*.", $._case_clause_guard_expression),
binaryExpr(prec.left, 6, "/", $._case_clause_guard_expression),
binaryExpr(prec.left, 6, "/.", $._case_clause_guard_expression)

I believe we want these higher than the +/-/etc. ones so that the expressions associate properly. For example if you add a branch to one of the cases in the test file

case value {
  n if n + 1 * 2 > 5 -> False
}

without the change it would be (n + 1) * 2 but it should associate as n + (1 * 2)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤦🏻‍♂️ whoops, thanks

Copy link
Member

@the-mikedavis the-mikedavis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@the-mikedavis the-mikedavis merged commit f35f5c9 into gleam-lang:main Jul 19, 2024
3 checks passed
@rawhat rawhat deleted the support-operators-in-guards branch July 19, 2024 16:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support for +, +., -, -., *, *., /, /. and % operators in guards.
3 participants