Skip to content

Remove unnecessary parentheses between ? and : in ternary expressions#396

Merged
laurentlb merged 1 commit intolaurentlb:masterfrom
therontarigo:ternaryprecedence
May 13, 2024
Merged

Remove unnecessary parentheses between ? and : in ternary expressions#396
laurentlb merged 1 commit intolaurentlb:masterfrom
therontarigo:ternaryprecedence

Conversation

@therontarigo
Copy link
Copy Markdown
Contributor

The rules for how ? : parse:

  • everything between ? and : is parsed as if grouped (just like ( ) and { }), so the parens can always be omitted from the middle expression.
  • The entire ? expr : is parsed as if it is one whole binary operator in relation to the expressions on either side of it, according to normal precedence rules, thus ?: gets its spot in the precedence table in the spec despite its more complex grammar.

Copy link
Copy Markdown
Owner

@laurentlb laurentlb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, thanks!

@laurentlb laurentlb merged commit 5b9066c into laurentlb:master May 13, 2024
@therontarigo therontarigo deleted the ternaryprecedence branch May 15, 2024 14:50
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 this pull request may close these issues.

2 participants