beta-0.89.2
[luatex.git] / source / libs / zziplib / zziplib-0.13.62 / docs / zzipdoc / textfileheader.py
blob2ac0896e5fd6016a904b3bcedaba38a3f35d5708
1 from match import Match
3 class TextFileHeader:
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:
16 return False
17 x = Match()
18 text = self.textfile.get_src_text()
19 if not text:
20 print "nonexistant file:", self.textfile.get_filename()
21 return False
22 if text & x(r"(?s)[/][*]+(\s(?:.(?!\*\/))*.)\*\/"
23 r"(?:\s*\#(?:define|ifdef|endif)[ ]*\S*[ ]*\S*)*"
24 r"(\s*\#include\s*<[^<>]*>(?:\s*//[^\n]*)?)"):
25 self.comment = x[1]
26 self.mainheader = x[2].strip()
27 elif text & x(r"(?s)[/][*]+(\s(?:.(?!\*\/))*.)\*\/"):
28 self.comment = x[1]
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()
32 return True
33 def src_mainheader(self):
34 return self.mainheader
35 def src_filecomment(self):
36 return self.comment
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)