예제 #1
0
 /// <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;
 }
예제 #2
0
 /// <inheritdoc/>
 protected override BnfAst SubstituteByReferenceImpl(BnfAst find, BnfAst replaceWith) => this;
예제 #3
0
 /// <inheritdoc/>
 protected override BnfAst SubstituteByReferenceImpl(BnfAst find, BnfAst replaceWith) =>
 new Seq(this.Elements.Select(e => e.SubstituteByReference(find, replaceWith)));
예제 #4
0
 /// <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 };
 }
예제 #5
0
 /// <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;
 }
예제 #6
0
 /// <inheritdoc/>
 protected override BnfAst SubstituteByReferenceImpl(BnfAst find, BnfAst replaceWith) =>
 new Rep0(this.Subexpr.SubstituteByReference(find, replaceWith));
예제 #7
0
 /// <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;
 }
예제 #8
0
 /// <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;
 }
예제 #9
0
 /// <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);
예제 #10
0
 /// <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);
예제 #11
0
 /// <inheritdoc/>
 protected override BnfAst SubstituteByReferenceImpl(BnfAst find, BnfAst replaceWith) => new FoldLeft(
     this.First.SubstituteByReference(find, replaceWith),
     this.Second.SubstituteByReference(find, replaceWith));
예제 #12
0
 /// <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;
 }
예제 #13
0
 /// <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;
 }
예제 #14
0
 /// <inheritdoc/>
 protected override BnfAst SubstituteByReferenceImpl(BnfAst find, BnfAst replaceWith) =>
 new Transform(this.Subexpr.SubstituteByReference(find, replaceWith), this.Method);
예제 #15
0
 /// <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;
 }