Edgewall Software

Changeset 171 for trunk/markup/input.py


Ignore:
Timestamp:
Aug 6, 2006, 8:07:21 PM (17 years ago)
Author:
cmlenz
Message:
  • Improve the accuracy of line numbers for text nodes, so that reported errors about syntax or evaluation errors in expressions point to the right line (not quite perfect yet, though).
  • Evaluation errors in expressions now include the original expression code in the traceback.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/markup/input.py

    r74 r171  
    110110        if pos is None:
    111111            pos = self._getpos()
     112        if kind is Stream.TEXT:
     113            # Expat reports the *end* of the text event as current position. We
     114            # try to fix that up here as much as possible. Unfortunately, the
     115            # offset is only valid for single-line text. For multi-line text,
     116            # it is apparently not possible to determine at what offset it
     117            # started
     118            if '\n' in data:
     119                lines = data.splitlines()
     120                lineno = pos[1] - len(lines) + 1
     121                offset = -1
     122            else:
     123                lineno = pos[1]
     124                offset = pos[2] - len(data)
     125            pos = (pos[0], lineno, offset)
    112126        self._queue.append((kind, data, pos))
    113127
    114128    def _getpos_unknown(self):
    115         return (self.filename or '<string>', -1, -1)
     129        return (self.filename, -1, -1)
    116130
    117131    def _getpos(self):
    118         return (self.filename or '<string>', self.expat.CurrentLineNumber,
     132        return (self.filename, self.expat.CurrentLineNumber,
    119133                self.expat.CurrentColumnNumber)
    120134
Note: See TracChangeset for help on using the changeset viewer.