-module(glisp@repl). -compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]). -export([main_repl/0]). -if(?OTP_RELEASE >= 27). -define(MODULEDOC(Str), -moduledoc(Str)). -define(DOC(Str), -doc(Str)). -else. -define(MODULEDOC(Str), -compile([])). -define(DOC(Str), -compile([])). -endif. -file("src/glisp/repl.gleam", 25). -spec repl_loop(gleam@dict:dict(binary(), glisp@ast:expr())) -> nil. repl_loop(Env) -> In = gleam@result:unwrap(input_ffi:input(<<"> "/utf8>>), <<""/utf8>>), case gleam@string:trim(In) of <<"exit"/utf8>> -> gleam_stdlib:println(<<"Goodbye!"/utf8>>), nil; <<""/utf8>> -> repl_loop(Env); In@1 -> Res = begin _pipe = glisp@tokenizer:tokenize(In@1), _pipe@1 = glisp@parser:parse(_pipe), gleam@result:then( _pipe@1, fun(Expr) -> glisp@eval:eval(Expr, Env) end ) end, case Res of {ok, Value} -> gleam_stdlib:println(glisp@ast:expr_to_string(Value)); {error, Err} -> gleam_stdlib:println(<<"Error: "/utf8, Err/binary>>) end, repl_loop(Env) end. -file("src/glisp/repl.gleam", 17). ?DOC( " Starts an interactive REPL (Read-Eval-Print Loop) for the GLisp interpreter.\n" "\n" " This function initializes the standard environment, displays a welcome message,\n" " and allows users to input Lisp expressions for immediate evaluation.\n" " The loop continues until the user types 'exit'.\n" ). -spec main_repl() -> nil. main_repl() -> gleam_stdlib:println( <<"Welcome to GLisp - A Lisp interpreter in Gleam!"/utf8>> ), gleam_stdlib:println( <<"Type expressions to evaluate, or 'exit' to quit."/utf8>> ), Env = glisp@stdlib:standard_env(), repl_loop(Env).