2 # All the little classes used in storing latex source data.
3 # Copyright 2012 DWARF Debugging Information Format Committee
8 if isIndivid(c) == "y":
10 if ord(c) >= ord('a') and ord(c) <= ord('z'):
12 if ord(c) >= ord('A') and ord(c) <= ord('Z'):
14 # It is tex/latex, so backslash starts a word.
22 if isIndivid(c) == "y":
24 if ord(c) >= ord('a') and ord(c) <= ord('z'):
26 if ord(c) >= ord('A') and ord(c) <= ord('Z'):
28 if ord(c) >= ord('0') and ord(c) <= ord('9'):
30 # This is so we allow the colon in our tags
61 # Class is "id", "ind","other","none"
63 def insertid(self,string):
65 self._tex = list(string)
66 self._underbar = self._tex
68 self._label = self._tex
69 def setIndivid(self,c):
75 def setInitialIdChar(self,c):
78 def setNextIdChar(self,c):
81 def setInitialOther(self,c):
87 def setNextOther(self,c):
94 """ This transforms the strings from the input form into
95 the internal forms we want.
102 while int(n) < len(self._tex):
104 if n < (len (self._tex) - 1) and c == "\\" and self._tex[n+1] == "-":
107 self._underbar += [c]
111 while int(n) < len(self._underbar):
112 c = self._underbar[n]
113 if n < (len (self._underbar) - 1) and c == "\\" and self._underbar[n+1] == "_":
120 while int(n) < len(self._std):
128 def dwprintquotedshortform(self,d):
129 print "'",self.shortform(d),"'",
130 def shortform(self,d):
133 if self._class == "ind":
135 self.dwprintquotedshortform(self._tex)
138 # This prints the token with end-line oddly.
140 self.dwprintquotedshortform(self._tex)
141 self.dwprintquotedshortform(self._underbar)
142 self.dwprintquotedshortform(self._std)
143 self.dwprintquotedshortform(self._label)
145 def dwwrite(self,outfile):
150 """using an input line, create a list of tokens for the line.
151 Legal class transitions in tokenize() are:
165 def tokenize(self,rec):
166 """using an input line, create a list of tokens for the line.
167 Legal class transitions in tokenize() are:
179 if c == "\n" or c == "\r":
180 # Just drop these for now. Allowing them
181 # would not be harmful.
183 elif dwclass == "none" or dwclass == "ind":
184 if isIndivid(c) == "y":
189 if isIdStart(c) == "y":
190 combotok.setInitialIdChar(c)
194 combotok.setInitialOther(c)
197 elif dwclass == "id":
198 if isIdNext(c) == "y":
199 combotok.setNextIdChar(c)
201 if isIndivid(c) == "y":
202 combotok.finishUpId()
203 self._toks += [combotok]
210 # Other class input, other starts here.
211 combotok.finishUpId()
212 self._toks += [combotok]
214 combotok.setInitialOther(c);
217 elif dwclass == "other":
218 if isIndivid(c) == "y":
219 self._toks += [combotok]
226 if isIdStart(c) == "y":
227 self._toks += [combotok]
229 combotok.setInitialIdChar(c);
232 combotok.setNextOther(c);
234 # Else case impossible.
236 #Finish up final non-empty other or id token
238 combotok.finishUpId()
239 self._toks += [combotok]
241 if dwclass == "other":
242 self._toks += [combotok]
244 def dwprint(self,linenum):
245 print "Number of tokens in line ",linenum," : ",len(self._toks)
246 if len(self._toks) == 0:
247 #Just print an empty line.
252 def dwwrite(self, outfile, linenum):
256 def dwtransformline(self,callfunc):
257 toks = callfunc(self._toks)
262 def __init__(self,name):
268 file = open(name,"r");
269 except IOError, message:
270 print >> sys.stderr , "File could not be opened: ", name
274 rec = file.readline()
283 self._lines += [aline]
286 print "Number of lines in ", self._name, ": ",len(self._lines)
288 for l in self._lines:
292 # The lnum is just for debugging messages.
294 outname = self._name + ".out"
297 outfile = open(outname,"w");
298 except IOError, message:
299 print >> sys.stderr , "Output File could not be opened: ", name
302 for l in self._lines:
303 l.dwwrite(outfile,lnum)
305 def dwtransformline(self,callfunc):
306 for l in self._lines:
307 l.dwtransformline(callfunc)
316 def addFile(self,name):
321 print "Number of files: ",len(self._files);
322 for f in self._files:
325 for f in self._files:
327 def dwtransformline(self,callfunc):
328 for f in self._files:
329 f.dwtransformline(callfunc)
332 def readFilelist(filelist):