public bool TryParse(ScripterParserInput input, out ScripterParserResult result) { result = new ScripterParserResult(); string content = input.Content; int index = input.Index; Func <string, ScripterParserResult, bool> error = (msg, res) => { res.Error = msg; return(false); }; if (String.IsNullOrEmpty(content)) { return(error("Empty or null content", result)); } int first = FindFirstAcceptableCharPos(content, index); int last = FindLastAcceptableCharPos(content, index); if (first == last) { return(error("Nothing found", result)); } string text = content.Substring(first, last - first + 1); result.Text = text; string[] parts = text.Split(_partsChars, StringSplitOptions.RemoveEmptyEntries); switch (parts.Length) { case 0: return(error("Empty or null content", result)); case 1: result.Name = parts[0].Trim(_partsTrim); return(true); case 2: result.Schema = parts[0].Trim(_partsTrim); result.Name = parts[1].Trim(_partsTrim); return(true); case 3: result.Database = parts[0].Trim(_partsTrim); result.Schema = parts[1].Trim(_partsTrim); result.Name = parts[2].Trim(_partsTrim); return(true); default: return(error("Unknown content format", result)); } }
public string Execute() { ScripterParserInput parserInput = null; if (!TryGetParserInput(out parserInput)) { return("Cannot find any input"); } ScripterParserResult parserResult = null; if (!_parser.TryParse(parserInput, out parserResult)) { return(parserResult.Error); } ScripterConfig config = _configStorage.Load(); var scripterInput = new ScripterInput() { Database = parserResult.Database, Schema = parserResult.Schema, Name = parserResult.Name, ScriptDatabaseContext = config.ScriptDatabaseContext, }; string scriptResult = null; if (!TryScript(scripterInput, out scriptResult)) { return(scriptResult); } IEditor editor = _hostCtx.GetNewEditor(); editor.SetContent(scriptResult); return("Success"); }
private bool TryGetParserInput(out ScripterParserInput input) { input = null; IResultGrid grid = _hostCtx.GetFocusedResultGrid(); if (grid != null) { input = new ScripterParserInput(grid.GetSelectedValue(), 0); } if (input == null) { IEditor editor = _hostCtx.GetCurrentEditor(); if (editor != null) { EditedLine line = editor.GetEditedLine(); input = new ScripterParserInput(line.Line, line.CaretPos); } } return(input != null); }