private FilePositionItem GetVarValueFromType(PowerBuilderFileType powerBuilderFileType, string text, FileClass fileClass, string varRegex) { string textInstanceRange = fileClass.Text.Substring(powerBuilderFileType.IndexStart, powerBuilderFileType.IndexInstanceVarEnd - powerBuilderFileType.IndexStart); Match match = Regex.Match(textInstanceRange, varRegex, RegexOptions.ExplicitCapture); if (match.Success) { string dataObjectSource = match.Groups["dataobj"].Value; return(new FilePositionItem() { LineNumberStart = MainEngine.Instance.GetTextLineByCharIndex(powerBuilderFileType.IndexStart + match.Groups["dataobj"].Index), ItemType = "Variable", Name = dataObjectSource }); } return(null); }
private string GetNodeTargetText(bool useInheritFrom) { if (treeView1.SelectedNode == null) { return(null); } PowerBuilderFileType powerBuilderFileType = treeView1.SelectedNode.Tag as PowerBuilderFileType; string textToSearch = ""; if (powerBuilderFileType == null) { var filePositionItem = treeView1.SelectedNode.Tag as FilePositionItem; if (filePositionItem != null && filePositionItem.ItemType == "DataObjectSource") { textToSearch = filePositionItem.Name; } if (filePositionItem != null && filePositionItem.ItemType == "function") { textToSearch = filePositionItem.Name; } if (filePositionItem != null && filePositionItem.ItemType == "event") { textToSearch = filePositionItem.Name; } if (filePositionItem != null && filePositionItem.ItemType == "dddw") { textToSearch = filePositionItem.Name; } } else { if (useInheritFrom == true && powerBuilderFileType.Name.ToLower().StartsWith("u")) { textToSearch = powerBuilderFileType.InheritFrom; } else { textToSearch = powerBuilderFileType.Name; } } return(textToSearch); }
public void AnalayzeFileForTypes(FileClass fileClass) { string text = fileClass.Text; try { //return; // var regex = new Regex(@"^event\s*(?<eventname>\w+)\s*(\((?<params>.*?)\))?;.*", RegexOptions.Multiline); // MatchCollection matchCollection = regex.Matches(text); //var test = Regex.Matches(text, @"(?<=event)\s*(?<eventname>\w+)\s*\((?<params>.+?)\);(.+?)(?=end event)", RegexOptions.Multiline); FillRnCounts(text); Match matchEndFarword = Regex.Match(text, "end forward", RegexOptions.ExplicitCapture, TimeSpan.FromSeconds(5)); int indexEndFarword = matchEndFarword.Groups[0].Index; string typeListRegex = @"(?si)[\n](global\s+type|type)+\s+(?<typename>\w+)\s+from\s+(?<inferitfrom>\w+)(\s+within\s+\w+)?(?<instatncevars>.*?)(?<endtype>end type)"; MatchCollection matchCollection = Regex.Matches(text, typeListRegex, RegexOptions.ExplicitCapture, TimeSpan.FromSeconds(5)); // Find Types PowerBuilderFileType fileType = null; fileClass.PowerBuilderFileTypes = new List <PowerBuilderFileType>(); foreach (Match matchType in matchCollection) { if (indexEndFarword > matchType.Groups[1].Index) { continue; } if (fileType != null) { fileType.IndexEnd = matchType.Groups[1].Index; fileType.LineNumberEnd = GetTextLineByCharIndex(fileType.IndexEnd); } //New type fileType = new PowerBuilderFileType(); fileType.Name = matchType.Groups["typename"].Value; fileType.InheritFrom = matchType.Groups["inferitfrom"].Value; fileType.IndexInstanceVarStart = matchType.Groups[3].Index; fileType.IndexStart = matchType.Groups[1].Index; fileType.IndexInstanceVarEnd = matchType.Groups["endtype"].Index; fileType.LineNumberStart = GetTextLineByCharIndex(fileType.IndexStart); fileType.LineNumberInstanceVarsEnd = GetTextLineByCharIndex(fileType.IndexInstanceVarEnd); fileClass.PowerBuilderFileTypes.Add(fileType); //Find Instance Vars if (matchType.Groups[3].Length > 5) { // } } string eventListRegex = @"(?si)([\n]event|^event)(.*?)(?<eventname>\w+)\s*(\((?<params>.*?)\))?;(?<body>.*?)(?<endevent>([\n]e|^e)nd event)"; foreach (var powerBuilderFileType in fileClass.PowerBuilderFileTypes) { int length = powerBuilderFileType.IndexEnd - powerBuilderFileType.IndexInstanceVarEnd; if (length < 0) { length = text.Length - powerBuilderFileType.IndexInstanceVarEnd; } var subText = text.Substring(powerBuilderFileType.IndexInstanceVarEnd, length); matchCollection = Regex.Matches(subText, eventListRegex, RegexOptions.ExplicitCapture, TimeSpan.FromSeconds(5)); foreach (Match eventMatch in matchCollection) { var filePositionItem = new FilePositionItem(); filePositionItem.Name = eventMatch.Groups[1].Value; filePositionItem.ItemType = "event"; filePositionItem.ItemParameters = eventMatch.Groups[2].Value; filePositionItem.IndexItemStart = eventMatch.Groups[1].Index + powerBuilderFileType.IndexInstanceVarEnd; filePositionItem.IndexItemEnd = eventMatch.Groups[4].Index + powerBuilderFileType.IndexInstanceVarEnd; filePositionItem.IsHasCode = eventMatch.Groups[3].Length > 5; filePositionItem.LineNumberStart = GetTextLineByCharIndex(filePositionItem.IndexItemStart); filePositionItem.LineNumberEnd = GetTextLineByCharIndex(filePositionItem.IndexItemEnd); powerBuilderFileType.Events.Add(filePositionItem); } } if (fileClass.PowerBuilderFileTypes.Count > 0) { string functionListRegex = @"(?si)([\n](public|private|protected)(\sfunction)?|^(public|private|protected)(\sfunction)?)\s*(?<functype>\w+)\s*(?<functname>\w+)\s*(\((?<params>[^\)]*?)\));+(?<body>.*?)(?<endfunct>end(\sfunction|\ssubroutine))"; // string functionListRegex = @"(?si)([\n](public|private)(\sfunction)?|^(public|private)(\sfunction)?)\s*(?<functype>\w+)\s*(?<functname>\w+)\s*(\((?<params>[^)]*?)\));+(?<body>.*?)(?<endfunct>end(\sfunction|\ssubroutine))"; //var powerBuilderFileType = fileClass.PowerBuilderFileTypes.FirstOrDefault(); foreach (var powerBuilderFileType in fileClass.PowerBuilderFileTypes) { int length = powerBuilderFileType.IndexEnd - powerBuilderFileType.IndexInstanceVarEnd; if (length < 0) { length = text.Length - powerBuilderFileType.IndexInstanceVarEnd; } var subText = text.Substring(powerBuilderFileType.IndexInstanceVarEnd, length); matchCollection = Regex.Matches(subText, functionListRegex, RegexOptions.ExplicitCapture, TimeSpan.FromSeconds(5)); foreach (Match eventMatch in matchCollection) { var filePositionItem = new FilePositionItem(); filePositionItem.Name = eventMatch.Groups[2].Value; filePositionItem.ReturnType = eventMatch.Groups[1].Value; filePositionItem.ItemType = "function"; filePositionItem.ItemParameters = eventMatch.Groups[3].Value; filePositionItem.IndexItemStart = eventMatch.Groups[2].Index + powerBuilderFileType.IndexInstanceVarEnd; filePositionItem.IndexItemEnd = eventMatch.Groups[5].Index + powerBuilderFileType.IndexInstanceVarEnd; filePositionItem.IsHasCode = eventMatch.Groups[4].Length > 5; filePositionItem.LineNumberStart = GetTextLineByCharIndex(filePositionItem.IndexItemStart); filePositionItem.LineNumberEnd = GetTextLineByCharIndex(filePositionItem.IndexItemEnd); powerBuilderFileType.Functions.Add(filePositionItem); } } } _rnCounts = null; } catch (Exception e) { MessageBox.Show(e.Message); } }