Packages
fast_xml
1.1.48
1.1.60
1.1.59
1.1.58
1.1.57
1.1.56
1.1.55
1.1.53
1.1.52
1.1.51
1.1.49
1.1.48
1.1.47
1.1.46
1.1.45
1.1.43
1.1.41
1.1.40
1.1.39
1.1.38
1.1.37
1.1.36
1.1.35
1.1.34
1.1.32
1.1.31
1.1.30
1.1.29
1.1.28
1.1.27
1.1.26
1.1.24
1.1.23
1.1.22
1.1.20
1.1.19
1.1.18
1.1.15
1.1.14
1.1.13
1.1.12
1.1.11
1.1.10
1.1.9
1.1.8
1.1.7
1.1.6
1.1.5
1.1.4
1.1.3
1.1.2
Fast Expat-based Erlang / Elixir XML parsing library
Current section
Files
Jump to
Current section
Files
src/fxml_gen_pt.erl
%%%-------------------------------------------------------------------
%%% @author Evgeny Khramtsov <ekhramtsov@process-one.net>
%%% @copyright (C) 2016-2021, Evgeny Khramtsov
%%% @doc
%%%
%%% @end
%%% Created : 27 May 2016 by Evgeny Khramtsov <ekhramtsov@process-one.net>
%%%-------------------------------------------------------------------
-module(fxml_gen_pt).
%% API
-export([parse_transform/2]).
-include("fxml_gen.hrl").
%%%===================================================================
%%% API
%%%===================================================================
parse_transform(Forms, _Options) ->
Result = lists:map(
fun(Form) ->
try
Form2 = erl_syntax_lib:map(
fun(Node) ->
transform(Node)
end, Form),
Form3 = erl_syntax:revert(Form2),
%%io:format("~s~n", [erl_prettypr:format(Form3)]),
Form3
catch
throw:{error, Line, Error} ->
{error, {Line, erl_parse, Error}}
end
end, Forms),
Result.
%%%===================================================================
%%% Internal functions
%%%===================================================================
transform(Form) ->
case erl_syntax:type(Form) of
application ->
case erl_syntax_lib:analyze_application(Form) of
{?AST_MARK, 1} ->
[Tree] = erl_syntax:application_arguments(Form),
NewTree = erl_syntax_lib:map(
fun(Node) ->
transform_variable(Node)
end, erl_syntax:abstract(Tree)),
erl_syntax:revert(NewTree);
_ ->
Form
end;
_ ->
Form
end.
transform_variable(Form) ->
try
Term = erl_syntax:concrete(Form),
atom = erl_syntax:type(Term),
"?" ++ Var = erl_syntax:atom_name(Term),
{ok, Tokens, _} = erl_scan:string(Var ++ "."),
{ok, [NewForm]} = erl_parse:parse_exprs(Tokens),
NewForm
catch _:_ ->
Form
end.