Skip to content

Commit 2e644e6

Browse files
committed
Fix trailing commas in json output
1 parent 1a13ea1 commit 2e644e6

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

source/diagnostics.h

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -186,37 +186,43 @@ namespace cpp2 {
186186

187187
// Print out symbol info to json
188188
o << "{\"symbols\": [";
189-
for(auto& d : diagnostics.symbols) {
189+
for(auto i = 0; auto& d : diagnostics.symbols) {
190+
++i;
190191
o
191192
<< "{ \"symbol\": \"" << d.symbol << "\", "
192193
<< "\"scope\": \"" << d.scope << "\", "
193194
<< "\"kind\": \"" << d.kind << "\", "
194195
<< "\"lineno\": " << d.position.lineno << ", "
195-
<< "\"colno\": " << d.position.colno << "}\n,";
196+
<< "\"colno\": " << d.position.colno
197+
<< (i < diagnostics.symbols.size() ? "},\n" : "}\n");
196198
}
197199

198200
// Print out error entries to json
199201
o << "],\n \"errors\": [";
200-
for(auto& e : diagnostics.errors) {
202+
for(auto i = 0; auto& e : diagnostics.errors) {
203+
++i;
201204
o
202205
<< "{\"symbol\": \"" << e.symbol << "\", "
203206
<< "\"lineno\": " << e.where.lineno << ", "
204207
<< "\"colno\": " << e.where.colno << ", "
205-
<< "\"msg\": \"" << sanitize_for_json(e.msg) << "\"}\n,";
208+
<< "\"msg\": \"" << sanitize_for_json(e.msg)
209+
<< (i < diagnostics.errors.size() ? "\"},\n" : "}\n");
206210
}
207211

208212
// Print out the our scope's source ranges as a map/object where:
209213
// keys - are the scope symbol names,
210214
// values - are their source range
211215
//
212216
o << "],\n \"scopes\": {";
213-
for(auto& s : diagnostics.scope_map) {
217+
for(auto i = 0; auto& s : diagnostics.scope_map) {
218+
++i;
214219
o
215220
<< "\"" << s.first << "\":"
216221
<< "{\"start\": { \"lineno\": " << s.second.start.lineno << ", "
217222
<< "\"colno\": " << s.second.start.colno << "},"
218223
<< "\"end\": { \"lineno\": " << s.second.end.lineno << ", "
219-
<< "\"colno\": " << s.second.end.colno << "}}\n,";
224+
<< "\"colno\": " << s.second.end.colno
225+
<< (i < diagnostics.scope_map.size() ? "}},\n" : "}}\n");
220226
}
221227

222228
o << "}}";

0 commit comments

Comments
 (0)