Exemple #1
0
        /// <summary>
        /// Try to match a function on the enumerator ensuring that the enumerator is restored on failure.
        /// </summary>
        /// <param name="enumerator">The enumerator to attempt to match on.</param>
        /// <param name="make">The callback function to match on the enumerator.</param>
        /// <param name="found">The out value that was found.</param>
        /// <returns>true if the matching function successfully made a match, false if not.</returns>
        static bool TryMake <T>(TokenEnumerator enumerator, TryMakeDelegate <T> make, out T found)
        {
            using (var checkpoint = enumerator.Checkpoint())
            {
                if (make(enumerator, out found))
                {
                    return(true);
                }

                checkpoint.Rollback();
            }

            return(false);
        }