/// <summary> /// Move on text data while the specified predicate is true /// </summary> /// <param name="pos"> start position </param> /// <param name="pr"></param> /// <returns></returns> public static Position MoveWhile(Position pos, IPredicateOf1 <char> pr) { while (Check(pos, pr)) { pos++; } return(pos); }
/// <summary> /// Move on stack of tokens while the specified predicate is false /// </summary> /// <param name="tokens"> stack with tokens </param> /// <param name="pr"></param> /// <returns></returns> public static List <IToken> MoveUntil(Stack <IToken> tokens, IPredicateOf1 <IToken> pr) { List <IToken> result = new List <IToken>(); while (!Check(tokens, pr)) { result.Add(tokens.Pop()); } return(result); }
/// <summary> /// Defines trueness of the specified predicate towards /// specified token /// </summary> /// <param name="tokens"> stack with specified token on top </param> /// <param name="pr"></param> /// <returns></returns> public static bool Check(Stack <IToken> tokens, IPredicateOf1 <IToken> pr) { return(tokens.Count != 0 && pr.Execute(tokens.Peek())); }
/// <summary> /// Defines trueness of the specified predicate towards /// char in specified position /// </summary> /// <param name="pos"></param> /// <param name="pr"></param> /// <returns></returns> public static bool Check(Position pos, IPredicateOf1 <char> pr) { return(!pos.IsEnd && !pos.IsBegin && pr.Execute(pos.Current)); }