public ForAction(ParseInfo parseInfo, Scope scope, DeltinScriptParser.ForContext forContext)
        {
            Scope varScope = scope.Child();

            if (forContext.define() != null)
            {
                DefinedVariable = new ScopedVariable(varScope, new DefineContextHandler(parseInfo, forContext.define()));
            }
            else if (forContext.initialVarset != null)
            {
                InitialVarSet = new SetVariableAction(parseInfo, varScope, forContext.initialVarset);
            }

            if (forContext.expr() != null)
            {
                Condition = DeltinScript.GetExpression(parseInfo, varScope, forContext.expr());
            }

            if (forContext.endingVarset != null)
            {
                SetVariableAction = new SetVariableAction(parseInfo, varScope, forContext.endingVarset);
            }

            // Get the block.
            if (forContext.block() != null)
            {
                Block = new BlockAction(parseInfo.SetLoop(this), varScope, forContext.block());
                // Get the path info.
                Path = new PathInfo(Block, DocRange.GetRange(forContext.FOR()), false);
            }
            else
            {
                parseInfo.Script.Diagnostics.Error("Expected a block.", DocRange.GetRange(forContext.RIGHT_PAREN()));
            }
        }
        public ForeachAction(ParseInfo parseInfo, Scope scope, DeltinScriptParser.ForeachContext foreachContext)
        {
            Scope varScope = scope.Child();

            ForeachVar = new ForeachVariable(varScope, new ForeachContextHandler(parseInfo, foreachContext));

            // Get the array that will be iterated on. Syntax error if it is missing.
            if (foreachContext.expr() != null)
            {
                Array = DeltinScript.GetExpression(parseInfo, scope, foreachContext.expr());
            }
            else
            {
                parseInfo.Script.Diagnostics.Error("Expected expression.", DocRange.GetRange(foreachContext.IN()));
            }

            // Get the foreach block. Syntax error if it is missing.
            if (foreachContext.block() != null)
            {
                Block = new BlockAction(parseInfo.SetLoop(this), varScope, foreachContext.block());
                // Get the path info.
                Path = new PathInfo(Block, DocRange.GetRange(foreachContext.FOREACH()), false);
            }
            else
            {
                parseInfo.Script.Diagnostics.Error("Expected block.", DocRange.GetRange(foreachContext.RIGHT_PAREN()));
            }
        }
        public IsAction(ParseInfo parseInfo, Scope scope, DeltinScriptParser.E_isContext isContext)
        {
            // Get the expression.
            expression = DeltinScript.GetExpression(parseInfo, scope, isContext.expr());

            // Get the type.
            if (isContext.type == null)
            {
                parseInfo.Script.Diagnostics.Error("Expected type name.", DocRange.GetRange(isContext.IS()));
            }
            else
            {
                CodeType type = parseInfo.TranslateInfo.GetCodeType(isContext.type.Text, parseInfo.Script.Diagnostics, DocRange.GetRange(isContext.type));

                // Make sure the received type is a class.
                if (type != null && type is ClassType == false)
                {
                    parseInfo.Script.Diagnostics.Error("Expected a class type.", DocRange.GetRange(isContext.type));
                }
                else
                {
                    checkingIfType = (ClassType)type;
                }
            }
        }
Ejemplo n.º 4
0
        public SetVariableAction(ParseInfo parseInfo, Scope scope, DeltinScriptParser.VarsetContext varsetContext)
        {
            IExpression variableExpression = DeltinScript.GetExpression(parseInfo, 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 = DeltinScript.GetExpression(parseInfo, scope, varsetContext.val);
                }
            }
            else if (varsetContext.INCREMENT() != null)
            {
                Operation = "++";
            }
            else if (varsetContext.DECREMENT() != null)
            {
                Operation = "--";
            }
        }
