wisp
 
(Arne Babenhauserheide)
2013-08-10: throw an exception when reducing indentation to an unknown

throw an exception when reducing indentation to an unknown indentation level.

diff --git a/.bugs/bugs b/.bugs/bugs
--- a/.bugs/bugs
+++ b/.bugs/bugs
@@ -1,5 +1,5 @@
 fails when I add stuff at the end of end of example.w        | owner:, open:False, id:08c68e1ce0c9798184c01806d2661a3220bff3cd, time:1363789693.79
-throw an exception when reducing indentation to an unknown indentation level. | owner:Arne Babenhauserheide <bab@draketo.de>, open:True, id:424186bd85f186b7279c5c59e2bd42f847284719, time:1376003568.91
+throw an exception when reducing indentation to an unknown indentation level. | owner:Arne Babenhauserheide <bab@draketo.de>, open:False, id:424186bd85f186b7279c5c59e2bd42f847284719, time:1376003568.91
 implement wisp in wisp                                       | owner:Arne Babenhauserheide <bab@draketo.de>, open:True, id:6299306916706410702029289bf32edab1e7f17c, time:1367113341.49
 inline ' : should be '(                                      | owner:Arne Babenhauserheide <bab@draketo.de>, open:False, id:72d534a8b23b4cb168017f1bb7d8816f0ea170c4, time:1366497335.26
 make this work: let : : origfile ( open-file : nth 1 : command-line ) r | owner:Arne Babenhauserheide <bab@draketo.de>, open:False, id:d6de2074a5017f1f29f34d142ce797981ed270a0, time:1366529287.67
diff --git a/wisp-guile.w b/wisp-guile.w
--- a/wisp-guile.w
+++ b/wisp-guile.w
@@ -212,7 +212,7 @@ let*
     ; display text
     set! lines : call-with-input-string text splitlines
     set! lines : linestoindented lines
-    display : list-ref lines 100
+    display : list-ref lines 0
 
 
 newline
diff --git a/wisp.py b/wisp.py
--- a/wisp.py
+++ b/wisp.py
@@ -75,6 +75,10 @@ def replaceinwisp(code, string, replacem
     return code, count
 
 
+class UndefinedIndentationLevel(IndentationError):
+    """Unindent does not match any outer indentation level."""
+
+
 class Line:
     def __init__(self, line):
         """Parse one line in which linebreaks within strings and
@@ -249,7 +253,8 @@ def nobracketbreaks(code):
 def processlines(lines, prev, codestartindex, levels, lisplines, emptylines):
     """Process all lines after the first."""
     # process further lines: adjust the content of the current line, but only append 
-    for line in lines[codestartindex+1:]:
+    for n, line in enumerate(lines[codestartindex+1:]):
+        n += codestartindex + 1
         # ignore empty lines and comment-only lines
         if line.empty:
             # simply keep empty lines and ignore their indentation
@@ -279,6 +284,8 @@ def processlines(lines, prev, codestarti
         # lower indent: parent funtion or variable. Find the number of brackets to close
         if prev.indent > line.indent:
             bracketstoclose = len([level for level in levels if level >= line.indent])
+            if not line.indent in levels[-bracketstoclose:]:
+                raise UndefinedIndentationLevel("Unindent of line " + str(n) + " does not match any outer indentation level.\n" + line.indent*" " + "|\n" + line.indent*" " + "v\n" + line.indent*" " + line.content)
             levels = levels[:-bracketstoclose + 1]
             if prev.continues:
                 bracketstoclose -= 1