Skip to content

Commit ca41803

Browse files
Fsc: add indentation to --tokenize output (#15347)
Co-authored-by: Kevin Ransom (msft) <[email protected]>
1 parent fa8b61b commit ca41803

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

src/Compiler/Driver/ParseAndCheckInputs.fs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ open System.IO
99
open System.Threading
1010
open System.Collections.Generic
1111

12+
open FSharp.Compiler.Parser
1213
open Internal.Utilities.Collections
1314
open Internal.Utilities.Library
1415
open Internal.Utilities.Library.Extras
@@ -509,9 +510,23 @@ type Tokenizer = unit -> Parser.token
509510

510511
// Show all tokens in the stream, for testing purposes
511512
let ShowAllTokensAndExit (tokenizer: Tokenizer, lexbuf: LexBuffer<char>, exiter: Exiter) =
513+
let mutable indent = 0
514+
512515
while true do
513516
let t = tokenizer ()
514-
printfn $"{Parser.token_to_string t} {lexbuf.LexemeRange}"
517+
518+
indent <-
519+
match t with
520+
| OBLOCKEND_IS_HERE -> max (indent - 1) 0
521+
| _ -> indent
522+
523+
let indentStr = String.replicate indent " "
524+
printfn $"{indentStr}{token_to_string t} {lexbuf.LexemeRange}"
525+
526+
indent <-
527+
match t with
528+
| OBLOCKBEGIN -> indent + 1
529+
| _ -> indent
515530

516531
match t with
517532
| Parser.EOF _ -> exiter.Exit 0

0 commit comments

Comments
 (0)