Ignore:
Timestamp:
02/20/06 12:41:45 (9 years ago)
Author:
xi
Message:

Cleanup error messages.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/pyyaml3000/lib/yaml/parser.py

    r51 r52  
    2121# flow_sequence_entry   ::= flow_node | KEY flow_node? (VALUE flow_node?)? 
    2222# flow_mapping_entry    ::= flow_node | KEY flow_node? (VALUE flow_node?)? 
    23 # 
     23 
     24# TODO: support for BOM within a stream. 
     25# stream ::= (BOM? implicit_document)? (BOM? explicit_document)* STREAM-END 
     26 
    2427# Note that there is a slight deviation from the specification. We require a 
    2528# non-empty node content if ANCHOR or TAG is specified. This disallow such 
     
    5962# flow_mapping_entry: { ALIAS ANCHOR TAG SCALAR FLOW-SEQUENCE-START FLOW-MAPPING-START KEY } 
    6063 
    61 from error import YAMLError 
     64from error import MarkedYAMLError 
    6265from tokens import * 
    6366from events import * 
    6467 
    65 class ParserError(YAMLError): 
    66  
    67     def __init__(self, context=None, context_marker=None, 
    68             problem=None, problem_marker=None): 
    69         self.context = context 
    70         self.context_marker = context_marker 
    71         self.problem = problem 
    72         self.problem_marker = problem_marker 
    73  
    74     def __str__(self): 
    75         lines = [] 
    76         for (place, marker) in [(self.context, self.context_marker), 
    77                                 (self.problem, self.problem_marker)]: 
    78             if place is not None: 
    79                 lines.append(place) 
    80                 if marker is not None: 
    81                     lines.append(str(marker)) 
    82         return '\n'.join(lines) 
     68class ParserError(MarkedYAMLError): 
     69    pass 
    8370 
    8471class Parser: 
     
    169156                if self.yaml_version is not None: 
    170157                    raise ParserError(None, None, 
    171                             "found duplicate YAML directive", token.start_marker()) 
     158                            "found duplicate YAML directive", token.start_marker) 
    172159                major, minor = token.value 
    173160                if major != 1: 
    174161                    raise ParserError(None, None, 
    175162                            "found incompatible YAML document (version 1.* is required)", 
    176                             token.start_marker()) 
     163                            token.start_marker) 
    177164                self.yaml_version = token.value 
    178165            elif token.name == u'TAG': 
     
    181168                    raise ParserError(None, None, 
    182169                            "duplicate tag handle %r" % handle.encode('utf-8'), 
    183                             token.start_marker()) 
     170                            token.start_marker) 
    184171                self.tag_handles[handle] = prefix 
    185172        for key in self.DEFAULT_TAGS: 
     
    394381            if self.scanner.check(FlowEntryToken): 
    395382                self.scanner.get() 
    396         if not self.scanner.check(FlowSequenceEndToken): 
    397             token = self.scanner.peek() 
    398             raise ParserError("while scanning a flow sequence", start_marker, 
    399                     "expected ']', but found %r" % token.id, token.start_marker) 
    400383        token = self.scanner.get() 
    401384        yield CollectionEndEvent(token.start_marker, token.end_marker) 
Note: See TracChangeset for help on using the changeset viewer.