Ejemplo n.º 5
0
        public ForeachAction(ParseInfo parseInfo, Scope scope, DeltinScriptParser.ForeachContext foreachContext)
        {
            Scope varScope = scope.Child();

            ForeachVar = new Var(foreachContext.name.Text, new Location(parseInfo.Script.Uri, DocRange.GetRange(foreachContext.name)), parseInfo);
            ForeachVar.VariableType = VariableType.ElementReference;
            ForeachVar.CodeType     = CodeType.GetCodeTypeFromContext(parseInfo, foreachContext.code_type());
            ForeachVar.Finalize(varScope);

            // Get the array that will be iterated on. Syntax error if it is missing.
            if (foreachContext.expr() != null)
            {
                Array = DeltinScript.GetExpression(parseInfo, scope, foreachContext.expr());
            }
            else
            {
                parseInfo.Script.Diagnostics.Error("Expected expression.", DocRange.GetRange(foreachContext.IN()));
            }

            // Get the foreach block. Syntax error if it is missing.
            if (foreachContext.block() != null)
            {
                Block = new BlockAction(parseInfo, varScope, foreachContext.block());
                // Get the path info.
                Path = new PathInfo(Block, DocRange.GetRange(foreachContext.FOREACH()), false);
            }
            else
            {
                parseInfo.Script.Diagnostics.Error("Expected block.", DocRange.GetRange(foreachContext.RIGHT_PAREN()));
            }
        }
Ejemplo n.º 6
0
 public ReturnAction(ParseInfo parseInfo, Scope scope, DeltinScriptParser.ReturnContext returnContext)
 {
     ErrorRange = DocRange.GetRange(returnContext.RETURN());
     if (returnContext.expr() != null)
     {
         ReturningValue = DeltinScript.GetExpression(parseInfo, scope, returnContext.expr());
     }
 }
 public CreateArrayAction(ParseInfo parseInfo, Scope scope, DeltinScriptParser.CreatearrayContext createArrayContext)
 {
     Values = new IExpression[createArrayContext.expr().Length];
     for (int i = 0; i < Values.Length; i++)
     {
         Values[i] = DeltinScript.GetExpression(parseInfo, scope, createArrayContext.expr(i));
     }
 }
Ejemplo n.º 8
0
 // Formatted
 public StringAction(ParseInfo parseInfo, Scope scope, DeltinScriptParser.Formatted_stringContext stringContext) : this(parseInfo.Script, stringContext.@string(), false)
 {
     FormatParameters = new IExpression[stringContext.expr().Length];
     for (int i = 0; i < FormatParameters.Length; i++)
     {
         FormatParameters[i] = DeltinScript.GetExpression(parseInfo, scope, stringContext.expr(i));
     }
     ParseString(parseInfo.Script);
 }
 public void SetupBlock()
 {
     if (ExpressionToParse == null)
     {
         return;
     }
     Expression = DeltinScript.GetExpression(parseInfo.SetCallInfo(CallInfo), scope, ExpressionToParse);
     ReturnType = Expression?.Type();
 }
Ejemplo n.º 10
0
 public void SetupBlock()
 {
     if (ExpressionToParse != null)
     {
         Expression = DeltinScript.GetExpression(parseInfo.SetCallInfo(CallInfo), scope, ExpressionToParse);
     }
     foreach (var listener in listeners)
     {
         listener.Applied();
     }
 }
Ejemplo n.º 11
0
 private void GetInitialValue()
 {
     // Get the initial value.
     if (_initalValueContext != null)
     {
         InitialValue = DeltinScript.GetExpression(parseInfo, _operationalScope, _initalValueContext);
         if (InitialValue?.Type() != null && InitialValue.Type().Constant() == TypeSettable.Constant && CodeType != InitialValue.Type())
         {
             parseInfo.Script.Diagnostics.Error($"The type '{InitialValue.Type().Name}' cannot be stored.", DocRange.GetRange(_initalValueContext));
         }
     }
 }
        public IfAction(ParseInfo parseInfo, Scope scope, DeltinScriptParser.IfContext ifContext)
        {
            if (ifContext.expr() == null)
            {
                parseInfo.Script.Diagnostics.Error("Expected expression.", DocRange.GetRange(ifContext.LEFT_PAREN()));
            }
            else
            {
                Expression = DeltinScript.GetExpression(parseInfo, scope, ifContext.expr());
            }

            var paths = new List <PathInfo>();

            if (ifContext.block() == null)
            {
                parseInfo.Script.Diagnostics.Error("Expected block.", DocRange.GetRange(ifContext.IF()));
            }
            else
            {
                Block = new BlockAction(parseInfo, scope, ifContext.block());
            }
            paths.Add(new PathInfo(Block, DocRange.GetRange(ifContext.IF()), false));

            if (ifContext.else_if() != null)
            {
                ElseIfs = new ElseIf[ifContext.else_if().Length];
                for (int i = 0; i < ElseIfs.Length; i++)
                {
                    ElseIfs[i] = new ElseIf(parseInfo, scope, ifContext.else_if(i));
                    paths.Add(new PathInfo(Block, DocRange.GetRange(ifContext.else_if(i).ELSE(), ifContext.else_if(i).IF()), false));
                }
            }
            else
            {
                ElseIfs = new ElseIf[0];
            }

            // If there is an else statement, get the else block.
            if (ifContext.@else() != null)
            {
                if (ifContext.block() == null)
                {
                    parseInfo.Script.Diagnostics.Error("Expected block.", DocRange.GetRange(ifContext.@else().block()));
                }
                else
                {
                    ElseBlock = new BlockAction(parseInfo, scope, ifContext.@else().block());
                }
                // Add the else path info.
                paths.Add(new PathInfo(ElseBlock, DocRange.GetRange(ifContext.@else().ELSE()), true));
            }
            Paths = paths.ToArray();
        }
