anchor.diff:  	    binary_to_list(B)
       end.
   
  +type(Is, Data, Imports) ->
  +    case lists:keyfind(type, 1, Is) of
  +	false ->
  +	    "untyped";
  +	{type, _, T, _} = Type ->
  +	    case binary:split(T, <<":">>) of
  +		[Pfx, Ts] ->
  +		    io:fwrite("trying to expand type ~s...~nData = ~p~n", [Ts, Data]),
  +
  +		    ImpData = orddict:fetch(Pfx, Imports),
  +		    case [D1 || {typedef,_,T1,D1} <- ImpData, Ts == T1] of
  +			[Def] ->
  +			    type(Def, ImpData, Imports);
  +			[] ->
  +			    descr_type(Type)
  +		    end;
  +		_ ->
  +		    case [D1 || {typedef,_,T1,D1} <- Data, T == T1] of
  +			[Def|_] ->
  +			    type(Def, Data, Imports);
  +			[] ->
  +			    descr_type(Type)
  +		    end
  +	    end
  +    end.
  +
  +descr_type({type, _, <<"enumeration">>, [{enum,_,E,I} |En]}) ->
  +    [ enum_value(I), " (", E, ")" | [ [ " | ", enum_value(I1), " (", E1, ")"]
  +				     || {enum,_,E1,I1} <- En ] ];
  +descr_type({type, _, <<"boolean">>, _}) ->
  +    "\"1\" (true) | \"0\" (false)";
  +descr_type({type, _, T, _}) ->
  +    T.
  +
  +enum_value(I) ->
  +    {value,_,V,_} = lists:keyfind(value, 1, I),
  +    ["\"", binary_to_list(V), "\""].
  +
   i(I) ->
       lists:duplicate(I,$\s).
  
positive.code: 
  to_json_rpc(Data, Dir) ->
      Imports = imports(Data, Dir),
      [{binary_to_list(N), mk_rpc_pair(InOut, N, Data, Imports)} || {rpc,_,N,InOut} <- Data].
  
  imports(Data, Dir) ->
      lists:foldl(
  
negative.code: 			   [Pfx, G1] ->
  			       {orddict:fetch(Pfx, Imports), G1}
  		       end,
      TypeDefs = [{typedef,L,Type,Def} || {typedef,L,Type,Def} <- Where],
      io:fwrite("TypeDefs = ~p~n", [TypeDefs]),
      Data1 = Data ++ TypeDefs,
      case [L || {grouping,_,Grp,L} <- Where,
  	       Grp == GrpName] of
  	[] ->
  	    [{"uses-not-found", binary_to_list(G)} | rpc_params(T, Data1, Imports)];
  	[Params] ->
  	    rpc_params(Params, Data1, Imports) ++ rpc_params(T, Data1, Imports)
      end;
  rpc_params([{leaf,_,N,Is}|T], Data, Imports) ->
      [{binary_to_list(N), "", descr(Is), type(Is,Data,Imports)}
       | rpc_params(T, Data, Imports)];
  rpc_params([{anyxml,_,N,Is}|T], Data, Imports) ->
      [{binary_to_list(N), "", descr(Is), type(Is,Data,Imports)}
       | rpc_params(T, Data, Imports)];
  rpc_params([{list,_,N,Items}|T], Data, Is) ->
      [{binary_to_list(N), {array, [{struct, rpc_params(Items, Data, Is)}]},
        descr(Items), type(Items, Data, Is)}
       | rpc_params(T, Data, Is)];
  rpc_params([_|T], Data, Is) ->
      rpc_params(T, Data, Is);
  