예제 #1
0
        /// <summary>
        /// Constructs an inner element of a regular expression composite tree.
        /// </summary>
        /// <param name="quantifier">A quantifier specifying how many times the element is repeated.</param>
        /// <exception cref="ArgumentNullException">Thrown if <paramref name="quantifier"/> is null.</exception>
        protected Element(Quantifier quantifier)
        {
            if (quantifier == null)
                throw new ArgumentNullException("quantifier");

            this.quantifier = quantifier;
        }
예제 #2
0
        /// <summary>
        /// Constructs an element representing a set of possible characters.
        /// </summary>
        /// <param name="quantifier">A quantifier specifying how many times the element is repeated.</param>
        /// <param name="characters">An array of characters to include into the set.</param>
        /// <exception cref="ArgumentNullException">Thrown if <paramref name="quantifier"/> or <paramref name="characters"/> are null.</exception>
        public ElementSet(Quantifier quantifier, char[] characters)
            : base(quantifier)
        {
            if (characters == null)
                throw new ArgumentNullException("characters");

            this.characters = characters;
        }
예제 #3
0
        /// <summary>
        /// Constructs an element representing a set of possible characters.
        /// </summary>
        /// <param name="quantifier">A quantifier specifying how many times the element is repeated.</param>
        /// <param name="raw">A raw string containing the characters to include into the set, 
        /// expressed in the usual regular expression syntax (example: "ABCX-Z0-9").</param>
        /// <exception cref="ArgumentNullException">Thrown if <paramref name="quantifier"/> or <paramref name="raw"/> are null.</exception>
        public ElementSet(Quantifier quantifier, string raw)
            : base(quantifier)
        {
            if (raw == null)
                throw new ArgumentNullException("raw");

            this.characters = Parse(raw);
        }
예제 #4
0
        /// <summary>
        /// Constructs an invariant literal text.
        /// </summary>
        /// <param name="quantifier">A quantifier specifying how many times the element is repeated.</param>
        /// <param name="literal">The invariant literal text.</param>
        /// <exception cref="ArgumentNullException">Thrown if <paramref name="quantifier"/> or <paramref name="literal"/> are null.</exception>
        public ElementLiteral(Quantifier quantifier, string literal)
            : base(quantifier)
        {
            if (literal == null)
                throw new ArgumentNullException("literal");

            this.literal = literal;
        }
예제 #5
0
        /// <summary>
        /// Constructs a group element that contains child elements.
        /// </summary>
        /// <param name="quantifier">A quantifier specifying how many times the element is repeated.</param>
        /// <param name="children">The child elements.</param>
        /// <exception cref="ArgumentNullException">Thrown if <paramref name="quantifier"/> or <paramref name="children"/> are null.</exception>
        public ElementGroup(Quantifier quantifier, IEnumerable<IElement> children)
            : base(quantifier)
        {
            if (children == null)
                throw new ArgumentNullException("children");

            this.children = new List<IElement>(children).ToArray();
        }
예제 #6
0
        /// <summary>
        /// Constructs an invariant literal text.
        /// </summary>
        /// <param name="quantifier">A quantifier specifying how many times the element is repeated.</param>
        /// <param name="literal">The invariant literal text.</param>
        /// <exception cref="ArgumentNullException">Thrown if <paramref name="quantifier"/> or <paramref name="literal"/> are null.</exception>
        public ElementLiteral(Quantifier quantifier, string literal)
            : base(quantifier)
        {
            if (literal == null)
            {
                throw new ArgumentNullException("literal");
            }

            this.literal = literal;
        }
예제 #7
0
        private void FinalizeElement(Quantifier quantifier)
        {
            if (token.IsOpen)
            {
                string result = token.Close(false);

                if (result.Length > 0)
                {
                    children.Add(new ElementLiteral(quantifier, result));
                }
            }
        }
예제 #8
0
        internal Parser(string input, Quantifier quantifier, ParsingInfo parsingInfo)
        {
            if (input == null)
                throw new ArgumentNullException("input");

            if (quantifier == null)
                throw new ArgumentNullException("quantifier");

            this.input = input;
            this.rootQuantifier = quantifier;
            this.parsingInfo = parsingInfo;
        }
예제 #9
0
        public void GetRandomQuantity(int minimum, int maximum)
        {
            var quantifier = new Quantifier(minimum, maximum);
            var random = new Random();

            Assert.Multiple(() =>
            {
                for (int i = 0; i < 100; i++)
                {
                    var actual = quantifier.GetRandomRepeat(random);
                    Assert.Between(actual, minimum, maximum);
                }
            });
        }
예제 #10
0
        internal Parser(string input, Quantifier quantifier, ParsingInfo parsingInfo)
        {
            if (input == null)
            {
                throw new ArgumentNullException("input");
            }

            if (quantifier == null)
            {
                throw new ArgumentNullException("quantifier");
            }

            this.input          = input;
            this.rootQuantifier = quantifier;
            this.parsingInfo    = parsingInfo;
        }
예제 #11
0
 internal Parser(string input, Quantifier quantifier)
     : this(input, quantifier, ParsingInfo.Root)
 {
 }
예제 #12
0
        private void FinalizeElement(Quantifier quantifier)
        {
            if (token.IsOpen)
            {
                string result = token.Close(false);

                if (result.Length > 0)
                {
                    children.Add(new ElementLiteral(quantifier, result));
                }
            }
        }
예제 #13
0
 internal Parser(string input, Quantifier quantifier)
     : this(input, quantifier, ParsingInfo.Root)
 {
 }
예제 #14
0
 public void Constructs_with_range_ok()
 {
     var quantifier = new Quantifier(2, 8);
     Assert.AreEqual(2, quantifier.Minimum);
     Assert.AreEqual(8, quantifier.Maximum);
 }
예제 #15
0
 /// <summary>
 /// Parses the specified expression in the context of the actual parsing mode.
 /// </summary>
 /// <param name="token">The text to parse.</param>
 /// <param name="quantifier">A quantifier to attach to the resulting element.</param>
 /// <returns>A resulting element representing the expression.</returns>
 public IElement ParseToken(string token, Quantifier quantifier)
 {
     return(parseToken(token, quantifier));
 }
예제 #16
0
 /// <summary>
 /// Parses the specified expression in the context of the actual parsing mode.
 /// </summary>
 /// <param name="token">The text to parse.</param>
 /// <param name="quantifier">A quantifier to attach to the resulting element.</param>
 /// <returns>A resulting element representing the expression.</returns>
 public IElement ParseToken(string token, Quantifier quantifier)
 {
     return parseToken(token, quantifier);
 }
예제 #17
0
 public void Constructs_with_constant_ok()
 {
     var quantifier = new Quantifier(5);
     Assert.AreEqual(5, quantifier.Minimum);
     Assert.AreEqual(5, quantifier.Maximum);
 }