Ejemplo n.º 13
0
        public DeleteAction(ParseInfo parseInfo, Scope scope, DeltinScriptParser.DeleteContext deleteContext)
        {
            DeleteValue = DeltinScript.GetExpression(parseInfo, scope, deleteContext.expr());

            if (DeleteValue.Type() == null)
            {
                parseInfo.Script.Diagnostics.Error("Expression has no type.", DocRange.GetRange(deleteContext.expr()));
            }
            else if (!DeleteValue.Type().CanBeDeleted)
            {
                parseInfo.Script.Diagnostics.Error($"Type '{DeleteValue.Type().Name}' cannot be deleted.", DocRange.GetRange(deleteContext.expr()));
            }
        }
Ejemplo n.º 14
0
        public WhileAction(ParseInfo parseInfo, Scope scope, DeltinScriptParser.WhileContext whileContext)
        {
            if (whileContext.expr() == null)
            {
                parseInfo.Script.Diagnostics.Error("Expected expression.", DocRange.GetRange(whileContext.LEFT_PAREN()));
            }
            else
            {
                Condition = DeltinScript.GetExpression(parseInfo, scope, whileContext.expr());
            }

            Block = new BlockAction(parseInfo, scope, whileContext.block());
            Path  = new PathInfo(Block, DocRange.GetRange(whileContext.WHILE()), false);
        }
        public TypeConvertAction(ParseInfo parseInfo, Scope scope, DeltinScriptParser.TypeconvertContext typeConvert)
        {
            Expression = DeltinScript.GetExpression(parseInfo, scope, typeConvert.expr());

            // Get the type. Syntax error if there is none.
            if (typeConvert.PART() == null)
            {
                parseInfo.Script.Diagnostics.Error("Expected type name.", DocRange.GetRange(typeConvert.LESS_THAN()));
            }
            else
            {
                ConvertingTo = parseInfo.TranslateInfo.GetCodeType(typeConvert.PART().GetText(), parseInfo.Script.Diagnostics, DocRange.GetRange(typeConvert.PART()));
            }
        }
        public RuleIfAction(ParseInfo parseInfo, Scope scope, DeltinScriptParser.Rule_ifContext ifContext)
        {
            // Syntax error if there is no expression.
            if (ifContext.expr() == null)
            {
                parseInfo.Script.Diagnostics.Error("Expected expression.", DocRange.GetRange(ifContext.RIGHT_PAREN()));
            }

            // Get the expression.
            else
            {
                Expression = DeltinScript.GetExpression(parseInfo, scope, ifContext.expr());
            }
        }
        public ValueInArrayAction(ParseInfo parseInfo, Scope scope, DeltinScriptParser.E_array_indexContext exprContext)
        {
            Expression      = DeltinScript.GetExpression(parseInfo, scope, exprContext.array);
            expressionRange = DocRange.GetRange(exprContext.array);

            if (exprContext.index == null)
            {
                parseInfo.Script.Diagnostics.Error("Expected an expression.", DocRange.GetRange(exprContext.INDEX_START()));
            }
            else
            {
                Index      = DeltinScript.GetExpression(parseInfo, scope, exprContext.index);
                indexRange = DocRange.GetRange(exprContext.index);
            }
        }
