Skip to content

Commit bc95f87

Browse files
authored
2 newlines at the end of terminal report for now (rescript-lang#93)
2 newlines turn into 1 inside bsb. Not sure why. Format is temporary, so this'll do until we remove it completely.
1 parent 0b798c4 commit bc95f87

File tree

11 files changed

+154
-110
lines changed

11 files changed

+154
-110
lines changed

syntax/src/napkin_diagnostics.ml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -136,14 +136,12 @@ let explain t =
136136
end
137137

138138
let toString t src =
139-
let ppf = Format.err_formatter in
140139
Napkin_diagnostics_printing_utils.Super_location.super_error_reporter
141-
ppf
140+
Format.err_formatter
142141
~src
143142
~startPos:t.startPos
144143
~endPos:t.endPos
145-
~msg:(explain t);
146-
Format.pp_print_flush ppf ()
144+
~msg:(explain t)
147145

148146
let make ~startPos ~endPos category = {
149147
startPos;
@@ -152,7 +150,9 @@ let make ~startPos ~endPos category = {
152150
}
153151

154152
let printReport diagnostics src =
155-
List.rev diagnostics |> List.iter (fun d -> toString d src)
153+
Format.fprintf Format.err_formatter "@[<v>";
154+
List.rev diagnostics |> List.iter (fun d -> toString d src);
155+
Format.fprintf Format.err_formatter "@]@."
156156

157157
let unexpected token context =
158158
Unexpected {token; context}

syntax/src/napkin_diagnostics_printing_utils.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,6 @@ let print src startPos endPos ppf () =
229229
let super_error_reporter ppf ~src ~startPos ~endPos ~msg =
230230
setup_colors ();
231231
(* open a vertical box. Everything in our message is indented 2 spaces *)
232-
Format.fprintf ppf "@[<v 2>@,%a@,%s@,@]" (print src startPos endPos) () msg;
232+
Format.fprintf ppf "@[<v 2>@,%a@,%s@]@," (print src startPos endPos) () msg;
233233

234234
end

syntax/tests/parsing/errors/expressions/__snapshots__/parse.spec.js.snap

Lines changed: 41 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ let x = ((let a = 1 in let b = 2 in fun pattern -> (\\"test\\" : int))
1717
1) (b): int => \\"hi\\"
1818
2) (b: int) => \\"hi\\"
1919
20-
20+
2121
Syntax error!
2222
parsing/errors/expressions/ambiguousArrow.js 6:3-23
2323
4let a = 1
@@ -30,7 +30,8 @@ let x = ((let a = 1 in let b = 2 in fun pattern -> (\\"test\\" : int))
3030
1) (pattern): int => \\"test\\"
3131
2) (pattern: int) => \\"test\\"
3232
33-
33+
34+
3435
========================================================"
3536
`;
3637

@@ -46,7 +47,8 @@ let xs = x.map (fun key -> [|key;(predicates.(key))|])
4647
3 │
4748
4849
Did you forget a \`]\` here?
49-
50+
51+
5052
========================================================"
5153
`;
5254

