2 # All the little classes used in storing latex source data.
3 # Copyright 2012 DWARF Debugging Information Format Committee
13 if isIndivid(c) == "y":
15 if ord(c) >= ord('a') and ord(c) <= ord('z'):
17 if ord(c) >= ord('A') and ord(c) <= ord('Z'):
19 # It is tex/latex, so backslash starts a word.
27 if isIndivid(c) == "y":
29 if ord(c) >= ord('a') and ord(c) <= ord('z'):
31 if ord(c) >= ord('A') and ord(c) <= ord('Z'):
33 if ord(c) >= ord('0') and ord(c) <= ord('9'):
35 # This is so we allow the colon in our tags
36 # Unfortunately, this gives trouble if we have a
37 # : at the end of a DW* name on input.
68 # Class is "id", "ind","other","none"
70 def insertid(self,string):
72 self._tex = list(string)
73 self._underbar = self._tex
75 self._label = self._tex
76 def setIndivid(self,c):
82 def setInitialIdChar(self,c):
85 def setNextIdChar(self,c):
88 def setInitialOther(self,c):
94 def setNextOther(self,c):
100 def finishUpId(self):
101 """ This transforms the strings from the input form into
102 the internal forms we want.
109 while int(n) < len(self._tex):
111 if n < (len (self._tex) - 1) and c == "\\" and self._tex[n+1] == "-":
114 self._underbar += [c]
118 while int(n) < len(self._underbar):
119 c = self._underbar[n]
120 if n < (len (self._underbar) - 1) and c == "\\" and self._underbar[n+1] == "_":
127 while int(n) < len(self._std):
135 def dwprintquotedshortform(self,d):
136 print "'",self.shortform(d),"'",
137 def shortform(self,d):
140 if self._class == "ind":
142 self.dwprintquotedshortform(self._tex)
145 # This prints the token with end-line oddly.
147 self.dwprintquotedshortform(self._tex)
148 self.dwprintquotedshortform(self._underbar)
149 self.dwprintquotedshortform(self._std)
150 self.dwprintquotedshortform(self._label)
152 def dwwrite(self,outfile):
157 """using an input line, create a list of tokens for the line.
158 Legal class transitions in tokenize() are:
172 def tokenize(self,rec):
173 """using an input line, create a list of tokens for the line.
174 Legal class transitions in tokenize() are:
189 if keepcomments == "d" and c == "%" and ( charnum == 0 or rec[charnum - 1] != "\\" ):
190 # Not keeping comments. We drop % and following to end of line
191 # unless preceeded by \
194 if c == "\n" or c == "\r":
195 # Just drop these for now. Allowing them
196 # would not be harmful.
198 elif dwclass == "none" or dwclass == "ind":
199 if isIndivid(c) == "y":
204 if isIdStart(c) == "y":
205 combotok.setInitialIdChar(c)
209 combotok.setInitialOther(c)
212 elif dwclass == "id":
213 if isIdNext(c) == "y":
214 combotok.setNextIdChar(c)
216 if isIndivid(c) == "y":
217 combotok.finishUpId()
218 self._toks += [combotok]
225 # Other class input, other starts here.
226 combotok.finishUpId()
227 self._toks += [combotok]
229 combotok.setInitialOther(c);
232 elif dwclass == "other":
233 if isIndivid(c) == "y":
234 self._toks += [combotok]
241 if isIdStart(c) == "y":
242 self._toks += [combotok]
244 combotok.setInitialIdChar(c);
247 combotok.setNextOther(c);
249 # Else case impossible.
251 #Finish up final non-empty other or id token
253 combotok.finishUpId()
254 self._toks += [combotok]
256 if dwclass == "other":
257 self._toks += [combotok]
259 def dwprint(self,linenum):
260 print "Number of tokens in line ",linenum," : ",len(self._toks)
261 if len(self._toks) == 0:
262 #Just print an empty line.
267 def dwwrite(self, outfile, linenum):
271 def dwtransformline(self,callfunc,myfile,lnum):
272 toks = callfunc(self._toks,myfile,lnum)
277 def __init__(self,name):
283 file = open(name,"r");
284 except IOError, message:
285 print >> sys.stderr , "File could not be opened: ", name
289 rec = file.readline()
298 self._lines += [aline]
301 print "Number of lines in ", self._name, ": ",len(self._lines)
303 for l in self._lines:
307 # The lnum is just for debugging messages.
309 outname = self._name + ".out"
312 outfile = open(outname,"w");
313 except IOError, message:
314 print >> sys.stderr , "Output File could not be opened: ", name
317 for l in self._lines:
318 l.dwwrite(outfile,lnum)
320 def dwtransformline(self,callfunc,myfile):
322 for l in self._lines:
323 l.dwtransformline(callfunc,myfile,lnum)
333 def addFile(self,name):
338 print "Number of files: ",len(self._files);
339 for f in self._files:
342 for f in self._files:
344 def dwtransformline(self,callfunc):
345 for f in self._files:
346 f.dwtransformline(callfunc,f)
349 def setkeepordeletecomments(val):
350 """ Pass in "k" or "d" to keep or delete comments, respectively """
354 def readFilelist(filelist):