static void Loop(Func<State,State> func, State initial) { var state = initial; while (true) { state = func(state); if (state.Exit) break; } }
static State Read(State state) { if(state.Current.Length == 0) Console.Write("es:> "); string read = null; if (!state.Piped || Console.In.Peek() != -1) { read = Console.ReadLine(); } if(state.Piped && read != null) Console.WriteLine(read); state.Read = read; return state; }
static State Eval(State state) { var str = state.Read; if(state.Read == null) { state.Exit = true;} var builder = state.Current; if (!string.IsNullOrEmpty(str)) { builder.AppendLine(str); state.Evaled = null; return state; } var command = builder.ToString(); builder.Clear(); state.Evaled = CommandProcessor.Process(command, state); return state; }
static State Print(State state) { if(state.Evaled != null) Console.WriteLine("\n" + state.Evaled); return state; }