/// <summary> /// Read a statement, which can potentially be a multiple-line statement suite (like a class declaration). /// </summary> /// <param name="continueInteraction">Should the console session continue, or did the user indicate /// that it should be terminated?</param> /// <returns>Expression to evaluate. null for empty input</returns> public string ReadStatement(out bool continueInteraction) { StringBuilder b = new StringBuilder(); int autoIndentSize = 0; if (!LanguageProvider.InputRedirected) { _console.Write(Prompt, Style.Prompt); } while (true) { string line = ReadLine(autoIndentSize); continueInteraction = true; if (line == null) { continueInteraction = false; return(null); } bool allowIncompleteStatement = TreatAsBlankLine(line, autoIndentSize); b.Append(line); b.Append("\n"); string code = b.ToString(); SourceCodeProperties props = _engine.GetCodeProperties(code, SourceCodeKind.InteractiveCode); if (SourceCodePropertiesUtils.IsCompleteOrInvalid(props, allowIncompleteStatement)) { return(props != SourceCodeProperties.IsEmpty ? code : null); } if (_options.AutoIndent && _options.AutoIndentSize != 0) { autoIndentSize = GetNextAutoIndentSize(code); } if (!LanguageProvider.InputRedirected) { // Keep on reading input _console.Write(PromptContinuation, Style.Prompt); } } }
/// <summary> /// Read a statement, which can potentially be a multiple-line statement suite (like a class declaration). /// </summary> /// <param name="continueInteraction">Should the console session continue, or did the user indicate /// that it should be terminated?</param> /// <returns>Expression to evaluate. null for empty input</returns> protected string ReadStatement(out bool continueInteraction) { StringBuilder b = new StringBuilder(); int autoIndentSize = 0; _console.Write(Prompt, Style.Prompt); while (true) { string line = ReadLine(autoIndentSize); continueInteraction = true; if (line == null || (_terminatingExitCode != null)) { continueInteraction = false; return(null); } bool allowIncompleteStatement = TreatAsBlankLine(line, autoIndentSize); b.Append(line); b.Append("\n"); string code = b.ToString(); ScriptSource command = _engine.CreateScriptSourceFromString(code, (code.Contains(Environment.NewLine))? SourceCodeKind.Statements : SourceCodeKind.InteractiveCode); ScriptCodeParseResult props = command.GetCodeProperties(_engine.GetCompilerOptions(_scope)); if (SourceCodePropertiesUtils.IsCompleteOrInvalid(props, allowIncompleteStatement)) { return(props != ScriptCodeParseResult.Empty ? code : null); } if (_options.AutoIndent && _options.AutoIndentSize != 0) { autoIndentSize = GetNextAutoIndentSize(code); } // Keep on reading input _console.Write(PromptContinuation, Style.Prompt); } }
/// <summary> /// Read a statement, which can potentially be a multiple-line statement suite (like a class declaration). /// </summary> /// <param name="continueInteraction">Should the console session continue, or did the user indicate /// that it should be terminated?</param> /// <returns>Expression to evaluate. null for empty input</returns> protected string ReadStatement(out bool continueInteraction) { StringBuilder b = new StringBuilder(); int autoIndentSize = 0; _console.Write(Prompt, Style.Prompt); while (true) { string line = ReadLine(autoIndentSize); continueInteraction = true; if (line == null || (_terminatingExitCode != null)) { continueInteraction = false; return(null); } bool allowIncompleteStatement = TreatAsBlankLine(line, autoIndentSize); b.Append(line); // Note that this does not use Environment.NewLine because some languages (eg. Python) only // recognize \n as a line terminator. b.Append("\n"); string code = b.ToString(); var props = GetCommandProperties(code); if (SourceCodePropertiesUtils.IsCompleteOrInvalid(props, allowIncompleteStatement)) { return(props != ScriptCodeParseResult.Empty ? code : null); } if (_options.AutoIndent && _options.AutoIndentSize != 0) { autoIndentSize = GetNextAutoIndentSize(code); } // Keep on reading input _console.Write(PromptContinuation, Style.Prompt); } }
private ScriptSource GetStatement(out bool continueInteraction) { ScriptSource source = null; StringBuilder codeBuilder = new StringBuilder(); int autoIndentSize = 0; this.Console.Write(Prompt, Style.Prompt); while (true) { string line = ReadLine(autoIndentSize); continueInteraction = true; if (line == null) { continueInteraction = false; return(source); } if (line == "$") { return(null); } bool allowIncompleteStatement = false; codeBuilder.Append(line); codeBuilder.Append('\n'); string code = codeBuilder.ToString(); var props = GetCommandPropertiesAndParse(code, out source); if (SourceCodePropertiesUtils.IsCompleteOrInvalid(props, allowIncompleteStatement)) { return(props != ScriptCodeParseResult.Empty ? source : null); } // Keep on reading input this.Console.Write(PromptContinuation, Style.Prompt); } }