Skip to content

Commit

Permalink
lang: Add anonymous Tuple syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
mhermier committed Mar 10, 2023
1 parent 1061ee4 commit 3454e2d
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/vm/wren_compiler.c
Original file line number Diff line number Diff line change
Expand Up @@ -1747,6 +1747,7 @@ typedef struct
// Forward declarations since the grammar is recursive.
static GrammarRule* getRule(TokenType type);
static void expression(Compiler* compiler);
static void maybeTuple(Compiler* compiler);
static void statement(Compiler* compiler);
static void definition(Compiler* compiler);
static void parsePrecedence(Compiler* compiler, Precedence precedence);
Expand Down Expand Up @@ -2138,7 +2139,7 @@ static void loadCoreVariable(Compiler* compiler, const char* name)
// A parenthesized expression.
static void grouping(Compiler* compiler, bool canAssign)
{
expression(compiler);
maybeTuple(compiler);
consume(compiler, TOKEN_RIGHT_PAREN, "Expect ')' after expression.");
}

Expand Down Expand Up @@ -2857,6 +2858,16 @@ void expression(Compiler* compiler)
parsePrecedence(compiler, PREC_LOWEST);
}

void maybeTuple(Compiler* compiler)
{
expression(compiler);

if (peek(compiler) == TOKEN_COMMA)
{
error(compiler, "Cannot create a tuple.");
}
}

// Returns the number of bytes for the arguments to the instruction
// at [ip] in [fn]'s bytecode.
static int getByteCountForArguments(const uint8_t* bytecode,
Expand Down

0 comments on commit 3454e2d

Please sign in to comment.