/// <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); }
/// <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)); }