/// <summary> /// Initializes a new instance of the <see cref="Rule"/> class. /// </summary> /// <param name="name">The name of the grammar rule.</param> /// <param name="ast">The AST of the rule.</param> /// <param name="publicApi">True, if the rule should be part of public API.</param> public Rule(string name, BnfAst ast, bool publicApi = true) { this.Name = name; this.Ast = ast; this.PublicApi = publicApi; this.VisualName = name; }
/// <inheritdoc/> protected override BnfAst SubstituteByReferenceImpl(BnfAst find, BnfAst replaceWith) => this;
/// <inheritdoc/> protected override BnfAst SubstituteByReferenceImpl(BnfAst find, BnfAst replaceWith) => new Seq(this.Elements.Select(e => e.SubstituteByReference(find, replaceWith)));
/// <summary> /// Initializes a new instance of the <see cref="Seq"/> class. /// </summary> /// <param name="first">The first subexpression to match.</param> /// <param name="second">The subexpression to match after <paramref name="first"/>.</param> public Seq(BnfAst first, BnfAst second) { this.Elements = new BnfAst[] { first, second }; }
/// <summary> /// Initializes a new instance of the <see cref="Placeholder"/> class. /// </summary> /// <param name="reference">The referenced AST.</param> public Placeholder(BnfAst reference) { this.Reference = reference; }
/// <inheritdoc/> protected override BnfAst SubstituteByReferenceImpl(BnfAst find, BnfAst replaceWith) => new Rep0(this.Subexpr.SubstituteByReference(find, replaceWith));
/// <summary> /// Initializes a new instance of the <see cref="Rep0"/> class. /// </summary> /// <param name="subexpr">The subexpression that can be repeated 0 or more times.</param> public Rep0(BnfAst subexpr) { this.Subexpr = subexpr; }
/// <summary> /// Initializes a new instance of the <see cref="Opt"/> class. /// </summary> /// <param name="subexpr">The optional subexpression.</param> public Opt(BnfAst subexpr) { this.Subexpr = subexpr; }
/// <summary> /// Implements <see cref="SubstituteByReference(BnfAst, BnfAst)"/>, when this instance is not equal to /// <paramref name="replaceWith"/>. /// </summary> /// <param name="find">The node to substitute.</param> /// <param name="replaceWith">The node to substituite <paramref name="find"/> for.</param> /// <returns>A node that has all <paramref name="find"/> nodes substituted to /// <paramref name="replaceWith"/>, by reference.</returns> protected abstract BnfAst SubstituteByReferenceImpl(BnfAst find, BnfAst replaceWith);
/// <summary> /// Substitutes a node by reference. /// </summary> /// <param name="find">The node to substitute.</param> /// <param name="replaceWith">The node to substituite <paramref name="find"/> for.</param> /// <returns>A node that has all <paramref name="find"/> nodes substituted to /// <paramref name="replaceWith"/>, by reference.</returns> public BnfAst SubstituteByReference(BnfAst find, BnfAst replaceWith) => ReferenceEquals(this, find) ? replaceWith : this.SubstituteByReferenceImpl(find, replaceWith);
/// <inheritdoc/> protected override BnfAst SubstituteByReferenceImpl(BnfAst find, BnfAst replaceWith) => new FoldLeft( this.First.SubstituteByReference(find, replaceWith), this.Second.SubstituteByReference(find, replaceWith));
/// <summary> /// Initializes a new instance of the <see cref="FoldLeft"/> class. /// </summary> /// <param name="first">The first element of the fold.</param> /// <param name="second">The second elements of the fold, that will be repeated.</param> public FoldLeft(BnfAst first, BnfAst second) { this.First = first; this.Second = second; }
/// <summary> /// Initializes a new instance of the <see cref="Group"/> class. /// </summary> /// <param name="subexpr">The grouped subexpression.</param> public Group(BnfAst subexpr) { this.Subexpr = subexpr; }
/// <inheritdoc/> protected override BnfAst SubstituteByReferenceImpl(BnfAst find, BnfAst replaceWith) => new Transform(this.Subexpr.SubstituteByReference(find, replaceWith), this.Method);
/// <summary> /// Initializes a new instance of the <see cref="Transform"/> class. /// </summary> /// <param name="subexpr">The subexpression to match.</param> /// <param name="method">The method to transform the result with.</param> public Transform(BnfAst subexpr, IMethodSymbol method) { this.Subexpr = subexpr; this.Method = method; }