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
31 # Unfortunately, this gives trouble if we have a
32 # : at the end of a DW* name on input.
63 # Class is "id", "ind","other","none"
65 def insertid(self,string):
67 self._tex = list(string)
68 self._underbar = self._tex
70 self._label = self._tex
71 def setIndivid(self,c):
77 def setInitialIdChar(self,c):
80 def setNextIdChar(self,c):
83 def setInitialOther(self,c):
89 def setNextOther(self,c):
96 """ This transforms the strings from the input form into
97 the internal forms we want.
104 while int(n) < len(self._tex):
106 if n < (len (self._tex) - 1) and c == "\\" and self._tex[n+1] == "-":
109 self._underbar += [c]
113 while int(n) < len(self._underbar):
114 c = self._underbar[n]
115 if n < (len (self._underbar) - 1) and c == "\\" and self._underbar[n+1] == "_":
122 while int(n) < len(self._std):
130 def dwprintquotedshortform(self,d):
131 print "'",self.shortform(d),"'",
132 def shortform(self,d):
135 if self._class == "ind":
137 self.dwprintquotedshortform(self._tex)
140 # This prints the token with end-line oddly.
142 self.dwprintquotedshortform(self._tex)
143 self.dwprintquotedshortform(self._underbar)
144 self.dwprintquotedshortform(self._std)
145 self.dwprintquotedshortform(self._label)
147 def dwwrite(self,outfile):
152 """using an input line, create a list of tokens for the line.
153 Legal class transitions in tokenize() are:
167 def tokenize(self,rec):
168 """using an input line, create a list of tokens for the line.
169 Legal class transitions in tokenize() are:
181 if c == "\n" or c == "\r":
182 # Just drop these for now. Allowing them
183 # would not be harmful.
185 elif dwclass == "none" or dwclass == "ind":
186 if isIndivid(c) == "y":
191 if isIdStart(c) == "y":
192 combotok.setInitialIdChar(c)
196 combotok.setInitialOther(c)
199 elif dwclass == "id":
200 if isIdNext(c) == "y":
201 combotok.setNextIdChar(c)
203 if isIndivid(c) == "y":
204 combotok.finishUpId()
205 self._toks += [combotok]
212 # Other class input, other starts here.
213 combotok.finishUpId()
214 self._toks += [combotok]
216 combotok.setInitialOther(c);
219 elif dwclass == "other":
220 if isIndivid(c) == "y":
221 self._toks += [combotok]
228 if isIdStart(c) == "y":
229 self._toks += [combotok]
231 combotok.setInitialIdChar(c);
234 combotok.setNextOther(c);
236 # Else case impossible.
238 #Finish up final non-empty other or id token
240 combotok.finishUpId()
241 self._toks += [combotok]
243 if dwclass == "other":
244 self._toks += [combotok]
246 def dwprint(self,linenum):
247 print "Number of tokens in line ",linenum," : ",len(self._toks)
248 if len(self._toks) == 0:
249 #Just print an empty line.
254 def dwwrite(self, outfile, linenum):
258 def dwtransformline(self,callfunc,myfile,lnum):
259 toks = callfunc(self._toks,myfile,lnum)
264 def __init__(self,name):
270 file = open(name,"r");
271 except IOError, message:
272 print >> sys.stderr , "File could not be opened: ", name
276 rec = file.readline()
285 self._lines += [aline]
288 print "Number of lines in ", self._name, ": ",len(self._lines)
290 for l in self._lines:
294 # The lnum is just for debugging messages.
296 outname = self._name + ".out"
299 outfile = open(outname,"w");
300 except IOError, message:
301 print >> sys.stderr , "Output File could not be opened: ", name
304 for l in self._lines:
305 l.dwwrite(outfile,lnum)
307 def dwtransformline(self,callfunc,myfile):
309 for l in self._lines:
310 l.dwtransformline(callfunc,myfile,lnum)
320 def addFile(self,name):
325 print "Number of files: ",len(self._files);
326 for f in self._files:
329 for f in self._files:
331 def dwtransformline(self,callfunc):
332 for f in self._files:
333 f.dwtransformline(callfunc,f)
336 def readFilelist(filelist):