| 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 part of yaml; | 5 part of yaml; |
| 6 | 6 |
| 7 /// Translates a string of characters into a YAML serialization tree. | 7 /// Translates a string of characters into a YAML serialization tree. |
| 8 /// | 8 /// |
| 9 /// This parser is designed to closely follow the spec. All productions in the | 9 /// This parser is designed to closely follow the spec. All productions in the |
| 10 /// spec are numbered, and the corresponding methods in the parser have the same | 10 /// spec are numbered, and the corresponding methods in the parser have the same |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 165 _Parser(String s) | 165 _Parser(String s) |
| 166 : this.s = s, | 166 : this.s = s, |
| 167 len = s.length, | 167 len = s.length, |
| 168 contextStack = <String>["document"], | 168 contextStack = <String>["document"], |
| 169 errorAnnotations = new _RangeMap(); | 169 errorAnnotations = new _RangeMap(); |
| 170 | 170 |
| 171 /// Return the character at the current position, then move that position | 171 /// Return the character at the current position, then move that position |
| 172 /// forward one character. Also updates the current line and column numbers. | 172 /// forward one character. Also updates the current line and column numbers. |
| 173 int next() { | 173 int next() { |
| 174 if (pos == len) return -1; | 174 if (pos == len) return -1; |
| 175 var char = s.charCodeAt(pos++); | 175 var char = s.codeUnitAt(pos++); |
| 176 if (isBreak(char)) { | 176 if (isBreak(char)) { |
| 177 line++; | 177 line++; |
| 178 column = 0; | 178 column = 0; |
| 179 } else { | 179 } else { |
| 180 column++; | 180 column++; |
| 181 } | 181 } |
| 182 | 182 |
| 183 if (farthestLine < line) { | 183 if (farthestLine < line) { |
| 184 farthestLine = line; | 184 farthestLine = line; |
| 185 farthestColumn = column; | 185 farthestColumn = column; |
| 186 farthestContext = contextStack.last; | 186 farthestContext = contextStack.last; |
| 187 } else if (farthestLine == line && farthestColumn < column) { | 187 } else if (farthestLine == line && farthestColumn < column) { |
| 188 farthestColumn = column; | 188 farthestColumn = column; |
| 189 farthestContext = contextStack.last; | 189 farthestContext = contextStack.last; |
| 190 } | 190 } |
| 191 farthestPos = pos; | 191 farthestPos = pos; |
| 192 | 192 |
| 193 return char; | 193 return char; |
| 194 } | 194 } |
| 195 | 195 |
| 196 /// Returns the character at the current position, or the character [i] | 196 /// Returns the code unit at the current position, or the character [i] |
| 197 /// characters after the current position. | 197 /// characters after the current position. |
| 198 /// | 198 /// |
| 199 /// Returns -1 if this would return a character after the end or before the | 199 /// Returns -1 if this would return a character after the end or before the |
| 200 /// beginning of the input string. | 200 /// beginning of the input string. |
| 201 int peek([int i = 0]) { | 201 int peek([int i = 0]) { |
| 202 var peekPos = pos + i; | 202 var peekPos = pos + i; |
| 203 return (peekPos >= len || peekPos < 0) ? -1 : s.charCodeAt(peekPos); | 203 return (peekPos >= len || peekPos < 0) ? -1 : s.codeUnitAt(peekPos); |
| 204 } | 204 } |
| 205 | 205 |
| 206 /// The truthiness operator. Returns `false` if [obj] is `null` or `false`, | 206 /// The truthiness operator. Returns `false` if [obj] is `null` or `false`, |
| 207 /// `true` otherwise. | 207 /// `true` otherwise. |
| 208 bool truth(obj) => obj != null && obj != false; | 208 bool truth(obj) => obj != null && obj != false; |
| 209 | 209 |
| 210 /// Consumes the current character if it matches [matcher]. Returns the result | 210 /// Consumes the current character if it matches [matcher]. Returns the result |
| 211 /// of [matcher]. | 211 /// of [matcher]. |
| 212 bool consume(bool matcher(int)) { | 212 bool consume(bool matcher(int)) { |
| 213 if (matcher(peek())) { | 213 if (matcher(peek())) { |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 297 for (int i = 0; i < n; i++) { | 297 for (int i = 0; i < n; i++) { |
| 298 if (!consume((c) => matcher(c, i))) return false; | 298 if (!consume((c) => matcher(c, i))) return false; |
| 299 } | 299 } |
| 300 return true; | 300 return true; |
| 301 }); | 301 }); |
| 302 | 302 |
| 303 /// Consumes the exact characters in [str], or nothing. | 303 /// Consumes the exact characters in [str], or nothing. |
| 304 /// | 304 /// |
| 305 /// Returns whether or not the string was consumed. | 305 /// Returns whether or not the string was consumed. |
| 306 bool rawString(String str) => | 306 bool rawString(String str) => |
| 307 nAtOnce(str.length, (c, i) => str.charCodeAt(i) == c); | 307 nAtOnce(str.length, (c, i) => str.codeUnitAt(i) == c); |
| 308 | 308 |
| 309 /// Consumes and returns a string of characters matching [matcher], or null if | 309 /// Consumes and returns a string of characters matching [matcher], or null if |
| 310 /// there are no such characters. | 310 /// there are no such characters. |
| 311 String stringOf(bool matcher(int)) => | 311 String stringOf(bool matcher(int)) => |
| 312 captureString(() => oneOrMore(() => consume(matcher))); | 312 captureString(() => oneOrMore(() => consume(matcher))); |
| 313 | 313 |
| 314 /// Calls [consumer] and returns the string that was consumed while doing so, | 314 /// Calls [consumer] and returns the string that was consumed while doing so, |
| 315 /// or null if [consumer] returned a falsey value. Automatically wraps | 315 /// or null if [consumer] returned a falsey value. Automatically wraps |
| 316 /// [consumer] in `transaction`. | 316 /// [consumer] in `transaction`. |
| 317 String captureString(consumer()) { | 317 String captureString(consumer()) { |
| (...skipping 1612 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1930 var pair = contents[i]; | 1930 var pair = contents[i]; |
| 1931 if (pair.first.contains(pos)) return pair.last; | 1931 if (pair.first.contains(pos)) return pair.last; |
| 1932 } | 1932 } |
| 1933 return null; | 1933 return null; |
| 1934 } | 1934 } |
| 1935 | 1935 |
| 1936 /// Associates [value] with [range]. | 1936 /// Associates [value] with [range]. |
| 1937 operator[]=(_Range range, E value) => | 1937 operator[]=(_Range range, E value) => |
| 1938 contents.add(new _Pair<_Range, E>(range, value)); | 1938 contents.add(new _Pair<_Range, E>(range, value)); |
| 1939 } | 1939 } |
| OLD | NEW |