public override string VisitASTView(ASTView astView) { var ast = astView.Nodes.Select(Generator.Find).ToList(); var mermaidMapper = new MermaidMapper(new ASTGenerator(ast)); mermaidMapper.Start().ToList(); var mermaidString = mermaidMapper.ToString().Trim(); var result = $@"<div class=""svg-container""><div class=""mermaid"">{mermaidString}</div></div>"; Parts.Add(result); return(result); }
public static List <IASTNode> ResolveImports(ASTGenerator generator) { var imports = new List <IASTNode>(); var _imports = generator.AST.FindAll(n => n is ASTImport).ToList(); _imports.ForEach(node => { var import = (ASTImport)node; var ast = ProjectContext.Instance?.GetAstForModule(import.ModuleName); if (!import.Imports.Any()) { var copies = ast? .FindAll(a => a is ASTType || a is ASTAlias || a is ASTData || a is ASTChoice || a is ASTView) .Select(a => { return(a switch { ASTType t => t.Clone() as IASTNode, ASTAlias t => t.Clone() as IASTNode, ASTData t => t.Clone() as IASTNode, ASTChoice t => t.Clone() as IASTNode, ASTView t => t.Clone() as IASTNode, _ => null }); }) .ToList() .Where(n => n != null) .OfType <IASTNode>() .ToList() ?? Enumerable.Empty <IASTNode>(); // For some reason the compiler cannot find that I filter out all of the // null's from the list and so I will only have a list of reference types // of type IASTNode... #pragma warning disable CS8620 // Argument cannot be used for parameter due to differences in the nullability of reference types. imports.AddRange(copies); #pragma warning restore CS8620 // Argument cannot be used for parameter due to differences in the nullability of reference types. }
public IEnumerable <IASTNode> Parse() { var annotations = new List <ASTAnnotation>(); var directives = new List <ASTDirective>(); while (HasNext() && Current.TokenType != TokenType.EndOfFile) { if (Current.TokenType == TokenType.KW_Type) { var(errors, t) = ASTType.Parse(this, annotations, directives); Errors.AddRange(errors); annotations = new List <ASTAnnotation>(); directives = new List <ASTDirective>(); yield return(t); } else if (Current.TokenType == TokenType.KW_Alias) { var(errors, alias) = ASTAlias.Parse(this, annotations, directives); Errors.AddRange(errors); annotations = new List <ASTAnnotation>(); directives = new List <ASTDirective>(); yield return(alias); } else if (Current.TokenType == TokenType.KW_Choice) { var(errors, result) = ASTChoice.Parse(this); Errors.AddRange(errors); yield return(result); annotations = new List <ASTAnnotation>(); directives = new List <ASTDirective>(); } else if (Current.TokenType == TokenType.KW_Data) { var(errors, data) = ASTData.Parse(this, annotations, directives); Errors.AddRange(errors); yield return(data); annotations = new List <ASTAnnotation>(); directives = new List <ASTDirective>(); } else if (Current.TokenType == TokenType.KW_View) { var(errors, data) = ASTView.Parse(this, annotations, directives); Errors.AddRange(errors); yield return(data); annotations = new List <ASTAnnotation>(); directives = new List <ASTDirective>(); } else if (Current.TokenType == TokenType.KW_Open) { var(errors, data) = ASTImport.Parse(this); Errors.AddRange(errors); yield return(data); annotations = new List <ASTAnnotation>(); directives = new List <ASTDirective>(); } else if (Current.TokenType == TokenType.KW_Flow) { var(errors, data) = ASTFlow.Parse(this); Errors.AddRange(errors); yield return(data); annotations = new List <ASTAnnotation>(); directives = new List <ASTDirective>(); } else if (Current.TokenType == TokenType.Annotation) { annotations = ASTAnnotation.Parse(this).ToList(); } else if (Current.TokenType == TokenType.Directive) { var(errors, dirs) = ASTDirective.Parse(this); Errors.AddRange(errors.ToList()); directives = dirs.ToList(); } else if (Current.TokenType == TokenType.Chapter) { yield return(new ASTChapter(Current.Value)); Next(); } else if (Current.TokenType == TokenType.Paragraph) { yield return(new ASTParagraph(Current.Value)); Next(); } else { Next(); } } yield break; }
public override XmlSchemaObject?VisitASTView(ASTView astView) => null;