From 6fee62f34191160b124f17e3701b6724d289149c Mon Sep 17 00:00:00 2001 From: "K. Lange" Date: Mon, 22 Feb 2021 13:51:45 +0900 Subject: [PATCH] Fix parsing of nested ternary --- src/compiler.c | 2 +- test/testNestedTernary.krk | 5 +++++ test/testNestedTernary.krk.expect | 4 ++++ 3 files changed, 10 insertions(+), 1 deletion(-) create mode 100644 test/testNestedTernary.krk create mode 100644 test/testNestedTernary.krk.expect diff --git a/src/compiler.c b/src/compiler.c index 1cd5e79..d76ce26 100644 --- a/src/compiler.c +++ b/src/compiler.c @@ -2394,7 +2394,7 @@ static void actualTernary(size_t count, KrkScanner oldScanner, Parser oldParser) emitByte(OP_POP); /* Pop the condition */ consume(TOKEN_ELSE, "Expected 'else' after ternary condition"); - parsePrecedence(PREC_OR); + parsePrecedence(PREC_TERNARY); KrkScanner outScanner = krk_tellScanner(); Parser outParser = parser; diff --git a/test/testNestedTernary.krk b/test/testNestedTernary.krk new file mode 100644 index 0000000..aa4289b --- /dev/null +++ b/test/testNestedTernary.krk @@ -0,0 +1,5 @@ +print('a' if False else 'b' if False else 'c') +print('a' if False else 'b' if True else 'c') +print('a' if True else 'b' if False else 'c') +print('a' if True else 'b' if True else 'c') + diff --git a/test/testNestedTernary.krk.expect b/test/testNestedTernary.krk.expect new file mode 100644 index 0000000..379a139 --- /dev/null +++ b/test/testNestedTernary.krk.expect @@ -0,0 +1,4 @@ +c +b +a +a