Ejemplo n.º 18
0
        public void Finalize(Scope scope)
        {
            // Get the initial value.
            if (context?.expr() != null)
            {
                InitialValue = DeltinScript.GetExpression(parseInfo, scope, context.expr());
                if (InitialValue?.Type() != null && InitialValue.Type().Constant() == TypeSettable.Constant && CodeType != InitialValue.Type())
                {
                    parseInfo.Script.Diagnostics.Error($"The type '{InitialValue.Type().Name}' cannot be stored.", DocRange.GetRange(context.expr()));
                }
            }

            // Add the variable to the scope.
            scope.AddVariable(this, parseInfo.Script.Diagnostics, DefinedAt.range);
            finalized = true;
        }
Ejemplo n.º 19
0
        public IExpression Parse(ParseInfo parseInfo, Scope scope, Scope getter, bool usedAsValue)
        {
            if (variable != null)
            {
                return(DeltinScript.GetVariable(parseInfo, scope, getter, variable, false));
            }
            if (method != null)
            {
                return(new CallMethodAction(parseInfo, scope, method, usedAsValue, getter));
            }
            if (expression != null)
            {
                return(DeltinScript.GetExpression(parseInfo, scope, expression, false, usedAsValue, getter));
            }

            throw new Exception();
        }
        public ElseIf(ParseInfo parseInfo, Scope scope, DeltinScriptParser.Else_ifContext elseIfContext)
        {
            if (elseIfContext.expr() == null)
            {
                parseInfo.Script.Diagnostics.Error("Expected expression.", DocRange.GetRange(elseIfContext.LEFT_PAREN()));
            }
            else
            {
                Expression = DeltinScript.GetExpression(parseInfo, scope, elseIfContext.expr());
            }

            if (elseIfContext.block() == null)
            {
                parseInfo.Script.Diagnostics.Error("Expected block.", DocRange.GetRange(elseIfContext.ELSE(), elseIfContext.IF()));
            }
            else
            {
                Block = new BlockAction(parseInfo, scope, elseIfContext.block());
            }
        }
Ejemplo n.º 21
0
        public SwitchAction(ParseInfo parseInfo, Scope scope, DeltinScriptParser.SwitchContext switchContext)
        {
            // Get the expression.
            if (switchContext.expr() == null)
            {
                parseInfo.Script.Diagnostics.Error("Expected expression.", DocRange.GetRange(switchContext.RIGHT_PAREN()));
            }
            else
            {
                Expression = DeltinScript.GetExpression(parseInfo, scope, switchContext.expr());
            }

            paths    = GetSections(ResolveElements(parseInfo.SetBreakHandler(this), scope, switchContext));
            pathInfo = new PathInfo[paths.Length];

            for (int i = 0; i < pathInfo.Length; i++)
            {
                pathInfo[i] = new PathInfo(paths[i].Block, paths[i].ErrorRange, paths[i].IsDefault);
            }
        }
        public TernaryConditionalAction(ParseInfo parseInfo, Scope scope, DeltinScriptParser.E_ternary_conditionalContext ternaryContext)
        {
            Condition = DeltinScript.GetExpression(parseInfo, scope, ternaryContext.condition);

            if (ternaryContext.consequent == null)
            {
                parseInfo.Script.Diagnostics.Error("Expected expression.", DocRange.GetRange(ternaryContext.TERNARY()));
            }
            else
            {
                Consequent = DeltinScript.GetExpression(parseInfo, scope, ternaryContext.consequent);
            }

            if (ternaryContext.alternative == null)
            {
                parseInfo.Script.Diagnostics.Error("Expected expression.", DocRange.GetRange(ternaryContext.TERNARY_ELSE()));
            }
            else
            {
                Alternative = DeltinScript.GetExpression(parseInfo, scope, ternaryContext.alternative);
            }
        }
        public TypeConvertAction(ParseInfo parseInfo, Scope scope, DeltinScriptParser.TypeconvertContext typeConvert)
        {
            // Get the expression. Syntax error if there is none.
            if (typeConvert.expr() == null)
            {
                parseInfo.Script.Diagnostics.Error("Expected expression.", DocRange.GetRange(typeConvert.GREATER_THAN()));
            }
            else
            {
                Expression = DeltinScript.GetExpression(parseInfo, scope, typeConvert.expr());
            }

            // Get the type. Syntax error if there is none.
            if (typeConvert.code_type() == null)
            {
                parseInfo.Script.Diagnostics.Error("Expected type name.", DocRange.GetRange(typeConvert.LESS_THAN()));
            }
            else
            {
                ConvertingTo = CodeType.GetCodeTypeFromContext(parseInfo, typeConvert.code_type());
            }
        }
        private void GetParts(ParseInfo parseInfo, Scope scope, DeltinScriptParser.ExprContext left, string op, DocRange opRange, DeltinScriptParser.ExprContext right)
        {
            // Left operator.
            if (left == null)
            {
                parseInfo.Script.Diagnostics.Error("Missing left operator.", opRange);
            }
            else
            {
                Left = DeltinScript.GetExpression(parseInfo, scope, left);
            }

            // Right operator.
            if (right == null)
            {
                parseInfo.Script.Diagnostics.Error("Missing right operator.", opRange);
            }
            else
            {
                Right = DeltinScript.GetExpression(parseInfo, scope, right);
            }

            Operator = op;
        }
        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 InverseAction(ParseInfo parseInfo, Scope scope, DeltinScriptParser.ExprContext exprContext)
 {
     Expression = DeltinScript.GetExpression(parseInfo, scope, exprContext);
 }
