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

Weird Operator Behavior #511

Closed
STRd6 opened this issue Apr 29, 2023 · 4 comments · Fixed by #581
Closed

Weird Operator Behavior #511

STRd6 opened this issue Apr 29, 2023 · 4 comments · Fixed by #581

Comments

@STRd6
Copy link
Contributor

STRd6 commented Apr 29, 2023

operator min

min 1, 2
min 1, 2

Becomes:

min(1, min(2, 1), 2);

It should be:

min(1, 2)
min(1, 2)

Adding semi-colons or assignments fixes it.

https://civet.dev/playground?code=b3BlcmF0b3IgbWluCgptaW4gMSwgMgptaW4gMSwgMg%3D%3D

@edemaine
Copy link
Collaborator

Fair point; that definitely seems confusing.

We currently allow binary operators at starts of lines to continue lines. For example:

x := 5
- x
or y
---
const x = 5 - x || y

I think this makes sense for symbol operators, and probably other built-in operators like and and or, because it couldn't mean anything else (in particular because - x currently cannot be interpreted as a unary -). For comparison, this isn't supported in CoffeeScript but part of it was proposed in jashkenas/coffeescript#5279

Perhaps custom operators should allow this only when they are IndentedFurther. So if you intended the current compilation of your example, you could write it this way:

min 1, 2
  min 1, 2

@STRd6
Copy link
Contributor Author

STRd6 commented May 3, 2023

I don't think it makes sense for our current custom operators since they are not infix, but it could make sense if they were.

@edemaine
Copy link
Collaborator

edemaine commented May 3, 2023

What do you mean that they're not infix? operator is specifically for making infix operators. Do you mean that they're optionally infix?

@STRd6
Copy link
Contributor Author

STRd6 commented May 3, 2023

You're correct, I had a moment of confusion.

The optionally infix is what I think this makes this behavior weird. I can see allowing your example of using IndentedFurther to match a custom operator as infix but it probably shouldn't match as infix if on the next line at the same level of indentation.

min 1, 2
  min 1, 2

Has this as a sensible parse:

min(1, min(2
  1), 2)
min 1, 2
min 1, 2

Should parse like this:

min(1, 2)
min(1, 2)

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 a pull request may close this issue.

2 participants