Add operator lambdas
This commit is contained in:
parent
b0e6418161
commit
9308f5b416
@ -335,7 +335,7 @@ exprAtom() ->
|
|||||||
?LAZY_P(begin
|
?LAZY_P(begin
|
||||||
Expr = ?LAZY_P(expr()),
|
Expr = ?LAZY_P(expr()),
|
||||||
choice(
|
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(bytes), token(string), token(char)
|
||||||
, token(int)
|
, token(int)
|
||||||
, ?RULE(token(hex), set_ann(format, hex, setelement(1, _1, int)))
|
, ?RULE(token(hex), set_ann(format, hex, setelement(1, _1, int)))
|
||||||
@ -472,6 +472,19 @@ id() -> token(id).
|
|||||||
tvar() -> token(tvar).
|
tvar() -> token(tvar).
|
||||||
str() -> token(string).
|
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) ->
|
token(Tag) ->
|
||||||
?RULE(tok(Tag),
|
?RULE(tok(Tag),
|
||||||
case _1 of
|
case _1 of
|
||||||
|
Loading…
x
Reference in New Issue
Block a user