Allow binary operators to be used as lambdas #876

Merged
ghallak merged 7 commits from ghallak/228 into master 2022-06-03 18:12:24 +09:00
Showing only changes of commit 9308f5b416 - Show all commits

View File

@ -335,7 +335,7 @@ exprAtom() ->
?LAZY_P(begin
Expr = ?LAZY_P(expr()),
choice(
[ id_or_addr(), con(), token(qid), token(qcon)
[ id_or_addr(), con(), token(qid), token(qcon), binop_as_lam()
, token(bytes), token(string), token(char)
, token(int)
, ?RULE(token(hex), set_ann(format, hex, setelement(1, _1, int)))
@ -472,6 +472,19 @@ id() -> token(id).
tvar() -> token(tvar).
str() -> token(string).
binop_as_lam() ->
BinOps = ['&&', '||',
'+', '-', '*', '/', '^', 'mod',
'==', '!=', '<', '>', '<=', '=<', '>=',
'..', '::', '++', '|>'],
OpToLam = fun(Op = {_, Ann}) ->
IdL = {id, Ann, "l"},
IdR = {id, Ann, "r"},
Arg = fun(Id) -> {arg, Ann, Id, type_wildcard(Ann)} end,
{lam, Ann, [Arg(IdL), Arg(IdR)], infix(IdL, Op, IdR)}
end,
?RULE(parens(choice(lists:map(fun token/1, BinOps))), OpToLam(_1)).
token(Tag) ->
?RULE(tok(Tag),
case _1 of