public override IGraph VisitGraph(DotGrammarParser.GraphContext context) { if ((context == null) || (ParsedGraph != null)) { throw new NotImplementedException(); } var id = context.id()?.GetText() ?? ModelHelper.DefaultGraphId; var isDirected = context.DIGRAPH() != null; var isStrict = context.STRICT() != null; ParsedGraph = Graph.CreateGraph(id, isDirected, isStrict); CurrentSubGraph = ParsedGraph; ParsedGraph.SetAttributes(GetGraphAttributes(context.stmt_list().stmt())); ParsedGraph.SetNodeAttributes(GetNodeAttributes(context.stmt_list().stmt())); ParsedGraph.SetEdgeAttributes(GetEdgeAttributes(context.stmt_list().stmt())); foreach (var stmtContext in context.stmt_list().stmt()) { HandleNode(stmtContext.node_stmt()); HandleEdgeLine(stmtContext.edge_stmt()); HandleSubgraph(stmtContext.subgraph()); HandleExitSubgraph(stmtContext.subgraph()); } return(ParsedGraph); }
private IList <NodePort> HandleSubgraph(DotGrammarParser.SubgraphContext context) { var nodeList = new List <NodePort>(); if (context == null) { return(nodeList); } var id = context.id() == null ? string.Format(CultureInfo.InvariantCulture, ModelHelper.NewSubGraphFormat, ParsedGraph.GetSubGraphs().Count() + 1) : context.id().GetText(); var graphAttrs = GetGraphAttributes(context.stmt_list().stmt()); var nodeAttrs = GetNodeAttributes(context.stmt_list().stmt()); var edgeAttrs = GetEdgeAttributes(context.stmt_list().stmt()); CurrentSubGraph = CurrentSubGraph.CreateSubGraph(id, graphAttrs, nodeAttrs, edgeAttrs); foreach (var stmtContext in context.stmt_list().stmt()) { nodeList.AddRange(HandleNode(stmtContext.node_stmt())); nodeList.AddRange(HandleEdgeLine(stmtContext.edge_stmt())); nodeList.AddRange(HandleSubgraph(stmtContext.subgraph())); HandleExitSubgraph(stmtContext.subgraph()); } return(nodeList); }