@@ -64,7 +66,8 @@ exports[`arrow.js 1`] = `
6466
3let b = 2
6567
6668
Did you forget a \`,\` here?
67-
69+
70+
6871
========================================================"
6972
`;
7073
@@ -104,7 +107,7 @@ let pipeline =
104107
17 │ let x = {
105108
106109
Did you forget a \`)\` here?
107-
110+
108111
Syntax error!
109112
parsing/errors/expressions/block.js 18:25-19:1
110113
16 │
@@ -115,7 +118,7 @@ let pipeline =
115118
21switch stack {
116119
117120
Did you forget a \`)\` here?
118-
121+
119122
Syntax error!
120123
parsing/errors/expressions/block.js 22:11-23:1
121124
20 │
@@ -126,7 +129,7 @@ let pipeline =
126129
25 │ buffer->Buffer.add_string(indentation)
127130
128131
Looks like there might be an expression missing here
129-
132+
130133
Syntax error!
131134
parsing/errors/expressions/block.js 26:7-27:1
132135
24 │ | Join(doc1, doc2) =>
@@ -137,7 +140,7 @@ let pipeline =
137140
29 │ let pipeline = switch scheduler {
138141
139142
Did you forget a \`)\` here?
140-
143+
141144
Syntax error!
142145
parsing/errors/expressions/block.js 30:10-31:1
143146
28 │
@@ -148,7 +151,8 @@ let pipeline =
148151
33 │
149152
150153
Looks like there might be an expression missing here
151-
154+
155+
152156
========================================================"
153157
`;
154158
@@ -168,7 +172,7 @@ let () = ((let open Foo in let exception End in x ())[@ns.braces ])
168172
3 │ let f = (g, h) => {
169173
170174
consecutive statements on a line must be separated by ';' or a newline
171-
175+
172176
Syntax error!
173177
parsing/errors/expressions/consecutive.res 4:7
174178
2
@@ -178,7 +182,7 @@ let () = ((let open Foo in let exception End in x ())[@ns.braces ])
178182
6
179183
180184
consecutive expressions on a line must be separated by ';' or a newline
181-
185+
182186
Syntax error!
183187
parsing/errors/expressions/consecutive.res 8:16-27
184188
6
@@ -188,7 +192,7 @@ let () = ((let open Foo in let exception End in x ())[@ns.braces ])
188192
10
189193
190194
consecutive expressions on a line must be separated by ';' or a newline
191-
195+
192196
Syntax error!
193197
parsing/errors/expressions/consecutive.res 12:11-20
194198
10
@@ -198,7 +202,8 @@ let () = ((let open Foo in let exception End in x ())[@ns.braces ])
198202
14 │ }
199203
200204
consecutive expressions on a line must be separated by ';' or a newline
201-
205+
206+
202207
========================================================"
203208
`;
204209
@@ -215,7 +220,7 @@ let f a b = ((())[@ns.braces ])
215220
3 │ let f = (a, b) => {}
216221
217222
This let-binding misses an expression
218-
223+
219224
Syntax error!
220225
parsing/errors/expressions/emptyBlock.js 3:20
221226
1 │ let x = {}
@@ -224,7 +229,8 @@ let f a b = ((())[@ns.braces ])
224229
4 │
225230
226231
Missing expression
227-
232+
233+
228234
========================================================"
229235
`;
230236
@@ -242,7 +248,8 @@ exports[`if.js 1`] = `
242248
5 │ }
243249
244250
Did you forget a \`{\` here?
245-
251+
252+
246253
========================================================"
247254
`;
248255
@@ -272,7 +279,7 @@ switch result {
272279
| _ => ()
273280
}
274281
275-
282+
276283
Syntax error!
277284
parsing/errors/expressions/ifLet.res 7:8-11:1
278285
5 │ if let Error(x) = result {
@@ -291,7 +298,8 @@ switch result {
291298
| _ => ()
292299
}
293300
294-
301+
302+
295303
========================================================"
296304
`;
297305
@@ -306,7 +314,8 @@ let x = ([%napkinscript.exprhole ]) + 1
306314
2 │
307315
308316
\`_\` isn't a valid name.
309-
317+
318+
310319
========================================================"
311320
`;
312321
@@ -326,7 +335,7 @@ let record = { field = ([%napkinscript.exprhole ]) }
326335
5 │
327336
328337
Did you forget a \`,\` here?
329-
338+
330339
Syntax error!
331340
parsing/errors/expressions/record.js 8:10-18
332341
6 │
@@ -336,7 +345,7 @@ let record = { field = ([%napkinscript.exprhole ]) }
336345
10}
337346
338347
Did you forget a \`:\` here?
339-
348+
340349
Syntax error!
341350
parsing/errors/expressions/record.js 13:9-17:0
342351
11 │
@@ -348,7 +357,8 @@ let record = { field = ([%napkinscript.exprhole ]) }
348357
17 │
349358
350359
Missing expression
351-
360+
361+
352362
========================================================"
353363
`;
354364
@@ -370,7 +380,8 @@ exports[`setField.js 1`] = `
370380
7}
371381
372382
It seems that this record field mutation misses an expression
373-
383+
384+
374385
========================================================"
375386
`;
376387
@@ -385,7 +396,8 @@ exports[`taggedTemplateLiterals.js 1`] = `
385396
2 │
386397
387398
Tagged template literals are currently restricted to identifiers like: json\`null\`.
388-
399+
400+
389401
========================================================"
390402
`;
391403
@@ -402,7 +414,8 @@ let parsedPayload = try Js.Json.parseExn response with | _ -> Js.Json.null
402414
4}
403415
404416
Did you forget a \`catch\` here?
405-
417+
418+
406419
========================================================"
407420
`;
408421
@@ -423,7 +436,7 @@ let x = (\\"hi\\" : string)
423436
Expressions with type constraints need to be wrapped in parens:
424437
(a + b: int)
425438
426-
439+
427440
Syntax error!
428441
parsing/errors/expressions/unexpectedConstraint.js 7:9-20
429442
5 │ }
@@ -434,6 +447,7 @@ let x = (\\"hi\\" : string)
434447
Expressions with type constraints need to be wrapped in parens:
435448
(\\"hi\\": string)
436449
437-
450+
451+
438452
========================================================"
439453
`;

syntax/tests/parsing/errors/other/__snapshots__/parse.spec.js.snap

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ exports[`patternMatching.js 1`] = `
1212
3 │
1313
1414
Pattern matching needs at least one case
15-
15+
16+
1617
========================================================"
1718
`;
1819

@@ -33,7 +34,7 @@ let x::y = myList
3334
3 │
3435
3536
Arrays can't use the \`...\` spread currently. Please use \`concat\` or other Array helpers.
36-
37+
3738
Syntax error!
3839
parsing/errors/other/spread.js 2:6-8
3940
1 │ let arr = [...x, ...y]
@@ -44,7 +45,7 @@ let x::y = myList
4445
Array's \`...\` spread is not supported in pattern matches.
4546
Explanation: such spread would create a subarray; out of performance concern, our pattern matching currently guarantees to never create new intermediate data.
4647
Solution: if it's to validate the first few elements, use a \`when\` clause + Array size check + \`get\` checks on the current pattern. If it's to obtain a subarray, use \`Array.sub\` or \`Belt.Array.slice\`.
47-
48+
4849
Syntax error!
4950
parsing/errors/other/spread.js 4:21-23
5051
2 │ let [...arr, _] = [1, 2, 3]
@@ -55,7 +56,7 @@ Solution: if it's to validate the first few elements, use a \`when\` clause + Ar
5556
5657
Records can only have one \`...\` spread, at the beginning.
5758
Explanation: since records have a known, fixed shape, a spread like \`{a, ...b}\` wouldn't make sense, as \`b\` would override every field of \`a\` anyway.
58-
59+
5960
Syntax error!
6061
parsing/errors/other/spread.js 5:15-18
6162
3 │
@@ -67,7 +68,7 @@ Explanation: since records have a known, fixed shape, a spread like \`{a, ...b}\
6768
Record's \`...\` spread is not supported in pattern matches.
6869
Explanation: you can't collect a subset of a record's field into its own record, since a record needs an explicit declaration and that subset wouldn't have one.
6970
Solution: you need to pull out each field you want explicitly.
70-
71+
7172
Syntax error!
7273
parsing/errors/other/spread.js 8:13-22
7374
6 │
@@ -77,6 +78,7 @@ Solution: you need to pull out each field you want explicitly.
7778
7879
List pattern matches only supports one \`...\` spread, at the end.
7980
Explanation: a list spread at the tail is efficient, but a spread in the middle would create new list[s]; out of performance concern, our pattern matching currently guarantees to never create new intermediate data.
80-
81+
82+
8183
========================================================"
8284
`;

