2 # Copyright (C) 2013 Hat, Inc.
4 # This library is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU Lesser General Public
6 # License as published by the Free Software Foundation; either
7 # version 2 of the License, or (at your option) any later version.
9 # This library is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 # Lesser General Public License for more details.
14 # You should have received a copy of the GNU Lesser General Public
15 # License along with this library; if not, write to the
16 # Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 # Boston, MA 02111-1307, USA.
23 class SectionsFile(object):
24 def __init__(self, sections):
25 self.sections = sections
28 class Section(object):
36 class Subsection(object):
37 def __init__(self, name):
42 def parse_sections_file(lines):
44 current_section = None
45 current_subsection = None
50 if not line or line.isspace():
53 if line == "<SECTION>":
54 current_section = Section()
55 sections.append(current_section)
56 current_subsection = Subsection(None)
57 current_section.subsections.append(current_subsection)
60 if line == "</SECTION>":
61 current_section = None
64 match = re.match(r"<FILE>(?P<contents>.*)</FILE>", line)
66 current_section.file = match.groupdict['contents']
69 match = re.match(r"<TITLE>(?P<contents>.*)</TITLE>", line)
71 current_section.title = match.groupdict['contents']
74 match = re.match(r"<INCLUDE>(?P<contents>.*)</INCLUDE>", line)
76 current_section.includes = match.groupdict['contents']
79 match = re.match(r"<SUBSECTION(?: (?P<name>.*))?>", line)
81 current_subsection = Subsection(match.groupdict.get('name', None))
82 current_section.subsections.append(current_subsection)
85 if line.startswith("<") and line.endswith(">"):
86 # Other directive to gtk-doc, not a symbol.
89 current_subsection.symbols.append(line)
91 return SectionsFile(sections)