Nicholas Boulenguez : Use Get_Line function instead of insisting on a maximum string...
[jackhill/mal.git] / ada / step1_read_print.adb
CommitLineData
673ee61c 1with Ada.Text_IO;
673ee61c
CM
2with Printer;
3with Reader;
4with Types;
5
6procedure Step1_Read_Print is
7
fbad73cb 8 function Read (Param : String) return Types.Mal_Handle is
673ee61c
CM
9 begin
10 return Reader.Read_Str (Param);
673ee61c
CM
11 end Read;
12
fbad73cb 13 function Eval (Param : Types.Mal_Handle) return Types.Mal_Handle is
673ee61c
CM
14 begin
15 return Param;
16 end Eval;
17
fbad73cb 18 function Print (Param : Types.Mal_Handle) return String is
673ee61c
CM
19 begin
20 return Printer.Pr_Str (Param);
21 end Print;
22
23 function Rep (Param : String) return String is
18e21187 24 AST, Evaluated_AST : Types.Mal_Handle;
673ee61c 25 begin
7895cb30 26
18e21187 27 AST := Read (Param);
7895cb30 28
18e21187
CM
29 if Types.Is_Null (AST) then
30 return "";
31 else
32 Evaluated_AST := Eval (AST);
33 return Print (Evaluated_AST);
34 end if;
7895cb30 35
311cbfc0 36 end Rep;
673ee61c
CM
37
38begin
673ee61c
CM
39 loop
40 Ada.Text_IO.Put ("user> ");
311cbfc0
CM
41 exit when Ada.Text_IO.End_Of_File;
42 Ada.Text_IO.Put_Line (Rep (Ada.Text_IO.Get_Line));
673ee61c 43 end loop;
673ee61c 44end Step1_Read_Print;