Exemple #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;
 }
Exemple #2
0
 /// <inheritdoc/>
 protected override BnfAst SubstituteByReferenceImpl(BnfAst find, BnfAst replaceWith) => this;
Exemple #3
0
 /// <inheritdoc/>
 protected override BnfAst SubstituteByReferenceImpl(BnfAst find, BnfAst replaceWith) =>
 new Seq(this.Elements.Select(e => e.SubstituteByReference(find, replaceWith)));
Exemple #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 };
 }
 /// <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;
 }
Exemple #6
0
 /// <inheritdoc/>
 protected override BnfAst SubstituteByReferenceImpl(BnfAst find, BnfAst replaceWith) =>
 new Rep0(this.Subexpr.SubstituteByReference(find, replaceWith));
Exemple #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;
 }
Exemple #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;
 }
Exemple #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);
Exemple #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);
Exemple #11
0
 /// <inheritdoc/>
 protected override BnfAst SubstituteByReferenceImpl(BnfAst find, BnfAst replaceWith) => new FoldLeft(
     this.First.SubstituteByReference(find, replaceWith),
     this.Second.SubstituteByReference(find, replaceWith));
Exemple #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;
 }
Exemple #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;
 }
Exemple #14
0
 /// <inheritdoc/>
 protected override BnfAst SubstituteByReferenceImpl(BnfAst find, BnfAst replaceWith) =>
 new Transform(this.Subexpr.SubstituteByReference(find, replaceWith), this.Method);
Exemple #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;
 }