public virtual string ToString(RegexNode node) { if (node == null) { throw new ArgumentNullException(nameof(node)); } switch (node) { case RegexAtomicGroupNode ag: return(ToAtomicGroupString(ag)); case RegexConditionalNode c: return(ToConditionalString(c)); case RegexPositiveLookaheadAssertionNode pla: return(ToPositiveLookaheadAssertionString(pla)); case RegexNegativeLookaheadAssertionNode nla: return(ToNegativeLookaheadAssertionString(nla)); case RegexPositiveLookbehindAssertionNode plb: return(ToPositiveLookbehindAssertionString(plb)); case RegexNegativeLookbehindAssertionNode nlb: return(ToNegativeLookbehindAssertionString(nlb)); case RegexGroupNode g: return(ToGroupString(g)); case RegexUnicodeCategoryNode un: return(ToUnicodeCategoryString(un)); default: return(ToNodeString(node)); } }
/// <summary> /// Create and add <see cref="RegexNode"/> to the generator, and include another <see cref="RegexNode"/> inside. /// </summary> /// <param name="innerNode">An existing <see cref="RegexNode"/> to be included.</param> /// <param name="min">Optional minimum number of occurance.</param> /// <param name="max">Optional maximum number of occurance.</param> /// <param name="quantifierOption">Optional quantifier option.</param> /// <returns><see cref="RegexGenerator"/></returns> public RegexGenerator Add(RegexNode innerNode, int?min = null, int?max = null, RegexQuantifierOption quantifierOption = RegexQuantifierOption.Greedy) { var node = new RegexNode(innerNode, min, max, quantifierOption); return(Add(node)); }
/// <summary> /// Create and add <see cref="RegexNode"/> to the generator. /// </summary> /// <param name="pattern">Regex pattern.</param> /// <param name="min">Optional minimum number of occurance.</param> /// <param name="max">Optional maximum number of occurance.</param> /// <param name="quantifierOption">Optional quantifier option.</param> /// <returns><see cref="RegexGenerator"/></returns> public RegexGenerator Add(string pattern, int?min = null, int?max = null, RegexQuantifierOption quantifierOption = RegexQuantifierOption.Greedy) { var node = new RegexNode(pattern, min, max, quantifierOption); return(Add(node)); }
/// <summary> /// Create and add <see cref="RegexConditionalNode"/> to the generator, and include another <see cref="RegexNode"/> inside. /// </summary> /// <param name="innerNode">An existing <see cref="RegexNode"/> to be included.</param> /// <param name="trueValue">Value of successful match.</param> /// <param name="falseValue">Value of failed match.</param> /// <param name="nameOrNumber">Name or number for backtracking.</param> /// <param name="min">Optional minimum number of occurance.</param> /// <param name="max">Optional maximum number of occurance.</param> /// <param name="quantifierOption">Optional quantifier option.</param> /// <returns><see cref="RegexGenerator"/></returns> /// <exception cref="ConditionalNotSupportedException">Conditional is not supported by <see cref="RegexLanguage"/>.</exception> public RegexGenerator AddConditional(RegexNode innerNode, string trueValue, string falseValue, string nameOrNumber = null, int?min = null, int?max = null, RegexQuantifierOption quantifierOption = RegexQuantifierOption.Greedy) { var conditionalNode = new RegexConditionalNode(innerNode, trueValue, falseValue, nameOrNumber, min, max, quantifierOption); return(AddConditional(conditionalNode)); }
/// <summary> /// Create and add <see cref="RegexNegativeLookbehindAssertionNode"/> to the generator, and include another <see cref="RegexNode"/> inside. /// </summary> /// <param name="innerNode">An existing <see cref="RegexNode"/> to be included.</param> /// <param name="min">Optional minimum number of occurance.</param> /// <param name="max">Optional maximum number of occurance.</param> /// <param name="quantifierOption">Optional quantifier option.</param> /// <returns><see cref="RegexGenerator"/></returns> /// <exception cref="NegativeLookbehindAssertionNotSupportedException">Negative lookbehind assertion is not supported by <see cref="RegexLanguage"/>.</exception> public RegexGenerator AddNegativeLookbehindAssertion(RegexNode innerNode, int?min = null, int?max = null, RegexQuantifierOption quantifierOption = RegexQuantifierOption.Greedy) { var negativeLookbehindAssertion = new RegexNegativeLookbehindAssertionNode(innerNode, min, max, quantifierOption); return(AddNegativeLookbehindAssertion(negativeLookbehindAssertion)); }
/// <summary> /// Create and add <see cref="RegexPositiveLookaheadAssertionNode"/> to the generator, and include another <see cref="RegexNode"/> inside. /// </summary> /// <param name="innerNode">An existing <see cref="RegexNode"/> to be included.</param> /// <param name="min">Optional minimum number of occurance.</param> /// <param name="max">Optional maximum number of occurance.</param> /// <param name="quantifierOption">Optional quantifier option.</param> /// <returns><see cref="RegexGenerator"/></returns> /// <exception cref="PositiveLookaheadAssertionNotSupportedException">Positive lookahead assertion is not supported by <see cref="RegexLanguage"/>.</exception> public RegexGenerator AddPositiveLookaheadAssertion(RegexNode innerNode, int?min = null, int?max = null, RegexQuantifierOption quantifierOption = RegexQuantifierOption.Greedy) { var positiveLookaheadAssertion = new RegexPositiveLookaheadAssertionNode(innerNode, min, max, quantifierOption); return(AddPositiveLookaheadAssertion(positiveLookaheadAssertion)); }
/// <summary> /// Create and add <see cref="RegexAtomicGroupNode"/> to the generator, and include another <see cref="RegexNode"/> inside. /// </summary> /// <param name="innerNode">An existing <see cref="RegexNode"/> to be included.</param> /// <param name="min">Optional minimum number of occurance.</param> /// <param name="max">Optional maximum number of occurance.</param> /// <param name="quantifierOption">Optional quantifier option.</param> /// <returns><see cref="RegexGenerator"/></returns> /// <exception cref="AtomicGroupNotSupportedException">Atomic group is not supported by <see cref="RegexLanguage"/>.</exception> public RegexGenerator AddAtomicGroup(RegexNode innerNode, int?min = null, int?max = null, RegexQuantifierOption quantifierOption = RegexQuantifierOption.Greedy) { var atomicGroup = new RegexAtomicGroupNode(innerNode, min, max, quantifierOption); return(AddAtomicGroup(atomicGroup)); }
/// <summary> /// Create and add <see cref="RegexGroupNode"/> to the generator, and include another <see cref="RegexNode"/> inside. /// </summary> /// <param name="node">An existing <see cref="RegexNode"/> to be included.</param> /// <param name="capturing">Defines the group to be capturing or not.</param> /// <param name="name">Optional name of capture group.</param> /// <param name="options">Optional inline options for the group.</param> /// <param name="min">Optional minimum number of occurance.</param> /// <param name="max">Optional maximum number of occurance.</param> /// <param name="quantifierOption">Optional quantifier option.</param> /// <returns><see cref="RegexGenerator"/></returns> /// <exception cref="NamedCapturingGroupNotSupportedException">Named capturing group is not supported by <see cref="RegexLanguage"/>.</exception> /// <exception cref="InlineGroupOptionsNotSupportedException">Inline group option is not supported by <see cref="RegexLanguage"/>.</exception> public RegexGenerator AddGroup(RegexNode node, bool capturing = true, string name = null, string options = null, int?min = null, int?max = null, RegexQuantifierOption quantifierOption = RegexQuantifierOption.Greedy) { var groupNode = new RegexGroupNode(node.ToString(RegexLanguageStrategy.Stringifier), capturing, name, options, min, max, quantifierOption); return(AddGroup(groupNode)); }
/// <summary> /// Initialize an instance of <see cref="RegexPositiveLookbehindAssertionNode"/>, and include another <see cref="RegexNode"/> inside. /// </summary> /// <param name="innerNode">An existing <see cref="RegexNode"/> to be included.</param> /// <param name="min">Optional minimum number of occurance.</param> /// <param name="max">Optional maximum number of occurance.</param> /// <param name="quantifierOption">Optional quantifier option.</param> public RegexPositiveLookbehindAssertionNode(RegexNode innerNode, int?min = null, int?max = null, RegexQuantifierOption quantifierOption = RegexQuantifierOption.Greedy) : base(innerNode, min, max, quantifierOption) { }
public override string ToString(RegexNode node) { return($"/{base.ToString(node)}/"); }
/// <summary> /// Initialize an instance of <see cref="RegexAtomicGroupNode"/>, and include another <see cref="RegexNode"/> inside. /// </summary> /// <param name="innerNode">An existing <see cref="RegexNode"/> to be included.</param> /// <param name="min">Optional minimum number of occurance.</param> /// <param name="max">Optional maximum number of occurance.</param> /// <param name="quantifierOption">Optional quantifier option.</param> public RegexAtomicGroupNode(RegexNode innerNode, int?min = null, int?max = null, RegexQuantifierOption quantifierOption = RegexQuantifierOption.Greedy) : base(innerNode, min, max, quantifierOption) { }