Exemplo n.º 1
0
        /// <summary>
        ///     Generates a regular expression that matches the specified regular expressions in any order.</summary>
        /// <typeparam name="TResult">
        ///     Type of the result object associated with each match of the regular expression.</typeparam>
        /// <param name="stringerexes">
        ///     The regular expressions to match.</param>
        public static Stringerex <IEnumerable <TResult> > InAnyOrder <TResult>(params Stringerex <TResult>[] stringerexes)
        {
            if (stringerexes == null)
            {
                throw new ArgumentNullException("stringerexes");
            }

            return(Generex.InAnyOrder <Stringerex <TResult>, Stringerex <IEnumerable <TResult> > >(
                       thenner: (prev, next) => prev.ThenRaw(next, InternalExtensions.Concat),
                       orer: (one, two) => one.Or(two),
                       constructor: () => new Stringerex <IEnumerable <TResult> >(Enumerable.Empty <TResult>()),
                       generexes: stringerexes));
        }
Exemplo n.º 2
0
 /// <summary>
 ///     Returns a regular expression that matches this regular expression, then attempts to match the specified other
 ///     regular expression and throws an exception if the second regular expression fails to match; otherwise, a
 ///     result object is generated from the result objects of the two matches.</summary>
 /// <typeparam name="TOther">
 ///     Type of the result object of the <paramref name="expectation"/>.</typeparam>
 /// <typeparam name="TCombined">
 ///     Type of the result object for the resulting regular expression.</typeparam>
 /// <param name="expectation">
 ///     The regular expression that is expected to match after the current one.</param>
 /// <param name="selector">
 ///     A selector which, in case of a match, generates the new result given the current result and the result object
 ///     of the match of the <paramref name="expectation"/>.</param>
 /// <param name="exceptionGenerator">
 ///     A selector which, in case of no match, generates the exception object to be thrown.</param>
 /// <returns>
 ///     The resulting regular expression.</returns>
 /// <remarks>
 ///     Regular expressions created by this method cannot match backwards. The full set of affected methods is listed
 ///     at <see cref="GenerexBase{T, TMatch, TGenerex, TGenerexMatch}.Then{TOtherGenerex, TOtherMatch,
 ///     TOtherGenerexMatch}(Func{TGenerexMatch, GenerexBase{T, TOtherMatch, TOtherGenerex, TOtherGenerexMatch}})"/>.</remarks>
 public Generex <T, TCombined> ThenExpectRaw <TOther, TCombined>(Generex <T, TOther> expectation, Func <TResult, TOther, TCombined> selector, Func <GenerexMatch <T, TResult>, Exception> exceptionGenerator)
 {
     if (expectation == null)
     {
         throw new ArgumentNullException("expectation");
     }
     if (selector == null)
     {
         throw new ArgumentNullException("selector");
     }
     return(then <Generex <T, TCombined>, LengthAndResult <TCombined>, GenerexMatch <T, TCombined>, GenerexMatch <T, TResult> >(m =>
                                                                                                                                expectation.process <Generex <T, TCombined>, GenerexMatch <T, TCombined>, TCombined>(m2 => selector(m.Result, m2.Result)).expect(() => exceptionGenerator(m)), createMatch));
 }
Exemplo n.º 3
0
        /// <summary>
        ///     Generates a regular expression that matches the specified regular expressions in any order.</summary>
        /// <param name="stringerexes">
        ///     The regular expressions to match.</param>
        public static Stringerex InAnyOrder(params Stringerex[] stringerexes)
        {
            if (stringerexes == null)
            {
                throw new ArgumentNullException("stringerexes");
            }

            return(Generex.InAnyOrder <Stringerex, Stringerex>(
                       thenner: (prev, next) => prev.Then(next),
                       orer: (one, two) => one.Or(two),
                       constructor: () => new Stringerex(),
                       generexes: stringerexes));
        }
Exemplo n.º 4
0
        /// <summary>
        ///     Generates a regular expression that matches the characters of the specified string in any order.</summary>
        /// <param name="characters">
        ///     A string containing the characters to match.</param>
        /// <param name="comparer">
        ///     The optional equality comparer to use to determine matching characters.</param>
        public static Stringerex InAnyOrder(string characters, IEqualityComparer <char> comparer = null)
        {
            if (characters == null)
            {
                throw new ArgumentNullException("characters");
            }

            comparer = comparer ?? EqualityComparer <char> .Default;

            return(Generex.InAnyOrder <Stringerex, Stringerex>(
                       thenner: (prev, next) => prev.Then(next),
                       orer: (one, two) => one.Or(two),
                       constructor: () => new Stringerex(),
                       generexes: characters.Select(ch => new Stringerex(ch, comparer)).ToArray()));
        }
Exemplo n.º 5
0
 /// <summary>
 ///     Returns a regular expression that matches this regular expression, followed by the specified one, and
 ///     generates a result object that combines the original two matches.</summary>
 public Generex <T, TCombined> ThenRaw <TOther, TCombined>(Generex <T, TOther> other, Func <TResult, TOther, TCombined> selector)
 {
     return(thenRaw <Generex <T, TOther>, GenerexMatch <T, TOther>, TOther, Generex <T, TCombined>, GenerexMatch <T, TCombined>, TCombined>(other, selector));
 }
Exemplo n.º 6
0
 /// <summary>
 ///     Returns a regular expression that matches this regular expression, followed by the specified one, and
 ///     generates a result object that combines the result of this regular expression with the match of the other.</summary>
 public Generex <T, TCombined> Then <TOther, TCombined>(Generex <T, TOther> other, Func <TResult, GenerexMatch <T, TOther>, TCombined> selector)
 {
     return(then <Generex <T, TOther>, GenerexMatch <T, TOther>, LengthAndResult <TOther>, Generex <T, TCombined>, GenerexMatch <T, TCombined>, TCombined>(other, selector));
 }
Exemplo n.º 7
0
 /// <summary>
 ///     Returns a regular expression that matches this regular expression, followed by the specified one, and
 ///     generates a result object that combines the result of this regular expression with the match of the other.</summary>
 public Generex <T, TCombined> Then <TCombined>(Generex <T> other, Func <TResult, GenerexMatch <T>, TCombined> selector)
 {
     return(then <Generex <T>, GenerexMatch <T>, int, Generex <T, TCombined>, GenerexMatch <T, TCombined>, TCombined>(other, selector));
 }
Exemplo n.º 8
0
 /// <summary>
 ///     Returns a regular expression that matches this regular expression one or more times, interspersed with a
 ///     separator. More times are prioritised.</summary>
 public Generex <T, IEnumerable <TResult> > RepeatWithSeparatorGreedy(Generex <T> separator)
 {
     return(ThenRaw(separator.Then(this).RepeatGreedy(), InternalExtensions.Concat));
 }