public SetVariableAction(ParseInfo parseInfo, Scope scope, DeltinScriptParser.VarsetContext varsetContext) { IExpression variableExpression = parseInfo.GetExpression(scope, varsetContext.var); // Get the variable being set. VariableResolve = new VariableResolve(new VariableResolveOptions(), variableExpression, DocRange.GetRange(varsetContext), parseInfo.Script.Diagnostics); // Get the operation. if (varsetContext.statement_operation() != null) { Operation = varsetContext.statement_operation().GetText(); // If there is no value, syntax error. if (varsetContext.val == null) { parseInfo.Script.Diagnostics.Error("Expected an expression.", DocRange.GetRange(varsetContext).end.ToRange()); } // Parse the value. else { Value = parseInfo.GetExpression(scope, varsetContext.val); } } else if (varsetContext.INCREMENT() != null) { Operation = "++"; } else if (varsetContext.DECREMENT() != null) { Operation = "--"; } }
public VarSetNode(DeltinScriptParser.VarsetContext context, BuildAstVisitor visitor) : base(new Location(visitor.file, Range.GetRange(context))) { Variable = visitor.VisitExpr(context.var); Node[] index = new Node[context.array()?.expr().Length ?? 0]; for (int i = 0; i < index.Length; i++) { index[i] = visitor.VisitExpr(context.array().expr(i)); } if (context.val != null) { Value = visitor.VisitExpr(context.val); } Operation = context.statement_operation()?.GetText(); if (Operation == null) { if (context.INCREMENT() != null) { Operation = "++"; } else if (context.DECREMENT() != null) { Operation = "--"; } } }
public override object VisitVarset(DeltinScriptParser.VarsetContext context) { if (context.statement_operation() != null && (context.expr().Length == 0 || context.children.IndexOf(context.expr().Last()) < context.children.IndexOf(context.statement_operation()) )) { _diagnostics.Error("Expected expression.", new Location(_file, Range.GetRange(context))); } return(base.VisitVarset(context)); }
public override Node VisitVarset(DeltinScriptParser.VarsetContext context) { IExpressionNode target = context.expr().Length == 2 ? (IExpressionNode)Visit(context.expr()[0]) : null; string variable = context.PART().GetText(); IExpressionNode index = null; if (context.array() != null) { index = (IExpressionNode)Visit(context.array().expr()); } string operation = context.statement_operation().GetText(); IExpressionNode value = (IExpressionNode)Visit(context.expr().Last()); Node node = new VarSetNode(target, variable, index, operation, value, Range.GetRange(context)); CheckRange(node); return(node); }
public SetVariableAction(ParseInfo parseInfo, Scope scope, DeltinScriptParser.VarsetContext varsetContext) { IExpression variableExpression = DeltinScript.GetExpression(parseInfo, scope, varsetContext.var); DocRange notAVariableRange = null; DocRange variableRange = null; if (variableExpression is CallVariableAction) { SetVariable = (CallVariableAction)variableExpression; variableRange = DocRange.GetRange(varsetContext.var); } else if (variableExpression is ExpressionTree) { Tree = (ExpressionTree)variableExpression; if (Tree.Completed) { if (Tree.Result is CallVariableAction == false) { notAVariableRange = Tree.ExprContextTree.Last().Range; } else { SetVariable = (CallVariableAction)Tree.Result; variableRange = Tree.ExprContextTree.Last().Range; } } } else if (variableExpression != null) { notAVariableRange = DocRange.GetRange(varsetContext.var); } if (notAVariableRange != null) { parseInfo.Script.Diagnostics.Error("Expected a variable.", notAVariableRange); } if (SetVariable != null && !SetVariable.Calling.Settable()) { parseInfo.Script.Diagnostics.Error($"The variable '{SetVariable.Calling.Name}' cannot be set to.", variableRange); } if (varsetContext.statement_operation() != null) { Operation = varsetContext.statement_operation().GetText(); if (varsetContext.val == null) { parseInfo.Script.Diagnostics.Error("Expected an expression.", DocRange.GetRange(varsetContext).end.ToRange()); } else { Value = DeltinScript.GetExpression(parseInfo, scope, varsetContext.val); } } else if (varsetContext.INCREMENT() != null) { Operation = "++"; } else if (varsetContext.DECREMENT() != null) { Operation = "--"; } }
public override Node VisitVarset(DeltinScriptParser.VarsetContext context) { return(new VarSetNode(context, this)); }