Commits

Henry Vieira committed 78a3f96

Added support to parse class members in containers

- Added another parse expression for parse_class_members()
- Added the container spec to a class references
- The current code is still very ugly (more now) and needs changes

Signed-off-by: Henry Vieira <hsvieira@yahoo.com>

  • Participants
  • Parent commits 583651b

Comments (0)

Files changed (2)

                     print '    "%s" -> "%s"' % (base_class, class_.get_name())
 
             if class_.references:
-                print '''    edge [
+                print '''
+        edge [
             dir = "forward"
             arrowhead = "vee"
             arrowtail = "none"
 
             for ref in class_.references:
                 if context.has_class_by_name(ref[0]) and ref[0] not in exclude_classes:
-                    print '    "%s" -> "%s" [ label="%s" fontsize = 7 ]' % (class_.get_name(), ref[0], ref[1])
+                    print '    "%s" -> "%s" [ label="%s%s" fontsize = 7 ]' % (class_.get_name(), ref[0], ref[1], ' contained in ' + ref[2])
 
     print '}'
 
     return class_specifier.scanString(source_code)
 
 # class members
-member_declaration = identifier('type') + Optional(Literal('*')) + Group(delimitedList(identifier))('members') + StringEnd()
-
 m = SkipTo(';') + Literal(';')
 member_specification = Literal('!') + Group(ZeroOrMore(Optional(access_specifier + Literal(':')) + m('decla')))('declaration')
 
+member_declaration_1 = identifier('type') + Optional(Literal('*')) + Group(delimitedList(identifier))('members') + StringEnd()
+
+content = Forward()
+container = Group(identifier.copy())('containers')
+c = Group(identifier + Optional('*'))('types') ^ content
+content << container + Literal('<') + delimitedList(c) + Literal('>') + Optional('*')
+member_declaration_2 = content + Group(delimitedList(identifier))('members') + StringEnd()
+
+containers = []
+
+def a(s,loc,toks):
+    global containers
+
+    containers.append(toks[0])
+
+container.setParseAction(a)
+
 def parse_class_members(source_code):
+    global containers
+
     mem = []
 
     source_code = remove_inline_class_def(source_code[1:-1])
             for i in m[0].declaration:
                 if i and i != ':' and i != ';':
                     try:
-                        p = member_declaration.parseString(i.strip())
+                        p = member_declaration_1.parseString(i.strip())
                         mem.append([])
                         mem[-1].append(p.type)
                         mem[-1].append([])
                         for j in p.members:
                             mem[-1][-1].append(j)
+                        mem[-1].append('')
                     except ParseException:
-                        pass # member declaration was not recgonized
+                            containers = []
+
+                            try:
+                                p = member_declaration_2.parseString(i.strip())
+
+                                c = ''
+                                for j in containers:
+                                    c += j[0] + '<'
+                                c += '>' * len(containers)
+
+                                for j in p.types:
+
+                                    mem.append([])
+                                    mem[-1].append(j)
+                                    mem[-1].append([])
+
+                                    if j != '*':
+                                        for k in p.members:
+                                            mem[-1][-1].append(k)
+
+                                    mem[-1].append(c)
+                            except ParseException:
+                                pass # member declaration was not recognized
 
     return mem