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/scanner.py

    r51 r52  
    1111__all__ = ['Scanner', 'ScannerError'] 
    1212 
    13 from error import YAMLError 
     13from error import MarkedYAMLError 
    1414from tokens import * 
    1515 
    16 class ScannerError(YAMLError): 
    17     # ScannerError: while reading a quoted string 
    18     #         in '...', line 5, column 10: 
    19     # key: "valu\?e" 
    20     #      ^ 
    21     # got unknown quote character '?' 
    22     #         in '...', line 5, column 15: 
    23     # key: "valu\?e" 
    24     #            ^ 
    25  
    26     def __init__(self, context=None, context_marker=None, 
    27             problem=None, problem_marker=None): 
    28         self.context = context 
    29         self.context_marker = context_marker 
    30         self.problem = problem 
    31         self.problem_marker = problem_marker 
    32  
    33     def __str__(self): 
    34         lines = [] 
    35         for (place, marker) in [(self.context, self.context_marker), 
    36                                 (self.problem, self.problem_marker)]: 
    37             if place is not None: 
    38                 lines.append(place) 
    39                 if marker is not None: 
    40                     lines.append(str(marker)) 
    41         return '\n'.join(lines) 
     16class ScannerError(MarkedYAMLError): 
     17    pass 
    4218 
    4319class SimpleKey: 
     
    197173        if ch == u'.' and self.check_document_end(): 
    198174            return self.fetch_document_end() 
     175 
     176        # TODO: support for BOM within a stream. 
     177        #if ch == u'\uFEFF': 
     178        #    return self.fetch_bom()    <-- issue BOMToken 
    199179 
    200180        # Note: the order of the following checks is NOT significant. 
     
    750730        # specification requires. Any such mark will be considered as a part 
    751731        # of the document. 
     732        # 
     733        # TODO: We need to make tab handling rules more sane. A good rule is 
     734        #   Tabs cannot precede tokens 
     735        #   BLOCK-SEQUENCE-START, BLOCK-MAPPING-START, BLOCK-END, 
     736        #   KEY(block), VALUE(block), BLOCK-ENTRY 
     737        # So the checking code is 
     738        #   if <TAB>: 
     739        #       self.allow_simple_keys = False 
     740        # We also need to add the check for `allow_simple_keys == True` to 
     741        # `unwind_indent` before issuing BLOCK-END. 
     742        # Scanners for block, flow, and plain scalars need to be modified. 
     743 
    752744        if self.reader.index == 0 and self.reader.peek() == u'\uFEFF': 
    753745            self.reader.forward() 
     
    794786        if not length: 
    795787            raise ScannerError("while scanning a directive", start_marker, 
    796                     "expected directive name, but found %r" % ch.encode('utf-8'), 
    797                     self.reader.get_marker()) 
     788                    "expected alphabetic or numeric character, but found %r" 
     789                    % ch.encode('utf-8'), self.reader.get_marker()) 
    798790        value = self.reader.prefix(length) 
    799791        self.reader.forward(length) 
    800792        ch = self.reader.peek() 
    801793        if ch not in u'\0 \r\n\x85\u2028\u2029': 
    802             raise ScannerError("while scanning a directive" % name, start_marker, 
     794            raise ScannerError("while scanning a directive", start_marker, 
    803795                    "expected alphabetic or numeric character, but found %r" 
    804796                    % ch.encode('utf-8'), self.reader.get_marker()) 
     
    812804        if self.reader.peek() != '.': 
    813805            raise ScannerError("while scanning a directive", start_marker, 
    814                     "expected a digit or '.', but found %r" % ch.encode('utf-8'), 
     806                    "expected a digit or '.', but found %r" 
     807                    % self.reader.peek().encode('utf-8'), 
    815808                    self.reader.get_marker()) 
    816809        self.reader.forward() 
     
    818811        if self.reader.peek() not in u'\0 \r\n\x85\u2028\u2029': 
    819812            raise ScannerError("while scanning a directive", start_marker, 
    820                     "expected a digit or ' ', but found %r" % ch.encode('utf-8'), 
     813                    "expected a digit or ' ', but found %r" 
     814                    % self.reader.peek().encode('utf-8'), 
    821815                    self.reader.get_marker()) 
    822816        return (major, minor) 
     
    849843        # See the specification for details. 
    850844        value = self.scan_tag_handle('directive', start_marker) 
    851         if self.reader.peek() != u' ': 
     845        ch = self.reader.peek() 
     846        if ch != u' ': 
    852847            raise ScannerError("while scanning a directive", start_marker, 
    853848                    "expected ' ', but found %r" % ch.encode('utf-8'), 
     
    903898        if not length: 
    904899            raise ScannerError("while scanning an %s" % name, start_marker, 
    905                     "expected anchor name, but found %r" % ch.encode('utf-8'), 
    906                     self.reader.get_marker()) 
     900                    "expected alphabetic or numeric character, but found %r" 
     901                    % ch.encode('utf-8'), self.reader.get_marker()) 
    907902        value = self.reader.prefix(length) 
    908903        self.reader.forward(length) 
     
    924919            suffix = self.scan_tag_uri('tag', start_marker) 
    925920            if self.reader.peek() != u'>': 
    926                 raise ScannerError("while parsing a tag", start_marking, 
    927                         "expected '>', but got %r" % self.reader.peek().encode('utf-8'), 
     921                raise ScannerError("while parsing a tag", start_marker, 
     922                        "expected '>', but found %r" % self.reader.peek().encode('utf-8'), 
    928923                        self.reader.get_marker()) 
    929924            self.reader.forward() 
     
    13101305        # For some strange reasons, the specification does not allow '_' in 
    13111306        # tag handles. I have allowed it anyway. 
    1312         if self.reader.peek() != u'!': 
     1307        ch = self.reader.peek() 
     1308        if ch != u'!': 
    13131309            raise ScannerError("while scanning a %s" % name, start_marker, 
    13141310                    "expected '!', but found %r" % ch.encode('utf-8'), 
Note: See TracChangeset for help on using the changeset viewer.