From b2ffa1db9688048d644aeda4c72fcb41cb68711a Mon Sep 17 00:00:00 2001 From: Alexey Shchepin Date: Thu, 5 May 2016 16:42:48 +0300 Subject: [PATCH] Add missed jlib:term_to_expr and jlib:expr_to_term functions --- src/jlib.erl | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/jlib.erl b/src/jlib.erl index 7bea7bb11..bad46898d 100644 --- a/src/jlib.erl +++ b/src/jlib.erl @@ -54,7 +54,8 @@ binary_to_integer/1, binary_to_integer/2, integer_to_binary/1, integer_to_binary/2, atom_to_binary/1, binary_to_atom/1, tuple_to_binary/1, - l2i/1, i2l/1, i2l/2, queue_drop_while/2]). + l2i/1, i2l/1, i2l/2, queue_drop_while/2, + expr_to_term/1, term_to_expr/1]). %% The following functions are deprecated and will be removed soon %% Use corresponding functions from jid.erl instead @@ -890,6 +891,14 @@ tuple_to_binary(T) -> atom_to_binary(A) -> erlang:atom_to_binary(A, utf8). +expr_to_term(Expr) -> + Str = binary_to_list(<>), + {ok, Tokens, _} = erl_scan:string(Str), + {ok, Term} = erl_parse:parse_term(Tokens), + Term. + +term_to_expr(Term) -> + list_to_binary(io_lib:print(Term)). l2i(I) when is_integer(I) -> I; l2i(L) when is_binary(L) -> binary_to_integer(L).