rescript-compiler icon indicating copy to clipboard operation
rescript-compiler copied to clipboard

add bitor (|) unified operator

Open MiryangJung opened this issue 7 months ago • 2 comments

I used the existing Token.Bar, it looks like there's a conflict with the | used in pattern matching, so I'm looking into it.

MiryangJung avatar Apr 06 '25 12:04 MiryangJung

Ok, this is actually ambiguous.

switch n {
| n => n | 1
      // ^ Is this an or-pattern or binary expression?

This is tricky because we don't force a delimiter at the end of the pattern (like , in Rust)

We can put it in a new region to avoid ambiguity

switch n {
| n => { n | 1 }
// or....
| n => ( n | 1 )

The problem is that our formatter actively tries to wipe it out.

cometkim avatar Apr 13 '25 02:04 cometkim

Maybe reviving local open syntax would help to deal with this kind of ambiguity

cometkim avatar Apr 14 '25 14:04 cometkim