NetComposer / nklib

NetComposer common library functions
Apache License 2.0
11 stars 38 forks source link

Added binary_text syntax_term. #21

Closed jrx-vag closed 5 years ago

jrx-vag commented 5 years ago

This new syntax will accept only binaries that contain printable unicode characters. Example: nklib_syntax:parse(#{a => [23, 234]}, #{a => binary_text}).
{error,{syntax_error,<<"a">>}}

nklib_syntax:parse(#{a => [97]}, #{a => binary_text}).
{ok,#{a => <<"a">>},[]}

kalta commented 5 years ago

Thanks, already inserted with an alternate representation:

spec(binary_text, []) ->
    {ok, <<>>};

spec(binary_text, Val) when is_binary(Val); is_integer(Val); is_atom(Val) ->
    spec(binary_text, nklib_util:to_list(Val));

spec(binary_text, [Int|_]=List) when is_integer(Int) ->
    case io_lib:printable_unicode_list(List) of
        true ->
            {ok, list_to_binary(List)};
        false ->
            error
    end;

spec(binary_text, _Val) ->
    error;