Ejemplo n.º 27
0
 public DeleteAction(ParseInfo parseInfo, Scope scope, DeltinScriptParser.DeleteContext deleteContext)
 {
     DeleteValue = DeltinScript.GetExpression(parseInfo, scope, deleteContext.expr());
 }
        public void SetContext(DeltinScriptParser.Call_parametersContext context)
        {
            if (_setContext)
            {
                throw new Exception("Already set the context for the overload chooser.");
            }
            CallContext = context;
            _setContext = true;

            IExpression[] values          = new IExpression[context.expr().Length];
            DocRange[]    errorRanges     = new DocRange[values.Length];
            var           parameterRanges = new List <DocRange>();

            for (int i = 0; i < values.Length; i++)
            {
                values[i]      = DeltinScript.GetExpression(parseInfo, getter, context.expr(i));
                errorRanges[i] = DocRange.GetRange(context.expr(i));
                parameterRanges.Add(errorRanges[i]);
            }

            if (!SetParameterCount(values.Length))
            {
                return;
            }
            if (values.Any(v => v == null))
            {
                return;
            }

            // Match by value types and parameter types.
            for (int i = 0; i < values.Length; i++)
            {
                foreach (var option in CurrentOptions)
                {
                    CompareParameterTypes(values[i], option, i, errorRanges[i]);
                }
            }
            GetBestOption();

            Values = new IExpression[Overload.Parameters.Length];
            for (int i = 0; i < values.Length; i++)
            {
                Values[i] = values[i];
            }

            if (values.Length < Overload.Parameters.Length)
            {
                parameterRanges.Add(new DocRange(
                                        DocRange.GetRange(context).end,
                                        CallRange.end
                                        ));
            }

            ParameterRanges = parameterRanges.ToArray();

            // Get the missing parameters.
            for (int i = values.Length; i < Values.Length; i++)
            {
                Values[i] = MissingParameter(Overload.Parameters[i]);
            }
            GetAdditionalData();
        }
        public void SetContext(DeltinScriptParser.Picky_parametersContext context)
        {
            if (_setContext)
            {
                throw new Exception("Already set the context for the overload chooser.");
            }
            PickyContext = context;
            _setContext  = true;

            PickyParameter[] parameters = new PickyParameter[context.picky_parameter().Length];
            for (int i = 0; i < parameters.Length; i++)
            {
                string      name       = context.picky_parameter(i).PART().GetText();
                IExpression expression = null;

                DocRange expressionRange = null;

                // Get the expression. If it doesn't exist, add a syntax error.
                if (context.picky_parameter(i).expr() != null)
                {
                    expression      = DeltinScript.GetExpression(parseInfo, getter, context.picky_parameter(i).expr());
                    expressionRange = DocRange.GetRange(context.picky_parameter(i).expr());
                }
                else
                {
                    parseInfo.Script.Diagnostics.Error("Expected expression.", DocRange.GetRange(context.picky_parameter(i).TERNARY_ELSE()));
                }

                var nameRange = DocRange.GetRange(context.picky_parameter(i).PART());

                // Syntax error if the parameter was already set.
                if (parameters.Any(p => p != null && p.Name == name))
                {
                    parseInfo.Script.Diagnostics.Error($"The parameter {name} was already set.", nameRange);
                }
                else
                {
                    // Add the parameter.
                    parameters[i] = new PickyParameter(
                        name,
                        expression,
                        DocRange.GetRange(context.picky_parameter(i)),
                        nameRange,
                        expressionRange
                        );
                }
            }

            if (!SetParameterCount(parameters.Length))
            {
                return;
            }

            // Match by value types and parameter types.
            foreach (var parameter in parameters)
            {
                foreach (var option in CurrentOptions)
                {
                    int index = -1;
                    for (int i = 0; i < option.Parameters.Length; i++)
                    {
                        if (option.Parameters[i].Name == parameter.Name)
                        {
                            index = i;
                            break;
                        }
                    }

                    if (index == -1)
                    {
                        // Syntax error if the parameter does not exist.
                        optionDiagnostics[option].Add(new Diagnostic(
                                                          string.Format(ErrorMessages.ParameterDoesntExist, parameter.Name),
                                                          parameter.NameRange,
                                                          Diagnostic.Error
                                                          ));
                    }
                    // parameter.Value is null if there is no expression.
                    // A syntax error for this was already thrown earlier.
                    else if (parameter.Value != null)
                    {
                        // Check the types.
                        CompareParameterTypes(parameter.Value, option, index, parameter.ExpressionRange);
                    }
                }
            }
            GetBestOption();

            List <string> pickyParameterCompletion = Overload.Parameters.Select(p => p.Name).ToList();

            ParameterRanges = new DocRange[Overload.Parameters.Length];
            IExpression[] values = new IExpression[Overload.Parameters.Length];
            for (int i = 0; i < values.Length; i++)
            {
                int parameterIndex = -1;
                for (int p = 0; p < parameters.Length && parameterIndex == -1; p++)
                {
                    if (parameters[p].Name == Overload.Parameters[i].Name)
                    {
                        parameterIndex = p;
                        pickyParameterCompletion.Remove(parameters[p].Name);
                    }
                }

                if (parameterIndex != -1)
                {
                    values[i]          = parameters[parameterIndex].Value;
                    ParameterRanges[i] = parameters[parameterIndex].FullRange;
                }
                else
                {
                    values[i] = MissingParameter(Overload.Parameters[i]);
                }
            }
            Values = values;

            // Add the picky parameter completion.
            parseInfo.Script.AddCompletionRange(new CompletionRange(pickyParameterCompletion.Select(p => new CompletionItem()
            {
                Label = p + ":",
                Kind  = CompletionItemKind.Field
            }).ToArray(), CallRange, CompletionRangeKind.Additive));

            GetAdditionalData();
        }
