Repository navigation
Give AND higher precedence than OR in the parser - #1999
Open
anubhavlal07 wants to merge 1 commit into
Open
anubhavlal07 wants to merge 1 commit into
anubhavlal07 wants to merge 1 commit into
Conversation
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1994
Problem
Parser.boolean()handledandandorin onematchAny(TokenKind.And, TokenKind.Or)loop, so both operators had the same precedence and grouped left to right.a or b and cwas parsed as(a or b) and c. The Roku device givesandhigher precedence thanorand evaluatesa or (b and c).Plain transpile output looked fine because the tokens are written back in their original order. Plugins that rebuild code from the AST, such as coverage instrumentation, got the wrong grouping.
Fix
boolean()is now split into two levels:boolean()handlesor, withbooleanAnd()for each operandbooleanAnd()handlesand, withrelational()for each operandBoth levels are still left-associative. The caller (
anonymousFunction) is unchanged, so ternary and??parsing are not affected. Transpiled output is the same.Tests
Added
precedencetests tosrc/parser/tests/expression/Boolean.spec.ts. They parse source text and check the shape of the resulting tree:a or b and c->(a or (b and c))a and b or c->((a and b) or c)a or b and c or d and e->((a or (b and c)) or (d and e))a and b and canda or b or cstay left-associativeWithout the parser change, the first and third tests fail. The full suite passes with the change (3250 passing) and so does
npm run lint.