Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(291)

Unified Diff: tools/line_doc_comments.dart

Issue 11638010: Convert /** comments to /// in pub. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Respond to review. Created 8 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | utils/pub/command_help.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/line_doc_comments.dart
diff --git a/tools/line_doc_comments.dart b/tools/line_doc_comments.dart
new file mode 100755
index 0000000000000000000000000000000000000000..aa7627cc0d977cb5161253bafe60da3e50caa50b
--- /dev/null
+++ b/tools/line_doc_comments.dart
@@ -0,0 +1,87 @@
+#!/usr/bin/env dart
+
+/// Converts block-style Doc comments in Dart code to line style.
+library line_doc_comments;
+import 'dart:io';
+
+import '../pkg/path/lib/path.dart' as path;
+
+final oneLineBlock = new RegExp(r'^(\s*)/\*\*\s?(.*)\*/\s*$');
+final startBlock = new RegExp(r'^(\s*)/\*\*(.*)$');
+final blockLine = new RegExp(r'^\s*\*\s?(.*)$');
+final endBlock = new RegExp(r'^\s*\*/\s*$');
+
+main() {
+ var args = new Options().arguments;
+ if (args.length != 1) {
+ print('Converts "/**"-style block doc comments in a directory ');
+ print('containing Dart code to "///"-style line doc comments.');
+ print('');
+ print('Usage: line_doc_coments.dart <dir>');
+ return;
+ }
+
+ var dir = new Directory(args[0]);
+ var lister = dir.list(recursive: true);
+ lister.onFile = (file) {
+ if (path.extension(file) != '.dart') return;
+ fixFile(file);
+ };
+}
+
+void fixFile(String path) {
+ var file = new File(path);
+ file.readAsLines().transform(fixContents).chain((fixed) {
+ return new File(path).writeAsString(fixed);
+ }).then((file) {
+ print(file.name);
+ });
+}
+
+String fixContents(List<String> lines) {
+ var buffer = new StringBuffer();
+ var inBlock = false;
+ var indent;
+ for (var line in lines) {
+ if (inBlock) {
+ // See if it's the end of the comment.
+ if (endBlock.hasMatch(line)) {
+ inBlock = false;
+
+ // Just a pointless line, delete it!
+ line = null;
+ } else {
+ var match = blockLine.firstMatch(line);
+ line = '$indent/// ${match[1]}';
+ }
+ } else {
+ // See if it's a one-line block comment like: /** Blah. */
+ var match = oneLineBlock.firstMatch(line);
+ if (match != null) {
+ if (match[2] != '') {
+ line = '${match[1]}/// ${match[2]}';
+ } else {
+ line = '${match[1]}///';
+ }
+ } else {
+ // See if it's the start of a block doc comment.
+ match = startBlock.firstMatch(line);
+ if (match != null) {
+ inBlock = true;
+ indent = match[1];
+ if (match[2] != '') {
+ // Got comment on /** line.
+ line = match[2];
+ } else {
+ // Just a pointless line, delete it!
+ line = null;
+ }
+ }
+ }
+ }
+
+ if (line != null) buffer.add('$line\n');
+ }
+
+ return buffer.toString();
+}
« no previous file with comments | « no previous file | utils/pub/command_help.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698