Skip to content

Commit

Permalink
Adding some more convenient constructors to call for common AST nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
djluck committed Nov 24, 2021
1 parent 20ca794 commit 16c9a5d
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions src/PromQL.Parser/Ast.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,16 @@ public interface Expr : IPromQlNode {}
public record AggregateExpr(string OperatorName, Expr Expr, Expr? Param,
ImmutableArray<string> GroupingLabels, bool Without) : Expr
{
public AggregateExpr(string operatorName, Expr expr)
: this (operatorName, expr, null, ImmutableArray<string>.Empty, false)
{
}

public AggregateExpr(string operatorName, Expr expr, Expr param, bool without = false, params string[] groupingLabels)
: this (operatorName, expr, param, groupingLabels.ToImmutableArray(), without)
{
}

public void Accept(IVisitor visitor) => visitor.Visit(this);
}

Expand All @@ -53,7 +63,7 @@ public record AggregateExpr(string OperatorName, Expr Expr, Expr? Param,
/// <param name="Operator">The operation of the expression</param>
/// <param name="VectorMatching">The matching behavior for the operation to be applied if both operands are Vectors.</param>
public record BinaryExpr(Expr LeftHandSide, Expr RightHandSide, Operators.Binary Operator,
VectorMatching? VectorMatching) : Expr
VectorMatching? VectorMatching = null) : Expr
{
public void Accept(IVisitor visitor) => visitor.Visit(this);
}
Expand Down Expand Up @@ -90,6 +100,11 @@ public VectorMatching(bool returnBool) : this (DefaultMatchCardinality, Immutabl
/// <param name="Args">Arguments used in the call.</param>
public record FunctionCall(string Identifier, ImmutableArray<Expr> Args) : Expr
{
public FunctionCall(string identifier, params Expr[] args)
: this (identifier, args.ToImmutableArray())
{
}

public void Accept(IVisitor visitor) => visitor.Visit(this);

protected virtual bool PrintMembers(StringBuilder builder)
Expand Down Expand Up @@ -183,7 +198,7 @@ public record StringLiteral(char Quote, string Value) : Expr
public void Accept(IVisitor visitor) => visitor.Visit(this);
}

public record SubqueryExpr(Expr Expr, Duration Range, Duration? Step) : Expr
public record SubqueryExpr(Expr Expr, Duration Range, Duration? Step = null) : Expr
{
public void Accept(IVisitor visitor) => visitor.Visit(this);
}
Expand Down

0 comments on commit 16c9a5d

Please sign in to comment.