<commit_before>%% Translate Kapok AST to Erlang Abstract Format.
-module(kapok_translate).
-export([translate/2,
         translate_arg/3,
         translate_args/2,
         to_abstract_format/1]).
-include("kapok.hrl").

%% block

translate({block, _Meta, Args}, Env) ->
  [First | Left] = Args,
  {HeadErl, TEnv} = kapok_translate:translate(First, Env),
  {BodyErl, TEnv1} = kapok_translate:translate(Left, TEnv),
  #{namespace := Namespace} = TEnv1,
  Erl = [HeadErl, kapok_namespace:export_forms(Namespace) | BodyErl],
  {Erl, TEnv1};

%% literals

%% number

%% integer
translate({number, Meta, Value}, Env) when is_integer(Value) ->
  {{integer, ?line(Meta), Value}, Env};
%% float
translate({number, Meta, Value}, Env) when is_float(Value) ->
  {{float, ?line(Meta), Value}, Env};

%% Operators
translate({Op, Meta, Number}, Env) when Op == '+', Op == '-' ->
  {Erl, TEnv} = translate(Number, Env),
  {{op, ?line(Meta), Op, Erl}, TEnv};

%% atom
translate({atom, Meta, Value}, Env) ->
  {{atom, ?line(Meta), Value}, Env};

%% Identifiers
translate({identifier, Meta, Identifier}, Env) ->
  %% search env to check whether identifier is a variable
  {{atom, ?line(Meta), list_to_atom(Identifier)}, Env};

%% binary string
%% TODO
%%translate({binary_string, Meta, Value}, Env) ->
%%  {{}};

%% list string
translate({list_string, Meta, Value}, Env) ->
  {{string, ?line(Meta), binary_to_list(Value)}, Env};

%% Containers

%% bitstring
translate({bitstring, Meta, Args}, Env) ->
  kapok_bitstring:translate(Meta, Args, Env);

%% list
translate({literal_list, _Meta, List}, Env) ->
  translate_list(List, [], Env);

%% Local call

%% special forms
translate({list, Meta, [{identifier, _, "ns"} | _] = Args}, Env) ->
  kapok_namespace:translate(Meta, Args, Env);

translate({list, Meta, [{identifier, _, Id} | _] = Args}, Env)
    when Id == "def";
         Id == "defp";
         Id == "defmacro";
         Id == "defmacrop" ->
  kapok_defs:translate(Meta, Args, Env);

translate({list, Meta, [{identifier, _, Id} | Args]},
          #{namespace := Namespace, functions := Functions, function_aliases := Aliases} = Env) ->
  Arity = length(Args),<commit_msg>add translation for binary string<commit_after>%% Translate Kapok AST to Erlang Abstract Format.
-module(kapok_translate).
-export([translate/2,
         translate_arg/3,
         translate_args/2,
         to_abstract_format/1]).
-include("kapok.hrl").

%% block

translate({block, _Meta, Args}, Env) ->
  [First | Left] = Args,
  {HeadErl, TEnv} = kapok_translate:translate(First, Env),
  {BodyErl, TEnv1} = kapok_translate:translate(Left, TEnv),
  #{namespace := Namespace} = TEnv1,
  Erl = [HeadErl, kapok_namespace:export_forms(Namespace) | BodyErl],
  {Erl, TEnv1};

%% literals

%% number

%% integer
translate({number, Meta, Value}, Env) when is_integer(Value) ->
  {{integer, ?line(Meta), Value}, Env};
%% float
translate({number, Meta, Value}, Env) when is_float(Value) ->
  {{float, ?line(Meta), Value}, Env};

%% Operators
translate({Op, Meta, Number}, Env) when Op == '+', Op == '-' ->
  {Erl, TEnv} = translate(Number, Env),
  {{op, ?line(Meta), Op, Erl}, TEnv};

%% atom
translate({atom, Meta, Value}, Env) ->
  {{atom, ?line(Meta), Value}, Env};

%% Identifiers
translate({identifier, Meta, Identifier}, Env) ->
  %% search env to check whether identifier is a variable
  {{atom, ?line(Meta), list_to_atom(Identifier)}, Env};

%% binary string
translate({binary_string, _Meta, Binary}, Env) ->
  translate(Binary, Env);

%% list string
translate({list_string, Meta, CharList}, Env) ->
  {{string, ?line(Meta), binary_to_list(CharList)}, Env};

%% Containers

%% bitstring
translate({bitstring, Meta, Args}, Env) ->
  kapok_bitstring:translate(Meta, Args, Env);

%% list
translate({literal_list, _Meta, List}, Env) ->
  translate_list(List, [], Env);

%% Local call

%% special forms
translate({list, Meta, [{identifier, _, "ns"} | _] = Args}, Env) ->
  kapok_namespace:translate(Meta, Args, Env);

translate({list, Meta, [{identifier, _, Id} | _] = Args}, Env)
    when Id == "def";
         Id == "defp";
         Id == "defmacro";
         Id == "defmacrop" ->
  kapok_defs:translate(Meta, Args, Env);

translate({list, Meta, [{identifier, _, Id} | Args]},
          #{namespace := Namespace, functions := Functions, function_aliases := Aliases} = Env) ->
  Arity = length(Args),
{'fraction_non_alphanumeric': 0.18738532110091743, 'fraction_numerical': 0.003211009174311927, 'mean_word_length': 4.437655860349127, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1536275', 'n_tokens_mistral': 1469, 'n_tokens_neox': 1479, 'n_words': 374}