0

I know the title is really bad but to be honest my question is a bit complex and I don't even know how to get a proper title :P

First of all, I will explain my situation. I am basically creating a parser that goes through code, Regex is mostly used in it. After that, I store all the data (or that's what I am planning to) in a tree of objects.

For understanding purposes, Here is the class where I store the code parts:

Public Class CodeParts

Public _fileName As String

Public Defines As New List(Of DefinesStruct)
Public Macros As New List(Of DefinesStruct)
Public Functions As New List(Of FunctionsStruct)
Public Stocks As New List(Of FunctionsStruct)
Public Publics As New List(Of FunctionsStruct)
Public Natives As New List(Of FunctionsStruct)
Public Enums As New List(Of EnumsStruct)
Public publicVariables As New List(Of VarStruct)
Public pawnDocs As New List(Of PawnDocParser)

Public Includes As New List(Of CodeParts)

'Helper Funcs.
Public Sub IsAlreadyParsed(ByRef res As Boolean, ByVal str As String, Optional parts As CodeParts = Nothing)
    If parts Is Nothing Then parts = Me

    For Each inc In parts.Includes
        If inc._fileName = str Then res = True : Exit Sub

        If inc.Includes.Count <> 0 Then
            IsAlreadyParsed(res, str, inc)
        End If
    Next

End Sub

End Class

You can see the line where it is written:

Public Includes As New List(Of CodeParts)

Files can sometimes contain includes which goes to another file and therefore parse that file too.

And now enough explaining and lets goto the problem :P

Well basically, I need to have properties like Parent and Root

Parent will just point to the object that the current object is a child of, Like just above it. And Root will goto the main object which have the Parent as Nothing since it doesn't have a parent.

Any help greatly appreciated and if something isn't clear, Just comment below :)

Ahmad45123
  • 402
  • 1
  • 4
  • 15
  • Sounds like both Root and Parent will be a property of type CodeParts. What specifically are you not sure about? – GendoIkari Dec 08 '15 at 21:53
  • Yeah, but the thing is how to make them actually work ? – Ahmad45123 Dec 08 '15 at 21:58
  • Like do I simply set their parent and root manually during creating of the object or there is a better way ? I was thinking if there is an interface for the TreeNode ? I want a similar functionality. – Ahmad45123 Dec 08 '15 at 22:00
  • When creating your CodeParts object, set the Parent property to the CodeParts object that had the include statement that got you where you are. You could pass that parent CodeParts object in as a parameter to your parsing functions. – GendoIkari Dec 08 '15 at 22:01
  • Why wouldn't you just create a property called `Root` that takes a instance of `CodeParts` and do the same for `parent`? Then require this in your `NEW()` – Steve Dec 08 '15 at 22:01
  • 1
    Some information on creating tree structures in general: http://stackoverflow.com/questions/66893/tree-data-structure-in-c-sharp – GendoIkari Dec 08 '15 at 22:02
  • Nice, Thanks a lot.. Just to make sure, Those properties will work by reference, right ? Like when I set the property and then edit the parent, Would it change in the child ? – Ahmad45123 Dec 08 '15 at 22:05
  • It WILL actually work, Thanks a lot @Gendolkari . You may mark the question as duplicate, I guess. – Ahmad45123 Dec 08 '15 at 22:09

0 Answers0