Changeset 52 for branches/pyyaml3000/lib/yaml/parser.py
- Timestamp:
- 02/20/06 12:41:45 (7 years ago)
- File:
-
- 1 edited
-
branches/pyyaml3000/lib/yaml/parser.py (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/pyyaml3000/lib/yaml/parser.py
r51 r52 21 21 # flow_sequence_entry ::= flow_node | KEY flow_node? (VALUE flow_node?)? 22 22 # 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 24 27 # Note that there is a slight deviation from the specification. We require a 25 28 # non-empty node content if ANCHOR or TAG is specified. This disallow such … … 59 62 # flow_mapping_entry: { ALIAS ANCHOR TAG SCALAR FLOW-SEQUENCE-START FLOW-MAPPING-START KEY } 60 63 61 from error import YAMLError64 from error import MarkedYAMLError 62 65 from tokens import * 63 66 from events import * 64 67 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) 68 class ParserError(MarkedYAMLError): 69 pass 83 70 84 71 class Parser: … … 169 156 if self.yaml_version is not None: 170 157 raise ParserError(None, None, 171 "found duplicate YAML directive", token.start_marker ())158 "found duplicate YAML directive", token.start_marker) 172 159 major, minor = token.value 173 160 if major != 1: 174 161 raise ParserError(None, None, 175 162 "found incompatible YAML document (version 1.* is required)", 176 token.start_marker ())163 token.start_marker) 177 164 self.yaml_version = token.value 178 165 elif token.name == u'TAG': … … 181 168 raise ParserError(None, None, 182 169 "duplicate tag handle %r" % handle.encode('utf-8'), 183 token.start_marker ())170 token.start_marker) 184 171 self.tag_handles[handle] = prefix 185 172 for key in self.DEFAULT_TAGS: … … 394 381 if self.scanner.check(FlowEntryToken): 395 382 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)400 383 token = self.scanner.get() 401 384 yield CollectionEndEvent(token.start_marker, token.end_marker)
Note: See TracChangeset
for help on using the changeset viewer.
