public string ProcessLambda(SystemNode system, SystemLambdaAction lambda, string currentTemplate) { var transitions = system.TransitionTo(lambda).ToArray(); bool hasTransition = (transitions?.Count() ?? -1) > 0; string transitionsNames = ""; if (hasTransition) { transitionsNames = string.Join(", ", transitions.Select(t => t.Name)); } currentTemplate = CodeGeneratorUtils.ConditionalText(hasTransition, "TRANSITION", currentTemplate); return(s_transitionToRegex.Replace(currentTemplate, transitionsNames)); }
private static void GenerateSystems(SystemsGraph systemsGraph) { var states = systemsGraph.nodes.OfType <SystemNode>().Where(s => s.Editable).ToList(); var systemsPath = systemsGraph.CodeGenerationPath; if (systemsPath.EndsWith("Systems")) { systemsPath = PathExtension.SystemPath(systemsPath); } else { systemsPath = PathExtension.SystemPath(Path.Combine(systemsPath, "Systems")); } if (!Directory.Exists(systemsPath)) { Directory.CreateDirectory(systemsPath); } var loadedTemplate = CodeGeneratorUtils.LoadTemplate("System"); foreach (var system in states) { var template = loadedTemplate; var systemName = system.StateName; // ICodeGeneratorSystemProcessorBeforeLambda var beforeLambdaProcessors = ProcessorsSelector.Selectors <ICodeGeneratorSystemProcessorBeforeLambda>(); foreach (var processor in beforeLambdaProcessors) { template = processor.ProcessBeforeLambda(systemsGraph, system, template); } // Process lambdas var lambdaTemplate = s_lambdaRegex.Match(template).Groups[2].Value; StringBuilder lambdaTemplateBuilder = new StringBuilder(); foreach (var lambda in system.Lambdas) { var currentTemplate = lambdaTemplate; // ICodeGeneratorSystemProcessorLambda var lambdaProcessors = ProcessorsSelector.Selectors <ICodeGeneratorSystemProcessorLambda>(); foreach (var processor in lambdaProcessors) { currentTemplate = processor.ProcessLambda(system, lambda, currentTemplate); } // Add lambda to others lambdaTemplateBuilder.AppendLine(currentTemplate); } template = CodeGeneratorUtils.ConditionalText(system.HasStructuralChanges, "STRUCTURAL_CHANGES", template); template = s_lambdaRegex.Replace(template, lambdaTemplateBuilder.ToString()); // ICodeGeneratorSystemProcessorAfterLambda var afterLambdaProcessors = ProcessorsSelector.Selectors <ICodeGeneratorSystemProcessorAfterLambda>(); foreach (var processor in afterLambdaProcessors) { template = processor.ProcessAfterLambda(systemsGraph, system, template); } // Generate file var systemPath = Path.Combine(systemsPath, $"{systemName}.cs"); GenerateSystemFile(systemName, systemPath, template); } }
public string ProcessLambda(SystemNode system, SystemLambdaAction lambda, string currentTemplate) => CodeGeneratorUtils.ConditionalText(lambda.Parallel, "PARALLEL", currentTemplate);
public string ProcessLambda(SystemNode system, SystemLambdaAction lambda, string currentTemplate) { currentTemplate = CodeGeneratorUtils.ConditionalText(lambda.HasSharedComponent, "HAS_SHARED", currentTemplate); return(CodeGeneratorUtils.ConditionalText(lambda.HasStructuralChanges, "STRUCTURAL_CHANGES", currentTemplate)); }