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

Side by Side Diff: pkg/analyzer_experimental/bin/formatter.dart

Issue 23451046: Formatter stdin processing support. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 3 months 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/env dart 1 #!/usr/bin/env dart
2 2
3 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 3 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
4 // for details. All rights reserved. Use of this source code is governed by a 4 // for details. All rights reserved. Use of this source code is governed by a
5 // BSD-style license that can be found in the LICENSE file. 5 // BSD-style license that can be found in the LICENSE file.
6 6
7 import 'dart:io'; 7 import 'dart:io';
8 import 'dart:utf';
8 9
9 import 'package:args/args.dart'; 10 import 'package:args/args.dart';
10 import 'package:path/path.dart' as path; 11 import 'package:path/path.dart' as path;
11 12
12 import 'package:analyzer_experimental/src/services/formatter_impl.dart'; 13 import 'package:analyzer_experimental/src/services/formatter_impl.dart';
13 14
14 15
15 const BINARY_NAME = 'dartfmt'; 16 const BINARY_NAME = 'dartfmt';
16 final dartFileRegExp = new RegExp(r'^[^.].*\.dart$', caseSensitive: false); 17 final dartFileRegExp = new RegExp(r'^[^.].*\.dart$', caseSensitive: false);
17 final argParser = _initArgParser(); 18 final argParser = _initArgParser();
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 } 69 }
69 } catch (e) { 70 } catch (e) {
70 _log('Unable to format "${file.path}": $e'); 71 _log('Unable to format "${file.path}": $e');
71 } 72 }
72 } 73 }
73 } 74 }
74 75
75 _isDartFile(file) => dartFileRegExp.hasMatch(path.basename(file.path)); 76 _isDartFile(file) => dartFileRegExp.hasMatch(path.basename(file.path));
76 77
77 _formatStdin(options) { 78 _formatStdin(options) {
78 _log('not supported yet!'); 79 var input = new StringBuffer();
79 // stdin.transform(new StringDecoder()) 80 stdin.transform(new Utf8DecoderTransformer())
80 // .listen((String data) => print(data), 81 .listen((data) => input.write(data),
81 // onError: (error) => print('Error reading from stdin'), 82 onError: (error) => _log('Error reading from stdin'),
82 // onDone: () => print('Finished reading data')); 83 onDone: () => print(_formatCU(input.toString())));
83 } 84 }
84 85
85 /// Initialize the arg parser instance. 86 /// Initialize the arg parser instance.
86 ArgParser _initArgParser() { 87 ArgParser _initArgParser() {
87 // NOTE: these flags are placeholders only! 88 // NOTE: these flags are placeholders only!
88 var parser = new ArgParser(); 89 var parser = new ArgParser();
89 parser.addFlag('write', abbr: 'w', negatable: false, 90 parser.addFlag('write', abbr: 'w', negatable: false,
90 help: 'Write reformatted sources to files (overwriting contents). ' 91 help: 'Write reformatted sources to files (overwriting contents). '
91 'Do not print reformatted sources to standard output.'); 92 'Do not print reformatted sources to standard output.');
92 parser.addFlag('help', abbr: 'h', negatable: false, 93 parser.addFlag('help', abbr: 'h', negatable: false,
(...skipping 22 matching lines...) Expand all
115 116
116 /// Format the given [src] as a compilation unit. 117 /// Format the given [src] as a compilation unit.
117 String _formatCU(src, {options: const FormatterOptions()}) => 118 String _formatCU(src, {options: const FormatterOptions()}) =>
118 new CodeFormatter(options).format(CodeKind.COMPILATION_UNIT, src); 119 new CodeFormatter(options).format(CodeKind.COMPILATION_UNIT, src);
119 120
120 /// Log the given [msg]. 121 /// Log the given [msg].
121 _log(String msg) { 122 _log(String msg) {
122 //TODO(pquitslund): add proper log support 123 //TODO(pquitslund): add proper log support
123 print(msg); 124 print(msg);
124 } 125 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698