/// <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; }
/// <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; }
/// <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); }
/// <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; }
/// <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(); }
/// <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; }
private void FinalizeElement(Quantifier quantifier) { if (token.IsOpen) { string result = token.Close(false); if (result.Length > 0) { children.Add(new ElementLiteral(quantifier, result)); } } }
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; }
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); } }); }
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; }
internal Parser(string input, Quantifier quantifier) : this(input, quantifier, ParsingInfo.Root) { }
public void Constructs_with_range_ok() { var quantifier = new Quantifier(2, 8); Assert.AreEqual(2, quantifier.Minimum); Assert.AreEqual(8, quantifier.Maximum); }
/// <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)); }
/// <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); }
public void Constructs_with_constant_ok() { var quantifier = new Quantifier(5); Assert.AreEqual(5, quantifier.Minimum); Assert.AreEqual(5, quantifier.Maximum); }