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

document operator precedence #1094

Open
punund opened this issue Mar 7, 2020 · 1 comment
Open

document operator precedence #1094

punund opened this issue Mar 7, 2020 · 1 comment

Comments

@punund
Copy link

punund commented Mar 7, 2020

I understand that tweaking operator precedence now means breaking legacy code.

But I still wish there were a table in the docs with operator precedence and associativity. Certain things, such as that precedence of >> is different from |> and <| regarding function appllication, are not obvious at all.

f a <| b    # f(a)(b)
f a >> b    # f(a >> b)
@rhendric
Copy link
Collaborator

rhendric commented Mar 7, 2020

There is a partial table of operator precedence here:

LiveScript/src/grammar.ls

Lines 460 to 487 in bc1c188

# Precedence and Associativity
# ----------------------------
# Following these rules is what makes
# `a + b * c` parse as `a + (b * c)` (rather than `(a + b) * c`),
# and `x = y = z` `x = (y = z)` (not `(x = y) = z`).
operators =
# Listed from lower precedence.
<[ left POST_IF ]>
<[ right ASSIGN HURL ]>
<[ right YIELD ]>
<[ right BACKPIPE ]>
<[ left PIPE ]>
<[ right , FOR WHILE EXTENDS INDENT SWITCH CASE TO BY LABEL ]>
<[ right LOGIC ]>
<[ left BITWISE ]>
<[ right COMPARE ]>
<[ left RELATION ]>
<[ right CONCAT ]>
<[ left SHIFT IMPORT CLONEPORT ]>
<[ left +- ]>
<[ left MATH ]>
<[ right UNARY ]>
<[ right POWER ]>
<[ right COMPOSE ]>
<[ nonassoc CREMENT ]>
<[ nonassoc ... ]>
<[ left BACKTICK ]>

But it doesn't explain the logic for inserting implicit parentheses, which treats some tokens like <| specially:

return true if tag in <[ POST_IF PIPE BACKPIPE ]>

I agree, it would be better if all of this were actually in one place in the documentation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants