Skip to content

Commit

Permalink
fix(grainfmt): Properly handle coalesing operator (grain-lang#1568)
Browse files Browse the repository at this point in the history
  • Loading branch information
ospencer authored Jan 2, 2023
1 parent 4a44690 commit 4595f97
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 3 deletions.
9 changes: 6 additions & 3 deletions compiler/src/formatting/format.re
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ let is_logic_op = fn =>
| "=="
| "!="
| "is"
| "isnt"
| "&&"
| "||" => true
| _ => false
Expand Down Expand Up @@ -104,7 +105,8 @@ let op_precedence = fn => {
| "!="
| "is" => 80
| "&&" => 40
| "||" => 30
| "||"
| "??" => 30
| _ => op_precedence(fn.[0])
};
} else if (String.length(fn) > 0) {
Expand Down Expand Up @@ -287,10 +289,11 @@ let infixop = (op: string) => {
| '<'
| '>'
| '&'
| '|' => true
| '|'
| '?' => true
| _ when op == "is" => true
| _ when op == "isnt" => true
| _ when op == "!=" => true
| _ when String.starts_with(~prefix="!=", op) => true
| _ => false
| exception _ => false
};
Expand Down
40 changes: 40 additions & 0 deletions compiler/test/formatter_inputs/infix.gr
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,43 @@ let trimString = (str: String, end: Bool) => {
else slice(i, charsLength, str)
}

(||+)
(||^)
(&&*&^%)
(|*)
(^^^)
(&-)
(==!)
(==$)
(==*==)
(!==^)
(<<<<<)
(<%>)
(<=>)
(>>>>)
(>>>>>>>>)
(><><><)
(+==)
(+!)
(++!)
(+-+)
(**//**)
(**)
(??)
(???)
(+.)
(-.)
(*.)
(/.)
(>>=)
(|>)
(>:)
(%%)
(===)
(!==)
(==?)
(&?)
(++)
(--)
(^*^)
(^-^)
41 changes: 41 additions & 0 deletions compiler/test/formatter_outputs/infix.gr
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,44 @@ let trimString = (str: String, end: Bool) => {
}
if (end) slice(0, i + 1, str) else slice(i, charsLength, str)
}

(||+)
(||^)
(&&*&^%)
(|*)
(^^^)
(&-)
(==!)
(==$)
(==*==)
(!==^)
(<<<<<)
(<%>)
(<=>)
(>>>>)
(>>>>>>>>)
(><><><)
(+==)
(+!)
(++!)
(+-+)
(**//**)
(**)
(??)
(???)
(+.)
(-.)
(*.)
(/.)
(>>=)
(|>)
(>:)
(%%)
(===)
(!==)
(==?)
(&?)
(++)
(--)
(^*^)
(^-^)

0 comments on commit 4595f97

Please sign in to comment.