| 71 | return self._results |
| 72 | |
| 73 | def readLine(self, line): |
| 74 | #this is the inner loop |
| 75 | self._lineNo = self._lineNo + 1 |
| 76 | stripped = string.lstrip(line) |
| 77 | if len(stripped) == 0: |
| 78 | if self._mode == PLAIN: |
| 79 | self.endPara() |
| 80 | else: #preformatted, append it |
| 81 | self._buf.append(line) |
| 82 | elif line[0]=='.': |
| 83 | # we have a command of some kind |
| 84 | self.endPara() |
| 85 | words = string.split(stripped[1:]) |
| 86 | cmd, args = words[0], words[1:] |
| 87 | |
| 88 | #is it a parser method? |
| 89 | if hasattr(self.__class__, cmd): |
| 90 | method = eval('self.'+cmd) |
| 91 | #this was very bad; any type error in the method was hidden |
| 92 | #we have to hack the traceback |
| 93 | try: |
| 94 | apply(method, tuple(args)) |
| 95 | except TypeError, err: |
| 96 | sys.stderr.write("Parser method: apply(%s,%s) %s at line %d\n" % (cmd, tuple(args), err, self._lineNo)) |
| 97 | raise |
| 98 | else: |
| 99 | # assume it is a paragraph style - |
| 100 | # becomes the formatter's problem |
| 101 | self.endPara() #end the last one |
| 102 | words = string.split(stripped, ' ', 1) |
| 103 | assert len(words)==2, "Style %s but no data at line %d" % (words[0], self._lineNo) |
| 104 | (styletag, data) = words |
| 105 | self._style = styletag[1:] |
| 106 | self._buf.append(data) |
| 107 | else: |
| 108 | #we have data, add to para |
| 109 | self._buf.append(line) |
| 110 | |
| 111 | def endPara(self): |
| 112 | #ends the current paragraph, or preformatted block |