@@ -278,13 +278,14 @@ if it were in a file. For example:
278278-module(my_module).
279279-export([foo/0]).
280280foo() ->
281- ok .
281+ {?MODULE, ?FUNCTION_NAME, ?LINE} .
282282```
283283
284284The module is then available for use in following prompts. For example:
285285
286286```
2872871> my_module:foo().
288+ {my_module, foo, 4}
288289```
289290
290291### Edge cases
@@ -752,54 +753,25 @@ run_test(Code, InitialBindings, Options) ->
752753 end
753754 end , InitialBindings , Tests ),
754755 [ok ];
755- {match , [_Line_Number , _Prefix = <<" -module(" >>, _Code ]} ->
756- [compile_string (Code )];
756+ {match , [_Line_Number , _Prefix = <<" -module(" >>, ModContent ]} ->
757+ [ModName | _ ] = binary :split (ModContent , [<<" )" >>]),
758+ [compile_string (Code , ModName )];
757759 _ ->
758760 []
759761 end
760762 end .
761763
762- compile_string (Code ) ->
763-
764- Toks =
765- case erl_scan :string (unicode :characters_to_list (Code ),
766- 0 ,
767- [text ]) of
768- {ok , T , _ } ->
769- T ;
770- {error , {Line ,Mod ,Reason }, _ } ->
771- Message = io_lib :format (" unknown:~p : ~ts " ,[Line , Mod :format_error (Reason )]),
772- throw ({error ,#{ message => Message , context => Code }})
773- end ,
774-
775- Forms = parse_tokens (Code , Toks ),
776-
777- {attribute ,_ ,module ,ModuleName } = lists :keyfind (module , 3 , Forms ),
778-
779- case compile :forms (Forms , [binary , return_errors , {source , atom_to_list (ModuleName ) ++ " .erl" }]) of
764+ compile_string (Code , ModName ) ->
765+ FileName = unicode :characters_to_list (ModName ) ++ " .erl" ,
766+ case compile :string (Code , [binary , return_errors , {source , FileName }]) of
780767 {ok , Module , Binary } ->
781- {module , Module } = code :load_binary (Module , " nofile " , Binary ),
768+ {module , Module } = code :load_binary (Module , FileName , Binary ),
782769 ok ;
783770 {error , Errors , Warnings } ->
784771 Messages = [begin [{_ , M }] = sys_messages :format_messages (File , " " , Msgs , []), M end || {File , Msgs } <- Errors ++ Warnings ],
785772 throw ({error ,#{ message => Messages , context => Code }})
786773 end .
787774
788- parse_tokens (_Code , []) -> [];
789- parse_tokens (Code , Toks ) ->
790- case lists :splitwith (fun (T ) ->
791- element (1 , T ) =/= dot
792- end , Toks ) of
793- {Ts , [{dot , _ } = Dot | Rest ]} ->
794- case erl_parse :parse_form (Ts ++ [Dot ]) of
795- {ok , Forms } ->
796- [Forms | parse_tokens (Code , Rest )];
797- {error , {Line , Mod , Reason }} ->
798- Message = io_lib :format (" unknown:~p : ~ts " ,[Line , Mod :format_error (Reason )]),
799- throw ({error ,#{ message => Message , context => Code }})
800- end
801- end .
802-
803775check_prompt_numbers (Tests ) ->
804776 check_prompt_numbers (Tests , 1 ).
805777
0 commit comments