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 setIndivid(self,c):
69 def setInitialIdChar(self,c):
72 def setNextIdChar(self,c):
75 def setInitialOther(self,c):
81 def setNextOther(self,c):
88 """ This transforms the strings from the input form into
89 the internal forms we want.
96 while int(n) < len(self._tex):
98 if n < (len (self._tex) - 1) and c == "\\" and self._tex[n+1] == "-":
101 self._underbar += [c]
105 while int(n) < len(self._underbar):
106 c = self._underbar[n]
107 if n < (len (self._underbar) - 1) and c == "\\" and self._underbar[n+1] == "_":
114 while int(n) < len(self._std):
122 def dwprintquotedshortform(self,d):
123 print "'",self.shortform(d),"'",
124 def shortform(self,d):
127 if self._class == "ind":
129 self.dwprintquotedshortform(self._tex)
132 # This prints the token with end-line oddly.
134 self.dwprintquotedshortform(self._tex)
135 self.dwprintquotedshortform(self._underbar)
136 self.dwprintquotedshortform(self._std)
137 self.dwprintquotedshortform(self._label)
139 def dwwrite(self,outfile):
144 """using an input line, create a list of tokens for the line.
145 Legal class transitions in tokenize() are:
159 def tokenize(self,rec):
160 """using an input line, create a list of tokens for the line.
161 Legal class transitions in tokenize() are:
173 if c == "\n" or c == "\r":
174 # Just drop these for now. Allowing them
175 # would not be harmful.
177 elif dwclass == "none" or dwclass == "ind":
178 if isIndivid(c) == "y":
183 if isIdStart(c) == "y":
184 combotok.setInitialIdChar(c)
188 combotok.setInitialOther(c)
191 elif dwclass == "id":
192 if isIdNext(c) == "y":
193 combotok.setNextIdChar(c)
195 if isIndivid(c) == "y":
196 combotok.finishUpId()
197 self._toks += [combotok]
204 # Other class input, other starts here.
205 combotok.finishUpId()
206 self._toks += [combotok]
208 combotok.setInitialOther(c);
211 elif dwclass == "other":
212 if isIndivid(c) == "y":
213 self._toks += [combotok]
220 if isIdStart(c) == "y":
221 self._toks += [combotok]
223 combotok.setInitialIdChar(c);
226 combotok.setNextOther(c);
228 # Else case impossible.
230 #Finish up final non-empty other or id token
232 combotok.finishUpId()
233 self._toks += [combotok]
235 if dwclass == "other":
236 self._toks += [combotok]
238 def dwprint(self,linenum):
239 print "Number of tokens in line ",linenum," : ",len(self._toks)
240 if len(self._toks) == 0:
241 #Just print an empty line.
246 def dwwrite(self, outfile, linenum):
253 def __init__(self,name):
259 file = open(name,"r");
260 except IOError, message:
261 print >> sys.stderr , "File could not be opened: ", name
265 rec = file.readline()
274 self._lines += [aline]
277 print "Number of lines in ", self._name, ": ",len(self._lines)
279 for l in self._lines:
283 # The lnum is just for debugging messages.
285 outname = self._name + ".out"
288 outfile = open(outname,"w");
289 except IOError, message:
290 print >> sys.stderr , "Output File could not be opened: ", name
293 for l in self._lines:
294 l.dwwrite(outfile,lnum)
304 def addFile(self,name):
309 print "Number of files: ",len(self._files);
310 for f in self._files:
313 for f in self._files:
318 def readFilelist(filelist):