From 16c9a5de3ffca391a78d07536dd2e3c2aaa17b88 Mon Sep 17 00:00:00 2001 From: James Luck Date: Thu, 25 Nov 2021 09:05:09 +1100 Subject: [PATCH] Adding some more convenient constructors to call for common AST nodes --- src/PromQL.Parser/Ast.cs | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/PromQL.Parser/Ast.cs b/src/PromQL.Parser/Ast.cs index 047c5f4..c438a3c 100644 --- a/src/PromQL.Parser/Ast.cs +++ b/src/PromQL.Parser/Ast.cs @@ -42,6 +42,16 @@ public interface Expr : IPromQlNode {} public record AggregateExpr(string OperatorName, Expr Expr, Expr? Param, ImmutableArray GroupingLabels, bool Without) : Expr { + public AggregateExpr(string operatorName, Expr expr) + : this (operatorName, expr, null, ImmutableArray.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); } @@ -53,7 +63,7 @@ public record AggregateExpr(string OperatorName, Expr Expr, Expr? Param, /// The operation of the expression /// The matching behavior for the operation to be applied if both operands are Vectors. 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); } @@ -90,6 +100,11 @@ public VectorMatching(bool returnBool) : this (DefaultMatchCardinality, Immutabl /// Arguments used in the call. public record FunctionCall(string Identifier, ImmutableArray 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) @@ -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); }