Ejemplo n.º 30
0
        private SwitchElement[] ResolveElements(ParseInfo parseInfo, Scope scope, DeltinScriptParser.SwitchContext switchContext)
        {
            List <SwitchElement> elements = new List <SwitchElement>();
            bool inSection  = false;
            bool caseError  = false;
            bool gotDefault = false;

            // Resolve paths.
            foreach (var switchElement in switchContext.switch_element())
            {
                // Syntax error if there is a statement before a case.
                if (switchElement.statement() != null && !inSection && !caseError)
                {
                    parseInfo.Script.Diagnostics.Error("Expected case or default.", DocRange.GetRange(switchElement));
                    caseError = true;
                }

                // Don't throw the syntax error multiple times in one switch.
                if (switchElement.DEFAULT() != null || switchElement.@case() != null)
                {
                    inSection = true;
                }

                // Default case.
                if (switchElement.DEFAULT() != null)
                {
                    if (gotDefault)
                    {
                        parseInfo.Script.Diagnostics.Error("Switch cannot have multiple defaults.", DocRange.GetRange(switchElement));
                    }
                    gotDefault = true;
                }

                // Get the statement
                if (switchElement.statement() != null)
                {
                    elements.Add(new SwitchElement(DeltinScript.GetStatement(parseInfo, scope, switchElement.statement())));
                }
                // Get the case
                else if (switchElement.@case() != null)
                {
                    elements.Add(new SwitchElement(DocRange.GetRange(switchElement.@case().CASE()), DeltinScript.GetExpression(parseInfo, scope, switchElement.@case().expr())));
                }
                // Get default
                else if (switchElement.DEFAULT() != null)
                {
                    elements.Add(new SwitchElement(DocRange.GetRange(switchElement.DEFAULT())));
                }
            }

            return(elements.ToArray());
        }