feat: allow call and unary expressions as map keys in compiler

Change the map key parsing precedence from PREC_PRIMARY to PREC_UNARY in
wren_compiler.c, enabling method calls (e.g., name.count), subscript
access (name[0]), and unary operators (-1, ~3) as valid map keys.

Add two test files: precedence.wren verifying the new key types work
correctly, and bad_key_precedence.wren confirming that binary operators
like addition still produce a parse error.
This commit is contained in:
Bob Nystrom
2015-12-23 00:00:50 +00:00
parent e929c7c997
commit dbd75f8905
3 changed files with 30 additions and 1 deletions
+1 -1
View File
@@ -1987,7 +1987,7 @@ static void map(Compiler* compiler, bool allowAssignment)
if (peek(compiler) == TOKEN_RIGHT_BRACE) break;
// The key.
parsePrecedence(compiler, false, PREC_PRIMARY);
parsePrecedence(compiler, false, PREC_UNARY);
consume(compiler, TOKEN_COLON, "Expect ':' after map key.");
ignoreNewlines(compiler);