public override bool Match(ref TokenSequence sequence, out string output) { string sequenceOriginal = sequence.ToString(); MatchingInvoker(); List <string> outputList = new List <string>(); bool res; foreach (ExpressionItem item in items) { string expressionString; res = item.Match(ref sequence, out expressionString); if (!res) { output = ""; LogSentInvoker("La expresión «" + this.Label + "» falló el reconocimiento, restaurando la secuencia (" + sequenceOriginal + ")"); MatchingFinishedInvoker(output); return(false); } outputList.Add(expressionString); } output = String.Format(formatString, outputList.ToArray()); LogSentInvoker("La expresion «" + this.Label + "» tuvo exito al reconocer, se produjo la salida «" + output + "»"); MatchingFinishedInvoker(output); return(true); }
/// <summary> /// Retrives the related items for a token from the remaining items list. /// </summary> /// <param name="matched"> /// The <see cref="Token"/> the items we are looking for are related to. /// </param> /// <param name="remainingItems"> /// A <see cref="TokenSequence"/> containing the yet to be matched items. /// </param> /// <param name="position"> /// A <see cref="ExpressionItemPosition"/> the position of the related item. /// </param> /// <returns> /// A <see cref="TokenSequence"/> containing the items related to the /// matched item found in the given position. /// </returns> protected TokenSequence GetRelatedItems(Token matched, TokenSequence remainingItems, ExpressionItemPosition position) { TokenSequence sequence = new TokenSequence(); string remainingItemsString = remainingItems.ToString(); int i = 0; while (i < remainingItems.Count) { Token checkedItem = remainingItems[i]; if (CheckTokenInRelatedSequence(matched, checkedItem, position)) { sequence.Append(checkedItem); remainingItems.RemoveAt(i); } else if (!SpecialPosition(matched, checkedItem)) { LogSentInvoker("Encontrado {0}, cancelando la creación de la secuencia de items «{1}» {2}", checkedItem.Text, position, matched.Type); break; } else { i++; } } LogSentInvoker("Extraida la secuencia ({0}) en posicion «{1}» de entre los elementos de ({2})", sequence, position, remainingItemsString); return(sequence); }