OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 /** | 5 /** |
6 * Translates a string of characters into a YAML serialization tree. | 6 * Translates a string of characters into a YAML serialization tree. |
7 * | 7 * |
8 * This parser is designed to closely follow the spec. All productions in the | 8 * This parser is designed to closely follow the spec. All productions in the |
9 * spec are numbered, and the corresponding methods in the parser have the same | 9 * spec are numbered, and the corresponding methods in the parser have the same |
10 * numbers. This is certainly not the most efficient way of parsing YAML, but it | 10 * numbers. This is certainly not the most efficient way of parsing YAML, but it |
(...skipping 423 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
434 | 434 |
435 /** | 435 /** |
436 * Throws an error saying that the parse failed. Uses [farthestLine], | 436 * Throws an error saying that the parse failed. Uses [farthestLine], |
437 * [farthestColumn], and [farthestContext] to provide additional information. | 437 * [farthestColumn], and [farthestContext] to provide additional information. |
438 */ | 438 */ |
439 parseFailed() { | 439 parseFailed() { |
440 throw new SyntaxError(farthestLine + 1, farthestColumn + 1, | 440 throw new SyntaxError(farthestLine + 1, farthestColumn + 1, |
441 "invalid YAML in $farthestContext"); | 441 "invalid YAML in $farthestContext"); |
442 } | 442 } |
443 | 443 |
444 /** Returns the number of spaces after the current position. */ | 444 /** Returns the number of spaces after the current position. */ |
445 int countIndentation() { | 445 int countIndentation() { |
446 var i = 0; | 446 var i = 0; |
447 while (peek(i) == SP) i++; | 447 while (peek(i) == SP) i++; |
448 return i; | 448 return i; |
449 } | 449 } |
450 | 450 |
451 /** Returns the indentation for a block scalar. */ | 451 /** Returns the indentation for a block scalar. */ |
452 int blockScalarAdditionalIndentation(_BlockHeader header, int indent) { | 452 int blockScalarAdditionalIndentation(_BlockHeader header, int indent) { |
453 if (!header.autoDetectIndent) return header.additionalIndent; | 453 if (!header.autoDetectIndent) return header.additionalIndent; |
454 | 454 |
(...skipping 21 matching lines...) Expand all Loading... |
476 if (maxSpaces > spaces) { | 476 if (maxSpaces > spaces) { |
477 throw new SyntaxError(maxSpacesLine + 1, maxSpaces, | 477 throw new SyntaxError(maxSpacesLine + 1, maxSpaces, |
478 "Leading empty lines may not be indented more than the first " | 478 "Leading empty lines may not be indented more than the first " |
479 "non-empty line."); | 479 "non-empty line."); |
480 } | 480 } |
481 | 481 |
482 return spaces - indent; | 482 return spaces - indent; |
483 } | 483 } |
484 | 484 |
485 /** Returns whether the current position is at the beginning of a line. */ | 485 /** Returns whether the current position is at the beginning of a line. */ |
486 bool get atStartOfLine() => column == 0; | 486 bool get atStartOfLine => column == 0; |
487 | 487 |
488 /** Returns whether the current position is at the end of the input. */ | 488 /** Returns whether the current position is at the end of the input. */ |
489 bool get atEndOfFile() => pos == len; | 489 bool get atEndOfFile => pos == len; |
490 | 490 |
491 /** | 491 /** |
492 * Given an indicator character, returns the type of that indicator (or null | 492 * Given an indicator character, returns the type of that indicator (or null |
493 * if the indicator isn't found. | 493 * if the indicator isn't found. |
494 */ | 494 */ |
495 int indicatorType(int char) { | 495 int indicatorType(int char) { |
496 switch (char) { | 496 switch (char) { |
497 case HYPHEN: return C_SEQUENCE_ENTRY; | 497 case HYPHEN: return C_SEQUENCE_ENTRY; |
498 case QUESTION_MARK: return C_MAPPING_KEY; | 498 case QUESTION_MARK: return C_MAPPING_KEY; |
499 case COLON: return C_MAPPING_VALUE; | 499 case COLON: return C_MAPPING_VALUE; |
(...skipping 1392 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1892 String toString() => '($first, $last)'; | 1892 String toString() => '($first, $last)'; |
1893 } | 1893 } |
1894 | 1894 |
1895 /** The information in the header for a block scalar. */ | 1895 /** The information in the header for a block scalar. */ |
1896 class _BlockHeader { | 1896 class _BlockHeader { |
1897 final int additionalIndent; | 1897 final int additionalIndent; |
1898 final int chomping; | 1898 final int chomping; |
1899 | 1899 |
1900 _BlockHeader(this.additionalIndent, this.chomping); | 1900 _BlockHeader(this.additionalIndent, this.chomping); |
1901 | 1901 |
1902 bool get autoDetectIndent() => additionalIndent == null; | 1902 bool get autoDetectIndent => additionalIndent == null; |
1903 } | 1903 } |
OLD | NEW |