anchor.diff: +%%%-------------------------------------------------------------------
   %%% @author Pablo Lamela <P.Lamela-Seijas@kent.ac.uk>
   %%% @copyright (C) 2014, Pablo Lamela Seijas
   %%% @doc
  -%%% Adds information about idioms to the structure
  +%%% Defines functions to add information about idioms to the structure.
  +%%% It also defines a framework to tag Erlang elements inside an Erlang
  +%%% structure so that they can be extracted and modified in place.
  +%%% Functions that start with "ts" define "templates tags" designed to
  +%%% work with erl_syntax elements. Functions that start with "t"
  +%%% define generic "templates tags" that may potentially work with any Erlang
  +%%% term. Template tags use a common reference that is used to tell
  +%%% apart Erlang terms that are part of the template tags from the ones
  +%%% that are not.
  +%%% For example, we may build a template like this:
  +%%% <p><code>
  +%%% Ref = make_ref().
  +%%% Template = {1, idiomizer:tvar(Ref, 'number_in_the_middle'), 3}.
  +%%% </code></p>
  +%%% And then we can match that template with any Erlang term
  +%%% by using {@link idiomizer:extract_vars/4} as follows:
  +%%% <p><code>
  +%%% {match, Dict} = idiomizer:extract_vars(Ref, Template, {1, 2, 3}, dict:new()).
  +%%% </code></p>
  +%%% Where <code>dict:to_list(Dict)</code> would be:
  +%%% <p><code> [{number_in_the_middle,2}] </code></p>
  +%%% And if we use templates which have the same name for several tags,
  +%%% {@link idiomizer:extract_vars/4} will check that they all match the
  +%%% same value.
   %%% @end
   %%% Created : 5 Feb 2014 by Pablo Lamela
  +%%%-------------------------------------------------------------------
   
   -module(idiomizer).
   
   -export([idiomize_module_info/1,
   	 tsatom_val/2, tsint_val/2, tsvar_name/2, tsvar_name_and_id/3, tsvar_id/2,
  -	 tcontainer/2, tvar/2, tobj/2, extract_vars/4, replace_vars/3,
  -	 tsoneellist_elid/2]).
  +	 tvar/2, tobj/2, extract_vars/4, replace_vars/3, tsoneellist_elid/2]).
   
   -include("records.hrl").
   -include("template_recs.hrl").
   
   %% General Function
   
  +%%% @doc
  +%%% Generates idiom information for a <code>#module_iface{}</code> record.
  +%%% It generates both generic information about statem model expansions,
  +%%% and it also detects common patterns defined in
  +%%% {@link idiom_definitions:idiom_template_list/1}
  +%%% @param MIface the <code>#module_iface{}</code> record to idiomize
  +%%% @return the idiomized <code>#module_iface{}</code> record
  +-spec idiomize_module_info(MIface :: #module_iface{}) -> #module_iface{}.
   idiomize_module_info(MIface) ->
       Ref = make_ref(),
       ArgsIdiomized = idiomize_module_info_args(MIface),
  
positive.code: 
  %% Tagging funcs
  
  tsatom_val(Ref, Value) ->
      tobj(Ref,
  	[{{erl_syntax, type}, atom},
           {{erl_syntax, atom_value}, Value}]).
  
  tsint_val(Ref, Value) ->
      tobj(Ref,
  	 [{{erl_syntax, type}, integer},
  	  {{erl_syntax, integer_value}, Value}]).
  
  tsvar_id(Ref, Id) ->
      tobj(Ref,
  	 [{{erl_syntax, type}, variable},
  	  {identity, Id}]).
  
  tsvar_name(Ref, Name) ->
      tobj(Ref,
  	 [{{erl_syntax, type}, variable},
            {{erl_syntax, variable_name}, Name}]).
  
  
  tsvar_name_and_id(Ref, Name, Value) ->
      tobj(Ref,
  	 [{{erl_syntax, type}, variable},
            {{erl_syntax, variable_name}, Name},
  	  {identity, Value}]).
  
  tsoneellist_elid(Ref, Value) ->
      tobj(Ref,
  	 [{{erl_syntax, list_length}, 1},
  
negative.code: 	end,
      G(G, F, Ref, Dict).
  
  %%% @doc
  %%% Replaces the elements in the dictionary Dict inside the template Template.
  %%% @param Ref the reference used to create the tags in the template, it is used
  %%% to reliably tell apart items that are template tags from those that are not,
  %%% which allows the use of several kinds of templates in the same structure.
  %%% @param Dict dictionary that stores the substitutions to make in the template.
  %%% On each entry of the dictionary, the key represents the name of a tag, and
  %%% the value represents the term that must be swapped with the tag. The dict
  %%% is of the same kind that the one generated by the function extract_vars.
  %%% All the names of the tags inside the template must have their entry on
  %%% the dictionary or otherwise the function will throw the exception
  %%% <code>unbound_variable</code>.
  %%% @param Template the template that must be used. Templates that are used
  %%% with replace_vars/3 function cannot have tags of the kind tobj.
  %%% @return the element generated from the template
  %%% @throws {unbound_variable, term()}
  %%% @see extract_vars/4
  -spec replace_vars(Ref :: reference(), Dict :: dict(), Template :: any()) -> any().
  replace_vars(Ref, Dict, Element) ->
      F = replace_mapper(Ref, Dict),
      F(Element).
  