Beispiel #1
0
    /// <summary>
    /// Constructs a sequence of regex constructs.
    /// </summary>
    /// <typeparam name="TSymbol">The symbol type.</typeparam>
    /// <param name="first">The first element in the sequence.</param>
    /// <param name="rest">The remaining sequence elements.</param>
    /// <returns>The sequence node constructed.</returns>
    public static IRegExNode <TSymbol> Seq <TSymbol>(IRegExNode <TSymbol> first, IEnumerable <IRegExNode <TSymbol> > rest)
    {
        var result = first;

        foreach (var second in rest)
        {
            result = new RegExSeqNode <TSymbol>(result, second);
        }
        return(result);
    }
Beispiel #2
0
 /// <summary>
 /// Constructs an alternative of regex constructs.
 /// </summary>
 /// <typeparam name="TSymbol">The symbol type.</typeparam>
 /// <param name="first">The first alternative.</param>
 /// <param name="rest">The remaining alternatives.</param>
 /// <returns>The alternative node constructed.</returns>
 public static IRegExNode <TSymbol> Or <TSymbol>(IRegExNode <TSymbol> first, params IRegExNode <TSymbol>[] rest) =>
 Or(first, rest as IEnumerable <IRegExNode <TSymbol> >);
Beispiel #3
0
 /// <summary>
 /// Constructs a node repeated between N and M times.
 /// </summary>
 /// <typeparam name="TSymbol">The symbol type.</typeparam>
 /// <param name="n">The minimum number of repetitions.</param>
 /// <param name="m">The maximum number of repetitions.</param>
 /// <param name="element">The element to construct the repetition from.</param>
 /// <returns>The repetition node constructed.</returns>
 public static IRegExNode <TSymbol> Between <TSymbol>(int n, int m, IRegExNode <TSymbol> element) => new RegExRepBetweenNode <TSymbol>(n, m, element);
Beispiel #4
0
 /// <summary>
 /// Constructs a node repeated at most N times.
 /// </summary>
 /// <typeparam name="TSymbol">The symbol type.</typeparam>
 /// <param name="n">The maximum number of repetitions.</param>
 /// <param name="element">The element to construct the repetition from.</param>
 /// <returns>The repetition node constructed.</returns>
 public static IRegExNode <TSymbol> AtMost <TSymbol>(int n, IRegExNode <TSymbol> element) => new RegExRepBetweenNode <TSymbol>(0, n, element);
Beispiel #5
0
 /// <summary>
 /// Constructs a node repeated at least N times.
 /// </summary>
 /// <typeparam name="TSymbol">The symbol type.</typeparam>
 /// <param name="n">The minimum number of repetitions.</param>
 /// <param name="element">The element to construct the repetition from.</param>
 /// <returns>The repetition node constructed.</returns>
 public static IRegExNode <TSymbol> AtLeast <TSymbol>(int n, IRegExNode <TSymbol> element) => new RegExRepBetweenNode <TSymbol>(n, null, element);
Beispiel #6
0
 /// <summary>
 /// Constructs a node repeated exactly N times.
 /// </summary>
 /// <typeparam name="TSymbol">The symbol type.</typeparam>
 /// <param name="n">The number of repetitions.</param>
 /// <param name="element">The element to construct the repetition from.</param>
 /// <returns>The repetition node constructed.</returns>
 public static IRegExNode <TSymbol> Exactly <TSymbol>(int n, IRegExNode <TSymbol> element) => new RegExRepBetweenNode <TSymbol>(n, n, element);
Beispiel #7
0
 /// <summary>
 /// Constructs an optional node from <paramref name="element"/>.
 /// </summary>
 /// <typeparam name="TSymbol">The symbol type.</typeparam>
 /// <param name="element">The element to construct the optional from.</param>
 /// <returns>The optional node constructed.</returns>
 public static IRegExNode <TSymbol> Opt <TSymbol>(IRegExNode <TSymbol> element) => new RegExOptNode <TSymbol>(element);
Beispiel #8
0
 /// <summary>
 /// Constructs a 1-or-more repetition node from <paramref name="element"/>.
 /// </summary>
 /// <typeparam name="TSymbol">The symbol type.</typeparam>
 /// <param name="element">The element to construct the repetition from.</param>
 /// <returns>The repetition node constructed.</returns>
 public static IRegExNode <TSymbol> Rep1 <TSymbol>(IRegExNode <TSymbol> element) => new RegExRep1Node <TSymbol>(element);