Extend compiler to allow bytes()/bytes as type

This commit is contained in:
Hans Svensson 2023-04-27 11:55:15 +02:00
parent 32a98112d3
commit fda58ec430
2 changed files with 10 additions and 5 deletions

View File

@ -4287,7 +4287,7 @@ pp({tuple_t, _, []}) ->
"unit";
pp({tuple_t, _, Cpts}) ->
["(", string:join(lists:map(fun pp/1, Cpts), " * "), ")"];
pp({bytes_t, _, any}) -> "bytes(_)";
pp({bytes_t, _, any}) -> "bytes()";
pp({bytes_t, _, Len}) ->
["bytes(", integer_to_list(Len), ")"];
pp({app_t, _, T, []}) ->

View File

@ -264,10 +264,11 @@ type300() ->
type400() ->
choice(
[?RULE(typeAtom(), optional(type_args()),
any_bytes(
case _2 of
none -> _1;
{ok, Args} -> {app_t, get_ann(_1), _1, Args}
end),
end)),
?RULE(id("bytes"), parens(token(int)),
{bytes_t, get_ann(_1), element(3, _2)})
]).
@ -792,3 +793,7 @@ auto_imports(L) when is_list(L) ->
auto_imports(T) when is_tuple(T) ->
auto_imports(tuple_to_list(T));
auto_imports(_) -> [].
any_bytes({id, Ann, "bytes"}) -> {bytes_t, Ann, any};
any_bytes({app_t, _, {id, Ann, "bytes"}, []}) -> {bytes_t, Ann, any};
any_bytes(Type) -> Type.