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 library mirrors_util; | 5 library mirrors_util; |
6 | 6 |
7 // TODO(rnystrom): Use "package:" URL (#4968). | 7 // TODO(rnystrom): Use "package:" URL (#4968). |
8 import 'mirrors.dart'; | 8 import 'mirrors.dart'; |
9 | 9 |
10 //------------------------------------------------------------------------------ | 10 //------------------------------------------------------------------------------ |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
106 if (object == null) return false; | 106 if (object == null) return false; |
107 _current = object; | 107 _current = object; |
108 object = null; | 108 object = null; |
109 return true; | 109 return true; |
110 } else { | 110 } else { |
111 _current = push(queue.removeFirst()); | 111 _current = push(queue.removeFirst()); |
112 return true; | 112 return true; |
113 } | 113 } |
114 } | 114 } |
115 } | 115 } |
| 116 |
| 117 final RegExp _singleLineCommentStart = new RegExp(r'^///? ?(.*)'); |
| 118 final RegExp _multiLineCommentStartEnd = |
| 119 new RegExp(r'^/\*\*? ?([\s\S]*)\*/$', multiLine: true); |
| 120 final RegExp _multiLineCommentLineStart = new RegExp(r'^[ \t]*\* ?(.*)'); |
| 121 |
| 122 /** |
| 123 * Pulls the raw text out of a comment (i.e. removes the comment |
| 124 * characters). |
| 125 */ |
| 126 String stripComment(String comment) { |
| 127 Match match = _singleLineCommentStart.firstMatch(comment); |
| 128 if (match != null) { |
| 129 return match[1]; |
| 130 } |
| 131 match = _multiLineCommentStartEnd.firstMatch(comment); |
| 132 if (match != null) { |
| 133 comment = match[1]; |
| 134 var sb = new StringBuffer(); |
| 135 List<String> lines = comment.split('\n'); |
| 136 for (int index = 0 ; index < lines.length ; index++) { |
| 137 String line = lines[index]; |
| 138 if (index == 0) { |
| 139 sb.add(line); // Add the first line unprocessed. |
| 140 continue; |
| 141 } |
| 142 sb.add('\n'); |
| 143 match = _multiLineCommentLineStart.firstMatch(line); |
| 144 if (match != null) { |
| 145 sb.add(match[1]); |
| 146 } else if (index < lines.length-1 || !line.trim().isEmpty) { |
| 147 // Do not add the last line if it only contains white space. |
| 148 // This interprets cases like |
| 149 // /* |
| 150 // * Foo |
| 151 // */ |
| 152 // as "\nFoo\n" and not as "\nFoo\n ". |
| 153 sb.add(line); |
| 154 } |
| 155 } |
| 156 return sb.toString(); |
| 157 } |
| 158 throw new ArgumentError('Invalid comment $comment'); |
| 159 } |
OLD | NEW |