Skip to content

Commit

Permalink
fix parsing for await foo() + e
Browse files Browse the repository at this point in the history
Summary: Await should take precedence over + (and other arithmetic binary operators)

Reviewed By: shannonzhu

Differential Revision: D24773686

fbshipit-source-id: d3f4cefe56a84604e89e376f9759f284000d3ed3
  • Loading branch information
SimranVirk authored and facebook-github-bot committed Nov 6, 2020
1 parent e3ddbf1 commit 3a3c2ef
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
1 change: 1 addition & 0 deletions parser/generator.mly
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,7 @@
%left AMPERSAND
%left PLUS MINUS
%left ASTERIKS PERCENT SLASH
%left AWAIT
%left TILDE
%left AT
%left DOT
Expand Down
38 changes: 37 additions & 1 deletion parser/test/generatorTest.ml
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,43 @@ let test_number _ =


let test_await _ =
assert_parsed_equal "await 1" [+Statement.Expression (+Expression.Await (+Expression.Integer 1))]
assert_parsed_equal "await 1" [+Statement.Expression (+Expression.Await (+Expression.Integer 1))];
assert_parsed_equal
"await foo() + 1"
[
+Statement.Expression
(+Expression.Call
{
callee =
+Expression.Name
(Name.Attribute
{
base =
+Expression.Await (+Expression.Call { callee = !"foo"; arguments = [] });
attribute = "__add__";
special = true;
});
arguments = [{ Call.Argument.name = None; value = +Expression.Integer 1 }];
});
];
assert_parsed_equal
"await foo() * 2"
[
+Statement.Expression
(+Expression.Call
{
callee =
+Expression.Name
(Name.Attribute
{
base =
+Expression.Await (+Expression.Call { callee = !"foo"; arguments = [] });
attribute = "__mul__";
special = true;
});
arguments = [{ Call.Argument.name = None; value = +Expression.Integer 2 }];
});
]


let test_name _ =
Expand Down

0 comments on commit 3a3c2ef

Please sign in to comment.