Пример #1
0
        /// <summary>
        /// Create a new Freezable EntityGetValue
        /// </summary>
        public static IFreezableStep CreateFreezableArrayAccess(
            IFreezableStep entityOrArray,
            IFreezableStep indexer,
            TextLocation?location)
        {
            var entityGetValueDict = new StepParameterDict
            {
                {
                    new StepParameterReference.Named(nameof(EntityGetValue <int> .Entity)),
                    new FreezableStepProperty.Step(entityOrArray, location)
                },
                {
                    new StepParameterReference.Named(nameof(EntityGetValue <int> .Property)),
                    new FreezableStepProperty.Step(indexer, location)
                },
            };

            var entityGetValueData = new FreezableStepData(entityGetValueDict, location);

            var entityGetValueStep = new CompoundFreezableStep(
                "EntityGetValue",
                entityGetValueData,
                location
                );

            var elementAtIndexDict = new StepParameterDict
            {
                {
                    new StepParameterReference.Named(nameof(ElementAtIndex <object> .Array)),
                    new FreezableStepProperty.Step(entityOrArray, location)
                },
                {
                    new StepParameterReference.Named(nameof(ElementAtIndex <object> .Index)),
                    new FreezableStepProperty.Step(indexer, location)
                },
            };

            var elementAtData = new FreezableStepData(elementAtIndexDict, location);

            var elementAtStep = new CompoundFreezableStep(
                "ElementAtIndex",
                elementAtData,
                location
                );

            var result = new OptionFreezableStep(new[] { entityGetValueStep, elementAtStep }, location);

            return(result);
        }
Пример #2
0
        /// <summary>
        /// Create a freezable Not step.
        /// </summary>
        public static IFreezableStep CreateFreezableNot(IFreezableStep boolean, TextLocation location)
        {
            var dict = new StepParameterDict
            {
                {
                    new StepParameterReference.Named(nameof(Not.Boolean)),
                    new FreezableStepProperty.Step(boolean, location)
                },
            };

            var fpd  = new FreezableStepData(dict, location);
            var step = new CompoundFreezableStep(nameof(Not), fpd, location);

            return(step);
        }
Пример #3
0
        /// <summary>
        /// Create a freezable GetVariable step.
        /// </summary>
        public static IFreezableStep CreateFreezableGetVariable(
            VariableName variableName,
            TextLocation?location)
        {
            var dict = new StepParameterDict
            {
                {
                    new StepParameterReference.Named(nameof(GetVariable <object> .Variable)),
                    new FreezableStepProperty.Variable(variableName, location)
                }
            };

            var fpd = new FreezableStepData(dict, location);

            var step = new CompoundFreezableStep(
                "GetVariable",
                fpd,
                location
                );

            return(step);
        }
Пример #4
0
        /// <summary>
        /// Create a freezable GetVariable step.
        /// </summary>
        public static IFreezableStep CreateFreezableSetVariable(
            FreezableStepProperty variableName,
            FreezableStepProperty value,
            TextLocation location)
        {
            var dict = new StepParameterDict
            {
                {
                    new StepParameterReference.Named(nameof(SetVariable <object> .Variable)), variableName
                },
                { new StepParameterReference.Named(nameof(SetVariable <object> .Value)), value },
            };

            var fpd = new FreezableStepData(dict, location);

            var step = new CompoundFreezableStep(
                "SetVariable",
                fpd,
                location
                );

            return(step);
        }
Пример #5
0
        /// <summary>
        /// Try to create an infix step
        /// </summary>
        public static Result <FreezableStepProperty, IError> TryCreateStep(
            TextLocation textLocation,
            string op,
            IReadOnlyList <Result <FreezableStepProperty, IError> > terms)
        {
            List <IError> errors = new();
            List <FreezableStepProperty> properties = new();

            foreach (var result in terms)
            {
                if (result.IsFailure)
                {
                    errors.Add(result.Error);
                }
                else
                {
                    properties.Add(result.Value);
                }
            }

            if (errors.Any())
            {
                return(Result.Failure <FreezableStepProperty, IError>(ErrorList.Combine(errors)));
            }

            var operatorData = OperatorLookup[op].ToList();

            if (!operatorData.Any())
            {
                return(new SingleError(
                           textLocation,
                           ErrorCode.CouldNotParse,
                           op,
                           "Operator"
                           ));
            }

            List <IFreezableStep> freezableSteps = new();

            foreach (var(_, stepName, termsName) in operatorData)
            {
                var stepParameterDict = new StepParameterDict()
                {
                    {
                        new StepParameterReference.Named(termsName), new FreezableStepProperty.StepList(
                            properties.Select(x => x.ConvertToStep()).ToImmutableList(),
                            textLocation
                            )
                    }
                };

                var data = new FreezableStepData(
                    stepParameterDict,
                    textLocation
                    );

                var step = new CompoundFreezableStep(stepName, data, textLocation);
                freezableSteps.Add(step);
            }

            if (freezableSteps.Count == 1)
            {
                return(new FreezableStepProperty.Step(freezableSteps.Single(), textLocation));
            }

            var alt = new OptionFreezableStep(freezableSteps, textLocation);

            return(new FreezableStepProperty.Step(alt, textLocation));
        }