diff markup/template.py @ 134:d681d2c3cd8d trunk

* 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.
author cmlenz
date Sun, 06 Aug 2006 18:07:21 +0000
parents 79f445396cd7
children 8332287b5508
line wrap: on
line diff
--- a/markup/template.py
+++ b/markup/template.py
@@ -812,12 +812,13 @@
         @param offset: the column number at which the text starts in the source
             (optional)
         """
-        def _interpolate(text, patterns):
+        def _interpolate(text, patterns, filename=filename, lineno=lineno,
+                         offset=offset):
             for idx, group in enumerate(patterns.pop(0).split(text)):
                 if idx % 2:
                     try:
                         yield EXPR, Expression(group, filename, lineno), \
-                              (lineno, offset)
+                              (filename, lineno, offset)
                     except SyntaxError, err:
                         raise TemplateSyntaxError(err, filename, lineno,
                                                   offset + (err.offset or 0))
@@ -826,8 +827,14 @@
                         for result in _interpolate(group, patterns[:]):
                             yield result
                     else:
-                        yield TEXT, group.replace('$$', '$'), (filename, lineno,
-                                                               offset)
+                        yield TEXT, group.replace('$$', '$'), \
+                              (filename, lineno, offset)
+                if '\n' in group:
+                    lines = group.splitlines()
+                    lineno += len(lines) - 1
+                    offset += len(lines[-1])
+                else:
+                    offset += len(group)
         return _interpolate(text, [cls._FULL_EXPR_RE, cls._SHORT_EXPR_RE])
     _interpolate = classmethod(_interpolate)
 
Copyright (C) 2012-2017 Edgewall Software