OLD | NEW |
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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 import 'dart:convert'; | 5 import 'dart:convert'; |
6 import 'dart:io' as io; | 6 import 'dart:io' as io; |
7 | 7 |
8 import '../lib/shared_messages.dart'; | 8 import '../lib/shared_messages.dart'; |
9 | 9 |
10 const String jsonPath = '../lib/generated/shared_messages.json'; | 10 const String jsonPath = '../lib/generated/shared_messages.json'; |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
105 if (message.howToFix != null) { | 105 if (message.howToFix != null) { |
106 out.write(",\n howToFix: ${escapeString(message.howToFix)}"); | 106 out.write(",\n howToFix: ${escapeString(message.howToFix)}"); |
107 } | 107 } |
108 if (message.options != null) { | 108 if (message.options != null) { |
109 out.write(",\n options: const ["); | 109 out.write(",\n options: const ["); |
110 out.write(message.options.map(escapeString).join(",")); | 110 out.write(message.options.map(escapeString).join(",")); |
111 out.writeln("]"); | 111 out.writeln("]"); |
112 } | 112 } |
113 if (message.examples != null) { | 113 if (message.examples != null) { |
114 out.writeln(",\n examples: const ["); | 114 out.writeln(",\n examples: const ["); |
| 115 |
| 116 String escapeExampleContent(String content) { |
| 117 if (content.contains("\n") || content.contains('"')) { |
| 118 return 'r"""\n$content"""'; |
| 119 } else if (content.contains("\\")) { |
| 120 return 'r"$content"'; |
| 121 } |
| 122 return '"$content"'; |
| 123 } |
115 for (var example in message.examples) { | 124 for (var example in message.examples) { |
116 if (example is String) { | 125 if (example is String) { |
117 out.writeln(" r'''"); | 126 out.write(" "); |
118 out.write(example); | 127 out.write(escapeExampleContent(example)); |
119 out.write("'''"); | |
120 } else if (example is Map) { | 128 } else if (example is Map) { |
121 out.writeln(" const {"); | 129 out.writeln(" const {"); |
122 example.forEach((String fileName, String content) { | 130 example.forEach((String fileName, String content) { |
123 out.writeln(" '$fileName': r'''"); | 131 out.writeln(" '$fileName': "); |
124 out.write(content); | 132 out.write(escapeExampleContent(content)); |
125 out.writeln("''',"); | 133 out.writeln(","); |
126 }); | 134 }); |
127 out.write(" }"); | 135 out.write(" }"); |
128 } | 136 } |
129 out.writeln(","); | 137 out.writeln(","); |
130 } | 138 } |
131 out.writeln(" ]"); | 139 out.writeln(" ]"); |
132 } | 140 } |
133 out.writeln(" ), // Generated. Don't edit."); | 141 out.writeln(" ), // Generated. Don't edit."); |
134 }); | 142 }); |
135 out.writeln("};"); | 143 out.writeln("};"); |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
213 /// Translates the shared messages in `../lib/shared_messages.dart` to JSON, | 221 /// Translates the shared messages in `../lib/shared_messages.dart` to JSON, |
214 /// dart2js, and analyzer formats. | 222 /// dart2js, and analyzer formats. |
215 /// | 223 /// |
216 /// Emits the json-output to [jsonPath], the dart2js-output to [dart2jsPath], | 224 /// Emits the json-output to [jsonPath], the dart2js-output to [dart2jsPath], |
217 /// and the analyzer-output to [analyzerPath]. | 225 /// and the analyzer-output to [analyzerPath]. |
218 void main() { | 226 void main() { |
219 emitJson(); | 227 emitJson(); |
220 emitDart2js(); | 228 emitDart2js(); |
221 emitAnalyzer(); | 229 emitAnalyzer(); |
222 } | 230 } |
OLD | NEW |