Function Decorating v0.0.3 FnDef

Summary

Functions

Generate AST for argument AST and its mediator

Add mediator argument to a function argument ast

Add meidator arguments to a function arguments list ast

Parse a function call into its parts: name and arguments

Functions

calc_full_arg(arg_ast, mediator_arg_ast)

Specs

calc_full_arg(Macro.t, Macro.t) :: Macro.t

Generate AST for argument AST and its mediator.

Examples

  iex> FnDef.calc_full_arg(quote context: __MODULE__ do first_name end, quote context: __MODULE__ do arg0 end)
  {:=, [], [{:first_name, [], __MODULE__}, {:arg0, [], __MODULE__}]}
decorate_arg(arg)

Specs

decorate_arg({Macro.t, non_neg_integer}) :: {Macro.t, Macro.t}

Add mediator argument to a function argument ast.

Returns {decorated argument name, decorated argument ast}

Examples

  iex> FnDef.decorate_arg({quote context: __MODULE__ do first_name end, 0})
  {{:arg0, [], FnDef}, {:=, [], [{:first_name, [], __MODULE__}, {:arg0, [], FnDef}]}}
decorate_args(args_ast)

Specs

decorate_args(list) :: {list, list}

Add meidator arguments to a function arguments list ast.

Mainly for the availabity to print unbounded arguments in a function call.

say(word) -> say(word = arg0)

Returns {[args names], [decorated args ast]}

Examples

  iex> FnDef.decorate_args(quote context: __MODULE__ do [a, b, _] end)
  {[{:arg0, [], FnDef}, {:arg1, [], FnDef}, {:arg2, [], FnDef}],
    [{:=, [], [{:a, [], __MODULE__}, {:arg0, [], FnDef}]},
      {:=, [], [{:b, [], __MODULE__}, {:arg1, [], FnDef}]},
      {:=, [], [{:_, [], __MODULE__}, {:arg2, [], FnDef}]}]}
parse_fn_name_and_args(short_head)

Parse a function call into its parts: name and arguments