vb6parse 1.0.1

vb6parse is a library for parsing and analyzing VB6 code, from projects, to controls, to modules, and forms.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
//! # Spc Function
//!
//! Used with the Print # statement or Print method to position output.
//!
//! ## Syntax
//!
//! ```vb
//! Spc(n)
//! ```
//!
//! ## Parameters
//!
//! - `n` - Required. Numeric expression specifying the number of spaces to insert before displaying or printing the next expression in the list.
//!
//! ## Return Value
//!
//! Used only with Print # statement and Print method. Returns a value used to insert space characters in output.
//!
//! ## Remarks
//!
//! The Spc function is used to insert spaces in output when using the Print # statement (for files) or the Print method (for the Immediate window or printer). Unlike the Space function which returns a string of spaces, Spc is a special formatting function that only works within Print statements.
//!
//! Key characteristics:
//! - Only valid within Print # or Print (Debug.Print) statements
//! - Inserts the specified number of space characters
//! - If current print position + n exceeds output line width, Spc skips to the next line
//! - If n is less than the output line width, the next print position is current position + n
//! - If n is greater than the output line width, the next print position is calculated as n Mod width
//! - Cannot be used independently or assigned to variables
//! - Returns a variant used internally by the Print statement
//!
//! The Spc function differs from related positioning functions:
//! - **Spc(n)**: Inserts n spaces from current position
//! - **Tab(n)**: Moves to column n (absolute positioning)
//! - **Space(n)**: Returns a string of n spaces (can be used anywhere)
//!
//! ## Typical Uses
//!
//! 1. **File Output**: Space elements in text file output
//! 2. **Report Formatting**: Create formatted reports with spacing
//! 3. **Column Alignment**: Align data in columns
//! 4. **Debug Output**: Format Debug.Print output
//! 5. **Printer Output**: Format printed output
//! 6. **Data Separation**: Separate data elements with spaces
//! 7. **Fixed-Width Output**: Create fixed-width formatted text
//! 8. **Log Files**: Format log file entries
//!
//! ## Basic Examples
//!
//! ```vb
//! ' Example 1: Print with spaces between items
//! Dim fileNum As Integer
//! fileNum = FreeFile
//! Open "output.txt" For Output As #fileNum
//! Print #fileNum, "Name"; Spc(10); "Age"; Spc(10); "City"
//! Close #fileNum
//! ' Outputs: "Name          Age          City"
//! ```
//!
//! ```vb
//! ' Example 2: Debug output with spacing
//! Debug.Print "Item:"; Spc(5); "Value"
//! ' Outputs: "Item:     Value"
//! ```
//!
//! ```vb
//! ' Example 3: Multiple Spc calls in one statement
//! Print #1, "A"; Spc(3); "B"; Spc(5); "C"
//! ' Outputs: "A   B     C"
//! ```
//!
//! ```vb
//! ' Example 4: Create formatted columns
//! Dim i As Integer
//! For i = 1 To 3
//!     Debug.Print i; Spc(10); i * 10; Spc(10); i * 100
//! Next i
//! ' Outputs aligned columns of numbers
//! ```
//!
//! ## Common Patterns
//!
//! ### Pattern 1: `FormatFileOutput`
//! Format data in file with consistent spacing
//! ```vb
//! Sub FormatFileOutput(fileNum As Integer, name As String, _
//!                      age As Integer, city As String)
//!     Print #fileNum, name; Spc(20 - Len(name)); _
//!                     age; Spc(10); city
//! End Sub
//! ```
//!
//! ### Pattern 2: `PrintAlignedData`
//! Print data with aligned columns
//! ```vb
//! Sub PrintAlignedData(label As String, value As Variant, spacing As Integer)
//!     Debug.Print label; Spc(spacing); value
//! End Sub
//! ```
//!
//! ### Pattern 3: `CreateTableRow`
//! Create table row with Spc spacing
//! ```vb
//! Sub CreateTableRow(fileNum As Integer, col1 As String, _
//!                    col2 As String, col3 As String)
//!     Print #fileNum, col1; Spc(15 - Len(col1)); _
//!                     col2; Spc(15 - Len(col2)); _
//!                     col3
//! End Sub
//! ```
//!
//! ### Pattern 4: `FormatLogEntry`
//! Format log entries with timestamps and messages
//! ```vb
//! Sub FormatLogEntry(fileNum As Integer, timestamp As String, _
//!                    level As String, message As String)
//!     Print #fileNum, timestamp; Spc(5); _
//!                     level; Spc(10 - Len(level)); _
//!                     message
//! End Sub
//! ```
//!
//! ### Pattern 5: `PrintWithIndent`
//! Print text with indentation using Spc
//! ```vb
//! Sub PrintWithIndent(fileNum As Integer, indentLevel As Integer, _
//!                     text As String)
//!     Print #fileNum, Spc(indentLevel * 4); text
//! End Sub
//! ```
//!
//! ### Pattern 6: `FormatKeyValuePair`
//! Format key-value pairs with consistent spacing
//! ```vb
//! Sub FormatKeyValuePair(fileNum As Integer, key As String, _
//!                        value As String, Optional totalWidth As Integer = 40)
//!     Dim spacesNeeded As Integer
//!     spacesNeeded = totalWidth - Len(key) - Len(value)
//!     If spacesNeeded < 1 Then spacesNeeded = 1
//!     Print #fileNum, key; Spc(spacesNeeded); value
//! End Sub
//! ```
//!
//! ### Pattern 7: `PrintHeader`
//! Print formatted header with separators
//! ```vb
//! Sub PrintHeader(fileNum As Integer, title1 As String, _
//!                 title2 As String, title3 As String)
//!     Print #fileNum, title1; Spc(15 - Len(title1)); _
//!                     title2; Spc(15 - Len(title2)); _
//!                     title3
//!     Print #fileNum, String(15, "-"); Spc(1); _
//!                     String(15, "-"); Spc(1); _
//!                     String(15, "-")
//! End Sub
//! ```
//!
//! ### Pattern 8: `DebugPrintArray`
//! Print array elements with spacing
//! ```vb
//! Sub DebugPrintArray(arr() As Variant)
//!     Dim i As Integer
//!     For i = LBound(arr) To UBound(arr)
//!         Debug.Print arr(i); Spc(5);
//!     Next i
//!     Debug.Print  ' New line
//! End Sub
//! ```
//!
//! ### Pattern 9: `FormatNumericTable`
//! Print numeric data in aligned columns
//! ```vb
//! Sub FormatNumericTable(fileNum As Integer, values() As Double)
//!     Dim i As Integer
//!     For i = LBound(values) To UBound(values)
//!         Print #fileNum, Format(values(i), "0.00"); Spc(10);
//!         If (i - LBound(values) + 1) Mod 5 = 0 Then
//!             Print #fileNum,  ' New line every 5 values
//!         End If
//!     Next i
//! End Sub
//! ```
//!
//! ### Pattern 10: `PrintReportLine`
//! Print formatted report line
//! ```vb
//! Sub PrintReportLine(fileNum As Integer, lineNum As Integer, _
//!                     description As String, amount As Double)
//!     Print #fileNum, Format(lineNum, "000"); Spc(5); _
//!                     description; Spc(30 - Len(description)); _
//!                     Format(amount, "$#,##0.00")
//! End Sub
//! ```
//!
//! ## Advanced Usage
//!
//! ### Example 1: `ReportWriter` Class
//! Generate formatted text reports with Spc
//! ```vb
//! ' Class: ReportWriter
//! Private m_fileNum As Integer
//! Private m_isOpen As Boolean
//!
//! Public Sub OpenReport(fileName As String)
//!     m_fileNum = FreeFile
//!     Open fileName For Output As #m_fileNum
//!     m_isOpen = True
//! End Sub
//!
//! Public Sub WriteHeader(title As String, col1 As String, _
//!                        col2 As String, col3 As String)
//!     If Not m_isOpen Then Exit Sub
//!     
//!     ' Center title
//!     Dim totalWidth As Integer
//!     totalWidth = 60
//!     Dim leftPad As Integer
//!     leftPad = (totalWidth - Len(title)) \ 2
//!     Print #m_fileNum, Spc(leftPad); title
//!     Print #m_fileNum, String(totalWidth, "=")
//!     Print #m_fileNum,
//!     
//!     ' Column headers
//!     Print #m_fileNum, col1; Spc(20 - Len(col1)); _
//!                       col2; Spc(20 - Len(col2)); _
//!                       col3
//!     Print #m_fileNum, String(20, "-"); Spc(1); _
//!                       String(20, "-"); Spc(1); _
//!                       String(20, "-")
//! End Sub
//!
//! Public Sub WriteDataRow(val1 As String, val2 As String, val3 As String)
//!     If Not m_isOpen Then Exit Sub
//!     
//!     Print #m_fileNum, val1; Spc(20 - Len(val1)); _
//!                       val2; Spc(20 - Len(val2)); _
//!                       val3
//! End Sub
//!
//! Public Sub WriteSummary(label As String, value As String)
//!     If Not m_isOpen Then Exit Sub
//!     
//!     Print #m_fileNum,
//!     Print #m_fileNum, String(60, "-")
//!     Print #m_fileNum, label; Spc(60 - Len(label) - Len(value)); value
//! End Sub
//!
//! Public Sub CloseReport()
//!     If m_isOpen Then
//!         Close #m_fileNum
//!         m_isOpen = False
//!     End If
//! End Sub
//!
//! Private Sub Class_Terminate()
//!     CloseReport
//! End Sub
//! ```
//!
//! ### Example 2: `LogFileFormatter` Module
//! Format log file entries with timestamps
//! ```vb
//! ' Module: LogFileFormatter
//! Private m_logFile As Integer
//! Private m_logOpen As Boolean
//!
//! Public Sub OpenLog(fileName As String)
//!     m_logFile = FreeFile
//!     Open fileName For Append As #m_logFile
//!     m_logOpen = True
//! End Sub
//!
//! Public Sub LogInfo(message As String)
//!     If Not m_logOpen Then Exit Sub
//!     Dim timestamp As String
//!     timestamp = Format(Now, "yyyy-mm-dd hh:nn:ss")
//!     Print #m_logFile, timestamp; Spc(5); "INFO"; Spc(10); message
//! End Sub
//!
//! Public Sub LogWarning(message As String)
//!     If Not m_logOpen Then Exit Sub
//!     Dim timestamp As String
//!     timestamp = Format(Now, "yyyy-mm-dd hh:nn:ss")
//!     Print #m_logFile, timestamp; Spc(5); "WARNING"; Spc(6); message
//! End Sub
//!
//! Public Sub LogError(message As String, Optional errorNum As Long = 0)
//!     If Not m_logOpen Then Exit Sub
//!     Dim timestamp As String
//!     timestamp = Format(Now, "yyyy-mm-dd hh:nn:ss")
//!     Print #m_logFile, timestamp; Spc(5); "ERROR"; Spc(8); message
//!     If errorNum <> 0 Then
//!         Print #m_logFile, Spc(30); "Error #"; errorNum
//!     End If
//! End Sub
//!
//! Public Sub LogDebug(category As String, message As String)
//!     If Not m_logOpen Then Exit Sub
//!     Dim timestamp As String
//!     timestamp = Format(Now, "yyyy-mm-dd hh:nn:ss")
//!     Print #m_logFile, timestamp; Spc(5); "DEBUG"; Spc(8); _
//!                        "["; category; "]"; Spc(3); message
//! End Sub
//!
//! Public Sub LogSeparator()
//!     If Not m_logOpen Then Exit Sub
//!     Print #m_logFile, String(80, "-")
//! End Sub
//!
//! Public Sub CloseLog()
//!     If m_logOpen Then
//!         Close #m_logFile
//!         m_logOpen = False
//!     End If
//! End Sub
//! ```
//!
//! ### Example 3: `DataTablePrinter` Class
//! Print data in formatted tables
//! ```vb
//! ' Class: DataTablePrinter
//! Private m_columnWidths() As Integer
//! Private m_fileNum As Integer
//!
//! Public Sub Initialize(fileNum As Integer, columnWidths() As Integer)
//!     Dim i As Integer
//!     m_fileNum = fileNum
//!     ReDim m_columnWidths(LBound(columnWidths) To UBound(columnWidths))
//!     For i = LBound(columnWidths) To UBound(columnWidths)
//!         m_columnWidths(i) = columnWidths(i)
//!     Next i
//! End Sub
//!
//! Public Sub PrintRow(values() As String)
//!     Dim i As Integer
//!     Dim spaces As Integer
//!     
//!     For i = LBound(values) To UBound(values)
//!         Print #m_fileNum, values(i);
//!         
//!         If i < UBound(values) Then
//!             spaces = m_columnWidths(i) - Len(values(i))
//!             If spaces < 1 Then spaces = 1
//!             Print #m_fileNum, Spc(spaces);
//!         End If
//!     Next i
//!     Print #m_fileNum,  ' New line
//! End Sub
//!
//! Public Sub PrintHeaderRow(headers() As String)
//!     Dim i As Integer
//!     
//!     PrintRow headers
//!     
//!     ' Print separator
//!     For i = LBound(m_columnWidths) To UBound(m_columnWidths)
//!         Print #m_fileNum, String(m_columnWidths(i), "-");
//!         If i < UBound(m_columnWidths) Then
//!             Print #m_fileNum, Spc(1);
//!         End If
//!     Next i
//!     Print #m_fileNum,  ' New line
//! End Sub
//!
//! Public Sub PrintRightAligned(values() As String)
//!     Dim i As Integer
//!     Dim spaces As Integer
//!     
//!     For i = LBound(values) To UBound(values)
//!         spaces = m_columnWidths(i) - Len(values(i))
//!         If spaces > 0 Then Print #m_fileNum, Spc(spaces);
//!         Print #m_fileNum, values(i);
//!         
//!         If i < UBound(values) Then
//!             Print #m_fileNum, Spc(1);
//!         End If
//!     Next i
//!     Print #m_fileNum,  ' New line
//! End Sub
//! ```
//!
//! ### Example 4: `DebugOutputHelper` Module
//! Format debug output with Spc
//! ```vb
//! ' Module: DebugOutputHelper
//!
//! Public Sub PrintVariable(varName As String, varValue As Variant)
//!     Debug.Print varName; Spc(20 - Len(varName)); "="; Spc(2); varValue
//! End Sub
//!
//! Public Sub PrintVariables(ParamArray vars() As Variant)
//!     Dim i As Integer
//!     For i = LBound(vars) To UBound(vars) Step 2
//!         If i + 1 <= UBound(vars) Then
//!             PrintVariable CStr(vars(i)), vars(i + 1)
//!         End If
//!     Next i
//! End Sub
//!
//! Public Sub PrintSection(title As String)
//!     Debug.Print
//!     Debug.Print String(50, "=")
//!     Dim leftPad As Integer
//!     leftPad = (50 - Len(title)) \ 2
//!     Debug.Print Spc(leftPad); title
//!     Debug.Print String(50, "=")
//!     Debug.Print
//! End Sub
//!
//! Public Sub PrintKeyValue(key As String, value As Variant, _
//!                          Optional totalWidth As Integer = 40)
//!     Dim spacesNeeded As Integer
//!     spacesNeeded = totalWidth - Len(key) - Len(CStr(value))
//!     If spacesNeeded < 1 Then spacesNeeded = 1
//!     Debug.Print key; Spc(spacesNeeded); value
//! End Sub
//!
//! Public Sub PrintIndented(level As Integer, text As String)
//!     Debug.Print Spc(level * 4); text
//! End Sub
//!
//! Public Sub PrintArray(arr() As Variant, Optional itemsPerLine As Integer = 5)
//!     Dim i As Integer
//!     Dim count As Integer
//!     count = 0
//!     
//!     For i = LBound(arr) To UBound(arr)
//!         Debug.Print arr(i); Spc(10);
//!         count = count + 1
//!         If count >= itemsPerLine Then
//!             Debug.Print  ' New line
//!             count = 0
//!         End If
//!     Next i
//!     
//!     If count > 0 Then Debug.Print  ' Final new line if needed
//! End Sub
//! ```
//!
//! ## Error Handling
//!
//! The Spc function itself doesn't typically generate errors, but the Print statement it's used with can:
//!
//! - **Error 52** (Bad file name or number): If file number is invalid
//! - **Error 54** (Bad file mode): If file not opened for output
//! - **Error 13** (Type mismatch): If n is not numeric
//!
//! Always ensure file is properly opened:
//! ```vb
//! On Error Resume Next
//! Print #fileNum, "Data"; Spc(10); "Value"
//! If Err.Number <> 0 Then
//!     MsgBox "Error writing to file: " & Err.Description
//! End If
//! ```
//!
//! ## Performance Considerations
//!
//! - Spc is very efficient for positioning output
//! - More efficient than concatenating `Space()` strings in Print statements
//! - No performance difference between Spc and Space within Print statements
//! - File I/O is the bottleneck, not Spc itself
//!
//! ## Best Practices
//!
//! 1. **Only in Print**: Use Spc only within Print # or Debug.Print statements
//! 2. **Validate Arguments**: Ensure n is positive and reasonable
//! 3. **Consistent Spacing**: Use constants for column widths
//! 4. **Calculate Dynamically**: Adjust spacing based on content length
//! 5. **Use Space Alternative**: Use `Space()` function if need string result
//! 6. **Combine with Tab**: Use Tab for absolute positioning, Spc for relative
//! 7. **Test Output**: Verify alignment with actual data
//! 8. **Monospace Fonts**: Ensure output viewed in monospace font
//! 9. **Handle Long Data**: Account for data that exceeds expected width
//! 10. **Document Format**: Comment expected column layout
//!
//! ## Comparison with Related Functions
//!
//! | Function | Usage Context | Positioning | Returns |
//! |----------|--------------|-------------|---------|
//! | Spc(n) | Print statements only | Relative (+n spaces) | Variant (internal) |
//! | Tab(n) | Print statements only | Absolute (column n) | Variant (internal) |
//! | Space(n) | Anywhere | N/A | String of n spaces |
//! | String(n, " ") | Anywhere | N/A | String of n spaces |
//!
//! ## Platform Considerations
//!
//! - Available in VB6, VBA (all versions)
//! - Part of Print statement syntax
//! - Behavior consistent across platforms
//! - Works with Debug.Print, Print # (files), and Printer.Print
//! - Output width depends on file width setting (default 80 characters)
//!
//! ## Limitations
//!
//! - Cannot be used outside Print statements
//! - Cannot assign Spc result to variable
//! - Cannot use in string concatenation
//! - Wrapping behavior depends on output width setting
//! - Not suitable for proportional fonts (use with monospace)
//! - Limited to text output scenarios
//!
//! ## Related Functions
//!
//! - `Tab`: Positions output at absolute column position
//! - `Space`: Returns string of spaces (can be used anywhere)
//! - `Print`: Statement that outputs data
//! - `Width`: Statement that sets output line width
//!
#[cfg(test)]
mod tests {
    use crate::*;