syntax/tests/parsing/errors/pattern/__snapshots__/parse.spec.js.snap

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ let 4 = for [%napkinscript.patternhole ] = 0 to 10 do Js.log \\"for\\" done
1414
3 │
1515
1616
I was expecting a name for this let-binding. Example: \`let message = \\"hello\\"\`
17-
17+
1818
Syntax error!
1919
parsing/errors/pattern/missing.res 2:5
2020
1 │ let = 2
@@ -23,7 +23,7 @@ let 4 = for [%napkinscript.patternhole ] = 0 to 10 do Js.log \\"for\\" done
2323
4 │ for in 0 to 10 {
2424
2525
I was expecting a name for this let-binding. Example: \`let message = \\"hello\\"\`
26-
26+
2727
Syntax error!
2828
parsing/errors/pattern/missing.res 4:5-6
2929
2 │ let = 4
@@ -33,7 +33,7 @@ let 4 = for [%napkinscript.patternhole ] = 0 to 10 do Js.log \\"for\\" done
3333
6}
3434
3535
A for-loop has the following form: \`for i in 0 to 10\`. Did you forget to supply a name before \`in\`?
36-
36+
3737
Syntax error!
3838
parsing/errors/pattern/missing.res 9:3-4
3939
7 │
@@ -43,6 +43,7 @@ let 4 = for [%napkinscript.patternhole ] = 0 to 10 do Js.log \\"for\\" done
4343
11 │
4444
4545
I was expecting a pattern to match on before the \`=>\`
46-
46+
47+
4748
========================================================"
4849
`;

0 commit comments

Comments
 (0)