1 from match
import Match
4 """ scan for a comment block at the source file start and fill the
5 inner text into self.comment - additionally scan for the first
6 #include statement and put the includename into self.mainheader
7 (TextFileHeader re-exports all => TextFile methods for processing)"""
8 def __init__(self
, textfile
= None):
9 self
.textfile
= textfile
# TextFile
10 self
.comment
= "" # src'style
11 self
.mainheader
= "" # src'style
12 def parse(self
, textfile
= None):
13 if textfile
is not None:
14 self
.textfile
= textfile
15 if self
.textfile
is None:
18 text
= self
.textfile
.get_src_text()
20 print "nonexistant file:", self
.textfile
.get_filename()
22 if text
& x(r
"(?s)[/][*]+(\s(?:.(?!\*\/))*.)\*\/"
23 r
"(?:\s*\#(?:define|ifdef|endif)[ ]*\S*[ ]*\S*)*"
24 r
"(\s*\#include\s*<[^<>]*>(?:\s*//[^\n]*)?)"):
26 self
.mainheader
= x
[2].strip()
27 elif text
& x(r
"(?s)[/][*]+(\s(?:.(?!\*\/))*.)\*\/"):
29 elif text
& x(r
"(?s)(?:\s*\#(?:define|ifdef|endif)[ ]*\S*[ ]*\S*)*"
30 r
"(\s*\#include\s*<[^<>]*>(?:\s*//[^\n]*)?)"):
31 self
.mainheader
= x
[1].strip()
33 def src_mainheader(self
):
34 return self
.mainheader
35 def src_filecomment(self
):
37 # re-export textfile functions - allows textfileheader to be used instead
38 def get_filename(self
):
39 return self
.textfile
.get_filename()
40 def get_src_text(self
):
41 return self
.textfile
.get_src_text()
42 def get_xml_text(self
):
43 return self
.textfile
.get_src_text()
44 def line_src__text(self
, offset
):
45 return self
.textfile
.line_src_text(offset
)
46 def line_xml__text(self
, offset
):
47 return self
.textfile
.line_xml_text(offset
)