Exemplo n.º 1
0
        private static void StartInteractiveMode()
        {
            codeLines = new StringBuilder();
            helper.PrintPrompt();
            var app = String.Empty;

            for (;;)
            {
                var source = app + Console.ReadLine();

                if (!String.IsNullOrEmpty(source))
                {
                    source = source.Trim('\0');

                    if (source.Length > 0)
                    {
                        if (source[0] == '#')
                        {
                            var cmd = new InteractiveCommands(vm, helper, opt);

                            var res = cmd.ProcessCommand(source);

                            if (res == InteractiveAction.Reset || res == InteractiveAction.EvalFile)
                            {
                                lastOffset = 0;
                                linker     = null;
                                vm         = null;
                            }

                            if (res == InteractiveAction.EvalFile)
                            {
                                InterpretFile(cmd.Data);
                            }

                            helper.PrintPrompt();
                            app = String.Empty;
                        }
                        else
                        {
                            if (!opt.Multiline)
                            {
                                Console.WriteLine();
                                InterpretString(source);
                                helper.PrintPrompt();
                                app = String.Empty;
                            }
                            else
                            {
                                if (source.Length >= 2 &&
                                    source[source.Length - 1] == ';' &&
                                    source[source.Length - 2] == ';')
                                {
                                    codeLines.AppendLine(source.TrimEnd(';'));
                                    Console.WriteLine();
                                    InterpretString(codeLines.ToString());
                                    codeLines = new StringBuilder();
                                    helper.PrintPrompt();
                                    app = String.Empty;
                                }
                                else
                                {
                                    codeLines.AppendLine(source);
                                    helper.PrintSecondaryPrompt();

                                    var indent = IndentHelper.GetIndent(source);
                                    app = new String(' ', indent);
                                    Console.Write(app);
                                }
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 2
0
        private static void StartInteractiveMode()
        {
            codeLines = new StringBuilder();
            helper.PrintPrompt();
            var app = String.Empty;

            for (;;)
            {
                var source = app + Console.ReadLine();

                if (!String.IsNullOrEmpty(source))
                {
                    source = source.Trim('\0');

                    if (source.Length > 0)
                    {
                        if (source[0] == '#')
                        {
                            var cmd = new InteractiveCommands(vm, helper, opt);

                            var res = cmd.ProcessCommand(source);

                            if (res == InteractiveAction.Reset || res == InteractiveAction.EvalFile)
                            {
                                lastOffset = 0;
                                linker = null;
                                vm = null;
                            }

                            if (res == InteractiveAction.EvalFile)
                                InterpretFile(cmd.Data);

                            helper.PrintPrompt();
                            app = String.Empty;
                        }
                        else
                        {
                            if (!opt.Multiline)
                            {
                                Console.WriteLine();
                                InterpretString(source);
                                helper.PrintPrompt();
                                app = String.Empty;
                            }
                            else
                            {
                                if (source.Length >= 2 &&
                                    source[source.Length - 1] == ';' &&
                                    source[source.Length - 2] == ';')
                                {
                                    codeLines.AppendLine(source.TrimEnd(';'));
                                    Console.WriteLine();
                                    InterpretString(codeLines.ToString());
                                    codeLines = new StringBuilder();
                                    helper.PrintPrompt();
                                    app = String.Empty;
                                }
                                else
                                {
                                    codeLines.AppendLine(source);
                                    helper.PrintSecondaryPrompt();

                                    var indent = IndentHelper.GetIndent(source);
                                    app = new String(' ', indent);
                                    Console.Write(app);
                                }
                            }
                        }
                    }
                }
            }
        }