예제 #1
0
        public static void Main(string[] args)
        {
            var evaluator = new Evaluator(new Parser(new Tokenizer()), new Environment(), Console.Out, Console.In);
            var prettyPrinter = new PrettyPrinter();

            Console.Out.WriteLine("End you statements with <Enter> <Ctrl-Z> <Enter>. Quit with <Ctrl-C>.");

            while (true)
            {
                Console.Out.WriteLine();
                Console.Out.Write("yalla> ");

                var input = Console.In.ReadToEnd();

                Console.Out.Write("=> ");
                try
                {
                    var result = prettyPrinter.PrettyPrint(evaluator.Evaluate(input));
                    Console.Out.Write(result);
                }
                catch (Exception ex)
                {
                    Console.Out.WriteLine("Unhandled exception: " + ex.GetType().ToString());
                    Console.Out.WriteLine("Content:");
                    Console.Out.WriteLine(ex.Message);
                }

                Console.Out.WriteLine();
            }
        }
예제 #2
0
        public void Run()
        {
            var evaluator = new Evaluator(new Parser(new Tokenizer()), new Environment(), stdOut, null);
            var prettyPrinter = new PrettyPrinter();

            evaluator.Evaluate("(defun parse-swank-listener-eval (msg)" +
                               "  (let ((form-str (assoc 'swank:listener-eval (assoc ':emacs-rex msg))))" +
                               "    (eval form-str)))");

            // wireshark filter: tcp.port eq 4005 and data

            try
            {
                while(true)
                {
                    var countChars = new char[6];

                    int c = reader.ReadBlock(countChars, 0, 6);

                    if (c == 6)
                    {
                        int count = int.Parse(new string(countChars), NumberStyles.HexNumber);

                        var buffer = new char[count];

                        reader.ReadBlock(buffer, 0, count);

                        var sbuf = new String(buffer);

                        messageCounter++;

                        if (sbuf.Contains("swank:connection-info"))
                        {
                            var message1 = CreateMessage("(:indentation-update ((\"tommy\" . 1)))");
                            writer.Write(message1);

                            var message = CreateMessage("(:return (:ok (:pid \"2229\" :style :spawn " +
                                                        "               :lisp-implementation (:type \"Yalla\" :name \"yalla\" :version \"0.1.0\") " +
                                                        "               :package (:name \"yalla.user\" :prompt \"yalla.user\") " +
                                                        "               :version \"20xx\")) 1)");
                            writer.Write(message);
                            writer.Flush();

                            Console.Out.WriteLine("Connection info sent!");
                        }
                        else if (sbuf.Contains("swank:create-repl"))
                        {
                            var message = CreateMessage("(:return (:ok (\"yalla.user\" \"yalla.user\")) 2)");

                            writer.Write(message);
                            writer.Flush();

                            Console.Out.WriteLine("Creating REPL!");
                        }
                        else if (sbuf.Contains("swank:operator-arglist"))
                        {
                            SwankReturn();
                        }
                        else if (sbuf.Contains("swank:listener-eval"))
                        {
                            try
                            {
                                var evalStr = "(parse-swank-listener-eval '" + sbuf + ")";
                                var result = evaluator.Evaluate(evalStr);
                                var returnString = prettyPrinter.EscapeString(prettyPrinter.PrettyPrint(result));

                                stdOut.Flush();

                                SwankWriteResult(returnString);
                            }
                            catch (Exception e)
                            {
                                var inner = GetInnerMostException(e);
                                SwankWrite(inner.Message);
                            }

                            SwankReturn();
                        }
                    }
                    else
                    {
                        throw new ArgumentOutOfRangeException("wtf?");
                    }
                }
            }
            catch (Exception)
            {
                Console.Out.WriteLine("Disconnected");
            }
        }