Implement the current set of rules for precedence partial ordering (#1096)

In the process, switch to an unambiguous grammar, using the
precedence-climbing method for operator precedence (suitably modified to
handle a partial precedence order) rather than Bison %precedence /
%prec.
This commit is contained in:
Richard Smith
2022-03-03 13:36:35 -08:00
committed by GitHub
parent f5f02babdd
commit 8c60ad2e19
5 changed files with 328 additions and 97 deletions
@@ -18,14 +18,14 @@ TEST(UnimplementedExampleTest, VerifyPrecedence) {
static constexpr std::string_view Program = R"(
package ExecutableSemanticsTest api;
fn Main() -> i32 {
return 1 __unimplemented_example_infix 2 + 3;
return 1 __unimplemented_example_infix 2 == 3;
}
)";
Arena arena;
EXPECT_THAT(ParseFromString(&arena, "dummy.carbon", Program, false),
ParsedAs(ASTDeclarations(
ElementsAre(MatchesFunctionDeclaration().WithBody(
BlockContentsAre(ElementsAre(MatchesReturn(MatchesAdd(
BlockContentsAre(ElementsAre(MatchesReturn(MatchesEq(
MatchesUnimplementedExpression(
"ExampleInfix", ElementsAre(MatchesLiteral(1),
MatchesLiteral(2))),