// TAKE WHERE public override ASTNode VisitTakeQueryStmt(CLUBSParser.TakeQueryStmtContext context) { TakeWhereActionNode node = new TakeWhereActionNode(new SourcePosition(context.start)); node.Quantity = Visit(context.quantity) as ExpressionNode; node.Query = Visit(context.query()) as QueryNode; return(node); }
// TAKE WHERE public override string Visit(TakeWhereActionNode node, object obj) { StringBuilder builder = new StringBuilder(); builder.Append("{\n"); builder.Append($"var _tempList = {Visit(node.Source)}.Where(x => {Visit(node.Query)}).Take({Visit(node.Quantity)}).ToList();\n"); builder.Append($"{Visit(node.Target)}.AddRange(_tempList);\n"); builder.Append($"_tempList.ForEach(x => {Visit(node.Source)}.Remove(x));\n"); builder.Append("}\n"); return(builder.ToString()); }
// TAKE WHERE public override TypeNode Visit(TakeWhereActionNode node, object obj) { VisitPutAction(node); // Call generic VisitPut method TypeNode quantityType = Visit(node.Quantity); TypeNode queryType = Visit(node.Query); // If quantity type is not Int, log error if (quantityType != StandardTypes.Int) { ErrorLogger.LogError(new ExpectedTypeError(StandardTypes.Int, quantityType.SourcePosition)); return(new ErrorTypeNode(node.SourcePosition)); } // If query type is not Bool, log error if (queryType != StandardTypes.Bool) { ErrorLogger.LogError(new ExpectedTypeError(StandardTypes.Bool, node.SourcePosition)); return(new ErrorTypeNode(node.SourcePosition)); } return(null); }
public abstract T Visit(TakeWhereActionNode node, object obj);