Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Functional operators #1154

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add tokens for |< and |>
mhermier committed Mar 13, 2023
commit 4197e470f241ab7ce0c723940ce54ed9182b4072
19 changes: 18 additions & 1 deletion src/vm/wren_compiler.c
Original file line number Diff line number Diff line change
@@ -73,6 +73,8 @@ typedef enum
TOKEN_GTGT,
TOKEN_PIPE,
TOKEN_PIPEPIPE,
TOKEN_PIPELT,
TOKEN_PIPEGT,
TOKEN_CARET,
TOKEN_AMP,
TOKEN_AMPAMP,
@@ -1112,7 +1114,20 @@ static void nextToken(Parser* parser)
case '~': makeToken(parser, TOKEN_TILDE); return;
case '?': makeToken(parser, TOKEN_QUESTION); return;

case '|': twoCharToken(parser, '|', TOKEN_PIPEPIPE, TOKEN_PIPE); return;
case '|':
if (matchChar(parser, '|'))
{
makeToken(parser, TOKEN_PIPEPIPE);
}
else if (matchChar(parser, '<'))
{
makeToken(parser, TOKEN_PIPELT);
}
else
{
twoCharToken(parser, '>', TOKEN_PIPEGT, TOKEN_PIPE);
}
return;
case '&': twoCharToken(parser, '&', TOKEN_AMPAMP, TOKEN_AMP); return;
case '=': twoCharToken(parser, '=', TOKEN_EQEQ, TOKEN_EQ); return;
case '!': twoCharToken(parser, '=', TOKEN_BANGEQ, TOKEN_BANG); return;
@@ -2769,6 +2784,8 @@ GrammarRule rules[] =
/* TOKEN_GTGT */ INFIX_OPERATOR(PREC_BITWISE_SHIFT, ">>"),
/* TOKEN_PIPE */ INFIX_OPERATOR(PREC_BITWISE_OR, "|"),
/* TOKEN_PIPEPIPE */ INFIX(PREC_LOGICAL_OR, or_),
/* TOKEN_PIPELT */ UNUSED,
/* TOKEN_PIPEGT */ UNUSED,
/* TOKEN_CARET */ INFIX_OPERATOR(PREC_BITWISE_XOR, "^"),
/* TOKEN_AMP */ INFIX_OPERATOR(PREC_BITWISE_AND, "&"),
/* TOKEN_AMPAMP */ INFIX(PREC_LOGICAL_AND, and_),