/// <summary> /// Try to make a callback in a transactional way. /// </summary> /// <param name="delegate">The callback to perform the match.</param> /// <param name="p1">The parameter to pass to the matching function.</param> /// <returns>true if the match could be made, false if not.</returns> protected bool TryMake <TIn>(TryMakeDelegate1 <TIn> @delegate, TIn p1) { var index = Enumerator.Index; if (@delegate(p1) == false) { Enumerator.Index = index; return(false); } return(true); }
/// <summary> /// Attempt to make a top level match that includes the end of stream. /// </summary> /// <param name="tryMakeFunction">The function to perform the match.</param> /// <param name="builder">The builder to accept the changes on.</param> /// <returns>true if the function was matched successfully, false if not.</returns> bool TryMakeWithEnd(TryMakeDelegate1 <ParseContext> tryMakeFunction, IDateTimeBuilder builder) { var context = new ParseContext(builder); var index = Enumerator.Index; Enumerator.TakeWhile(TokenKind.Space); if (tryMakeFunction(context) && TryMakeEnd()) { builder.Year = context.Year; builder.Month = context.Month; builder.Day = context.Day; builder.Hour = context.Hour; builder.Minute = context.Minute; builder.Second = context.Second; return(true); } Enumerator.Index = index; return(false); }