Converting string to match specification

Vladimir Sekissov svg@REDACTED
Thu Jul 31 18:15:44 CEST 2003


Opps, sorry, I forgot code.

-module(test).

-export([str2ms/1]).

str2ms(FunStr) ->
  {ok, Tokens, _} = erl_scan:string(FunStr),
  {ok, [Form]} = erl_parse:parse_exprs(Tokens),
  {'fun', _, {clauses, Clauses}} = Form,
  case ms_transform:transform_from_shell(ets, Clauses, []) of
    {error,[{_,[{_,_,Code}|_]}|_],_} ->
      io:format("Error: ~s~n",
		[ms_transform:format_error(Code)]),
      {error,transform_error};
    Else ->
      Else
  end.


(svg@REDACTED)17> test:str2ms("fun (X) -> {x, X} end.").
[{'$1',[],[{{x,'$1'}}]}]


Best Regards,
Vladimir Sekissov

svg> Please look at function source of
svg> 
svg> dbg:fun2ms/1 in runtime_tools/src/dbg.erl
svg> 
svg> You need simply change ?MODULE(== dbg) to `ets' at line 48.
svg> 
svg> Best Regards,
svg> Vladimir Sekissov
svg> 
svg> anders_nygren2002> I want to be able to take a string containing a fun
svg> anders_nygren2002> and convert it to a match specification.
svg> anders_nygren2002> Similar to what i can get with the ms_transform parse
svg> anders_nygren2002> transform, but I want to make it at runtime.
svg> anders_nygren2002> Match=ets:fun2ms(fun (X)->{x,X} end)
svg> anders_nygren2002> 
svg> anders_nygren2002> I have been playing with erl_scan, erl_parse and
svg> anders_nygren2002> ms_transform, but I have not been able to get it to
svg> anders_nygren2002> work. Any hints?
svg> anders_nygren2002> 
svg> anders_nygren2002> 
svg> anders_nygren2002> 
svg> anders_nygren2002> _____________________________________________________
svg> anders_nygren2002> Gå före i kön och få din sajt värderad på nolltid med Yahoo! Express
svg> anders_nygren2002> Se mer på: http://se.docs.yahoo.com/info/express/help/index.html



More information about the erlang-questions mailing list