free_vars/1

Bengt Kleberg Bengt.Kleberg@REDACTED
Mon Sep 8 10:08:53 CEST 2003


Richard Carlsson wrote:
...deleted

> If you take a look at the module 'epp_dodger.erl' in the syntax_tools
> contribution, it does a similar trick to get code containing macros past
> the parser. (It handles most "sane" uses of macros.) You might be able
> to use it directly, or just steal some parts of the code.
> 

thank you for the help.

epp_dodger has some well thought out functions (unexported, but that is 
easily handled). unfortunatly the most lowlevel ones (scan_macro/1 and 
scan_form/1) gives the unwanted result of turning the macro into a free 
variable.

input lines:
	case catch free_vars(Lines) of
	{error, Reason} ->
		io:format( "CRASH ~w: ~s~n", [?MODULE, Reason] );
	Free ->
		Function_head = function_head( Free ),
		io:put_chars(lists:append( Function_head, Lines ))
	end,
result:
(MODULE,Lines) ->

the more high level ones (parse_tokens/1 and rewrite_form/1) crash:

{"init terminating in do_boot",{put_chars,[{io,format,[<0.19.0>,"CRASH 
~w: ~s~n",[erlrefactor,{1,erl_parse,["syntax error before: 
",["'case'"]]}]]},{erlrefactor,main,1},{init,start_it,1},{init,start_em,1}]}} 



i will (try to) keep epp_dodger in mind when my macros_to_atoms/1 starts 
to fail me.


bengt




More information about the erlang-questions mailing list