public override bool TryGetTokenFromInput(ITextCursor textCursor, out T token) { var match = false; token = default(T); var word = textCursor.Next(); T parsedWord; if (!string.IsNullOrEmpty(word) && TryParseWord(word, out parsedWord)) { var validValues = GetValidValues(textCursor.Context); if (validValues != null) { match = HasMatch(parsedWord, textCursor.Context, out token); } else { token = parsedWord; match = true; } } return(match); }
public override bool TryGetTokenFromInput(ITextCursor textCursor, out T token) { var tokenText = textCursor.Next(); var match = TryParse(tokenText, out token) && Expression != null && Expression.IsMatch(tokenText); return(match); }
public override bool TryGetTokenFromInput(ITextCursor textCursor, out string token) { var match = false; token = null; if (ValidValues != null && ValidValues.Length > 0) { string matchText = null; var queryText = string.Empty; while (string.IsNullOrEmpty(matchText) && ValidValues.Any(v => v.Length >= queryText.Length)) { var tokenPeek = textCursor.Next(); if (string.IsNullOrWhiteSpace(tokenPeek)) { break; } queryText = textCursor.RightToLeftParsing ? $"{tokenPeek} {queryText}" : $"{queryText} {tokenPeek}"; matchText = TryGetMatchText(ValidValues, queryText.Trim()); } if (!string.IsNullOrEmpty(matchText)) { token = matchText; match = true; } } else { var queryText = textCursor.All(); if (!string.IsNullOrEmpty(queryText)) { token = queryText; match = true; } } return(match); }
public override bool TryGetTokenFromInput(ITextCursor textCursor, out string token) { var match = false; token = null; if (ValidValues != null && ValidValues.Length > 0) { string matchText = null; var queryText = string.Empty; while (true) { var tokenPeek = textCursor.Peek(); if (string.IsNullOrWhiteSpace(tokenPeek)) { break; } if (textCursor.RightToLeftParsing) { queryText = $"{tokenPeek} {queryText}"; } else { queryText = $"{queryText} {tokenPeek}"; } queryText = queryText.Trim(); string[] matchTexts; if (textCursor.RightToLeftParsing) { matchTexts = ValidValues .Where(t => t.EndsWith(queryText, StringComparison.InvariantCultureIgnoreCase)) .OrderByDescending(t => t.Length) .ToArray(); } else { matchTexts = ValidValues .Where(t => t.StartsWith(queryText, StringComparison.InvariantCultureIgnoreCase)) .OrderByDescending(t => t.Length) .ToArray(); } if (matchTexts.Length >= 1) { // Avança o cursor textCursor.Next(); if (matchTexts.Any(t => t.Equals(queryText, StringComparison.InvariantCultureIgnoreCase))) { matchText = queryText; } } else { break; } } if (!string.IsNullOrEmpty(matchText)) { token = matchText; match = true; } } else { var queryText = textCursor.All(); if (!string.IsNullOrEmpty(queryText)) { token = queryText; match = true; } } return(match); }