public static bool IsEmpty <TLetter>(this RxNode <TLetter> node)
            where TLetter : IEquatable <TLetter>, IComparable <TLetter>
        {
            int min;
            int?max;

            node.ComputeLengths(out min, out max);
            return(max == 0);
        }
示例#2
0
 public bool Equals(RxNode <TLetter> other)
 {
     if (ReferenceEquals(other, null))
     {
         return(false);
     }
     if (ReferenceEquals(other, this))
     {
         return(true);
     }
     return((other.GetType() == this.GetType()) && this.EqualsInternal(other));
 }
 public RxQuantified(RxNode <TLetter> inner, int min, int?max)
 {
     if (min < 0)
     {
         throw new ArgumentOutOfRangeException(nameof(min), $"{nameof(min)} cannot be inferior to 0");
     }
     if (max.HasValue && (max.Value < min))
     {
         throw new ArgumentOutOfRangeException(nameof(max), $"{nameof(max)} cannot be inferior to {nameof(min)}");
     }
     this.Inner = inner;
     this.Min   = min;
     this.Max   = max;
 }
 public RxAccept(RxNode <TLetter> inner, SymbolId symbol, int?precedence)
 {
     this.Symbol = symbol;
     if (precedence.HasValue)
     {
         this.AcceptPrecedence = precedence.Value;
     }
     else
     {
         inner.ComputeLengths(out var min, out var max);
         this.AcceptPrecedence = min == max ? int.MaxValue : min *(ushort.MaxValue + 1) + max.GetValueOrDefault(ushort.MaxValue);
     }
     this.Inner = inner;
 }
示例#5
0
 protected abstract bool EqualsInternal(RxNode <TLetter> other);
 public static RxNode <TLetter> Optimize <TLetter>(this RxNode <TLetter> node)
     where TLetter : IEquatable <TLetter>, IComparable <TLetter>
 {
     return(node.Visit(new OptimizerVisitor <TLetter>(), null));
 }
 public static IEnumerable <TResult> VisitBinary <TLetter, TBinaryNode, TContext, TResult>(this RxNode <TLetter> node, IRegexVisitor <TLetter, TContext, TResult> visitor, TContext context)
     where TBinaryNode : RxBinaryNode <TLetter>
     where TLetter : IEquatable <TLetter>, IComparable <TLetter>
 {
     if (node is TBinaryNode binaryNode)
     {
         return(binaryNode.Left.VisitBinary <TLetter, TBinaryNode, TContext, TResult>(visitor, context)
                .Concat(binaryNode.Right.VisitBinary <TLetter, TBinaryNode, TContext, TResult>(visitor, context)));
     }
     return(new[] { node.Visit(visitor, context) });
 }
 protected override bool EqualsInternal(RxNode <TLetter> other)
 {
     return(true);
 }
 public RxConcatenation(RxNode <TLetter> left, RxNode <TLetter> right) : base(left, right)
 {
 }
        protected override bool EqualsInternal(RxNode <TLetter> other)
        {
            var otherConcatenation = (RxConcatenation <TLetter>)other;

            return(otherConcatenation.Left.Equals(this.Left) && otherConcatenation.Right.Equals(this.Right));
        }
 protected override bool EqualsInternal(RxNode <TLetter> other)
 {
     return(((RxAccept <TLetter>)other).Symbol == this.Symbol);
 }
示例#12
0
 protected override bool EqualsInternal(RxNode <TLetter> other)
 {
     return(this.letters.Equals(((RxMatch <TLetter>)other).Letters));
 }
 public RxAlternation(RxNode <TLetter> left, RxNode <TLetter> right) : base(left, right)
 {
 }
示例#14
0
 protected RxBinaryNode(RxNode <TLetter> left, RxNode <TLetter> right)
 {
     this.Left  = left;
     this.Right = right;
 }
        protected override bool EqualsInternal(RxNode <TLetter> other)
        {
            var otherQuantifier = (RxQuantified <TLetter>)other;

            return(this.Inner.Equals(otherQuantifier.Inner) && (this.Min == otherQuantifier.Min) && (this.Max == otherQuantifier.Max));
        }