Changeset 188


Ignore:
Timestamp:
06/16/06 03:23:05 (8 years ago)
Author:
xi
Message:

Fix several problems caused by ill-formed documents.

The line number is not calculated correctly for DOS-style line breaks.

Fix error reporting in remove_possible_simple_key. The problem is caused by the document:

+foo: &A bar
+*A ]

Raise an error for a complex key which is not indented correctly, for instance:

? "foo"
 : "bar"
Location:
pyyaml/trunk
Files:
2 added
2 edited

Legend:

Unmodified
Added
Removed
  • pyyaml/trunk/lib/yaml/reader.py

    r173 r188  
    140140            self.index += 1 
    141141            if ch in u'\n\x85\u2028\u2029'  \ 
    142                     or (ch == u'\r' and self.buffer[self.pointer+1] != u'\n'): 
     142                    or (ch == u'\r' and self.buffer[self.pointer] != u'\n'): 
    143143                self.line += 1 
    144144                self.column = 0 
  • pyyaml/trunk/lib/yaml/scanner.py

    r149 r188  
    215215 
    216216        # Is it the flow entry indicator? 
    217         if ch in u',': 
     217        if ch == u',': 
    218218            return self.fetch_flow_entry() 
    219219 
    220220        # Is it the block entry indicator? 
    221         if ch in u'-' and self.check_block_entry(): 
     221        if ch == u'-' and self.check_block_entry(): 
    222222            return self.fetch_block_entry() 
    223223 
     
    326326            key = self.possible_simple_keys[self.flow_level] 
    327327             
    328             # I don't think it's possible, but I could be wrong. 
    329             assert not key.required 
    330             #if key.required: 
    331             #    raise ScannerError("while scanning a simple key", key.mark, 
    332             #            "could not found expected ':'", self.get_mark()) 
     328            if key.required: 
     329                raise ScannerError("while scanning a simple key", key.mark, 
     330                        "could not found expected ':'", self.get_mark()) 
     331 
     332            del self.possible_simple_keys[self.flow_level] 
    333333 
    334334    # Indentation functions. 
     
    588588                            "mapping values are not allowed here", 
    589589                            self.get_mark()) 
     590 
     591            # If this value starts a new block mapping, we need to add 
     592            # BLOCK-MAPPING-START.  It will be detected as an error later by 
     593            # the parser. 
     594            if not self.flow_level: 
     595                if self.add_indent(self.column): 
     596                    mark = self.get_mark() 
     597                    self.tokens.append(BlockMappingStartToken(mark, mark)) 
    590598 
    591599            # Simple keys are allowed after ':' in the block context. 
Note: See TracChangeset for help on using the changeset viewer.