Changeset 3502:407376a6a538 in livinglogic.python.xist

Show
Ignore:
Timestamp:
07/14/08 18:42:27 (11 years ago)
Author:
Walter Doerwald <walter@…>
Branch:
default
Tags:
rel-3-3-1
Message:

For "unclosed block" errors, include the location of the start of the block in the exception.

Files:
4 modified

Legend:

Unmodified
Added
Removed
  • NEWS.rst

    r3497 r3502  
     1Changes in 3.3.1 (released 07/14/2008) 
     2-------------------------------------- 
     3 
     4*   Fixed a bug in the implementation of the "not" operator in UL4. 
     5 
     6*   When the ``UL4`` compiler encounters unclosed blocks, it will now include 
     7    the start location of the block in the error message. 
     8 
     9 
    110Changes in 3.3 (released 07/11/2008) 
    211------------------------------------ 
  • setup.py

    r3472 r3502  
    211211args = dict( 
    212212    name="ll-xist", 
    213     version="3.3", 
     213    version="3.3.1", 
    214214    description="Extensible HTML/XML generator", 
    215215    long_description=descr, 
  • src/ll/ul4c.py

    r3500 r3502  
    11451145        # This stack stores for each nested for/foritem/if/elif/else the following information: 
    11461146        # 1) Which construct we're in (i.e. "if" or "for") 
     1147        # 2) The start location of the construct 
    11471148        # For ifs: 
    1148         # 2) How many if's or elif's we have seen (this is used for simulating elif's via nested if's, for each additional elif, we have one more endif to add) 
    1149         # 3) Whether we've already seen the else 
     1149        # 3) How many if's or elif's we have seen (this is used for simulating elif's via nested if's, for each additional elif, we have one more endif to add) 
     1150        # 4) Whether we've already seen the else 
    11501151        stack = [] 
    11511152 
     
    11661167                    r = parseexpr(self) 
    11671168                    self.opcode("if", r1=r) 
    1168                     stack.append(("if", 1, False)) 
     1169                    stack.append(("if", location, 1, False)) 
    11691170                elif location.type == "elif": 
    11701171                    if not stack or stack[-1][0] != "if": 
    11711172                        raise BlockError("elif doesn't match any if") 
    1172                     elif stack[-1][2]: 
     1173                    elif stack[-1][3]: 
    11731174                        raise BlockError("else already seen in elif") 
    11741175                    self.opcode("else") 
    11751176                    r = parseexpr(self) 
    11761177                    self.opcode("if", r1=r) 
    1177                     stack[-1] = ("if", stack[-1][1]+1, False) 
     1178                    stack[-1] = ("if", stack[-1][1], stack[-1][2]+1, False) 
    11781179                elif location.type == "else": 
    11791180                    if not stack or stack[-1][0] != "if": 
    11801181                        raise BlockError("else doesn't match any if") 
    1181                     elif stack[-1][2]: 
     1182                    elif stack[-1][3]: 
    11821183                        raise BlockError("duplicate else") 
    11831184                    self.opcode("else") 
    1184                     stack[-1] = ("if", stack[-1][1], True) 
     1185                    stack[-1] = ("if", stack[-1][1], stack[-1][2], True) 
    11851186                elif location.type == "end": 
    11861187                    if not stack: 
     
    11981199                    last = stack.pop() 
    11991200                    if last[0] == "if": 
    1200                         for i in xrange(last[1]): 
     1201                        for i in xrange(last[2]): 
    12011202                            self.opcode("endif") 
    12021203                    else: # last[0] == "for": 
     
    12041205                elif location.type == "for": 
    12051206                    parsefor(self) 
    1206                     stack.append(("for",)) 
     1207                    stack.append(("for", location)) 
    12071208                elif location.type == "break": 
    12081209                    if not any(entry[0] == "for" for entry in stack): 
     
    12251226                del self.location 
    12261227        if stack: 
    1227             raise BlockError("unclosed blocks") 
     1228            raise BlockError("block unclosed").decorate(stack[-1][1]) 
    12281229 
    12291230    def __str__(self): 
  • test/test_ul4.py

    r3501 r3502  
    290290 
    291291def test_block_errors(): 
    292     checkcompileerror("unclosed blocks", '<?for x in data?>') 
     292    checkcompileerror("in .<.for x in data.>..*block unclosed", '<?for x in data?>') 
    293293    checkcompileerror("endif doesn't match any if", '<?for x in data?><?end if?>') 
    294294    checkcompileerror("not in any block", '<?end?>') 
     
    296296    checkcompileerror("not in any block", '<?end if?>') 
    297297    checkcompileerror("else doesn't match any if", '<?else?>') 
    298     checkcompileerror("unclosed blocks", '<?if data?>') 
    299     checkcompileerror("unclosed blocks", '<?if data?><?else?>') 
     298    checkcompileerror("in .<.if data.>..*block unclosed", '<?if data?>') 
     299    checkcompileerror("in .<.if data.>..*block unclosed", '<?if data?><?else?>') 
    300300    checkcompileerror("duplicate else", '<?if data?><?else?><?else?>') 
    301301    checkcompileerror("else already seen in elif", '<?if data?><?else?><?elif data?>')