Skip to content

Commit

Permalink
Add support for % operator in case guards (#96)
Browse files Browse the repository at this point in the history
  • Loading branch information
giacomocavalieri authored Sep 1, 2024
1 parent 426e670 commit 16e775f
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 1 deletion.
3 changes: 2 additions & 1 deletion grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,8 @@ module.exports = grammar({
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)
binaryExpr(prec.left, 6, "/.", $._case_clause_guard_expression),
binaryExpr(prec.left, 6, "%", $._case_clause_guard_expression)
),
_case_clause_guard_unit: ($) =>
choice(
Expand Down
35 changes: 35 additions & 0 deletions test/corpus/cases.txt
Original file line number Diff line number Diff line change
Expand Up @@ -218,3 +218,38 @@ case var {
(discard)))
(record
(constructor_name))))))

================================================================================
Case with int remainder in guard
================================================================================

case var {
_ if 11 % 2 == 0 -> True
_ -> False
}

--------------------------------------------------------------------------------

(source_file
(case
(case_subjects
(identifier))
(case_clauses
(case_clause
(case_clause_patterns
(case_clause_pattern
(discard)))
(case_clause_guard
(binary_expression
(binary_expression
(integer)
(integer))
(integer)))
(record
(constructor_name)))
(case_clause
(case_clause_patterns
(case_clause_pattern
(discard)))
(record
(constructor_name))))))
11 changes: 11 additions & 0 deletions test/highlight/cases.gleam
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
pub fn case_with_remainder() {
case todo {
_ if 1 % 2 == 0 -> todo
// ^ number
// ^ operator
// ^ number
// ^ operator
// ^ number
_ -> todo
}
}

0 comments on commit 16e775f

Please sign in to comment.