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

fix(grainfmt): Properly handle coalesing operator #1568

Merged
merged 1 commit into from
Jan 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
}

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