public Node ParseBusinessObject(string boText) { boText = preProcessText(boText); var nodeHeap = new LinkedList<Node>(); var boNode = new Node(); boNode.NodeType = NodeType.BusinessObject; nodeHeap.AddLast(boNode); var currentDocuLines = new LinkedList<string>(); var currenctAnnotations = new LinkedList<Annotation>(); foreach (var line in boText.Split('\n')) { var parseLine = line.Trim(); // Skip emty lines if (parseLine.Length == 0) { continue; } // Line Handling while (parseLine.StartsWith("[")) { var splitLine = parseLine.Split(new char[1] { ']' }, 2); currenctAnnotations = ParseAnnotations(splitLine.First() + "]"); parseLine = splitLine.Last().Trim(); } if (parseLine.StartsWith("businessobject")) { nodeHeap.Last.Value.Name = CleanLineEnding(parseLine.Split(SPACER)[1]); nodeHeap.Last.Value.Annotation = currenctAnnotations; nodeHeap.Last.Value.DocumentationLines = currentDocuLines; } else if (parseLine.StartsWith("element")) { nodeHeap.Last.Value.Element.AddLast(ParseElement(parseLine, currenctAnnotations)); nodeHeap.Last.Value.Element.Last.Value.DocumentationLines = currentDocuLines; } else if (parseLine.StartsWith("association")) { nodeHeap.Last.Value.Association.AddLast(ParseAssociation(parseLine, currenctAnnotations)); nodeHeap.Last.Value.Association.Last.Value.DocumentationLines = currentDocuLines; } else if (parseLine.StartsWith("message")) { nodeHeap.Last.Value.Message.AddLast(ParseMessage(parseLine)); nodeHeap.Last.Value.Message.Last.Value.DocumentationLines = currentDocuLines; } else if (parseLine.StartsWith("action")) { nodeHeap.Last.Value.Action.AddLast(ParseAction(parseLine)); nodeHeap.Last.Value.Action.Last.Value.DocumentationLines = currentDocuLines; } else if (parseLine.StartsWith("///")) { currentDocuLines.AddLast(parseLine.TrimStart('/')); } else if (parseLine.StartsWith("node")) { var newNode = ParseNode(parseLine); nodeHeap.Last.Value.ChildNode.AddLast(newNode); nodeHeap.AddLast(newNode); nodeHeap.Last.Value.DocumentationLines = currentDocuLines; // Close Heap at "special" Nodes if (parseLine.Trim().EndsWith(";")) { nodeHeap.RemoveLast(); } } else if (parseLine.StartsWith("}")) { // Node Close if (nodeHeap.Count > 1) { nodeHeap.RemoveLast(); } } if (currenctAnnotations.Count != 0) { currenctAnnotations = new LinkedList<Annotation>(); } if (parseLine.StartsWith("///") == false && currentDocuLines.Count != 0) { currentDocuLines = new LinkedList<string>(); } } return boNode; }
private Node ParseNode(string line) { var node = new Node(); line = line.Split(SPACER, 2, StringSplitOptions.RemoveEmptyEntries)[1]; line = CleanLineEnding(line); if (line.Contains("[")) { var splittedLine = line.Split(new string[1] { "[" }, 2, StringSplitOptions.RemoveEmptyEntries); node.Name = splittedLine.First(); line = splittedLine.Last().Replace("[", "").Replace("]", ""); splittedLine = line.Split(new string[1] { "," }, 2, StringSplitOptions.RemoveEmptyEntries); node.Multiplicity = GetMultiplicity(splittedLine.First(), splittedLine.Last()); } else { node.Name = line; node.Multiplicity = Multiplicity.ZeroToOne; } return node; }