Exemple #1
0
        public override object Validate(ParseInfo parseInfo, IExpression value, DocRange valueRange, object additionalData)
        {
            base.Validate(parseInfo, value, valueRange, additionalData);

            // Get the custom color applier.
            var applier = (CustomColorApplier)additionalData;

            // If there is no value.
            if (value == null)
            {
                applier.Set(_component);
            }
            else
            {
                // Resolve the expression.
                ConstantExpressionResolver.Resolve(value, value => {
                    // If the expression is a number, set the component.
                    if (value is NumberAction numberAction)
                    {
                        applier.Set(_component, numberAction.Value);
                    }
                    // Parameter default value.
                    else if (value is ExpressionOrWorkshopValue expressionOrWorkshop && expressionOrWorkshop.WorkshopValue is NumberElement numberElement)
                    {
                        applier.Set(_component, numberElement.Value);
                    }
Exemple #2
0
            public override object Validate(ParseInfo parseInfo, IExpression value, DocRange valueRange)
            {
                var values = new List <string>();

                ConstantExpressionResolver.Resolve(value, expr => {
                    // If the resulting expression is a CreateArray,
                    if (expr is CreateArrayAction array)
                    {
                        var error = new ConstStringElementErrorHandler(parseInfo.Script.Diagnostics, valueRange);

                        // Iterate through each element in the array and get the string value.
                        foreach (var value in array.Values)
                        {
                            ConstantExpressionResolver.Resolve(value, expr => {
                                // Make sure the value is a string.
                                if (value is StringAction stringAction)
                                {
                                    values.Add(stringAction.Value);
                                }
                                // Otherwise, add an error.
                                else
                                {
                                    error.AddError();
                                }
                            });
                        }
                    }
                    // Otherwise, add an error.
                    else if (valueRange != null)
                    {
                        parseInfo.Script.Diagnostics.Error("Expected a string array", valueRange);
                    }
                });
                return(values);
            }
Exemple #3
0
        public void Call(ParseInfo parseInfo, DocRange callRange)
        {
            if (parseInfo.SourceExpression != null)
            {
                parseInfo.SourceExpression.OnResolve(expr => ConstantExpressionResolver.Resolve(expr, expr => {
                    // Get the lambda that is being invoked.
                    if (expr is LambdaAction source)
                    {
                        // Recursion and error check.
                        LambdaInvokeApply(parseInfo, source, callRange);

                        // Parameter invocation states.
                        for (int i = 0; i < source.InvokedState.Length; i++)
                        {
                            if (source.InvokedState[i].Invoked)
                            {
                                Parameters[i].Invoked.WasInvoked();
                            }
                        }
                    }
                    // The lambda is being invoked from a parameter.
                    else if (ParameterInvocableBridge(expr, out IBridgeInvocable invocable))
                    {
                        invocable.WasInvoked();
                    }
                    // This will only run if a way to resolve lambdas was not accounted for.
                    // Unresolved lambdas will not throw any errors if a restricted value is inside and the lambda is invoked.
                    // Unresolved lambdas also cannot check for recursion.
                    else
                    {
                        parseInfo.Script.Diagnostics.Warning("Source lambda not found, contact zez- I mean, deltin.", callRange);
                    }
                }));
            }
        }
Exemple #4
0
 public override object Validate(ParseInfo parseInfo, IExpression value, DocRange valueRange, object additionalData)
 {
     ConstantExpressionResolver.Resolve(value, value => {
         // Parameter value is map.
         if (!(value is EnumValuePair enumValue && enumValue.Member.Enum.Name == "Map"))
         {
             parseInfo.Script.Diagnostics.Error("Expected a map value.", valueRange);
         }
     });