    #[test]
    fn spc_basic() {
        let source = r#"
Sub Test()
    Debug.Print "A"; Spc(5); "B"
End Sub
"#;
        let (cst_opt, _failures) = ConcreteSyntaxTree::from_text("test.bas", source).unpack();
        let cst = cst_opt.expect("CST should be parsed");

        let tree = cst.to_serializable();

        let mut settings = insta::Settings::clone_current();
        settings
            .set_snapshot_path("../../../../../snapshots/syntax/library/functions/graphics/spc");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn spc_with_variable() {
        let source = r#"
Sub Test()
    Dim spaces As Integer
    spaces = 10
    Print #1, "Data"; Spc(spaces); "Value"
End Sub
"#;
        let (cst_opt, _failures) = ConcreteSyntaxTree::from_text("test.bas", source).unpack();
        let cst = cst_opt.expect("CST should be parsed");

        let tree = cst.to_serializable();

        let mut settings = insta::Settings::clone_current();
        settings
            .set_snapshot_path("../../../../../snapshots/syntax/library/functions/graphics/spc");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn spc_file_output() {
        let source = r#"
Sub Test()
    Dim fileNum As Integer
    fileNum = FreeFile
    Open "test.txt" For Output As #fileNum
    Print #fileNum, "Name"; Spc(10); "Age"
    Close #fileNum
End Sub
"#;
        let (cst_opt, _failures) = ConcreteSyntaxTree::from_text("test.bas", source).unpack();
        let cst = cst_opt.expect("CST should be parsed");

        let tree = cst.to_serializable();

        let mut settings = insta::Settings::clone_current();
        settings
            .set_snapshot_path("../../../../../snapshots/syntax/library/functions/graphics/spc");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn spc_debug_print() {
        let source = r#"
Sub Test()
    Debug.Print "Label:"; Spc(15); "Value"
End Sub
"#;
        let (cst_opt, _failures) = ConcreteSyntaxTree::from_text("test.bas", source).unpack();
        let cst = cst_opt.expect("CST should be parsed");

        let tree = cst.to_serializable();

        let mut settings = insta::Settings::clone_current();
        settings
            .set_snapshot_path("../../../../../snapshots/syntax/library/functions/graphics/spc");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn spc_multiple_calls() {
        let source = r#"
Sub Test()
    Print #1, "A"; Spc(3); "B"; Spc(5); "C"
End Sub
"#;
        let (cst_opt, _failures) = ConcreteSyntaxTree::from_text("test.bas", source).unpack();
        let cst = cst_opt.expect("CST should be parsed");

        let tree = cst.to_serializable();

        let mut settings = insta::Settings::clone_current();
        settings
            .set_snapshot_path("../../../../../snapshots/syntax/library/functions/graphics/spc");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn spc_in_loop() {
        let source = r"
Sub Test()
    Dim i As Integer
    For i = 1 To 10
        Debug.Print i; Spc(5); i * 10
    Next i
End Sub
";
        let (cst_opt, _failures) = ConcreteSyntaxTree::from_text("test.bas", source).unpack();
        let cst = cst_opt.expect("CST should be parsed");

        let tree = cst.to_serializable();

        let mut settings = insta::Settings::clone_current();
        settings
            .set_snapshot_path("../../../../../snapshots/syntax/library/functions/graphics/spc");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn spc_calculated_spacing() {
        let source = r#"
Sub Test()
    Dim name As String
    name = "John"
    Print #1, name; Spc(20 - Len(name)); "Age"
End Sub
"#;
        let (cst_opt, _failures) = ConcreteSyntaxTree::from_text("test.bas", source).unpack();
        let cst = cst_opt.expect("CST should be parsed");

        let tree = cst.to_serializable();

        let mut settings = insta::Settings::clone_current();
        settings
            .set_snapshot_path("../../../../../snapshots/syntax/library/functions/graphics/spc");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn spc_with_numbers() {
        let source = r"
Sub Test()
    Debug.Print 100; Spc(10); 200; Spc(10); 300
End Sub
";
        let (cst_opt, _failures) = ConcreteSyntaxTree::from_text("test.bas", source).unpack();
        let cst = cst_opt.expect("CST should be parsed");

        let tree = cst.to_serializable();

        let mut settings = insta::Settings::clone_current();
        settings
            .set_snapshot_path("../../../../../snapshots/syntax/library/functions/graphics/spc");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn spc_class_usage() {
        let source = r"
Class Reporter
    Public Sub WriteRow(f As Integer, a As String, b As String)
        Print #f, a; Spc(10); b
    End Sub
End Class
";
        let (cst_opt, _failures) = ConcreteSyntaxTree::from_text("test.bas", source).unpack();
        let cst = cst_opt.expect("CST should be parsed");

        let tree = cst.to_serializable();

        let mut settings = insta::Settings::clone_current();
        settings
            .set_snapshot_path("../../../../../snapshots/syntax/library/functions/graphics/spc");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn spc_if_statement() {
        let source = r#"
Sub Test()
    If condition Then
        Debug.Print "True"; Spc(5); "Yes"
    End If
End Sub
"#;
        let (cst_opt, _failures) = ConcreteSyntaxTree::from_text("test.bas", source).unpack();
        let cst = cst_opt.expect("CST should be parsed");

        let tree = cst.to_serializable();

        let mut settings = insta::Settings::clone_current();
        settings
            .set_snapshot_path("../../../../../snapshots/syntax/library/functions/graphics/spc");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn spc_elseif() {
        let source = r#"
Sub Test()
    If x = 1 Then
        Print #1, "One"; Spc(5); "1"
    ElseIf x = 2 Then
        Print #1, "Two"; Spc(5); "2"
    End If
End Sub
"#;
        let (cst_opt, _failures) = ConcreteSyntaxTree::from_text("test.bas", source).unpack();
        let cst = cst_opt.expect("CST should be parsed");

        let tree = cst.to_serializable();

        let mut settings = insta::Settings::clone_current();
        settings
            .set_snapshot_path("../../../../../snapshots/syntax/library/functions/graphics/spc");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn spc_select_case() {
        let source = r#"
Sub Test()
    Select Case value
        Case 1
            Print #1, "One"; Spc(10); "Value"
        Case 2
            Print #1, "Two"; Spc(10); "Value"
    End Select
End Sub
"#;
        let (cst_opt, _failures) = ConcreteSyntaxTree::from_text("test.bas", source).unpack();
        let cst = cst_opt.expect("CST should be parsed");

        let tree = cst.to_serializable();

        let mut settings = insta::Settings::clone_current();
        settings
            .set_snapshot_path("../../../../../snapshots/syntax/library/functions/graphics/spc");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn spc_do_while() {
        let source = r"
Sub Test()
    Do While i < 10
        Print #1, i; Spc(5); i * 2
        i = i + 1
    Loop
End Sub
";
        let (cst_opt, _failures) = ConcreteSyntaxTree::from_text("test.bas", source).unpack();
        let cst = cst_opt.expect("CST should be parsed");

        let tree = cst.to_serializable();

        let mut settings = insta::Settings::clone_current();
        settings
            .set_snapshot_path("../../../../../snapshots/syntax/library/functions/graphics/spc");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn spc_do_until() {
        let source = r#"
Sub Test()
    Do Until i >= 10
        Debug.Print "Item"; Spc(8); i
        i = i + 1
    Loop
End Sub
"#;
        let (cst_opt, _failures) = ConcreteSyntaxTree::from_text("test.bas", source).unpack();
        let cst = cst_opt.expect("CST should be parsed");

        let tree = cst.to_serializable();

        let mut settings = insta::Settings::clone_current();
        settings
            .set_snapshot_path("../../../../../snapshots/syntax/library/functions/graphics/spc");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn spc_while_wend() {
        let source = r"
Sub Test()
    While count < 5
        Print #1, count; Spc(10); count * 10
        count = count + 1
    Wend
End Sub
";
        let (cst_opt, _failures) = ConcreteSyntaxTree::from_text("test.bas", source).unpack();
        let cst = cst_opt.expect("CST should be parsed");

        let tree = cst.to_serializable();

        let mut settings = insta::Settings::clone_current();
        settings
            .set_snapshot_path("../../../../../snapshots/syntax/library/functions/graphics/spc");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn spc_with_statement() {
        let source = r#"
Sub Test()
    With reporter
        Print #.FileNum, "Name"; Spc(10); "Value"
    End With
End Sub
"#;
        let (cst_opt, _failures) = ConcreteSyntaxTree::from_text("test.bas", source).unpack();
        let cst = cst_opt.expect("CST should be parsed");

        let tree = cst.to_serializable();

        let mut settings = insta::Settings::clone_current();
        settings
            .set_snapshot_path("../../../../../snapshots/syntax/library/functions/graphics/spc");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn spc_format_function() {
        let source = r#"
Sub Test()
    Dim amount As Double
    amount = 123.45
    Print #1, "Total:"; Spc(5); Format(amount, "$#,##0.00")
End Sub
"#;
        let (cst_opt, _failures) = ConcreteSyntaxTree::from_text("test.bas", source).unpack();
        let cst = cst_opt.expect("CST should be parsed");

        let tree = cst.to_serializable();

        let mut settings = insta::Settings::clone_current();
        settings
            .set_snapshot_path("../../../../../snapshots/syntax/library/functions/graphics/spc");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn spc_zero_spaces() {
        let source = r#"
Sub Test()
    Debug.Print "A"; Spc(0); "B"
End Sub
"#;
        let (cst_opt, _failures) = ConcreteSyntaxTree::from_text("test.bas", source).unpack();
        let cst = cst_opt.expect("CST should be parsed");

        let tree = cst.to_serializable();

        let mut settings = insta::Settings::clone_current();
        settings
            .set_snapshot_path("../../../../../snapshots/syntax/library/functions/graphics/spc");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn spc_large_number() {
        let source = r#"
Sub Test()
    Print #1, "Start"; Spc(50); "End"
End Sub
"#;
        let (cst_opt, _failures) = ConcreteSyntaxTree::from_text("test.bas", source).unpack();
        let cst = cst_opt.expect("CST should be parsed");

        let tree = cst.to_serializable();

        let mut settings = insta::Settings::clone_current();
        settings
            .set_snapshot_path("../../../../../snapshots/syntax/library/functions/graphics/spc");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn spc_function_call() {
        let source = r"
Sub Test()
    Debug.Print GetLabel(); Spc(10); GetValue()
End Sub
";
        let (cst_opt, _failures) = ConcreteSyntaxTree::from_text("test.bas", source).unpack();
        let cst = cst_opt.expect("CST should be parsed");

        let tree = cst.to_serializable();

        let mut settings = insta::Settings::clone_current();
        settings
            .set_snapshot_path("../../../../../snapshots/syntax/library/functions/graphics/spc");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn spc_header_row() {
        let source = r#"
Sub Test()
    Print #1, "Name"; Spc(15); "Age"; Spc(10); "City"
    Print #1, String(15, "-"); Spc(1); String(10, "-"); Spc(1); String(15, "-")
End Sub
"#;
        let (cst_opt, _failures) = ConcreteSyntaxTree::from_text("test.bas", source).unpack();
        let cst = cst_opt.expect("CST should be parsed");

        let tree = cst.to_serializable();

        let mut settings = insta::Settings::clone_current();
        settings
            .set_snapshot_path("../../../../../snapshots/syntax/library/functions/graphics/spc");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn spc_nested_function() {
        let source = r#"
Sub Test()
    Dim width As Integer
    width = 20
    Debug.Print "Item"; Spc(width - Len("Item")); "Value"
End Sub
"#;
        let (cst_opt, _failures) = ConcreteSyntaxTree::from_text("test.bas", source).unpack();
        let cst = cst_opt.expect("CST should be parsed");

        let tree = cst.to_serializable();

        let mut settings = insta::Settings::clone_current();
        settings
            .set_snapshot_path("../../../../../snapshots/syntax/library/functions/graphics/spc");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn spc_error_handling() {
        let source = r#"
Sub Test()
    On Error Resume Next
    Print #fileNum, "Data"; Spc(10); "Value"
    If Err.Number <> 0 Then
        MsgBox "Error"
    End If
End Sub
"#;
        let (cst_opt, _failures) = ConcreteSyntaxTree::from_text("test.bas", source).unpack();
        let cst = cst_opt.expect("CST should be parsed");

        let tree = cst.to_serializable();

        let mut settings = insta::Settings::clone_current();
        settings
            .set_snapshot_path("../../../../../snapshots/syntax/library/functions/graphics/spc");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn spc_on_error_goto() {
        let source = r#"
Sub Test()
    On Error GoTo ErrorHandler
    Print #1, "Label"; Spc(spacing); "Value"
    Exit Sub
ErrorHandler:
    MsgBox "Error printing"
End Sub
"#;
        let (cst_opt, _failures) = ConcreteSyntaxTree::from_text("test.bas", source).unpack();
        let cst = cst_opt.expect("CST should be parsed");

        let tree = cst.to_serializable();

        let mut settings = insta::Settings::clone_current();
        settings
            .set_snapshot_path("../../../../../snapshots/syntax/library/functions/graphics/spc");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn spc_indentation() {
        let source = r#"
Sub Test()
    Dim level As Integer
    level = 3
    Print #1, Spc(level * 4); "Indented text"
End Sub
"#;
        let (cst_opt, _failures) = ConcreteSyntaxTree::from_text("test.bas", source).unpack();
        let cst = cst_opt.expect("CST should be parsed");

        let tree = cst.to_serializable();

        let mut settings = insta::Settings::clone_current();
        settings
            .set_snapshot_path("../../../../../snapshots/syntax/library/functions/graphics/spc");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn spc_report_formatting() {
        let source = r#"
Sub Test()
    Dim lineNum As Integer
    Dim desc As String
    lineNum = 1
    desc = "Item description"
    Print #1, Format(lineNum, "000"); Spc(5); desc; Spc(30 - Len(desc)); "$100.00"
End Sub
"#;
        let (cst_opt, _failures) = ConcreteSyntaxTree::from_text("test.bas", source).unpack();
        let cst = cst_opt.expect("CST should be parsed");

        let tree = cst.to_serializable();

        let mut settings = insta::Settings::clone_current();
        settings
            .set_snapshot_path("../../../../../snapshots/syntax/library/functions/graphics/spc");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }

    #[test]
    fn spc_log_entry() {
        let source = r#"
Sub Test()
    Dim timestamp As String
    timestamp = Format(Now, "yyyy-mm-dd hh:nn:ss")
    Print #1, timestamp; Spc(5); "INFO"; Spc(10); "Application started"
End Sub
"#;
        let (cst_opt, _failures) = ConcreteSyntaxTree::from_text("test.bas", source).unpack();
        let cst = cst_opt.expect("CST should be parsed");

        let tree = cst.to_serializable();

        let mut settings = insta::Settings::clone_current();
        settings
            .set_snapshot_path("../../../../../snapshots/syntax/library/functions/graphics/spc");
        settings.set_prepend_module_to_snapshot(false);
        let _guard = settings.bind_to_scope();
        insta::assert_yaml_snapshot!(tree);
    }
}