| OLD | NEW |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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 library Peg Parser; | 5 library Peg Parser; |
| 6 | 6 |
| 7 /* | 7 /* |
| 8 * The following functions are combinators for building Rules. | 8 * The following functions are combinators for building Rules. |
| 9 * | 9 * |
| 10 * A rule is one of the following | 10 * A rule is one of the following |
| (...skipping 763 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 774 // A map from position to result. Can this be replaced with something | 774 // A map from position to result. Can this be replaced with something |
| 775 // smaller? | 775 // smaller? |
| 776 // TODO: figure out how to discard the map and parseInstance after parsing. | 776 // TODO: figure out how to discard the map and parseInstance after parsing. |
| 777 Map<int,Object> map; | 777 Map<int,Object> map; |
| 778 | 778 |
| 779 _MemoRule(this._rule); | 779 _MemoRule(this._rule); |
| 780 | 780 |
| 781 _match(state, pos) { | 781 _match(state, pos) { |
| 782 // See if we are still parsing the same input. Relies on the fact that the | 782 // See if we are still parsing the same input. Relies on the fact that the |
| 783 // input is a string and strings are immutable. | 783 // input is a string and strings are immutable. |
| 784 if (parseInstance !== state._text) { | 784 if (!identical(parseInstance, state._text)) { |
| 785 map = new Map<int,Object>(); | 785 map = new Map<int,Object>(); |
| 786 parseInstance = state._text; | 786 parseInstance = state._text; |
| 787 } | 787 } |
| 788 // TODO: does this have to check or preserve parse state (like | 788 // TODO: does this have to check or preserve parse state (like |
| 789 // inWhitespaceMode, error position info etc?) | 789 // inWhitespaceMode, error position info etc?) |
| 790 // Stored result can be null (memoized failure). | 790 // Stored result can be null (memoized failure). |
| 791 if (map.containsKey(pos)) { | 791 if (map.containsKey(pos)) { |
| 792 return map[pos]; | 792 return map[pos]; |
| 793 } | 793 } |
| 794 var match = _rule.match(state, pos); | 794 var match = _rule.match(state, pos); |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 849 add(s); | 849 add(s); |
| 850 add(t); | 850 add(t); |
| 851 add(u); | 851 add(u); |
| 852 add(v); | 852 add(v); |
| 853 add(w); | 853 add(w); |
| 854 add(x); | 854 add(x); |
| 855 add(y); | 855 add(y); |
| 856 add(z); | 856 add(z); |
| 857 return list; | 857 return list; |
| 858 } | 858 } |
| OLD | NEW |