aboutsummaryrefslogtreecommitdiff
path: root/lib/docs/main.js
blob: 0b9a0aa87caf61c443270ef6560a33c92aef5aa0 (plain)
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
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201
4202
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245
4246
4247
4248
4249
4250
4251
4252
4253
4254
4255
4256
4257
4258
4259
4260
4261
4262
4263
4264
4265
4266
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278
4279
4280
4281
4282
4283
4284
4285
4286
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
4305
4306
4307
4308
4309
4310
4311
4312
4313
4314
4315
4316
4317
4318
4319
4320
4321
4322
4323
4324
4325
4326
4327
4328
4329
4330
4331
4332
4333
4334
4335
4336
4337
4338
4339
4340
4341
4342
4343
4344
4345
4346
4347
4348
4349
4350
4351
4352
4353
4354
4355
4356
4357
4358
4359
4360
4361
4362
4363
4364
4365
4366
4367
4368
4369
4370
4371
4372
4373
4374
4375
4376
4377
4378
4379
4380
4381
4382
4383
4384
4385
4386
4387
4388
4389
4390
4391
4392
4393
4394
4395
4396
4397
4398
4399
4400
4401
4402
4403
4404
4405
4406
4407
4408
4409
4410
4411
4412
4413
4414
4415
4416
4417
4418
4419
4420
4421
4422
4423
4424
4425
4426
4427
4428
4429
4430
4431
4432
4433
4434
4435
4436
4437
4438
4439
4440
4441
4442
4443
4444
4445
4446
4447
4448
4449
4450
4451
4452
4453
4454
4455
4456
4457
4458
4459
4460
4461
4462
4463
4464
4465
4466
4467
4468
4469
4470
4471
4472
4473
4474
4475
4476
4477
4478
4479
4480
4481
4482
4483
4484
4485
4486
4487
4488
4489
4490
4491
4492
4493
4494
4495
4496
4497
4498
4499
4500
4501
4502
4503
4504
4505
4506
4507
4508
4509
4510
4511
4512
4513
4514
4515
4516
4517
4518
4519
4520
4521
4522
4523
4524
4525
4526
4527
4528
4529
4530
4531
4532
4533
4534
4535
4536
4537
4538
4539
4540
4541
4542
4543
4544
4545
4546
4547
4548
4549
4550
4551
4552
4553
4554
4555
4556
4557
4558
4559
4560
4561
4562
4563
4564
4565
4566
4567
4568
4569
4570
4571
4572
4573
4574
4575
4576
4577
4578
4579
4580
4581
4582
4583
4584
4585
4586
4587
4588
4589
4590
4591
4592
4593
4594
4595
4596
4597
4598
4599
4600
4601
4602
4603
4604
4605
4606
4607
4608
4609
4610
4611
4612
4613
4614
4615
4616
4617
4618
4619
4620
4621
4622
4623
4624
4625
4626
4627
4628
4629
4630
4631
4632
4633
4634
4635
4636
4637
4638
4639
4640
4641
4642
4643
4644
4645
4646
4647
4648
4649
4650
4651
4652
4653
4654
4655
4656
4657
4658
4659
4660
4661
4662
4663
4664
4665
4666
4667
4668
4669
4670
4671
4672
4673
4674
4675
4676
4677
4678
4679
4680
4681
4682
4683
4684
4685
4686
4687
4688
4689
4690
4691
4692
4693
4694
4695
4696
4697
4698
4699
4700
4701
4702
4703
4704
4705
4706
4707
4708
4709
4710
4711
4712
4713
4714
4715
4716
4717
4718
4719
4720
4721
4722
4723
4724
4725
4726
4727
4728
4729
4730
4731
4732
4733
4734
4735
4736
4737
4738
4739
4740
4741
4742
4743
4744
4745
4746
4747
4748
4749
4750
4751
4752
4753
4754
4755
4756
4757
4758
4759
4760
4761
4762
4763
4764
4765
4766
4767
4768
4769
4770
4771
4772
4773
4774
4775
4776
4777
4778
4779
4780
4781
4782
4783
4784
4785
4786
4787
4788
4789
4790
4791
4792
4793
4794
4795
4796
4797
4798
4799
4800
4801
4802
4803
4804
4805
4806
4807
4808
4809
4810
4811
4812
4813
4814
4815
4816
4817
4818
4819
4820
4821
4822
4823
4824
4825
4826
4827
4828
4829
4830
4831
4832
4833
4834
4835
4836
4837
4838
4839
4840
4841
4842
4843
4844
4845
4846
4847
4848
4849
4850
4851
4852
4853
4854
4855
4856
4857
4858
4859
4860
4861
4862
4863
4864
4865
4866
4867
4868
4869
4870
4871
4872
4873
4874
4875
4876
4877
4878
4879
4880
4881
4882
4883
4884
4885
4886
4887
4888
4889
4890
4891
4892
4893
4894
4895
4896
4897
4898
4899
4900
4901
4902
4903
4904
4905
4906
4907
4908
4909
4910
4911
4912
4913
4914
4915
4916
4917
4918
4919
4920
4921
4922
4923
4924
4925
4926
4927
4928
4929
4930
4931
4932
4933
4934
4935
4936
4937
4938
"use strict";

var zigAnalysis;

const NAV_MODES = {
  API: "#A;",
  GUIDES: "#G;",
};

(function () {
  const domStatus = document.getElementById("status");
  const domSectNav = document.getElementById("sectNav");
  const domListNav = document.getElementById("listNav");
  const domApiSwitch = document.getElementById("ApiSwitch");
  const domGuideSwitch = document.getElementById("guideSwitch");
  const domGuidesMenu = document.getElementById("guidesMenu");
  const domApiMenu = document.getElementById("apiMenu");
  const domGuidesList = document.getElementById("guidesList");
  const domSectMainMod = document.getElementById("sectMainMod");
  const domSectMods = document.getElementById("sectMods");
  const domListMods = document.getElementById("listMods");
  const domSectTypes = document.getElementById("sectTypes");
  const domListTypes = document.getElementById("listTypes");
  const domSectTests = document.getElementById("sectTests");
  const domListTests = document.getElementById("listTests");
  const domSectDocTests = document.getElementById("sectDocTests");
  const domDocTestsCode = document.getElementById("docTestsCode");
  const domSectNamespaces = document.getElementById("sectNamespaces");
  const domListNamespaces = document.getElementById("listNamespaces");
  const domSectErrSets = document.getElementById("sectErrSets");
  const domListErrSets = document.getElementById("listErrSets");
  const domSectFns = document.getElementById("sectFns");
  const domListFns = document.getElementById("listFns");
  const domSectFields = document.getElementById("sectFields");
  const domListFields = document.getElementById("listFields");
  const domSectGlobalVars = document.getElementById("sectGlobalVars");
  const domListGlobalVars = document.getElementById("listGlobalVars");
  const domSectValues = document.getElementById("sectValues");
  const domListValues = document.getElementById("listValues");
  const domFnProto = document.getElementById("fnProto");
  const domFnProtoCode = document.getElementById("fnProtoCode");
  const domFnSourceLink = document.getElementById("fnSourceLink");
  const domSectParams = document.getElementById("sectParams");
  const domListParams = document.getElementById("listParams");
  const domTldDocs = document.getElementById("tldDocs");
  const domSectFnErrors = document.getElementById("sectFnErrors");
  const domListFnErrors = document.getElementById("listFnErrors");
  const domTableFnErrors = document.getElementById("tableFnErrors");
  const domFnErrorsAnyError = document.getElementById("fnErrorsAnyError");
  const domFnExamples = document.getElementById("fnExamples");
  // const domListFnExamples = (document.getElementById("listFnExamples"));
  const domFnNoExamples = document.getElementById("fnNoExamples");
  const domDeclNoRef = document.getElementById("declNoRef");
  const domSearch = document.getElementById("search");
  const domSectSearchResults = document.getElementById("sectSearchResults");
  const domSectSearchAllResultsLink = document.getElementById("sectSearchAllResultsLink");
  const domDocs = document.getElementById("docs");
  const domGuidesSection = document.getElementById("guides");
  const domActiveGuide = document.getElementById("activeGuide");
  
  const domListSearchResults = document.getElementById("listSearchResults");
  const domSectSearchNoResults = document.getElementById("sectSearchNoResults");
  const domSectInfo = document.getElementById("sectInfo");
  // const domTdTarget = (document.getElementById("tdTarget"));
  const domTdZigVer = document.getElementById("tdZigVer");
  const domHdrName = document.getElementById("hdrName");
  const domHelpModal = document.getElementById("helpModal");
  const domSearchPlaceholder = document.getElementById("searchPlaceholder");
  const sourceFileUrlTemplate = "src/{{mod}}/{{file}}.html#L{{line}}"
  const domLangRefLink = document.getElementById("langRefLink");

  let searchTimer = null;
  let searchTrimResults = true;

  let escapeHtmlReplacements = {
    "&": "&",
    '"': """,
    "<": "&lt;",
    ">": "&gt;",
  };

  let typeKinds = indexTypeKinds();
  let typeTypeId = findTypeTypeId();
  let pointerSizeEnum = { One: 0, Many: 1, Slice: 2, C: 3 };

  let declSearchIndex = new RadixTree();
  window.search = declSearchIndex;

  // for each module, is an array with modules to get to this one
  let canonModPaths = computeCanonicalModulePaths();

  // for each decl, is an array with {declNames, modNames} to get to this one
  let canonDeclPaths = null; // lazy; use getCanonDeclPath

  // for each type, is an array with {declNames, modNames} to get to this one
  let canonTypeDecls = null; // lazy; use getCanonTypeDecl

  let curNav = {
    mode: NAV_MODES.API,
    activeGuide: "",
    // each element is a module name, e.g. @import("a") then within there @import("b")
    // starting implicitly from root module
    modNames: [],
    // same as above except actual modules, not names
    modObjs: [],
    // Each element is a decl name, `a.b.c`, a is 0, b is 1, c is 2, etc.
    // empty array means refers to the module itself
    declNames: [],
    // these will be all types, except the last one may be a type or a decl
    declObjs: [],
    // (a, b, c, d) comptime call; result is the value the docs refer to
    callName: null,
  };

  let curNavSearch = "";
  let curSearchIndex = -1;
  let imFeelingLucky = false;

  let rootIsStd = detectRootIsStd();

  // map of decl index to list of non-generic fn indexes
  // let nodesToFnsMap = indexNodesToFns();
  // map of decl index to list of comptime fn calls
  // let nodesToCallsMap = indexNodesToCalls();

  let guidesSearchIndex = {}; 
  window.guideSearch = guidesSearchIndex;
  parseGuides();

  // identifiers can contain '?' so we want to allow typing
  // the question mark when the search is focused instead of toggling the help modal
  let canToggleHelpModal = true;

  domSearch.disabled = false;
  domSearch.addEventListener("keydown", onSearchKeyDown, false);
  domSearch.addEventListener("input", onSearchInput, false);
  domSearch.addEventListener("focus", ev => {
    domSearchPlaceholder.classList.add("hidden");
    canToggleHelpModal = false;
  });
  domSearch.addEventListener("blur", ev => {
    if (domSearch.value.length == 0)
      domSearchPlaceholder.classList.remove("hidden");
    canToggleHelpModal = true;
  });
  domSectSearchAllResultsLink.addEventListener('click', onClickSearchShowAllResults, false);
  function onClickSearchShowAllResults(ev) {
    ev.preventDefault();
    ev.stopPropagation();
    searchTrimResults = false;
    onHashChange();
  }

  if (location.hash == "") {
    location.hash = "#A;";
  }

  // make the modal disappear if you click outside it
  domHelpModal.addEventListener("click", ev => {
    if (ev.target.className == "help-modal")
      domHelpModal.classList.add("hidden");
  });

  window.addEventListener("hashchange", onHashChange, false);
  window.addEventListener("keydown", onWindowKeyDown, false);
  onHashChange();

  let langRefVersion = zigAnalysis.params.zigVersion;
  if (!/^\d+\.\d+\.\d+$/.test(langRefVersion)) {
    // the version is probably not released yet
    langRefVersion = "master";
  }
  domLangRefLink.href = `https://ziglang.org/documentation/${langRefVersion}/`;

  function renderTitle() {
    let suffix = " - Zig";
    switch (curNav.mode) {
      case NAV_MODES.API:
        let list = curNav.modNames.concat(curNav.declNames);
        if (list.length === 0) {
          document.title = zigAnalysis.modules[zigAnalysis.rootMod].name + suffix;
        } else {
          document.title = list.join(".") + suffix;
        }
        return;
      case NAV_MODES.GUIDES:
        document.title = "[G] " + curNav.activeGuide + suffix;
        return;
    }
  }

  function isDecl(x) {
    return "value" in x;
  }

  function isType(x) {
    return "kind" in x && !("value" in x);
  }

  function isContainerType(x) {
    return isType(x) && typeKindIsContainer(x.kind);
  }

  function typeShorthandName(expr) {
    let resolvedExpr = resolveValue({ expr: expr });
    if (!("type" in resolvedExpr)) {
      return null;
    }
    let type = getType(resolvedExpr.type);

    outer: for (let i = 0; i < 10000; i += 1) {
      switch (type.kind) {
        case typeKinds.Optional:
        case typeKinds.Pointer:
          let child = type.child;
          let resolvedChild = resolveValue(child);
          if ("type" in resolvedChild) {
            type = getType(resolvedChild.type);
            continue;
          } else {
            return null;
          }
        default:
          break outer;
      }

      if (i == 9999) throw "Exhausted typeShorthandName quota";
    }

    let name = undefined;
    if (type.kind === typeKinds.Struct) {
      name = "struct";
    } else if (type.kind === typeKinds.Enum) {
      name = "enum";
    } else if (type.kind === typeKinds.Union) {
      name = "union";
    } else {
      console.log("TODO: unhalndled case in typeShortName");
      return null;
    }

    return escapeHtml(name);
  }

  function typeKindIsContainer(typeKind) {
    return (
      typeKind === typeKinds.Struct ||
      typeKind === typeKinds.Union ||
      typeKind === typeKinds.Enum ||
      typeKind === typeKinds.Opaque
    );
  }

  function declCanRepresentTypeKind(typeKind) {
    return typeKind === typeKinds.ErrorSet || typeKindIsContainer(typeKind);
  }

  //
  // function findCteInRefPath(path) {
  //     for (let i = path.length - 1; i >= 0; i -= 1) {
  //         const ref = path[i];
  //         if ("string" in ref) continue;
  //         if ("comptimeExpr" in ref) return ref;
  //         if ("refPath" in ref) return findCteInRefPath(ref.refPath);
  //         return null;
  //     }

  //     return null;
  // }

  function resolveValue(value) {
    let i = 0;
    while (true) {
      i += 1;
      if (i >= 10000) {
        throw "resolveValue quota exceeded"
      }

      if ("refPath" in value.expr) {
        value = { expr: value.expr.refPath[value.expr.refPath.length - 1] };
        continue;
      }

      if ("declRef" in value.expr) {
        value = getDecl(value.expr.declRef).value;
        continue;
      }

      if ("as" in value.expr) {
        value = {
          typeRef: zigAnalysis.exprs[value.expr.as.typeRefArg],
          expr: zigAnalysis.exprs[value.expr.as.exprArg],
        };
        continue;
      }

      return value;
    }
  }

  function resolveGenericRet(genericFunc) {
    if (genericFunc.generic_ret == null) return null;
    let result = resolveValue({expr: genericFunc.generic_ret});
    
    let i = 0;
    while (true) {
      i += 1;
      if (i >= 10000) {
        throw "resolveGenericRet quota exceeded"
      }

      if ("call" in result.expr) {
        let call = zigAnalysis.calls[result.expr.call];
        let resolvedFunc = resolveValue({ expr: call.func });
        if (!("type" in resolvedFunc.expr)) return null;
        let callee = getType(resolvedFunc.expr.type);
        if (!callee.generic_ret) return null;
        result = resolveValue({ expr: callee.generic_ret });
        continue;
      }

      return result;
    }
  }

  //    function typeOfDecl(decl){
  //        return decl.value.typeRef;
  //
  //        let i = 0;
  //        while(i < 1000) {
  //            i += 1;
  //            console.assert(isDecl(decl));
  //            if ("type" in decl.value) {
  //                return ({ type: typeTypeId });
  //            }
  //
  ////            if ("string" in decl.value) {
  ////                return ({ type: {
  ////                  kind: typeKinds.Pointer,
  ////                  size: pointerSizeEnum.One,
  ////                  child: });
  ////            }
  //
  //            if ("refPath" in decl.value) {
  //                decl =  ({
  //                  value: decl.value.refPath[decl.value.refPath.length -1]
  //                });
  //                continue;
  //            }
  //
  //            if ("declRef" in decl.value) {
  //                decl = zigAnalysis.decls[decl.value.declRef];
  //                continue;
  //            }
  //
  //            if ("int" in decl.value) {
  //                return decl.value.int.typeRef;
  //            }
  //
  //            if ("float" in decl.value) {
  //                return decl.value.float.typeRef;
  //            }
  //
  //            if ("array" in decl.value) {
  //                return decl.value.array.typeRef;
  //            }
  //
  //            if ("struct" in decl.value) {
  //                return decl.value.struct.typeRef;
  //            }
  //
  //            if ("comptimeExpr" in decl.value) {
  //                const cte = zigAnalysis.comptimeExprs[decl.value.comptimeExpr];
  //                return cte.typeRef;
  //            }
  //
  //            if ("call" in decl.value) {
  //                const fn_call = zigAnalysis.calls[decl.value.call];
  //                let fn_decl = undefined;
  //                if ("declRef" in fn_call.func) {
  //                    fn_decl = zigAnalysis.decls[fn_call.func.declRef];
  //                } else if ("refPath" in fn_call.func) {
  //                    console.assert("declRef" in fn_call.func.refPath[fn_call.func.refPath.length -1]);
  //                    fn_decl = zigAnalysis.decls[fn_call.func.refPath[fn_call.func.refPath.length -1].declRef];
  //                } else throw {};
  //
  //                const fn_decl_value = resolveValue(fn_decl.value);
  //                console.assert("type" in fn_decl_value); //TODO handle comptimeExpr
  //                const fn_type = (zigAnalysis.types[fn_decl_value.type]);
  //                console.assert(fn_type.kind === typeKinds.Fn);
  //                return fn_type.ret;
  //            }
  //
  //            if ("void" in decl.value) {
  //                return ({ type: typeTypeId });
  //            }
  //
  //            if ("bool" in decl.value) {
  //                return ({ type: typeKinds.Bool });
  //            }
  //
  //            console.log("TODO: handle in `typeOfDecl` more cases: ", decl);
  //            console.assert(false);
  //            throw {};
  //        }
  //        console.assert(false);
  //        return ({});
  //    }
  function renderGuides() {
    renderTitle();

    // set guide mode
    domGuideSwitch.classList.add("active");
    domApiSwitch.classList.remove("active");
    domDocs.classList.add("hidden");
    domGuidesSection.classList.remove("hidden");
    domActiveGuide.classList.add("hidden");
    domApiMenu.classList.add("hidden");
    domSectSearchResults.classList.add("hidden");
    domSectSearchAllResultsLink.classList.add("hidden");
    domSectSearchNoResults.classList.add("hidden");

    // sidebar guides list
    const section_list = zigAnalysis.guide_sections;
    resizeDomList(domGuidesList, section_list.length, '<div><h2><span></span></h2><ul class="modules"></ul></div>');
    for (let j = 0; j < section_list.length; j += 1) {
        const section = section_list[j];
        const domSectionName = domGuidesList.children[j].children[0].children[0];
        const domGuides = domGuidesList.children[j].children[1];
        domSectionName.textContent = section.name;
        resizeDomList(domGuides, section.guides.length, '<li><a href="#"></a></li>');
        for (let i = 0; i < section.guides.length; i += 1) {
          const guide = section.guides[i];
          let liDom = domGuides.children[i];
          let aDom = liDom.children[0];
          aDom.textContent = guide.title;
          aDom.setAttribute("href", NAV_MODES.GUIDES + guide.name);
          if (guide.name === curNav.activeGuide) {
            aDom.classList.add("active");
          } else {
            aDom.classList.remove("active");
          }
        }
    }
  
    if (section_list.length > 0) {
      domGuidesMenu.classList.remove("hidden");
    }

    
    if (curNavSearch !== "") {
          return renderSearchGuides();
    }

    // main content
    let activeGuide = undefined;
    outer: for (let i = 0; i < zigAnalysis.guide_sections.length; i += 1) {
      const section = zigAnalysis.guide_sections[i];
      for (let j = 0; j < section.guides.length; j += 1) {
        const guide = section.guides[j];
        if (guide.name == curNav.activeGuide) {
          activeGuide = guide;
          break outer;
        }
      }
    }        
    
    if (activeGuide == undefined) {
      const root_file_idx = zigAnalysis.modules[zigAnalysis.rootMod].file;
      const root_file_name = getFile(root_file_idx).name;
      domActiveGuide.innerHTML = markdown(`
          # Zig Guides
          These autodocs don't contain any guide.

          While the API section is a reference guide autogenerated from Zig source code,
          guides are meant to be handwritten explanations that provide for example:

          - how-to explanations for common use-cases 
          - technical documentation 
          - information about advanced usage patterns
          
          You can add guides by specifying which markdown files to include
          in the top level doc comment of your root file, like so:

          (At the top of *${root_file_name}*)
          \`\`\`
          //!zig-autodoc-guide: intro.md
          //!zig-autodoc-guide: quickstart.md
          //!zig-autodoc-guide: advanced-docs/advanced-stuff.md
          \`\`\`

          You can also create sections to group guides together:

          \`\`\`
          //!zig-autodoc-section: CLI Usage
          //!zig-autodoc-guide: cli-basics.md
          //!zig-autodoc-guide: cli-advanced.md
          \`\`\`
           
        
          **Note that this feature is still under heavy development so expect bugs**
          **and missing features!**

          Happy writing!
        `);
    } else {
      domActiveGuide.innerHTML = markdown(activeGuide.body);
    }
    domActiveGuide.classList.remove("hidden");
  }

  function renderApi() {
    // set Api mode
    domApiSwitch.classList.add("active");
    domGuideSwitch.classList.remove("active");
    domGuidesSection.classList.add("hidden");
    domDocs.classList.remove("hidden");
    domApiMenu.classList.remove("hidden");
    domGuidesMenu.classList.add("hidden");

    domStatus.classList.add("hidden");
    domFnProto.classList.add("hidden");
    domSectParams.classList.add("hidden");
    domTldDocs.classList.add("hidden");
    domSectMainMod.classList.add("hidden");
    domSectMods.classList.add("hidden");
    domSectTypes.classList.add("hidden");
    domSectTests.classList.add("hidden");
    domSectDocTests.classList.add("hidden");
    domSectNamespaces.classList.add("hidden");
    domSectErrSets.classList.add("hidden");
    domSectFns.classList.add("hidden");
    domSectFields.classList.add("hidden");
    domSectSearchResults.classList.add("hidden");
    domSectSearchAllResultsLink.classList.add("hidden");
    domSectSearchNoResults.classList.add("hidden");
    domSectInfo.classList.add("hidden");
    domHdrName.classList.add("hidden");
    domSectNav.classList.add("hidden");
    domSectFnErrors.classList.add("hidden");
    domFnExamples.classList.add("hidden");
    domFnNoExamples.classList.add("hidden");
    domDeclNoRef.classList.add("hidden");
    domFnErrorsAnyError.classList.add("hidden");
    domTableFnErrors.classList.add("hidden");
    domSectGlobalVars.classList.add("hidden");
    domSectValues.classList.add("hidden");

    renderTitle();
    renderInfo();
    renderModList();

    if (curNavSearch !== "") {
          return renderSearchAPI();
    }

    let rootMod = zigAnalysis.modules[zigAnalysis.rootMod];
    let mod = rootMod;
    curNav.modObjs = [mod];
    for (let i = 0; i < curNav.modNames.length; i += 1) {
      let childMod = zigAnalysis.modules[mod.table[curNav.modNames[i]]];
      if (childMod == null) {
        return render404();
      }
      mod = childMod;
      curNav.modObjs.push(mod);
    }

    let currentType = getType(mod.main);
    curNav.declObjs = [currentType];
    let lastDecl = mod.main;
    for (let i = 0; i < curNav.declNames.length; i += 1) {
      let childDecl = findSubDecl(currentType, curNav.declNames[i]);
      window.last_decl = childDecl;
      if (childDecl == null || childDecl.is_private === true) {
        return render404();
      }
      lastDecl = childDecl;

      let childDeclValue = resolveValue(childDecl.value).expr;
      if ("type" in childDeclValue) {
        const t = getType(childDeclValue.type);
        if (t.kind != typeKinds.Fn) {
          childDecl = t;
        }
      }

      currentType = childDecl;
      curNav.declObjs.push(currentType);
    }



    window.x = currentType;

    renderNav();

    let last = curNav.declObjs[curNav.declObjs.length - 1];
    let lastIsDecl = isDecl(last);
    let lastIsType = isType(last);
    let lastIsContainerType = isContainerType(last);

    renderDocTest(lastDecl);

    if (lastIsContainerType) {
      return renderContainer(last);
    }

    if (!lastIsDecl && !lastIsType) {
      return renderUnknownDecl(last);
    }

    if (lastIsType) {
      return renderType(last);
    }

    if (lastIsDecl && last.kind === "var") {
      return renderVar(last);
    }

    if (lastIsDecl && last.kind === "const") {
      const value = resolveValue(last.value);
      if ("type" in value.expr) {
        let typeObj = getType(value.expr.type);
        if (typeObj.kind === typeKinds.Fn) {
          return renderFn(last);
        }
      }
      return renderValue(last);
    }

  }

  function render() {
    switch (curNav.mode) {
      case NAV_MODES.API:
        return renderApi();
      case NAV_MODES.GUIDES:
        return renderGuides();
      default:
        throw "?";
    }
  }


  function renderDocTest(decl) {
    if (!decl.decltest) return;
    const astNode = getAstNode(decl.decltest);
    domSectDocTests.classList.remove("hidden");
    domDocTestsCode.innerHTML = renderZigSource(astNode.code);
  }

  function renderZigSource(code) {
    let lines = code.split("\n");
    let result = "";
    let indent_level = 0;
    for (let i = 0; i < lines.length; i += 1) {
      let line = lines[i].trim();
      if (line[0] == "}") indent_level -= 1;
      for (let j = 0; j < indent_level; j += 1) {
        result += "    ";
      }
      if (line.startsWith("\\\\")) result += "    "
      result += line;
      if (i != lines.length - 1) result += "\n";
      if (line[line.length - 1] == "{") indent_level += 1;
    }
    return result;
  }

  function renderUnknownDecl(decl) {
    domDeclNoRef.classList.remove("hidden");

    let docs = getAstNode(decl.src).docs;
    if (docs != null) {
      domTldDocs.innerHTML = markdown(docs);
    } else {
      domTldDocs.innerHTML =
        "<p>There are no doc comments for this declaration.</p>";
    }
    domTldDocs.classList.remove("hidden");
  }

  function typeIsErrSet(typeIndex) {
    let typeObj = getType(typeIndex);
    return typeObj.kind === typeKinds.ErrorSet;
  }

  function typeIsStructWithNoFields(typeIndex) {
    let typeObj = getType(typeIndex);
    if (typeObj.kind !== typeKinds.Struct) return false;
    return typeObj.field_types.length == 0;
  }

  function typeIsGenericFn(typeIndex) {
    let typeObj = getType(typeIndex);
    if (typeObj.kind !== typeKinds.Fn) {
      return false;
    }
    return typeObj.generic_ret != null;
  }

  function renderFn(fnDecl) {
    if ("refPath" in fnDecl.value.expr) {
      let last = fnDecl.value.expr.refPath.length - 1;
      let lastExpr = fnDecl.value.expr.refPath[last];
      console.assert("declRef" in lastExpr);
      fnDecl = getDecl(lastExpr.declRef);
    }

    let value = resolveValue(fnDecl.value);
    console.assert("type" in value.expr);
    let typeObj = getType(value.expr.type);

    domFnProtoCode.innerHTML = exprName(value.expr, {
      wantHtml: true,
      wantLink: true,
      fnDecl,
    });

    domFnSourceLink.innerHTML = "[<a target=\"_blank\" href=\"" + sourceFileLink(fnDecl) + "\">src</a>]";

    let docsSource = null;
    let srcNode = getAstNode(fnDecl.src);
    if (srcNode.docs != null) {
      docsSource = srcNode.docs;
    }

    renderFnParamDocs(fnDecl, typeObj);

    let retExpr = resolveValue({ expr: typeObj.ret }).expr;
    if ("type" in retExpr) {
      let retIndex = retExpr.type;
      let errSetTypeIndex = null;
      let retType = getType(retIndex);
      if (retType.kind === typeKinds.ErrorSet) {
        errSetTypeIndex = retIndex;
      } else if (retType.kind === typeKinds.ErrorUnion) {
        errSetTypeIndex = retType.err.type;
      }
      if (errSetTypeIndex != null) {
        let errSetType = getType(errSetTypeIndex);
        renderErrorSet(errSetType);
      }
    }

    let protoSrcIndex = fnDecl.src;
    if (typeIsGenericFn(value.expr.type)) {
      // does the generic_ret contain a container?
      var resolvedGenericRet = resolveValue({ expr: typeObj.generic_ret });

      if ("call" in resolvedGenericRet.expr) {
        let call = zigAnalysis.calls[resolvedGenericRet.expr.call];
        let resolvedFunc = resolveValue({ expr: call.func });
        if (!("type" in resolvedFunc.expr)) return;
        let callee = getType(resolvedFunc.expr.type);
        if (!callee.generic_ret) return;
        resolvedGenericRet = resolveValue({ expr: callee.generic_ret });
      }

      // TODO: see if unwrapping the `as` here is a good idea or not.
      if ("as" in resolvedGenericRet.expr) {
        resolvedGenericRet = {
          expr: zigAnalysis.exprs[resolvedGenericRet.expr.as.exprArg],
        };
      }

      if (!("type" in resolvedGenericRet.expr)) return;
      const genericType = getType(resolvedGenericRet.expr.type);
      if (isContainerType(genericType)) {
        renderContainer(genericType);
      }

      // old code
      // let instantiations = nodesToFnsMap[protoSrcIndex];
      // let calls = nodesToCallsMap[protoSrcIndex];
      // if (instantiations == null && calls == null) {
      //     domFnNoExamples.classList.remove("hidden");
      // } else if (calls != null) {
      //     // if (fnObj.combined === undefined) fnObj.combined = allCompTimeFnCallsResult(calls);
      //     if (fnObj.combined != null) renderContainer(fnObj.combined);

      //     resizeDomList(domListFnExamples, calls.length, '<li></li>');

      //     for (let callI = 0; callI < calls.length; callI += 1) {
      //         let liDom = domListFnExamples.children[callI];
      //         liDom.innerHTML = getCallHtml(fnDecl, calls[callI]);
      //     }

      //     domFnExamples.classList.remove("hidden");
      // } else if (instantiations != null) {
      //     // TODO
      // }
    } else {
      domFnExamples.classList.add("hidden");
      domFnNoExamples.classList.add("hidden");
    }

    let protoSrcNode = getAstNode(protoSrcIndex);
    if (
      docsSource == null &&
      protoSrcNode != null &&
      protoSrcNode.docs != null
    ) {
      docsSource = protoSrcNode.docs;
    }
    if (docsSource != null) {
      domTldDocs.innerHTML = markdown(docsSource, fnDecl);
      domTldDocs.classList.remove("hidden");
    }
    domFnProto.classList.remove("hidden");
  }

  function renderFnParamDocs(fnDecl, typeObj) {
    let docCount = 0;

    let fnNode = getAstNode(fnDecl.src);
    let fields = fnNode.fields;
    let isVarArgs = fnNode.varArgs;

    for (let i = 0; i < fields.length; i += 1) {
      let field = fields[i];
      let fieldNode = getAstNode(field);
      if (fieldNode.docs != null) {
        docCount += 1;
      }
    }
    if (docCount == 0) {
      return;
    }

    resizeDomList(domListParams, docCount, "<div></div>");
    let domIndex = 0;

    for (let i = 0; i < fields.length; i += 1) {
      let field = fields[i];
      let fieldNode = getAstNode(field);
      let docs = fieldNode.docs;
      if (fieldNode.docs == null) {
        continue;
      }
      let docsNonEmpty = docs !== "";
      let divDom = domListParams.children[domIndex];
      domIndex += 1;

      let value = typeObj.params[i];
      let preClass = docsNonEmpty ? ' class="fieldHasDocs"' : "";
      let html = "<pre" + preClass + ">" + escapeHtml(fieldNode.name) + ": ";
      if (isVarArgs && i === typeObj.params.length - 1) {
        html += "...";
      } else {
        let name = exprName(value, { wantHtml: false, wantLink: false });
        html += '<span class="tok-kw">' + name + "</span>";
      }

      html += ",</pre>";

      if (docsNonEmpty) {
        html += '<div class="fieldDocs">' + markdown(docs) + "</div>";
      }
      divDom.innerHTML = html;
    }
    domSectParams.classList.remove("hidden");
  }

  function renderNav() {
    let len = curNav.modNames.length + curNav.declNames.length;
    resizeDomList(domListNav, len, '<li><a href="#"></a></li>');
    let list = [];
    let hrefModNames = [];
    let hrefDeclNames = [];
    for (let i = 0; i < curNav.modNames.length; i += 1) {
      hrefModNames.push(curNav.modNames[i]);
      let name = curNav.modNames[i];
      list.push({
        name: name,
        link: navLink(hrefModNames, hrefDeclNames),
      });
    }
    for (let i = 0; i < curNav.declNames.length; i += 1) {
      hrefDeclNames.push(curNav.declNames[i]);
      list.push({
        name: curNav.declNames[i],
        link: navLink(hrefModNames, hrefDeclNames),
      });
    }

    for (let i = 0; i < list.length; i += 1) {
      let liDom = domListNav.children[i];
      let aDom = liDom.children[0];
      aDom.textContent = list[i].name;
      aDom.setAttribute("href", list[i].link);
      if (i + 1 == list.length) {
        aDom.classList.add("active");
      } else {
        aDom.classList.remove("active");
      }
    }

    domSectNav.classList.remove("hidden");
  }

  function renderInfo() {
    domTdZigVer.textContent = zigAnalysis.params.zigVersion;
    //domTdTarget.textContent = zigAnalysis.params.builds[0].target;

    domSectInfo.classList.remove("hidden");
  }

  function render404() {
    domStatus.textContent = "404 Not Found";
    domStatus.classList.remove("hidden");
  }

  function renderModList() {
    const rootMod = zigAnalysis.modules[zigAnalysis.rootMod];
    let list = [];
    for (let key in rootMod.table) {
      let modIndex = rootMod.table[key];
      if (zigAnalysis.modules[modIndex] == null) continue;
      if (key == rootMod.name) continue;
      list.push({
        name: key,
        mod: modIndex,
      });
    }

    {
      let aDom = domSectMainMod.children[1].children[0].children[0];
      aDom.textContent = rootMod.name;
      aDom.setAttribute("href", navLinkMod(zigAnalysis.rootMod));
      if (rootMod.name === curNav.modNames[0]) {
        aDom.classList.add("active");
      } else {
        aDom.classList.remove("active");
      }
      domSectMainMod.classList.remove("hidden");
    }

    list.sort(function (a, b) {
      return operatorCompare(a.name.toLowerCase(), b.name.toLowerCase());
    });

    if (list.length !== 0) {
      resizeDomList(domListMods, list.length, '<li><a href="#"></a></li>');
      for (let i = 0; i < list.length; i += 1) {
        let liDom = domListMods.children[i];
        let aDom = liDom.children[0];
        aDom.textContent = list[i].name;
        aDom.setAttribute("href", navLinkMod(list[i].mod));
        if (list[i].name === curNav.modNames[0]) {
          aDom.classList.add("active");
        } else {
          aDom.classList.remove("active");
        }
      }

      domSectMods.classList.remove("hidden");
    }
  }

  function navLink(modNames, declNames, callName) {
    let base = curNav.mode;

    if (modNames.length === 0 && declNames.length === 0) {
      return base;
    } else if (declNames.length === 0 && callName == null) {
      return base + modNames.join(".");
    } else if (callName == null) {
      return base + modNames.join(".") + ":" + declNames.join(".");
    } else {
      return (
        base + modNames.join(".") + ":" + declNames.join(".") + ";" + callName
      );
    }
  }

  function navLinkMod(modIndex) {
    return navLink(canonModPaths[modIndex], []);
  }

  function navLinkDecl(childName) {
    return navLink(curNav.modNames, curNav.declNames.concat([childName]));
  }

  function findDeclNavLink(declName) {
    if (curNav.declObjs.length == 0) return null;
    const curFile = getAstNode(curNav.declObjs[curNav.declObjs.length - 1].src).file;

    for (let i = curNav.declObjs.length - 1; i >= 0; i--) {
      const curDecl = curNav.declObjs[i];
      const curDeclName = curNav.declNames[i - 1];
      if (curDeclName == declName) {
        const declPath = curNav.declNames.slice(0, i);
        return navLink(curNav.modNames, declPath);
      }

      const subDecl = findSubDecl(curDecl, declName);

      if (subDecl != null) {
        if (subDecl.is_private === true) {
          return sourceFileLink(subDecl);
        } else {
          const declPath = curNav.declNames.slice(0, i).concat([declName]);
          return navLink(curNav.modNames, declPath);
        }
      }
    }

    //throw("could not resolve links for '" + declName + "'");
  }

  //
  //  function navLinkCall(callObj) {
  //      let declNamesCopy = curNav.declNames.concat([]);
  //      let callName = (declNamesCopy.pop());

  //      callName += '(';
  //          for (let arg_i = 0; arg_i < callObj.args.length; arg_i += 1) {
  //              if (arg_i !== 0) callName += ',';
  //              let argObj = callObj.args[arg_i];
  //              callName += getValueText(argObj, argObj, false, false);
  //          }
  //          callName += ')';

  //      declNamesCopy.push(callName);
  //      return navLink(curNav.modNames, declNamesCopy);
  //  }

  function resizeDomListDl(dlDom, desiredLen) {
    // add the missing dom entries
    for (let i = dlDom.childElementCount / 2; i < desiredLen; i += 1) {
      dlDom.insertAdjacentHTML("beforeend", "<dt></dt><dd></dd>");
    }
    // remove extra dom entries
    while (desiredLen < dlDom.childElementCount / 2) {
      dlDom.removeChild(dlDom.lastChild);
      dlDom.removeChild(dlDom.lastChild);
    }
  }

  function resizeDomList(listDom, desiredLen, templateHtml) {
    // add the missing dom entries
    for (let i = listDom.childElementCount; i < desiredLen; i += 1) {
      listDom.insertAdjacentHTML("beforeend", templateHtml);
    }
    // remove extra dom entries
    while (desiredLen < listDom.childElementCount) {
      listDom.removeChild(listDom.lastChild);
    }
  }

  function walkResultTypeRef(wr) {
    if (wr.typeRef) return wr.typeRef;
    let resolved = resolveValue(wr);
    if (wr === resolved) {
      return { type: 0 };
    }
    return walkResultTypeRef(resolved);
  }

  function exprName(expr, opts) {
    switch (Object.keys(expr)[0]) {
      default:
        throw "this expression is not implemented yet";
      case "bool": {
        if (expr.bool) {
          return "true";
        }
        return "false";
      }
      case "&": {
        return "&" + exprName(zigAnalysis.exprs[expr["&"]], opts);
      }
      case "compileError": {
        let compileError = expr.compileError;
        return "@compileError(" + exprName(zigAnalysis.exprs[compileError], opts) + ")";
      }
      case "enumLiteral": {
        let literal = expr.enumLiteral;
        return "." + literal;
      }
      case "void": {
        return "void";
      }
      case "slice": {
        let payloadHtml = "";
        const lhsExpr = zigAnalysis.exprs[expr.slice.lhs];
        const startExpr = zigAnalysis.exprs[expr.slice.start];
        let decl = exprName(lhsExpr, opts);
        let start = exprName(startExpr, opts);
        let end = "";
        let sentinel = "";
        if (expr.slice["end"]) {
          const endExpr = zigAnalysis.exprs[expr.slice.end];
          let end_ = exprName(endExpr, opts);
          end += end_;
        }
        if (expr.slice["sentinel"]) {
          const sentinelExpr = zigAnalysis.exprs[expr.slice.sentinel];
          let sentinel_ = exprName(sentinelExpr, opts);
          sentinel += " :" + sentinel_;
        }
        payloadHtml += decl + "[" + start + ".." + end + sentinel + "]";
        return payloadHtml;
      }
      case "sliceLength": {
        let payloadHtml = "";
        const lhsExpr = zigAnalysis.exprs[expr.sliceLength.lhs];
        const startExpr = zigAnalysis.exprs[expr.sliceLength.start];
        const lenExpr = zigAnalysis.exprs[expr.sliceLength.len];
        let decl = exprName(lhsExpr, opts);
        let start = exprName(startExpr, opts);
        let len = exprName(lenExpr, opts);
        let sentinel = "";
        if (expr.sliceLength["sentinel"]) {
            const sentinelExpr = zigAnalysis.exprs[expr.sliceLength.sentinel];
            let sentinel_ = exprName(sentinelExpr, options);
            sentinel += " :" + sentinel_;
        }
        payloadHtml += decl + "[" + start + "..][0.." + len + sentinel + "]";
        return payloadHtml;
      }
      case "sliceIndex": {
        const sliceIndex = zigAnalysis.exprs[expr.sliceIndex];
        return exprName(sliceIndex, opts, opts);
      }
      case "cmpxchg": {
        const typeIndex = zigAnalysis.exprs[expr.cmpxchg.type];
        const ptrIndex = zigAnalysis.exprs[expr.cmpxchg.ptr];
        const expectedValueIndex =
          zigAnalysis.exprs[expr.cmpxchg.expected_value];
        const newValueIndex = zigAnalysis.exprs[expr.cmpxchg.new_value];
        const successOrderIndex = zigAnalysis.exprs[expr.cmpxchg.success_order];
        const failureOrderIndex = zigAnalysis.exprs[expr.cmpxchg.failure_order];

        const type = exprName(typeIndex, opts);
        const ptr = exprName(ptrIndex, opts);
        const expectedValue = exprName(expectedValueIndex, opts);
        const newValue = exprName(newValueIndex, opts);
        const successOrder = exprName(successOrderIndex, opts);
        const failureOrder = exprName(failureOrderIndex, opts);

        let fnName = "@";

        switch (expr.cmpxchg.name) {
          case "cmpxchg_strong": {
            fnName += "cmpxchgStrong";
            break;
          }
          case "cmpxchg_weak": {
            fnName += "cmpxchgWeak";
            break;
          }
          default: {
            console.log("There's only cmpxchg_strong and cmpxchg_weak");
          }
        }

        return (
          fnName +
          "(" +
          type +
          ", " +
          ptr +
          ", " +
          expectedValue +
          ", " +
          newValue +
          ", " +
          "." +
          successOrder +
          ", " +
          "." +
          failureOrder +
          ")"
        );
      }
      case "cmpxchgIndex": {
        const cmpxchgIndex = zigAnalysis.exprs[expr.cmpxchgIndex];
        return exprName(cmpxchgIndex, opts);
      }
      case "switchOp": {
        let condExpr = zigAnalysis.exprs[expr.switchOp.cond_index];
        let ast = getAstNode(expr.switchOp.src);
        let file_name = expr.switchOp.file_name;
        let outer_decl_index = expr.switchOp.outer_decl;
        let outer_decl = getType(outer_decl_index);
        let line = 0;
        // console.log(expr.switchOp)
        // console.log(outer_decl)
        while (outer_decl_index !== 0 && outer_decl.line_number > 0) {
          line += outer_decl.line_number;
          outer_decl_index = outer_decl.outer_decl;
          outer_decl = getType(outer_decl_index);
          // console.log(outer_decl)
        }
        line += ast.line + 1;
        let payloadHtml = "";
        let cond = exprName(condExpr, opts);

        payloadHtml +=
          "</br>" +
          "node_name: " +
          ast.name +
          "</br>" +
          "file: " +
          file_name +
          "</br>" +
          "line: " +
          line +
          "</br>";
        payloadHtml +=
          "switch(" +
          cond +
          ") {" +
          '<a href="/src/' +
          file_name +
          "#L" +
          line +
          '">' +
          "..." +
          "</a>}";
        return payloadHtml;
      }
      case "switchIndex": {
        const switchIndex = zigAnalysis.exprs[expr.switchIndex];
        return exprName(switchIndex, opts);
      }
      case "fieldRef": {
        const field_idx = expr.fieldRef.index;
        const type = getType(expr.fieldRef.type);
        const field = getAstNode(type.src).fields[field_idx];
        const name = getAstNode(field).name;
        return name;
      }
      case "enumToInt": {
        const enumToInt = zigAnalysis.exprs[expr.enumToInt];
        return "@enumToInt(" + exprName(enumToInt, opts) + ")";
      }
      case "bitSizeOf": {
        const bitSizeOf = zigAnalysis.exprs[expr.bitSizeOf];
        return "@bitSizeOf(" + exprName(bitSizeOf, opts) + ")";
      }
      case "sizeOf": {
        const sizeOf = zigAnalysis.exprs[expr.sizeOf];
        return "@sizeOf(" + exprName(sizeOf, opts) + ")";
      }
      case "builtinIndex": {
        const builtinIndex = zigAnalysis.exprs[expr.builtinIndex];
        return exprName(builtinIndex, opts);
      }
      case "builtin": {
        const param_expr = zigAnalysis.exprs[expr.builtin.param];
        let param = exprName(param_expr, opts);

        let payloadHtml = "@";
        switch (expr.builtin.name) {
          case "align_of": {
            payloadHtml += "alignOf";
            break;
          }
          case "bool_to_int": {
            payloadHtml += "boolToInt";
            break;
          }
          case "embed_file": {
            payloadHtml += "embedFile";
            break;
          }
          case "error_name": {
            payloadHtml += "errorName";
            break;
          }
          case "panic": {
            payloadHtml += "panic";
            break;
          }
          case "set_runtime_safety": {
            payloadHtml += "setRuntimeSafety";
            break;
          }
          case "sqrt": {
            payloadHtml += "sqrt";
            break;
          }
          case "sin": {
            payloadHtml += "sin";
            break;
          }
          case "cos": {
            payloadHtml += "cos";
            break;
          }
          case "tan": {
            payloadHtml += "tan";
            break;
          }
          case "exp": {
            payloadHtml += "exp";
            break;
          }
          case "exp2": {
            payloadHtml += "exp2";
            break;
          }
          case "log": {
            payloadHtml += "log";
            break;
          }
          case "log2": {
            payloadHtml += "log2";
            break;
          }
          case "log10": {
            payloadHtml += "log10";
            break;
          }
          case "fabs": {
            payloadHtml += "fabs";
            break;
          }
          case "floor": {
            payloadHtml += "floor";
            break;
          }
          case "ceil": {
            payloadHtml += "ceil";
            break;
          }
          case "trunc": {
            payloadHtml += "trunc";
            break;
          }
          case "round": {
            payloadHtml += "round";
            break;
          }
          case "tag_name": {
            payloadHtml += "tagName";
            break;
          }
          case "reify": {
            payloadHtml += "Type";
            break;
          }
          case "type_name": {
            payloadHtml += "typeName";
            break;
          }
          case "frame_type": {
            payloadHtml += "Frame";
            break;
          }
          case "frame_size": {
            payloadHtml += "frameSize";
            break;
          }
          case "work_item_id": {
            payloadHtml += "workItemId";
            break;
          }
          case "work_group_size": {
            payloadHtml += "workGroupSize";
            break;
          }
          case "work_group_id": {
            payloadHtml += "workGroupId";
            break;
          }
          case "ptr_to_int": {
            payloadHtml += "ptrToInt";
            break;
          }
          case "error_to_int": {
            payloadHtml += "errorToInt";
            break;
          }
          case "int_to_error": {
            payloadHtml += "intToError";
            break;
          }
          case "max": {
            payloadHtml += "max";
            break;
          }
          case "min": {
            payloadHtml += "min";
            break;
          }
          case "bit_not": {
            return "~" + param;
          }
          case "clz": {
            return "@clz(T" + ", " + param + ")";
          }
          case "ctz": {
            return "@ctz(T" + ", " + param + ")";
          }
          case "pop_count": {
            return "@popCount(T" + ", " + param + ")";
          }
          case "byte_swap": {
            return "@byteSwap(T" + ", " + param + ")";
          }
          case "bit_reverse": {
            return "@bitReverse(T" + ", " + param + ")";
          }
          default:
            console.log("builtin function not handled yet or doesn't exist!");
        }
        return payloadHtml + "(" + param + ")";
      }
      case "builtinBinIndex": {
        const builtinBinIndex = zigAnalysis.exprs[expr.builtinBinIndex];
        return exprName(builtinBinIndex, opts);
      }
      case "builtinBin": {
        const lhsOp = zigAnalysis.exprs[expr.builtinBin.lhs];
        const rhsOp = zigAnalysis.exprs[expr.builtinBin.rhs];
        let lhs = exprName(lhsOp, opts);
        let rhs = exprName(rhsOp, opts);

        let payloadHtml = "@";
        switch (expr.builtinBin.name) {
          case "float_to_int": {
            payloadHtml += "floatToInt";
            break;
          }
          case "int_to_float": {
            payloadHtml += "intToFloat";
            break;
          }
          case "int_to_ptr": {
            payloadHtml += "intToPtr";
            break;
          }
          case "int_to_enum": {
            payloadHtml += "intToEnum";
            break;
          }
          case "float_cast": {
            payloadHtml += "floatCast";
            break;
          }
          case "int_cast": {
            payloadHtml += "intCast";
            break;
          }
          case "ptr_cast": {
            payloadHtml += "ptrCast";
            break;
          }
          case "const_cast": {
            payloadHtml += "constCast";
            break;
          }
          case "volatile_cast": {
            payloadHtml += "volatileCast";
            break;
          }
          case "truncate": {
            payloadHtml += "truncate";
            break;
          }
          case "has_decl": {
            payloadHtml += "hasDecl";
            break;
          }
          case "has_field": {
            payloadHtml += "hasField";
            break;
          }
          case "bit_reverse": {
            payloadHtml += "bitReverse";
            break;
          }
          case "div_exact": {
            payloadHtml += "divExact";
            break;
          }
          case "div_floor": {
            payloadHtml += "divFloor";
            break;
          }
          case "div_trunc": {
            payloadHtml += "divTrunc";
            break;
          }
          case "mod": {
            payloadHtml += "mod";
            break;
          }
          case "rem": {
            payloadHtml += "rem";
            break;
          }
          case "mod_rem": {
            payloadHtml += "rem";
            break;
          }
          case "shl_exact": {
            payloadHtml += "shlExact";
            break;
          }
          case "shr_exact": {
            payloadHtml += "shrExact";
            break;
          }
          case "bitcast": {
            payloadHtml += "bitCast";
            break;
          }
          case "align_cast": {
            payloadHtml += "alignCast";
            break;
          }
          case "vector_type": {
            payloadHtml += "Vector";
            break;
          }
          case "reduce": {
            payloadHtml += "reduce";
            break;
          }
          case "splat": {
            payloadHtml += "splat";
            break;
          }
          case "offset_of": {
            payloadHtml += "offsetOf";
            break;
          }
          case "bit_offset_of": {
            payloadHtml += "bitOffsetOf";
            break;
          }
          default:
            console.log("builtin function not handled yet or doesn't exist!");
        }
        return payloadHtml + "(" + lhs + ", " + rhs + ")";
      }
      case "binOpIndex": {
        const binOpIndex = zigAnalysis.exprs[expr.binOpIndex];
        return exprName(binOpIndex, opts);
      }
      case "binOp": {
        const lhsOp = zigAnalysis.exprs[expr.binOp.lhs];
        const rhsOp = zigAnalysis.exprs[expr.binOp.rhs];
        let lhs = exprName(lhsOp, opts);
        let rhs = exprName(rhsOp, opts);

        let print_lhs = "";
        let print_rhs = "";

        if (lhsOp["binOpIndex"]) {
          print_lhs = "(" + lhs + ")";
        } else {
          print_lhs = lhs;
        }
        if (rhsOp["binOpIndex"]) {
          print_rhs = "(" + rhs + ")";
        } else {
          print_rhs = rhs;
        }

        let operator = "";

        switch (expr.binOp.name) {
          case "add": {
            operator += "+";
            break;
          }
          case "addwrap": {
            operator += "+%";
            break;
          }
          case "add_sat": {
            operator += "+|";
            break;
          }
          case "sub": {
            operator += "-";
            break;
          }
          case "subwrap": {
            operator += "-%";
            break;
          }
          case "sub_sat": {
            operator += "-|";
            break;
          }
          case "mul": {
            operator += "*";
            break;
          }
          case "mulwrap": {
            operator += "*%";
            break;
          }
          case "mul_sat": {
            operator += "*|";
            break;
          }
          case "div": {
            operator += "/";
            break;
          }
          case "shl": {
            operator += "<<";
            break;
          }
          case "shl_sat": {
            operator += "<<|";
            break;
          }
          case "shr": {
            operator += ">>";
            break;
          }
          case "bit_or": {
            operator += "|";
            break;
          }
          case "bit_and": {
            operator += "&";
            break;
          }
          case "array_cat": {
            operator += "++";
            break;
          }
          case "array_mul": {
            operator += "**";
            break;
          }
          case "cmp_eq": {
            operator += "==";
            break;
          }
          case "cmp_neq": {
            operator += "!=";
            break;
          }
          case "cmp_gt": {
            operator += ">";
            break;
          }
          case "cmp_gte": {
            operator += ">=";
            break;
          }
          case "cmp_lt": {
            operator += "<";
            break;
          }
          case "cmp_lte": {
            operator += "<=";
            break;
          }
          default:
            console.log("operator not handled yet or doesn't exist!");
        }

        return print_lhs + " " + operator + " " + print_rhs;
      }
      case "errorSets": {
        const errUnionObj = getType(expr.errorSets);
        let lhs = exprName(errUnionObj.lhs, opts);
        let rhs = exprName(errUnionObj.rhs, opts);
        return lhs + " || " + rhs;
      }
      case "errorUnion": {
        const errUnionObj = getType(expr.errorUnion);
        let lhs = exprName(errUnionObj.lhs, opts);
        let rhs = exprName(errUnionObj.rhs, opts);
        return lhs + "!" + rhs;
      }
      case "struct": {
        // const struct_name =
        //   zigAnalysis.decls[expr.struct[0].val.typeRef.refPath[0].declRef].name;
        const struct_name = ".";
        let struct_body = "";
        struct_body += struct_name + "{ ";
        for (let i = 0; i < expr.struct.length; i++) {
          const fv = expr.struct[i];
          const field_name = fv.name;
          const field_value = exprName(fv.val.expr, opts);
          // TODO: commented out because it seems not needed. if it deals
          //       with a corner case, please add a comment when re-enabling it.
          // let field_value = exprArg[Object.keys(exprArg)[0]];
          // if (field_value instanceof Object) {
          //   value_field = exprName(value_field)
          //     zigAnalysis.decls[value_field[0].val.typeRef.refPath[0].declRef]
          //       .name;
          // }
          struct_body += "." + field_name + " = " + field_value;
          if (i !== expr.struct.length - 1) {
            struct_body += ", ";
          } else {
            struct_body += " ";
          }
        }
        struct_body += "}";
        return struct_body;
      }
      case "typeOf_peer": {
        let payloadHtml = "@TypeOf(";
        for (let i = 0; i < expr.typeOf_peer.length; i++) {
          let elem = zigAnalysis.exprs[expr.typeOf_peer[i]];
          payloadHtml += exprName(elem, { wantHtml: true, wantLink: true });
          if (i !== expr.typeOf_peer.length - 1) {
            payloadHtml += ", ";
          }
        }
        payloadHtml += ")";
        return payloadHtml;
      }
      case "alignOf": {
        const alignRefArg = zigAnalysis.exprs[expr.alignOf];
        let payloadHtml =
          "@alignOf(" +
          exprName(alignRefArg, { wantHtml: true, wantLink: true }) +
          ")";
        return payloadHtml;
      }
      case "typeOf": {
        const typeRefArg = zigAnalysis.exprs[expr.typeOf];
        let payloadHtml =
          "@TypeOf(" +
          exprName(typeRefArg, { wantHtml: true, wantLink: true }) +
          ")";
        return payloadHtml;
      }
      case "typeInfo": {
        const typeRefArg = zigAnalysis.exprs[expr.typeInfo];
        let payloadHtml =
          "@typeInfo(" +
          exprName(typeRefArg, { wantHtml: true, wantLink: true }) +
          ")";
        return payloadHtml;
      }
      case "null": {
        if (opts.wantHtml) {
          return '<span class="tok-null">null</span>';
        } else {
          return "null";
        }
      }
      case "array": {
        let payloadHtml = ".{";
        for (let i = 0; i < expr.array.length; i++) {
          if (i != 0) payloadHtml += ", ";
          let elem = zigAnalysis.exprs[expr.array[i]];
          payloadHtml += exprName(elem, opts);
        }
        return payloadHtml + "}";
      }
      case "comptimeExpr": {
        return renderZigSource(zigAnalysis.comptimeExprs[expr.comptimeExpr].code);
      }
      case "call": {
        let call = zigAnalysis.calls[expr.call];
        let payloadHtml = "";

        switch (Object.keys(call.func)[0]) {
          default:
            throw "TODO";
          case "declRef":
          case "refPath": {
            payloadHtml += exprName(call.func, opts);
            break;
          }
        }
        payloadHtml += "(";

        for (let i = 0; i < call.args.length; i++) {
          if (i != 0) payloadHtml += ", ";
          payloadHtml += exprName(call.args[i], opts);
        }

        payloadHtml += ")";
        return payloadHtml;
      }
      case "as": {
        // @Check : this should be done in backend because there are legit @as() calls
        // const typeRefArg = zigAnalysis.exprs[expr.as.typeRefArg];
        const exprArg = zigAnalysis.exprs[expr.as.exprArg];
        // return "@as(" + exprName(typeRefArg, opts) +
        //   ", " + exprName(exprArg, opts) + ")";
        return exprName(exprArg, opts);
      }
      case "declRef": {
        const name = getDecl(expr.declRef).name;

        if (opts.wantHtml) {
          let payloadHtml = "";
          if (opts.wantLink) {
            payloadHtml += '<a href="' + findDeclNavLink(name) + '">';
          }
          payloadHtml +=
            '<span class="tok-kw" style="color:lightblue;">' +
            name +
            "</span>";
          if (opts.wantLink) payloadHtml += "</a>";
          return payloadHtml;
        } else {
          return name;
        }
      }
      case "refPath": {
        let firstComponent = expr.refPath[0];
        let name = exprName(firstComponent, opts);
        let url = undefined;
        if (opts.wantLink && "declRef" in firstComponent) {
          url = findDeclNavLink(getDecl(firstComponent.declRef).name);
        }
        for (let i = 1; i < expr.refPath.length; i++) {
          let component = undefined;
          if ("string" in expr.refPath[i]) {
            component = expr.refPath[i].string;
          } else {
            component = exprName(expr.refPath[i], { ...opts, wantLink: false });
            if (opts.wantLink && "declRef" in expr.refPath[i]) {
              url += "." + getDecl(expr.refPath[i].declRef).name;
              component = '<a href="' + url + '">' +
                component +
                "</a>";
            }
          }
          name += "." + component;
        }
        return name;
      }
      case "int": {
        return "" + expr.int;
      }
      case "float": {
        return "" + expr.float.toFixed(2);
      }
      case "float128": {
        return "" + expr.float128.toFixed(2);
      }
      case "undefined": {
        return "undefined";
      }
      case "string": {
        return '"' + escapeHtml(expr.string) + '"';
      }

      case "int_big": {
        return (expr.int_big.negated ? "-" : "") + expr.int_big.value;
      }

      case "anytype": {
        return "anytype";
      }

      case "this": {
        return "@This()";
      }

      case "type": {
        let name = "";

        let typeObj = expr.type;
        if (typeof typeObj === "number") typeObj = getType(typeObj);
        switch (typeObj.kind) {
          default:
            throw "TODO";
          case typeKinds.Struct: {
            let structObj = typeObj;
            let name = "";
            let layout = "";
            if (structObj.layout !== null) {
              switch (structObj.layout.enumLiteral) {
                case "Packed": {
                  layout = "packed ";
                  break;
                }
                case "Extern": {
                  layout = "extern ";
                  break;
                }
              }
            }
            if (opts.wantHtml) {
              name = "<span class='tok-kw'>" + layout + "struct</span>";
            } else {
              name = layout + "struct";
            }
            if (structObj.backing_int !== null) {
              name += "(" + exprName(structObj.backing_int, opts) + ")";
            }
            name += " { ";
            if (structObj.field_types.length > 1 && opts.wantHtml) { name += "</br>"; }
            let indent = "";
            if (structObj.field_types.length > 1 && opts.wantHtml) {
              indent = "&nbsp;&nbsp;&nbsp;&nbsp;"
            }
            if (opts.indent && structObj.field_types.length > 1) {
              indent = opts.indent + indent;
            }
            let structNode = getAstNode(structObj.src);
            let field_end = ",";
            if (structObj.field_types.length > 1 && opts.wantHtml) {
              field_end += "</br>";
            } else {
              field_end += " ";
            }

            for (let i = 0; i < structObj.field_types.length; i += 1) {
              let fieldNode = getAstNode(structNode.fields[i]);
              let fieldName = fieldNode.name;
              let html = indent;
              if (!structObj.is_tuple) {
                html += escapeHtml(fieldName);
              }

              let fieldTypeExpr = structObj.field_types[i];
              if (!structObj.is_tuple) {
                html += ": ";
              }

              html += exprName(fieldTypeExpr, { ...opts, indent: indent });

              if (structObj.field_defaults[i] !== null) {
                html += " = " + exprName(structObj.field_defaults[i], opts);
              }

              html += field_end;

              name += html;
            }
            if (opts.indent && structObj.field_types.length > 1) {
              name += opts.indent;
            }
            name += "}";
            return name;
          }
          case typeKinds.Enum: {
            let enumObj = typeObj;
            let name = "";
            if (opts.wantHtml) {
              name = "<span class='tok-kw'>enum</span>";
            } else {
              name = "enum";
            }
            if (enumObj.tag) {
              name += "(" + exprName(enumObj.tag, opts) + ")";
            }
            name += " { ";
            let enumNode = getAstNode(enumObj.src);
            let fields_len = enumNode.fields.length;
            if (enumObj.nonexhaustive) {
              fields_len += 1;
            }
            if (fields_len > 1 && opts.wantHtml) { name += "</br>"; }
            let indent = "";
            if (fields_len > 1) {
              if (opts.wantHtml) {
                indent = "&nbsp;&nbsp;&nbsp;&nbsp;";
              } else {
                indent = "    ";
              }
            }
            if (opts.indent) {
              indent = opts.indent + indent;
            }
            let field_end = ",";
            if (fields_len > 1 && opts.wantHtml) {
              field_end += "</br>";
            } else {
              field_end += " ";
            }
            for (let i = 0; i < enumNode.fields.length; i += 1) {
              let fieldNode = getAstNode(enumNode.fields[i]);
              let fieldName = fieldNode.name;
              let html = indent + escapeHtml(fieldName);

              if (enumObj.values[i] !== null) {
                html += " = " + exprName(enumObj.values[i], opts);
              }

              html += field_end;

              name += html;
            }
            if (enumObj.nonexhaustive) {
              name += indent + "_" + field_end;
            }
            if (opts.indent) {
              name += opts.indent;
            }
            name += "}";
            return name;
          }
          case typeKinds.Union: {
            let unionObj = typeObj;
            let name = "";
            let layout = "";
            if (unionObj.layout !== null) {
              switch (unionObj.layout.enumLiteral) {
                case "Packed": {
                  layout = "packed ";
                  break;
                }
                case "Extern": {
                  layout = "extern ";
                  break;
                }
              }
            }
            if (opts.wantHtml) {
              name = "<span class='tok-kw'>" + layout + "union</span>";
            } else {
              name = layout + "union";
            }
            if (unionObj.auto_tag) {
              if (opts.wantHtml) {
                name += "(<span class='tok-kw'>enum</span>";
              } else {
                name += "(enum";
              }
              if (unionObj.tag) {
                name += "(" + exprName(unionObj.tag, opts) + "))";
              } else {
                name += ")";
              }
            } else if (unionObj.tag) {
              name += "(" + exprName(unionObj.tag, opts) + ")";
            }
            name += " { ";
            if (unionObj.field_types.length > 1 && opts.wantHtml) {
              name += "</br>";
            }
            let indent = "";
            if (unionObj.field_types.length > 1 && opts.wantHtml) {
              indent = "&nbsp;&nbsp;&nbsp;&nbsp;"
            }
            if (opts.indent) {
              indent = opts.indent + indent;
            }
            let unionNode = getAstNode(unionObj.src);
            let field_end = ",";
            if (unionObj.field_types.length > 1 && opts.wantHtml) {
              field_end += "</br>";
            } else {
              field_end += " ";
            }
            for (let i = 0; i < unionObj.field_types.length; i += 1) {
              let fieldNode = getAstNode(unionNode.fields[i]);
              let fieldName = fieldNode.name;
              let html = indent + escapeHtml(fieldName);

              let fieldTypeExpr = unionObj.field_types[i];
              html += ": ";

              html += exprName(fieldTypeExpr, { ...opts, indent: indent });

              html += field_end;

              name += html;
            }
            if (opts.indent) {
              name += opts.indent;
            }
            name += "}";
            return name;
          }
          case typeKinds.Opaque: {
            let opaqueObj = typeObj;
            return opaqueObj;
          }
          case typeKinds.ComptimeExpr: {
            return "anyopaque";
          }
          case typeKinds.Array: {
            let arrayObj = typeObj;
            let name = "[";
            let lenName = exprName(arrayObj.len, opts);
            let sentinel = arrayObj.sentinel
              ? ":" + exprName(arrayObj.sentinel, opts)
              : "";
            // let is_mutable = arrayObj.is_multable ? "const " : "";

            if (opts.wantHtml) {
              name +=
                '<span class="tok-number">' + lenName + sentinel + "</span>";
            } else {
              name += lenName + sentinel;
            }
            name += "]";
            // name += is_mutable;
            name += exprName(arrayObj.child, opts);
            return name;
          }
          case typeKinds.Optional:
            return "?" + exprName(typeObj.child, opts);
          case typeKinds.Pointer: {
            let ptrObj = typeObj;
            let sentinel = ptrObj.sentinel
              ? ":" + exprName(ptrObj.sentinel, opts)
              : "";
            let is_mutable = !ptrObj.is_mutable ? "const " : "";
            let name = "";
            switch (ptrObj.size) {
              default:
                console.log("TODO: implement unhandled pointer size case");
              case pointerSizeEnum.One:
                name += "*";
                name += is_mutable;
                break;
              case pointerSizeEnum.Many:
                name += "[*";
                name += sentinel;
                name += "]";
                name += is_mutable;
                break;
              case pointerSizeEnum.Slice:
                if (ptrObj.is_ref) {
                  name += "*";
                }
                name += "[";
                name += sentinel;
                name += "]";
                name += is_mutable;
                break;
              case pointerSizeEnum.C:
                name += "[*c";
                name += sentinel;
                name += "]";
                name += is_mutable;
                break;
            }
            // @check: after the major changes in arrays the consts are came from switch above
            // if (!ptrObj.is_mutable) {
            //     if (opts.wantHtml) {
            //         name += '<span class="tok-kw">const</span> ';
            //     } else {
            //         name += "const ";
            //     }
            // }
            if (ptrObj.is_allowzero) {
              name += "allowzero ";
            }
            if (ptrObj.is_volatile) {
              name += "volatile ";
            }
            if (ptrObj.has_addrspace) {
              name += "addrspace(";
              name += "." + "";
              name += ") ";
            }
            if (ptrObj.has_align) {
              let align = exprName(ptrObj.align, opts);
              if (opts.wantHtml) {
                name += '<span class="tok-kw">align</span>(';
              } else {
                name += "align(";
              }
              if (opts.wantHtml) {
                name += '<span class="tok-number">' + align + "</span>";
              } else {
                name += align;
              }
              if (ptrObj.hostIntBytes != null) {
                name += ":";
                if (opts.wantHtml) {
                  name +=
                    '<span class="tok-number">' +
                    ptrObj.bitOffsetInHost +
                    "</span>";
                } else {
                  name += ptrObj.bitOffsetInHost;
                }
                name += ":";
                if (opts.wantHtml) {
                  name +=
                    '<span class="tok-number">' +
                    ptrObj.hostIntBytes +
                    "</span>";
                } else {
                  name += ptrObj.hostIntBytes;
                }
              }
              name += ") ";
            }
            //name += typeValueName(ptrObj.child, wantHtml, wantSubLink, null);
            name += exprName(ptrObj.child, opts);
            return name;
          }
          case typeKinds.Float: {
            let floatObj = typeObj;

            if (opts.wantHtml) {
              return '<span class="tok-type">' + floatObj.name + "</span>";
            } else {
              return floatObj.name;
            }
          }
          case typeKinds.Int: {
            let intObj = typeObj;
            let name = intObj.name;
            if (opts.wantHtml) {
              return '<span class="tok-type">' + name + "</span>";
            } else {
              return name;
            }
          }
          case typeKinds.ComptimeInt:
            if (opts.wantHtml) {
              return '<span class="tok-type">comptime_int</span>';
            } else {
              return "comptime_int";
            }
          case typeKinds.ComptimeFloat:
            if (opts.wantHtml) {
              return '<span class="tok-type">comptime_float</span>';
            } else {
              return "comptime_float";
            }
          case typeKinds.Type:
            if (opts.wantHtml) {
              return '<span class="tok-type">type</span>';
            } else {
              return "type";
            }
          case typeKinds.Bool:
            if (opts.wantHtml) {
              return '<span class="tok-type">bool</span>';
            } else {
              return "bool";
            }
          case typeKinds.Void:
            if (opts.wantHtml) {
              return '<span class="tok-type">void</span>';
            } else {
              return "void";
            }
          case typeKinds.EnumLiteral:
            if (opts.wantHtml) {
              return '<span class="tok-type">(enum literal)</span>';
            } else {
              return "(enum literal)";
            }
          case typeKinds.NoReturn:
            if (opts.wantHtml) {
              return '<span class="tok-type">noreturn</span>';
            } else {
              return "noreturn";
            }
          case typeKinds.ErrorSet: {
            let errSetObj = typeObj;
            if (errSetObj.fields == null) {
              return '<span class="tok-type">anyerror</span>';
            } else if (errSetObj.fields.length == 0) {
              return "error{}";
            } else if (errSetObj.fields.length == 1) {
              return "error{" + errSetObj.fields[0].name + "}";
            } else {
              // throw "TODO";
              let html = "error{ " + errSetObj.fields[0].name;
              for (let i = 1; i < errSetObj.fields.length; i++) html += ", " + errSetObj.fields[i].name;
              html += " }";
              return html;
            }
          }

          case typeKinds.ErrorUnion: {
            let errUnionObj = typeObj;
            let lhs = exprName(errUnionObj.lhs, opts);
            let rhs = exprName(errUnionObj.rhs, opts);
            return lhs + "!" + rhs;
          }
          case typeKinds.InferredErrorUnion: {
            let errUnionObj = typeObj;
            let payload = exprName(errUnionObj.payload, opts);
            return "!" + payload;
          }
          case typeKinds.Fn: {
            let fnObj = typeObj;
            let fnDecl = opts.fnDecl;
            let linkFnNameDecl = opts.linkFnNameDecl;
            opts.fnDecl = null;
            opts.linkFnNameDecl = null;
            let payloadHtml = "";
            if (opts.addParensIfFnSignature && fnObj.src == 0) {
              payloadHtml += "(";
            }
            if (fnObj.is_extern) {
              if (opts.wantHtml) {
                payloadHtml += '<span class="tok-kw">extern </span>';
              } else {
                payloadHtml += "extern ";
              }
            } else if (fnObj.has_cc) {
              let cc_expr = zigAnalysis.exprs[fnObj.cc];
              if (cc_expr.enumLiteral === "Inline") {
                if(opts.wantHtml) {
                payloadHtml += '<span class="tok-kw">inline </span>'
                } else {
                  payloadHtml += "inline "
                }
              }
            }
            if (fnObj.has_lib_name) {
              payloadHtml += '"' + fnObj.lib_name + '" ';
            }
            if (opts.wantHtml) {
              payloadHtml += '<span class="tok-kw">fn </span>';
              if (fnDecl) {
                payloadHtml += '<span class="tok-fn">';
                if (linkFnNameDecl) {
                  payloadHtml +=
                    '<a href="' + linkFnNameDecl + '">' +
                    escapeHtml(fnDecl.name) +
                    "</a>";
                } else {
                  payloadHtml += escapeHtml(fnDecl.name);
                }
                payloadHtml += "</span>";
              }
            } else {
              payloadHtml += "fn ";
            }
            payloadHtml += "(";
            if (fnObj.params) {
              let fields = null;
              let isVarArgs = false;
              if (fnObj.src != 0) {
                let fnNode = getAstNode(fnObj.src);
                fields = fnNode.fields;
                isVarArgs = fnNode.varArgs;
              }

              for (let i = 0; i < fnObj.params.length; i += 1) {
                if (i != 0) {
                  payloadHtml += ", ";
                }

                if (opts.wantHtml) {
                  payloadHtml +=
                    "<span class='argBreaker'><br>&nbsp;&nbsp;&nbsp;&nbsp;</span>";
                }
                let value = fnObj.params[i];
                let paramValue = resolveValue({ expr: value });

                if (fields != null) {
                  let paramNode = getAstNode(fields[i]);

                  if (paramNode.varArgs) {
                    payloadHtml += "...";
                    continue;
                  }

                  if (paramNode.noalias) {
                    if (opts.wantHtml) {
                      payloadHtml += '<span class="tok-kw">noalias</span> ';
                    } else {
                      payloadHtml += "noalias ";
                    }
                  }

                  if (paramNode.comptime) {
                    if (opts.wantHtml) {
                      payloadHtml += '<span class="tok-kw">comptime</span> ';
                    } else {
                      payloadHtml += "comptime ";
                    }
                  }

                  let paramName = paramNode.name;
                  if (paramName != null) {
                    // skip if it matches the type name
                    if (!shouldSkipParamName(paramValue, paramName)) {
                      payloadHtml += paramName + ": ";
                    }
                  }
                }

                if (isVarArgs && i === fnObj.params.length - 1) {
                  payloadHtml += "...";
                } else if ("alignOf" in value) {
                  payloadHtml += exprName(value, opts);
                } else if ("typeOf" in value) {
                  payloadHtml += exprName(value, opts);
                } else if ("typeOf_peer" in value) {
                  payloadHtml += exprName(value, opts);
                } else if ("declRef" in value) {
                  payloadHtml += exprName(value, opts);
                } else if ("call" in value) {
                  payloadHtml += exprName(value, opts);
                } else if ("refPath" in value) {
                  payloadHtml += exprName(value, opts);
                } else if ("type" in value) {
                  payloadHtml += exprName(value, opts);
                  //payloadHtml += '<span class="tok-kw">' + name + "</span>";
                } else if ("binOpIndex" in value) {
                  payloadHtml += exprName(value, opts);
                } else if ("comptimeExpr" in value) {
                  let comptimeExpr =
                    zigAnalysis.comptimeExprs[value.comptimeExpr].code;
                  if (opts.wantHtml) {
                    payloadHtml +=
                      '<span class="tok-kw">' + comptimeExpr + "</span>";
                  } else {
                    payloadHtml += comptimeExpr;
                  }
                } else if (opts.wantHtml) {
                  payloadHtml += '<span class="tok-kw">anytype</span>';
                } else {
                  payloadHtml += "anytype";
                }
              }
            }

            if (opts.wantHtml) {
              payloadHtml += "<span class='argBreaker'>,<br></span>";
            }
            payloadHtml += ") ";

            if (fnObj.has_align) {
              let align = zigAnalysis.exprs[fnObj.align];
              payloadHtml += "align(" + exprName(align, opts) + ") ";
            }
            if (fnObj.has_cc) {
              let cc = zigAnalysis.exprs[fnObj.cc];
              if (cc) {
                if (cc.enumLiteral !== "Inline") {
                  payloadHtml += "callconv(" + exprName(cc, opts) + ") ";
                }
              }
            }

            if (fnObj.is_inferred_error) {
              payloadHtml += "!";
            }
            if (fnObj.ret != null) {
              payloadHtml += exprName(fnObj.ret, {
                ...opts,
                addParensIfFnSignature: true,
              });
            } else if (opts.wantHtml) {
              payloadHtml += '<span class="tok-kw">anytype</span>';
            } else {
              payloadHtml += "anytype";
            }

            if (opts.addParensIfFnSignature && fnObj.src == 0) {
              payloadHtml += ")";
            }
            return payloadHtml;
          }
          // if (wantHtml) {
          //     return escapeHtml(typeObj.name);
          // } else {
          //     return typeObj.name;
          // }
        }
      }
    }
  }

  function shouldSkipParamName(typeRef, paramName) {
    let resolvedTypeRef = resolveValue({ expr: typeRef });
    if ("type" in resolvedTypeRef) {
      let typeObj = getType(resolvedTypeRef.type);
      if (typeObj.kind === typeKinds.Pointer) {
        let ptrObj = typeObj;
        if (getPtrSize(ptrObj) === pointerSizeEnum.One) {
          const value = resolveValue(ptrObj.child);
          return typeValueName(value, false, true).toLowerCase() === paramName;
        }
      }
    }
    return false;
  }

  function getPtrSize(typeObj) {
    return typeObj.size == null ? pointerSizeEnum.One : typeObj.size;
  }

  function renderType(typeObj) {
    let name;
    if (
      rootIsStd &&
      typeObj ===
      getType(zigAnalysis.modules[zigAnalysis.rootMod].main)
    ) {
      name = "std";
    } else {
      name = exprName({ type: typeObj }, { wantHtml: false, wantLink: false });
    }
    if (name != null && name != "") {
      domHdrName.innerText =
        name + " (" + zigAnalysis.typeKinds[typeObj.kind] + ")";
      domHdrName.classList.remove("hidden");
    }
    if (typeObj.kind == typeKinds.ErrorSet) {
      renderErrorSet(typeObj);
    }
  }

  function renderErrorSet(errSetType) {
    if (errSetType.fields == null) {
      domFnErrorsAnyError.classList.remove("hidden");
    } else {
      let errorList = [];
      for (let i = 0; i < errSetType.fields.length; i += 1) {
        let errObj = errSetType.fields[i];
        //let srcObj = zigAnalysis.astNodes[errObj.src];
        errorList.push(errObj);
      }
      errorList.sort(function (a, b) {
        return operatorCompare(a.name.toLowerCase(), b.name.toLowerCase());
      });

      resizeDomListDl(domListFnErrors, errorList.length);
      for (let i = 0; i < errorList.length; i += 1) {
        let nameTdDom = domListFnErrors.children[i * 2 + 0];
        let descTdDom = domListFnErrors.children[i * 2 + 1];
        nameTdDom.textContent = errorList[i].name;
        let docs = errorList[i].docs;
        if (docs != null) {
          descTdDom.innerHTML = markdown(docs);
        } else {
          descTdDom.textContent = "";
        }
      }
      domTableFnErrors.classList.remove("hidden");
    }
    domSectFnErrors.classList.remove("hidden");
  }

  //     function allCompTimeFnCallsHaveTypeResult(typeIndex, value) {
  //         let srcIndex = zigAnalysis.fns[value].src;
  //         let calls = nodesToCallsMap[srcIndex];
  //         if (calls == null) return false;
  //         for (let i = 0; i < calls.length; i += 1) {
  //             let call = zigAnalysis.calls[calls[i]];
  //             if (call.result.type !== typeTypeId) return false;
  //         }
  //         return true;
  //     }
  //
  //     function allCompTimeFnCallsResult(calls) {
  //         let firstTypeObj = null;
  //         let containerObj = {
  //             privDecls: [],
  //         };
  //         for (let callI = 0; callI < calls.length; callI += 1) {
  //             let call = zigAnalysis.calls[calls[callI]];
  //             if (call.result.type !== typeTypeId) return null;
  //             let typeObj = zigAnalysis.types[call.result.value];
  //             if (!typeKindIsContainer(typeObj.kind)) return null;
  //             if (firstTypeObj == null) {
  //                 firstTypeObj = typeObj;
  //                 containerObj.src = typeObj.src;
  //             } else if (firstTypeObj.src !== typeObj.src) {
  //                 return null;
  //             }
  //
  //             if (containerObj.fields == null) {
  //                 containerObj.fields = (typeObj.fields || []).concat([]);
  //             } else for (let fieldI = 0; fieldI < typeObj.fields.length; fieldI += 1) {
  //                 let prev = containerObj.fields[fieldI];
  //                 let next = typeObj.fields[fieldI];
  //                 if (prev === next) continue;
  //                 if (typeof(prev) === 'object') {
  //                     if (prev[next] == null) prev[next] = typeObj;
  //                 } else {
  //                     containerObj.fields[fieldI] = {};
  //                     containerObj.fields[fieldI][prev] = firstTypeObj;
  //                     containerObj.fields[fieldI][next] = typeObj;
  //                 }
  //             }
  //
  //             if (containerObj.pubDecls == null) {
  //                 containerObj.pubDecls = (typeObj.pubDecls || []).concat([]);
  //             } else for (let declI = 0; declI < typeObj.pubDecls.length; declI += 1) {
  //                 let prev = containerObj.pubDecls[declI];
  //                 let next = typeObj.pubDecls[declI];
  //                 if (prev === next) continue;
  //                 // TODO instead of showing "examples" as the public declarations,
  //                     // do logic like this:
  //                 //if (typeof(prev) !== 'object') {
  //                     //    let newDeclId = zigAnalysis.decls.length;
  //                     //    prev = clone(zigAnalysis.decls[prev]);
  //                     //    prev.id = newDeclId;
  //                     //    zigAnalysis.decls.push(prev);
  //                     //    containerObj.pubDecls[declI] = prev;
  //                     //}
  //                 //mergeDecls(prev, next, firstTypeObj, typeObj);
  //             }
  //         }
  //         for (let declI = 0; declI < containerObj.pubDecls.length; declI += 1) {
  //             let decl = containerObj.pubDecls[declI];
  //             if (typeof(decl) === 'object') {
  //                 containerObj.pubDecls[declI] = containerObj.pubDecls[declI].id;
  //             }
  //         }
  //         return containerObj;
  //     }

  function renderValue(decl) {
    let resolvedValue = resolveValue(decl.value);

    if (resolvedValue.expr.fieldRef) {
      const declRef = decl.value.expr.refPath[0].declRef;
      const type = getDecl(declRef);
      domFnProtoCode.innerHTML =
        '<span class="tok-kw">const</span> ' +
        escapeHtml(decl.name) +
        ": " +
        type.name +
        " = " +
        exprName(decl.value.expr, { wantHtml: true, wantLink: true }) +
        ";";
    } else if (
      resolvedValue.expr.string !== undefined ||
      resolvedValue.expr.call !== undefined ||
      resolvedValue.expr.comptimeExpr !== undefined
    ) {
      let typeRef = null;
      if (resolvedValue.typeRef !== undefined) {
        typeRef = resolvedValue.typeRef;
      }
      domFnProtoCode.innerHTML =
        '<span class="tok-kw">const</span> ' +
        escapeHtml(decl.name) +
        ": " +
        exprName(typeRef !== null ? typeRef : resolvedValue.expr, { wantHtml: true, wantLink: true }) +
        " = " +
        exprName(decl.value.expr, { wantHtml: true, wantLink: true }) +
        ";";
    } else if (resolvedValue.expr.compileError) {
      domFnProtoCode.innerHTML =
        '<span class="tok-kw">const</span> ' +
        escapeHtml(decl.name) +
        " = " +
        exprName(decl.value.expr, { wantHtml: true, wantLink: true }) +
        ";";
    } else {
      domFnProtoCode.innerHTML =
        '<span class="tok-kw">const</span> ' +
        escapeHtml(decl.name) +
        ": " +
        exprName(resolvedValue.typeRef, { wantHtml: true, wantLink: true }) +
        " = " +
        exprName(decl.value.expr, { wantHtml: true, wantLink: true }) +
        ";";
    }

    let docs = getAstNode(decl.src).docs;
    if (docs != null) {
      // TODO: it shouldn't just be decl.parent_container, but rather 
      //       the type that the decl holds (if the value is a type)
      domTldDocs.innerHTML = markdown(docs, getType(decl.parent_container));
      
      domTldDocs.classList.remove("hidden");
    }

    domFnProto.classList.remove("hidden");
  }

  function renderVar(decl) {
    let resolvedVar = resolveValue(decl.value);

    if (resolvedVar.expr.fieldRef) {
      const declRef = decl.value.expr.refPath[0].declRef;
      const type = getDecl(declRef);
      domFnProtoCode.innerHTML =
        '<span class="tok-kw">var</span> ' +
        escapeHtml(decl.name) +
        ": " +
        type.name +
        " = " +
        exprName(decl.value.expr, { wantHtml: true, wantLink: true }) +
        ";";
    } else if (
      resolvedVar.expr.string !== undefined ||
      resolvedVar.expr.call !== undefined ||
      resolvedVar.expr.comptimeExpr !== undefined
    ) {
      domFnProtoCode.innerHTML =
        '<span class="tok-kw">var</span> ' +
        escapeHtml(decl.name) +
        ": " +
        exprName(resolvedVar.typeRef !== null ? resolvedVar.typeRef : resolvedVar.expr, { wantHtml: true, wantLink: true }) +
        " = " +
        exprName(decl.value.expr, { wantHtml: true, wantLink: true }) +
        ";";
    } else if (resolvedVar.expr.compileError) {
      domFnProtoCode.innerHTML =
        '<span class="tok-kw">var</span> ' +
        escapeHtml(decl.name) +
        " = " +
        exprName(decl.value.expr, { wantHtml: true, wantLink: true }) +
        ";";
    } else {
      domFnProtoCode.innerHTML =
        '<span class="tok-kw">var</span> ' +
        escapeHtml(decl.name) +
        ": " +
        exprName(resolvedVar.typeRef, { wantHtml: true, wantLink: true }) +
        " = " +
        exprName(decl.value.expr, { wantHtml: true, wantLink: true }) +
        ";";
    }

    let docs = getAstNode(decl.src).docs;
    if (docs != null) {
      domTldDocs.innerHTML = markdown(docs);
      domTldDocs.classList.remove("hidden");
    }

    domFnProto.classList.remove("hidden");
  }

  function categorizeDecls(
    decls,
    typesList,
    namespacesList,
    errSetsList,
    fnsList,
    varsList,
    valsList,
    testsList,
    unsList
  ) {
    for (let i = 0; i < decls.length; i += 1) {
      let decl = getDecl(decls[i]);
      let declValue = resolveValue(decl.value);

      // if (decl.isTest) {
      //   testsList.push(decl);
      //   continue;
      // }

      if (decl.kind === "var") {
        varsList.push(decl);
        continue;
      }

      if (decl.kind === "const") {
        if ("type" in declValue.expr) {
          // We have the actual type expression at hand.
          const typeExpr = getType(declValue.expr.type);
          if (typeExpr.kind == typeKinds.Fn) {
            const funcRetExpr = resolveValue({
              expr: typeExpr.ret,
            });
            if (
              "type" in funcRetExpr.expr &&
              funcRetExpr.expr.type == typeTypeId
            ) {
              if (typeIsErrSet(declValue.expr.type)) {
                errSetsList.push(decl);
              } else if (typeIsStructWithNoFields(declValue.expr.type)) {
                namespacesList.push(decl);
              } else {
                typesList.push(decl);
              }
            } else {
              fnsList.push(decl);
            }
          } else {
            if (typeIsErrSet(declValue.expr.type)) {
              errSetsList.push(decl);
            } else if (typeIsStructWithNoFields(declValue.expr.type)) {
              namespacesList.push(decl);
            } else {
              typesList.push(decl);
            }
          }
        } else if (declValue.typeRef) {
          if ("type" in declValue.typeRef && declValue.typeRef == typeTypeId) {
            // We don't know what the type expression is, but we know it's a type.
            typesList.push(decl);
          } else {
            valsList.push(decl);
          }
        } else {
          valsList.push(decl);
        }
      }

      if (decl.is_uns) {
        unsList.push(decl);
      }
    }
  }

  function sourceFileLink(decl) {
    const srcNode = getAstNode(decl.src);
    const srcFile = getFile(srcNode.file);
    return sourceFileUrlTemplate.
      replace("{{mod}}", zigAnalysis.modules[srcFile.modIndex].name).
      replace("{{file}}", srcFile.name).
      replace("{{line}}", srcNode.line + 1);
  }

  function renderContainer(container) {
    let typesList = [];

    let namespacesList = [];

    let errSetsList = [];

    let fnsList = [];

    let varsList = [];

    let valsList = [];

    let testsList = [];

    let unsList = [];

    categorizeDecls(
      container.pubDecls,
      typesList,
      namespacesList,
      errSetsList,
      fnsList,
      varsList,
      valsList,
      testsList,
      unsList
    );
    if (curNav.showPrivDecls)
      categorizeDecls(
        container.privDecls,
        typesList,
        namespacesList,
        errSetsList,
        fnsList,
        varsList,
        valsList,
        testsList,
        unsList
      );

    while (unsList.length > 0) {
      let uns = unsList.shift();
      let declValue = resolveValue(uns.value);
      if (!("type" in declValue.expr)) continue;
      let uns_container = getType(declValue.expr.type);
      if (!isContainerType(uns_container)) continue;
      categorizeDecls(
        uns_container.pubDecls,
        typesList,
        namespacesList,
        errSetsList,
        fnsList,
        varsList,
        valsList,
        testsList,
        unsList
      );
      if (curNav.showPrivDecls)
        categorizeDecls(
          uns_container.privDecls,
          typesList,
          namespacesList,
          errSetsList,
          fnsList,
          varsList,
          valsList,
          testsList,
          unsList
        );
    }

    typesList.sort(byNameProperty);
    namespacesList.sort(byNameProperty);
    errSetsList.sort(byNameProperty);
    fnsList.sort(byNameProperty);
    varsList.sort(byNameProperty);
    valsList.sort(byNameProperty);
    testsList.sort(byNameProperty);

    if (container.src != null) {
      let docs = getAstNode(container.src).docs;
      if (docs != null) {
        domTldDocs.innerHTML = markdown(docs, container);
        domTldDocs.classList.remove("hidden");
      }
    }

    if (typesList.length !== 0) {
      resizeDomList(
        domListTypes,
        typesList.length,
        '<li><a href=""></a></li>'
      );
      for (let i = 0; i < typesList.length; i += 1) {
        let liDom = domListTypes.children[i];
        let aDom = liDom.children[0];
        let decl = typesList[i];
        aDom.textContent = decl.name;
        aDom.setAttribute("href", navLinkDecl(decl.name));
      }
      domSectTypes.classList.remove("hidden");
    }
    if (namespacesList.length !== 0) {
      resizeDomList(
        domListNamespaces,
        namespacesList.length,
        '<li><a href="#"></a></li>'
      );
      for (let i = 0; i < namespacesList.length; i += 1) {
        let liDom = domListNamespaces.children[i];
        let aDom = liDom.children[0];
        let decl = namespacesList[i];
        aDom.textContent = decl.name;
        aDom.setAttribute("href", navLinkDecl(decl.name));
      }
      domSectNamespaces.classList.remove("hidden");
    }

    if (errSetsList.length !== 0) {
      resizeDomList(
        domListErrSets,
        errSetsList.length,
        '<li><a href="#"></a></li>'
      );
      for (let i = 0; i < errSetsList.length; i += 1) {
        let liDom = domListErrSets.children[i];
        let aDom = liDom.children[0];
        let decl = errSetsList[i];
        aDom.textContent = decl.name;
        aDom.setAttribute("href", navLinkDecl(decl.name));
      }
      domSectErrSets.classList.remove("hidden");
    }

    if (fnsList.length !== 0) {
      resizeDomList(
        domListFns,
        fnsList.length,
        "<div><dt><div class=\"fnSignature\"></div><div></div></dt><dd></dd></div>"
      );

      for (let i = 0; i < fnsList.length; i += 1) {
        let decl = fnsList[i];
        let trDom = domListFns.children[i];

        let tdFnSignature = trDom.children[0].children[0];
        let tdFnSrc = trDom.children[0].children[1];
        let tdDesc = trDom.children[1];

        let declType = resolveValue(decl.value);
        console.assert("type" in declType.expr);
        tdFnSignature.innerHTML = exprName(declType.expr, {
          wantHtml: true,
          wantLink: true,
          fnDecl: decl,
          linkFnNameDecl: navLinkDecl(decl.name),
        });
        tdFnSrc.innerHTML = "<a style=\"float: right;\" target=\"_blank\" href=\"" +
          sourceFileLink(decl) + "\">[src]</a>";

        let docs = getAstNode(decl.src).docs;
        if (docs != null) {
          docs = docs.trim();
          var short = shortDesc(docs);
          if (short != docs) {
            short = markdown(short, container);
            var long = markdown(docs, container); // TODO: this needs to be the file top lvl struct
            tdDesc.innerHTML =
              "<div class=\"expand\" ><span class=\"button\" onclick=\"toggleExpand(event)\"></span><div class=\"sum-less\">" + short + "</div>" + "<div class=\"sum-more\">" + long + "</div></details>";
          }
          else {
            tdDesc.innerHTML = markdown(short, container);
          }
        } else {
          tdDesc.innerHTML = "<p><i>No documentation provided.</i><p>";
        }
      }
      domSectFns.classList.remove("hidden");
    }

    let containerNode = getAstNode(container.src);
    if (containerNode.fields && containerNode.fields.length > 0) {
      resizeDomList(domListFields, containerNode.fields.length, "<div></div>");

      for (let i = 0; i < containerNode.fields.length; i += 1) {
        let fieldNode = getAstNode(containerNode.fields[i]);
        let divDom = domListFields.children[i];
        let fieldName = fieldNode.name;
        let docs = fieldNode.docs;
        let docsNonEmpty = docs != null && docs !== "";
        let extraPreClass = docsNonEmpty ? " fieldHasDocs" : "";

        let html =
          '<div class="mobile-scroll-container"><pre class="scroll-item' +
          extraPreClass +
          '">' +
          escapeHtml(fieldName);

        if (container.kind === typeKinds.Enum) {
          let value = container.values[i];
          if (value !== null) {
            html += " = " + exprName(value, { wantHtml: true, wantLink: true });
          }
        } else {
          let fieldTypeExpr = container.field_types[i];
          if (container.kind !== typeKinds.Struct || !container.is_tuple) {
            html += ": ";
          }
          html += exprName(fieldTypeExpr, { wantHtml: true, wantLink: true });
          let tsn = typeShorthandName(fieldTypeExpr);
          if (tsn) {
            html += "<span> (" + tsn + ")</span>";
          }
          if (container.kind === typeKinds.Struct && !container.is_tuple) {
            let defaultInitExpr = container.field_defaults[i];
            if (defaultInitExpr !== null) {
              html += " = " + exprName(defaultInitExpr, { wantHtml: true, wantLink: true });
            }
          }
        }

        html += ",</pre></div>";

        if (docsNonEmpty) {
          html += '<div class="fieldDocs">' + markdown(docs) + "</div>";
        }
        divDom.innerHTML = html;
      }
      domSectFields.classList.remove("hidden");
    }

    if (varsList.length !== 0) {
      resizeDomList(
        domListGlobalVars,
        varsList.length,
        '<tr><td><a href="#"></a></td><td></td><td></td></tr>'
      );
      for (let i = 0; i < varsList.length; i += 1) {
        let decl = varsList[i];
        let trDom = domListGlobalVars.children[i];

        let tdName = trDom.children[0];
        let tdNameA = tdName.children[0];
        let tdType = trDom.children[1];
        let tdDesc = trDom.children[2];

        tdNameA.setAttribute("href", navLinkDecl(decl.name));
        tdNameA.textContent = decl.name;

        tdType.innerHTML = exprName(walkResultTypeRef(decl.value), {
          wantHtml: true,
          wantLink: true,
        });

        let docs = getAstNode(decl.src).docs;
        if (docs != null) {
          tdDesc.innerHTML = shortDescMarkdown(docs);
        } else {
          tdDesc.textContent = "";
        }
      }
      domSectGlobalVars.classList.remove("hidden");
    }

    if (valsList.length !== 0) {
      resizeDomList(
        domListValues,
        valsList.length,
        '<tr><td><a href="#"></a></td><td></td><td></td></tr>'
      );
      for (let i = 0; i < valsList.length; i += 1) {
        let decl = valsList[i];
        let trDom = domListValues.children[i];

        let tdName = trDom.children[0];
        let tdNameA = tdName.children[0];
        let tdType = trDom.children[1];
        let tdDesc = trDom.children[2];

        tdNameA.setAttribute("href", navLinkDecl(decl.name));
        tdNameA.textContent = decl.name;

        tdType.innerHTML = exprName(walkResultTypeRef(decl.value), {
          wantHtml: true,
          wantLink: true,
        });

        let docs = getAstNode(decl.src).docs;
        if (docs != null) {
          tdDesc.innerHTML = shortDescMarkdown(docs);
        } else {
          tdDesc.textContent = "";
        }
      }
      domSectValues.classList.remove("hidden");
    }

    if (testsList.length !== 0) {
      resizeDomList(
        domListTests,
        testsList.length,
        '<tr><td><a href="#"></a></td><td></td><td></td></tr>'
      );
      for (let i = 0; i < testsList.length; i += 1) {
        let decl = testsList[i];
        let trDom = domListTests.children[i];

        let tdName = trDom.children[0];
        let tdNameA = tdName.children[0];
        let tdType = trDom.children[1];
        let tdDesc = trDom.children[2];

        tdNameA.setAttribute("href", navLinkDecl(decl.name));
        tdNameA.textContent = decl.name;

        tdType.innerHTML = exprName(walkResultTypeRef(decl.value), {
          wantHtml: true,
          wantLink: true,
        });

        let docs = getAstNode(decl.src).docs;
        if (docs != null) {
          tdDesc.innerHTML = shortDescMarkdown(docs);
        } else {
          tdDesc.textContent = "";
        }
      }
      domSectTests.classList.remove("hidden");
    }
  }

  function operatorCompare(a, b) {
    if (a === b) {
      return 0;
    } else if (a < b) {
      return -1;
    } else {
      return 1;
    }
  }

  function detectRootIsStd() {
    let rootMod = zigAnalysis.modules[zigAnalysis.rootMod];
    if (rootMod.table["std"] == null) {
      // no std mapped into the root module
      return false;
    }
    let stdMod = zigAnalysis.modules[rootMod.table["std"]];
    if (stdMod == null) return false;
    return rootMod.file === stdMod.file;
  }

  function indexTypeKinds() {
    let map = {};
    for (let i = 0; i < zigAnalysis.typeKinds.length; i += 1) {
      map[zigAnalysis.typeKinds[i]] = i;
    }
    // This is just for debugging purposes, not needed to function
    let assertList = [
      "Type",
      "Void",
      "Bool",
      "NoReturn",
      "Int",
      "Float",
      "Pointer",
      "Array",
      "Struct",
      "ComptimeFloat",
      "ComptimeInt",
      "Undefined",
      "Null",
      "Optional",
      "ErrorUnion",
      "ErrorSet",
      "Enum",
      "Union",
      "Fn",
      "Opaque",
      "Frame",
      "AnyFrame",
      "Vector",
      "EnumLiteral",
    ];
    for (let i = 0; i < assertList.length; i += 1) {
      if (map[assertList[i]] == null)
        throw new Error("No type kind '" + assertList[i] + "' found");
    }
    return map;
  }

  function findTypeTypeId() {
    for (let i = 0; i < zigAnalysis.types.length; i += 1) {
      if (getType(i).kind == typeKinds.Type) {
        return i;
      }
    }
    throw new Error("No type 'type' found");
  }


  function updateCurNav() {
    curNav = {
      mode: NAV_MODES.API,
      modNames: [],
      modObjs: [],
      declNames: [],
      declObjs: [],
      callName: null,
    };
    curNavSearch = "";

    const mode = location.hash.substring(0, 3);
    let query = location.hash.substring(3);

    let qpos = query.indexOf("?");
    let nonSearchPart;
    if (qpos === -1) {
      nonSearchPart = query;
    } else {
      nonSearchPart = query.substring(0, qpos);
      curNavSearch = decodeURIComponent(query.substring(qpos + 1));
    }

    const DEFAULT_HASH = NAV_MODES.API + zigAnalysis.modules[zigAnalysis.rootMod].name;
    switch (mode) {
      case NAV_MODES.API:
        // #A;MODULE:decl.decl.decl?search-term
        curNav.mode = mode;

        let parts = nonSearchPart.split(":");
        if (parts[0] == "") {
          location.hash = DEFAULT_HASH;
        } else {
          curNav.modNames = decodeURIComponent(parts[0]).split(".");
        }

        if (parts[1] != null) {
          curNav.declNames = decodeURIComponent(parts[1]).split(".");
        }

        return;
      case NAV_MODES.GUIDES:
        
        const sections = zigAnalysis.guide_sections;
        if (sections.length != 0 && sections[0].guides.length != 0 && nonSearchPart == "") {
          location.hash = NAV_MODES.GUIDES + sections[0].guides[0].name;
          if (qpos != -1) {
            location.hash += query.substring(qpos);
          }
          return;
        }

        curNav.mode = mode;
        curNav.activeGuide = nonSearchPart;

        return;
      default:
        location.hash = DEFAULT_HASH;
        return;
    }
  }

  function onHashChange() {
    updateCurNav();
    if (domSearch.value !== curNavSearch) {
      domSearch.value = curNavSearch;
      if (domSearch.value.length == 0)
        domSearchPlaceholder.classList.remove("hidden");
      else
        domSearchPlaceholder.classList.add("hidden");
    }
    render();
    if (imFeelingLucky) {
      imFeelingLucky = false;
      activateSelectedResult();
    }
  }

  function findSubDecl(parentTypeOrDecl, childName) {
    let parentType = parentTypeOrDecl;
    {
      // Generic functions / resolving decls
      if ("value" in parentType) {
        const rv = resolveValue(parentType.value);
        if ("type" in rv.expr) {
          const t = getType(rv.expr.type);
          parentType = t;
          if (t.kind == typeKinds.Fn && t.generic_ret != null) {
            let resolvedGenericRet = resolveValue({ expr: t.generic_ret });

            if ("call" in resolvedGenericRet.expr) {
              let call = zigAnalysis.calls[resolvedGenericRet.expr.call];
              let resolvedFunc = resolveValue({ expr: call.func });
              if (!("type" in resolvedFunc.expr)) return null;
              let callee = getType(resolvedFunc.expr.type);
              if (!callee.generic_ret) return null;
              resolvedGenericRet = resolveValue({ expr: callee.generic_ret });
            }

            if ("type" in resolvedGenericRet.expr) {
              parentType = getType(resolvedGenericRet.expr.type);
            }
          }
        }
      }
    }

    if (parentType.pubDecls) {
      for (let i = 0; i < parentType.pubDecls.length; i += 1) {
        let declIndex = parentType.pubDecls[i];
        let childDecl = getDecl(declIndex);
        if (childDecl.name === childName) {
          childDecl.find_subdecl_idx = declIndex;
          return childDecl;
        } else if (childDecl.is_uns) {
          let declValue = resolveValue(childDecl.value);
          if (!("type" in declValue.expr)) continue;
          let uns_container = getType(declValue.expr.type);
          let uns_res = findSubDecl(uns_container, childName);
          if (uns_res !== null) return uns_res;
        }
      }
    }

    if (parentType.privDecls) {
      for (let i = 0; i < parentType.privDecls.length; i += 1) {
        let declIndex = parentType.privDecls[i];
        let childDecl = getDecl(declIndex);
        if (childDecl.name === childName) {
          childDecl.find_subdecl_idx = declIndex;
          childDecl.is_private = true;
          return childDecl;
        } else if (childDecl.is_uns) {
          let declValue = resolveValue(childDecl.value);
          if (!("type" in declValue.expr)) continue;
          let uns_container = getType(declValue.expr.type);
          let uns_res = findSubDecl(uns_container, childName);
          uns_res.is_private = true;
          if (uns_res !== null) return uns_res;
        }
      }
    }

    return null;
  }

  function computeCanonicalModulePaths() {
    let list = new Array(zigAnalysis.modules.length);
    // Now we try to find all the modules from root.
    let rootMod = zigAnalysis.modules[zigAnalysis.rootMod];
    // Breadth-first to keep the path shortest possible.
    let stack = [
      {
        path: [],
        mod: rootMod,
      },
    ];
    while (stack.length !== 0) {
      let item = stack.shift();
      for (let key in item.mod.table) {
        let childModIndex = item.mod.table[key];
        if (list[childModIndex] != null) continue;
        let childMod = zigAnalysis.modules[childModIndex];
        if (childMod == null) continue;

        let newPath = item.path.concat([key]);
        list[childModIndex] = newPath;
        stack.push({
          path: newPath,
          mod: childMod,
        });
      }
    }

    for (let i = 0; i < zigAnalysis.modules.length; i += 1) {
      const p = zigAnalysis.modules[i];
      // TODO
      // declSearchIndex.add(p.name, {moduleId: i});
    }
    return list;
  }

  function computeCanonDeclPaths() {
    let list = new Array(zigAnalysis.decls.length);
    canonTypeDecls = new Array(zigAnalysis.types.length);

    for (let modI = 0; modI < zigAnalysis.modules.length; modI += 1) {
      let mod = zigAnalysis.modules[modI];
      let modNames = canonModPaths[modI];
      if (modNames === undefined) continue;

      let stack = [
        {
          declNames: [],
          declIndexes: [],
          type: getType(mod.main),
        },
      ];
      while (stack.length !== 0) {
        let item = stack.shift();

        if (isContainerType(item.type)) {
          let t = item.type;

          let len = t.pubDecls ? t.pubDecls.length : 0;
          for (let declI = 0; declI < len; declI += 1) {
            let declIndex = t.pubDecls[declI];
            if (list[declIndex] != null) continue;

            let decl = getDecl(declIndex);
              
            if (decl.is_uns) {
              let unsDeclList = [decl];
              while(unsDeclList.length != 0) {
                let unsDecl = unsDeclList.pop();
                let unsDeclVal = resolveValue(unsDecl.value);
                if (!("type" in unsDeclVal.expr)) continue;
                let unsType = getType(unsDeclVal.expr.type);
                if (!isContainerType(unsType)) continue;
                let unsPubDeclLen = unsType.pubDecls ? unsType.pubDecls.length : 0;
                for (let unsDeclI = 0; unsDeclI < unsPubDeclLen; unsDeclI += 1) {
                  let childDeclIndex = unsType.pubDecls[unsDeclI];
                  let childDecl = getDecl(childDeclIndex);
                  
                  if (childDecl.is_uns) {
                    unsDeclList.push(childDecl);
                  } else {
                    addDeclToSearchResults(childDecl, childDeclIndex, modNames, item, list, stack);
                  }
                }
              }
            } else {
              addDeclToSearchResults(decl, declIndex, modNames, item, list, stack);
            }
          }
        }
      }
    }
    window.cdp = list;
    return list;
  }

function addDeclToSearchResults(decl, declIndex, modNames, item, list, stack) {
  let declVal = resolveValue(decl.value);
  let declNames = item.declNames.concat([decl.name]);
  let declIndexes = item.declIndexes.concat([declIndex]);

  if (list[declIndex] != null) return;
  list[declIndex] = {
    modNames: modNames,
    declNames: declNames,
    declIndexes: declIndexes,
  };

  // add to search index
  {
    declSearchIndex.add(decl.name, {declIndex});
  }
  
  
  if ("type" in declVal.expr) {
    let value = getType(declVal.expr.type);
    if (declCanRepresentTypeKind(value.kind)) {
      canonTypeDecls[declVal.type] = declIndex;
    }

    if (isContainerType(value)) {
      stack.push({
        declNames: declNames,
        declIndexes: declIndexes,
        type: value,
      });
    }

    // Generic function
    if (typeIsGenericFn(declVal.expr.type)) {
      let ret = resolveGenericRet(value);
      if (ret != null && "type" in ret.expr) {
        let generic_type = getType(ret.expr.type);
        if (isContainerType(generic_type)) {
          stack.push({
            declNames: declNames,
            declIndexes: declIndexes,
            type: generic_type,
          });
        }
      }
    }
  }
}

  function getCanonDeclPath(index) {
    if (canonDeclPaths == null) {
      canonDeclPaths = computeCanonDeclPaths();
    }
    //let cd = (canonDeclPaths);
    return canonDeclPaths[index];
  }

  function getCanonTypeDecl(index) {
    getCanonDeclPath(0);
    //let ct = (canonTypeDecls);
    return canonTypeDecls[index];
  }

  function escapeHtml(text) {
    return text.replace(/[&"<>]/g, function (m) {
      return escapeHtmlReplacements[m];
    });
  }

  function shortDesc(docs) {
    const trimmed_docs = docs.trim();
    let index = trimmed_docs.indexOf("\n\n");
    let cut = false;

    if (index < 0 || index > 80) {
      if (trimmed_docs.length > 80) {
        index = 80;
        cut = true;
      } else {
        index = trimmed_docs.length;
      }
    }

    let slice = trimmed_docs.slice(0, index);
    if (cut) slice += "...";
    return slice;
  }

  function shortDescMarkdown(docs) {
    return markdown(shortDesc(docs));
  }

  function parseGuides() {
    for (let j = 0; j < zigAnalysis.guide_sections.length; j+=1){
      const section = zigAnalysis.guide_sections[j];
      for (let i = 0; i < section.guides.length; i+=1){
        let reader = new commonmark.Parser({smart: true});
        const guide = section.guides[i];
        const ast = reader.parse(guide.body);        
        
        // Find the first text thing to use as a sidebar title
        guide.title = "[empty guide]";
        {
          let walker = ast.walker();
          let event, node;
          while ((event = walker.next())) {
            node = event.node;
            if (node.type === 'text') {
              guide.title = node.literal;
              break;
            }
          }        
        }
        // Index this guide
        {
          let walker = ast.walker();
          let event, node;
          while ((event = walker.next())) {
            node = event.node;
            if (event.entering == true && node.type === 'text') {
                indexTextForGuide(j, i, node);          
            }
          }        
        }
      }  
    }
  }

  function indexTextForGuide(section_idx, guide_idx, node){
    const terms = node.literal.split(" ");
    for (let i = 0; i < terms.length; i += 1){
      const t = terms[i];
      if (!guidesSearchIndex[t]) guidesSearchIndex[t] = new Set();
      node.guide = {section_idx, guide_idx};
      guidesSearchIndex[t].add(node);
    }  
  }
  

  function markdown(input, contextType) {
    const raw_lines = input.split("\n"); // zig allows no '\r', so we don't need to split on CR

    const lines = [];

    // PHASE 1:
    // Dissect lines and determine the type for each line.
    // Also computes indentation level and removes unnecessary whitespace

    let is_reading_code = false;
    let code_indent = 0;
    for (let line_no = 0; line_no < raw_lines.length; line_no++) {
      const raw_line = raw_lines[line_no];

      const line = {
        indent: 0,
        raw_text: raw_line,
        text: raw_line.trim(),
        type: "p", // p, h1 … h6, code, ul, ol, blockquote, skip, empty
        ordered_number: -1, // NOTE: hack to make the type checker happy
      };

      if (!is_reading_code) {
        while (
          line.indent < line.raw_text.length &&
          line.raw_text[line.indent] == " "
        ) {
          line.indent += 1;
        }

        if (line.text.startsWith("######")) {
          line.type = "h6";
          line.text = line.text.substr(6);
        } else if (line.text.startsWith("#####")) {
          line.type = "h5";
          line.text = line.text.substr(5);
        } else if (line.text.startsWith("####")) {
          line.type = "h4";
          line.text = line.text.substr(4);
        } else if (line.text.startsWith("###")) {
          line.type = "h3";
          line.text = line.text.substr(3);
        } else if (line.text.startsWith("##")) {
          line.type = "h2";
          line.text = line.text.substr(2);
        } else if (line.text.startsWith("#")) {
          line.type = "h1";
          line.text = line.text.substr(1);
        } else if (line.text.match(/^-[ \t]+.*$/)) {
          // line starts with a hyphen, followed by spaces or tabs
          const match = line.text.match(/^-[ \t]+/);
          line.type = "ul";
          line.text = line.text.substr(match[0].length);
        } else if (line.text.match(/^\d+\.[ \t]+.*$/)) {
          // line starts with {number}{dot}{spaces or tabs}
          const match = line.text.match(/(\d+)\.[ \t]+/);
          line.type = "ol";
          line.text = line.text.substr(match[0].length);
          line.ordered_number = Number(match[1].length);
        } else if (line.text == "```") {
          line.type = "skip";
          is_reading_code = true;
          code_indent = line.indent;
        } else if (line.text == "") {
          line.type = "empty";
        }
      } else {
        if (line.text == "```") {
          is_reading_code = false;
          line.type = "skip";
        } else {
          line.type = "code";
          line.text = line.raw_text.substr(code_indent); // remove the indent of the ``` from all the code block
        }
      }

      if (line.type != "skip") {
        lines.push(line);
      }
    }

    // PHASE 2:
    // Render HTML from markdown lines.
    // Look at each line and emit fitting HTML code

    function markdownInlines(innerText, contextType) {
      // inline types:
      // **{INLINE}**       : <strong>
      // __{INLINE}__       : <u>
      // ~~{INLINE}~~       : <s>
      //  *{INLINE}*        : <emph>
      //  _{INLINE}_        : <emph>
      //  `{TEXT}`          : <code>
      //  [{INLINE}]({URL}) : <a>
      // ![{TEXT}]({URL})   : <img>
      // [[std;format.fmt]] : <a> (inner link)

      const formats = [
        {
          marker: "**",
          tag: "strong",
        },
        {
          marker: "~~",
          tag: "s",
        },
        {
          marker: "__",
          tag: "u",
        },
        {
          marker: "*",
          tag: "em",
        },
      ];

      const stack = [];

      let innerHTML = "";
      let currentRun = "";

      function flushRun() {
        if (currentRun != "") {
          innerHTML += escapeHtml(currentRun);
        }
        currentRun = "";
      }

      let parsing_code = false;
      let codetag = "";
      let in_code = false;

      // state used to link decl references
      let quote_start = undefined;
      let quote_start_html = undefined;

      for (let i = 0; i < innerText.length; i++) {
        if (parsing_code && in_code) {
          if (innerText.substr(i, codetag.length) == codetag) {
            // remove leading and trailing whitespace if string both starts and ends with one.
            if (
              currentRun[0] == " " &&
              currentRun[currentRun.length - 1] == " "
            ) {
              currentRun = currentRun.substr(1, currentRun.length - 2);
            }
            flushRun();
            i += codetag.length - 1;
            in_code = false;
            parsing_code = false;
            innerHTML += "</code>";
            codetag = "";

            // find out if this is a decl that should be linked
            const maybe_decl_path = innerText.substr(quote_start, i-quote_start);
            const decl_hash = detectDeclPath(maybe_decl_path, contextType);
            if (decl_hash) {
              const anchor_opening_tag = "<a href='"+ decl_hash +"'>";
              innerHTML = innerHTML.slice(0, quote_start_html) 
                + anchor_opening_tag
                + innerHTML.slice(quote_start_html) + "</a>";
            }
          } else {
            currentRun += innerText[i];
          }
          continue;
        }

        if (innerText[i] == "`") {
          flushRun();
          if (!parsing_code) {
            quote_start = i + 1;
            quote_start_html = innerHTML.length;
            innerHTML += "<code>";
          }
          parsing_code = true;
          codetag += "`";
          continue;
        }

        if (parsing_code) {
          currentRun += innerText[i];
          in_code = true;
        } else {
          let any = false;
          for (
            let idx = stack.length > 0 ? -1 : 0;
            idx < formats.length;
            idx++
          ) {
            const fmt = idx >= 0 ? formats[idx] : stack[stack.length - 1];
            if (innerText.substr(i, fmt.marker.length) == fmt.marker) {
              flushRun();
              if (stack[stack.length - 1] == fmt) {
                stack.pop();
                innerHTML += "</" + fmt.tag + ">";
              } else {
                stack.push(fmt);
                innerHTML += "<" + fmt.tag + ">";
              }
              i += fmt.marker.length - 1;
              any = true;
              break;
            }
          }
          if (!any) {
            currentRun += innerText[i];
          }
        }
      }
      flushRun();

      if (in_code) {
        in_code = false;
        parsing_code = false;
        innerHTML += "</code>";
        codetag = "";
      }

      while (stack.length > 0) {
        const fmt = stack.pop();
        innerHTML += "</" + fmt.tag + ">";
      }

      return innerHTML;
    }

    function detectDeclPath(text, context) {
      let result = "";
      let separator = ":";
      const components = text.split(".");
      let curDeclOrType = undefined;
      
      let curContext = context;
      let limit = 10000;
      while (curContext) {
        limit -= 1;
        
        if (limit == 0) {
          throw "too many iterations";
        }
        
        curDeclOrType = findSubDecl(curContext, components[0]);
        
        if (!curDeclOrType) {
          if (curContext.parent_container == null) break;
          curContext = getType(curContext.parent_container);
          continue;
        }

        if (curContext == context) {
          separator = '.';
          result = location.hash + separator + components[0];
        } else {
          // We had to go up, which means we need a new path!
          const canonPath = getCanonDeclPath(curDeclOrType.find_subdecl_idx);
          if (!canonPath) return;
          
          let lastModName = canonPath.modNames[canonPath.modNames.length - 1];
          let fullPath = lastModName + ":" + canonPath.declNames.join(".");
        
          separator = '.';
          result = "#A;" + fullPath;
        }

        break;
      } 

      if (!curDeclOrType) {
        for (let i = 0; i < zigAnalysis.modules.length; i += 1){
          const p = zigAnalysis.modules[i];
          if (p.name == components[0]) {
            curDeclOrType = getType(p.main);
            result += "#A;" + components[0];
            break;
          }
        }
      }

      if (!curDeclOrType) return null;
      
      for (let i = 1; i < components.length; i += 1) {
        curDeclOrType = findSubDecl(curDeclOrType, components[i]);
        if (!curDeclOrType) return null;
        result += separator + components[i];
        separator = '.';
      }

      return result;
      
    }

    function previousLineIs(type, line_no) {
      if (line_no > 0) {
        return lines[line_no - 1].type == type;
      } else {
        return false;
      }
    }

    function nextLineIs(type, line_no) {
      if (line_no < lines.length - 1) {
        return lines[line_no + 1].type == type;
      } else {
        return false;
      }
    }

    function getPreviousLineIndent(line_no) {
      if (line_no > 0) {
        return lines[line_no - 1].indent;
      } else {
        return 0;
      }
    }

    function getNextLineIndent(line_no) {
      if (line_no < lines.length - 1) {
        return lines[line_no + 1].indent;
      } else {
        return 0;
      }
    }

    let html = "";
    for (let line_no = 0; line_no < lines.length; line_no++) {
      const line = lines[line_no];

      switch (line.type) {
        case "h1":
        case "h2":
        case "h3":
        case "h4":
        case "h5":
        case "h6":
          html +=
            "<" +
            line.type +
            ">" +
            markdownInlines(line.text, contextType) +
            "</" +
            line.type +
            ">\n";
          break;

        case "ul":
        case "ol":
          if (
            !previousLineIs(line.type, line_no) ||
            getPreviousLineIndent(line_no) < line.indent
          ) {
            html += "<" + line.type + ">\n";
          }

          html += "<li>" + markdownInlines(line.text, contextType) + "</li>\n";

          if (
            !nextLineIs(line.type, line_no) ||
            getNextLineIndent(line_no) < line.indent
          ) {
            html += "</" + line.type + ">\n";
          }
          break;

        case "p":
          if (!previousLineIs("p", line_no)) {
            html += "<p>\n";
          }
          html += markdownInlines(line.text, contextType) + "\n";
          if (!nextLineIs("p", line_no)) {
            html += "</p>\n";
          }
          break;

        case "code":
          if (!previousLineIs("code", line_no)) {
            html += "<pre><code>";
          }
          html += escapeHtml(line.text) + "\n";
          if (!nextLineIs("code", line_no)) {
            html += "</code></pre>\n";
          }
          break;
      }
    }

    return html;
  }

  function activateSelectedResult() {
    if (domSectSearchResults.classList.contains("hidden")) {
      return;
    }

    let liDom = domListSearchResults.children[curSearchIndex];
    if (liDom == null && domListSearchResults.children.length !== 0) {
      liDom = domListSearchResults.children[0];
    }
    if (liDom != null) {
      let aDom = liDom.children[0];
      location.href = aDom.getAttribute("href");
      curSearchIndex = -1;
    }
    domSearch.blur();
  }

  // hide the modal if it's visible or return to the previous result page and unfocus the search
  function onEscape(ev) {
    if (!domHelpModal.classList.contains("hidden")) {
      domHelpModal.classList.add("hidden");
      ev.preventDefault();
      ev.stopPropagation();
    } else {
      domSearch.value = "";
      domSearch.blur();
      domSearchPlaceholder.classList.remove("hidden");
      curSearchIndex = -1;
      ev.preventDefault();
      ev.stopPropagation();
      startSearch();
    }
  }
  

  function onSearchKeyDown(ev) {
    switch (getKeyString(ev)) {
      case "Enter":
        // detect if this search changes anything
        let terms1 = getSearchTerms();
        startSearch();
        updateCurNav();
        let terms2 = getSearchTerms();
        // we might have to wait for onHashChange to trigger
        imFeelingLucky = terms1.join(" ") !== terms2.join(" ");
        if (!imFeelingLucky) activateSelectedResult();

        ev.preventDefault();
        ev.stopPropagation();
        return;
      case "Esc":
        onEscape(ev);
        return
      case "Up":
        moveSearchCursor(-1);
        ev.preventDefault();
        ev.stopPropagation();
        return;
      case "Down":
        // TODO: make the page scroll down if the search cursor is out of the screen
        moveSearchCursor(1);
        ev.preventDefault();
        ev.stopPropagation();
        return;
      default:
        // Search is triggered via an `input` event handler, not on arbitrary `keydown` events.
        ev.stopPropagation();
        return;
    }
  }

  function onSearchInput(ev) {
    curSearchIndex = -1;
    startAsyncSearch();
  }

  function moveSearchCursor(dir) {
    if (
      curSearchIndex < 0 ||
      curSearchIndex >= domListSearchResults.children.length
    ) {
      if (dir > 0) {
        curSearchIndex = -1 + dir;
      } else if (dir < 0) {
        curSearchIndex = domListSearchResults.children.length + dir;
      }
    } else {
      curSearchIndex += dir;
    }
    if (curSearchIndex < 0) {
      curSearchIndex = 0;
    }
    if (curSearchIndex >= domListSearchResults.children.length) {
      curSearchIndex = domListSearchResults.children.length - 1;
    }
    renderSearchCursor();
  }

  function getKeyString(ev) {
    let name;
    let ignoreShift = false;
    switch (ev.which) {
      case 13:
        name = "Enter";
        break;
      case 27:
        name = "Esc";
        break;
      case 38:
        name = "Up";
        break;
      case 40:
        name = "Down";
        break;
      default:
        ignoreShift = true;
        name =
          ev.key != null
            ? ev.key
            : String.fromCharCode(ev.charCode || ev.keyCode);
    }
    if (!ignoreShift && ev.shiftKey) name = "Shift+" + name;
    if (ev.altKey) name = "Alt+" + name;
    if (ev.ctrlKey) name = "Ctrl+" + name;
    return name;
  }

  function onWindowKeyDown(ev) {
    switch (getKeyString(ev)) {
      case "Esc":
        onEscape(ev);
        break;
      case "s":
        if (domHelpModal.classList.contains("hidden")) {
          if (ev.target == domSearch) break;

          domSearch.focus();
          domSearch.select();
          domDocs.scrollTo(0, 0);
          ev.preventDefault();
          ev.stopPropagation();
          startAsyncSearch();
        }
        break;
      case "?":
        if (!canToggleHelpModal) break;

        // toggle the help modal
        if (!domHelpModal.classList.contains("hidden")) {
            onEscape(ev);
        } else {
            ev.preventDefault();
            ev.stopPropagation();
            showHelpModal();
        }
        break;
    }
  }

  function showHelpModal() {
    domHelpModal.classList.remove("hidden");
    domHelpModal.style.left =
      window.innerWidth / 2 - domHelpModal.clientWidth / 2 + "px";
    domHelpModal.style.top =
      window.innerHeight / 2 - domHelpModal.clientHeight / 2 + "px";
    domHelpModal.focus();
    domSearch.blur();
  }

  function clearAsyncSearch() {
    if (searchTimer != null) {
      clearTimeout(searchTimer);
      searchTimer = null;
    }
  }

  function startAsyncSearch() {
    clearAsyncSearch();
    searchTimer = setTimeout(startSearch, 100);
  }
  function startSearch() {
    clearAsyncSearch();
    let oldHash = location.hash;
    let parts = oldHash.split("?");
    // TODO: make a tooltip that shows the user that we've replaced their dots
    let box_text = domSearch.value.replaceAll(".", " ");
    let newPart2 = box_text === "" ? "" : "?" + box_text;
    location.replace(parts.length === 1 ? oldHash + newPart2 : parts[0] + newPart2);
  }
  function getSearchTerms() {
    let list = curNavSearch.trim().split(/[ \r\n\t]+/);
    return list;
  }

  function renderSearchGuides() {
    const searchTrimmed = false;
    let ignoreCase = curNavSearch.toLowerCase() === curNavSearch;
    
    let terms = getSearchTerms();
    let matchedItems = new Set();

    for (let i = 0; i < terms.length; i += 1) {
      const nodes = guidesSearchIndex[terms[i]];
      if (nodes) {
        for (const n of nodes) {      
          matchedItems.add(n);
        }
      }
    }

    
    
    if (matchedItems.size !== 0) {
      // Build up the list of search results
      let matchedItemsHTML = "";

      for (const node of matchedItems) {
        const text = node.literal;
        const href = "";

        matchedItemsHTML += "<li><a href=\"" + href + "\">" + text + "</a></li>";
      }

      // Replace the search results using our newly constructed HTML string
      domListSearchResults.innerHTML = matchedItemsHTML;
      if (searchTrimmed) {
        domSectSearchAllResultsLink.classList.remove("hidden");
      }
      renderSearchCursor();

      domSectSearchResults.classList.remove("hidden");
    } else {
      domSectSearchNoResults.classList.remove("hidden");
    }
  }

  function renderSearchAPI(){
    if (canonDeclPaths == null) {
      canonDeclPaths = computeCanonDeclPaths();
    }
    let declSet = new Set();
    let otherDeclSet = new Set(); // for low quality results
    let declScores = {};
    
    let ignoreCase = curNavSearch.toLowerCase() === curNavSearch;
    let term_list = getSearchTerms();
    for (let i = 0; i < term_list.length; i += 1) {
      let term = term_list[i];
      let result = declSearchIndex.search(term.toLowerCase());
      if (result == null) {
        domSectSearchNoResults.classList.remove("hidden");
        domSectSearchResults.classList.add("hidden");
        return;
      }

      let termSet = new Set();
      let termOtherSet = new Set();

      for (let list of [result.full, result.partial]) {
        for (let r of list) {
          const d = r.declIndex;
          const decl = getDecl(d);
          const canonPath = getCanonDeclPath(d);

          // collect unconditionally for the first term
          if (i == 0) {
            declSet.add(d);
          } else {
            // path intersection for subsequent terms
            let found = false;
            for (let p of canonPath.declIndexes) {
              if (declSet.has(p)) {
                found = true;
                break;
              }   
            }
            if (!found) {
              otherDeclSet.add(d);
            } else {
              termSet.add(d);
            }
          }
          
          if (declScores[d] == undefined) declScores[d] = 0;
        
          // scores (lower is better)
          let decl_name = decl.name;
          if (ignoreCase) decl_name = decl_name.toLowerCase();

          // shallow path are preferable
          const path_depth = canonPath.declNames.length * 50;
          // matching the start of a decl name is good
          const match_from_start = decl_name.startsWith(term) ? -term.length * (1 -ignoreCase) : (decl_name.length - term.length) + 1; 
          // being a perfect match is good
          const is_full_match = (list == result.full) ? -decl_name.length * (2 - ignoreCase) : decl_name.length - term.length;
          // matching the end of a decl name is good
          const matches_the_end = decl_name.endsWith(term) ? -term.length * (1 - ignoreCase) : (decl_name.length - term.length) + 1;
          // explicitly penalizing scream case decls
          const decl_is_scream_case = decl.name.toUpperCase() != decl.name ? 0 : decl.name.length;  
        
          const score =  path_depth 
            + match_from_start 
            + is_full_match 
            + matches_the_end 
            + decl_is_scream_case;

          declScores[d] += score;        
        }
      }
      if (i != 0) {
        for (let d of declSet) {
          if (termSet.has(d)) continue;
          let found = false;
          for (let p of getCanonDeclPath(d).declIndexes) {
            if (termSet.has(p) || otherDeclSet.has(p)) {
              found = true;
              break;
            }   
          }
          if (found) {
            declScores[d] = declScores[d] / term_list.length;
          }
          
          termOtherSet.add(d);
        }
        declSet = termSet;
        for (let d of termOtherSet) {
          otherDeclSet.add(d);
        }
        
      }
    }

    let matchedItems = {
      high_quality: [],
      low_quality: [],
    };
    for (let idx of declSet) {
      matchedItems.high_quality.push({points: declScores[idx], declIndex: idx})
    }
    for (let idx of otherDeclSet) {
      matchedItems.low_quality.push({points: declScores[idx], declIndex: idx})
    }
    
    matchedItems.high_quality.sort(function (a, b) {
      let cmp = operatorCompare(a.points, b.points);
      return cmp;
    });
    matchedItems.low_quality.sort(function (a, b) {
      let cmp = operatorCompare(a.points, b.points);
      return cmp;
    });
    
    // Build up the list of search results
    let matchedItemsHTML = "";

    for (let list of [matchedItems.high_quality, matchedItems.low_quality]) {
      if (list == matchedItems.low_quality && list.length > 0) {
        matchedItemsHTML += "<hr class='other-results'>"
      }
      for (let result of list) {
        const points = result.points;
        const match = result.declIndex;

        let canonPath = getCanonDeclPath(match);
        if (canonPath == null) continue;

        let lastModName = canonPath.modNames[canonPath.modNames.length - 1];
        let text = lastModName + "." + canonPath.declNames.join(".");
      

        const href = navLink(canonPath.modNames, canonPath.declNames);

        matchedItemsHTML += "<li><a href=\"" + href + "\">" +  text + "</a></li>";
      }
    }

    // Replace the search results using our newly constructed HTML string
    domListSearchResults.innerHTML = matchedItemsHTML;
    renderSearchCursor();

    domSectSearchResults.classList.remove("hidden");
  }
   
  function renderSearchAPIOld() {
    let matchedItems = [];
    let ignoreCase = curNavSearch.toLowerCase() === curNavSearch;
    let terms = getSearchTerms();

    decl_loop: for (
      let declIndex = 0;
      declIndex < zigAnalysis.decls.length;
      declIndex += 1
    ) {
      let canonPath = getCanonDeclPath(declIndex);
      if (canonPath == null) continue;

      let decl = getDecl(declIndex);
      let lastModName = canonPath.modNames[canonPath.modNames.length - 1];
      let fullPathSearchText =
        lastModName + "." + canonPath.declNames.join(".");
      let astNode = getAstNode(decl.src);
      let fileAndDocs = ""; //zigAnalysis.files[astNode.file];
      // TODO: understand what this piece of code is trying to achieve
      //       also right now `files` are expressed as a hashmap.
      if (astNode.docs != null) {
        fileAndDocs += "\n" + astNode.docs;
      }
      let fullPathSearchTextLower = fullPathSearchText;
      if (ignoreCase) {
        fullPathSearchTextLower = fullPathSearchTextLower.toLowerCase();
        fileAndDocs = fileAndDocs.toLowerCase();
      }

      let points = 0;
      for (let termIndex = 0; termIndex < terms.length; termIndex += 1) {
        let term = terms[termIndex];

        // exact, case sensitive match of full decl path
        if (fullPathSearchText === term) {
          points += 4;
          continue;
        }
        // exact, case sensitive match of just decl name
        if (decl.name == term) {
          points += 3;
          continue;
        }
        // substring, case insensitive match of full decl path
        if (fullPathSearchTextLower.indexOf(term) >= 0) {
          points += 2;
          continue;
        }
        if (fileAndDocs.indexOf(term) >= 0) {
          points += 1;
          continue;
        }

        continue decl_loop;
      }

      matchedItems.push({
        decl: decl,
        path: canonPath,
        points: points,
      });
    }

    if (matchedItems.length !== 0) {
      matchedItems.sort(function (a, b) {
        let cmp = operatorCompare(b.points, a.points);
        if (cmp != 0) return cmp;
        return operatorCompare(a.decl.name, b.decl.name);
      });

      let searchTrimmed = false;
      const searchTrimResultsMaxItems = 60;
      if (searchTrimResults && matchedItems.length > searchTrimResultsMaxItems) {
        matchedItems = matchedItems.slice(0, searchTrimResultsMaxItems);
        searchTrimmed = true;
      }

      // Build up the list of search results
      let matchedItemsHTML = "";

      for (let i = 0; i < matchedItems.length; i += 1) {
        const match = matchedItems[i];
        const lastModName = match.path.modNames[match.path.modNames.length - 1];

        const text = lastModName + "." + match.path.declNames.join(".");
        const href = navLink(match.path.modNames, match.path.declNames);

        matchedItemsHTML += "<li><a href=\"" + href + "\">" + text + "</a></li>";
      }

      // Replace the search results using our newly constructed HTML string
      domListSearchResults.innerHTML = matchedItemsHTML;
      if (searchTrimmed) {
        domSectSearchAllResultsLink.classList.remove("hidden");
      }
      renderSearchCursor();

      domSectSearchResults.classList.remove("hidden");
    } else {
      domSectSearchNoResults.classList.remove("hidden");
    }
  }

  function renderSearchCursor() {
    for (let i = 0; i < domListSearchResults.children.length; i += 1) {
      let liDom = domListSearchResults.children[i];
      if (curSearchIndex === i) {
        liDom.classList.add("selected");
      } else {
        liDom.classList.remove("selected");
      }
    }
  }

  // function indexNodesToCalls() {
  //     let map = {};
  //     for (let i = 0; i < zigAnalysis.calls.length; i += 1) {
  //         let call = zigAnalysis.calls[i];
  //         let fn = zigAnalysis.fns[call.fn];
  //         if (map[fn.src] == null) {
  //             map[fn.src] = [i];
  //         } else {
  //             map[fn.src].push(i);
  //         }
  //     }
  //     return map;
  // }

  function byNameProperty(a, b) {
    return operatorCompare(a.name, b.name);
  }


  function getDecl(idx) {
    const decl = zigAnalysis.decls[idx];
    return {
      name: decl[0],
      kind: decl[1],
      src: decl[2],
      value: decl[3],
      decltest: decl[4],
      is_uns: decl[5],
      parent_container: decl[6],
    };
  }

  function getAstNode(idx) {
    const ast = zigAnalysis.astNodes[idx];
    return {
      file: ast[0],
      line: ast[1],
      col: ast[2],
      name: ast[3],
      code: ast[4],
      docs: ast[5],
      fields: ast[6],
      comptime: ast[7],
    };
  }

  function getFile(idx) {
    const file = zigAnalysis.files[idx];
    return {
      name: file[0],
      modIndex: file[1],
    };
  }

  function getType(idx) {
    const ty = zigAnalysis.types[idx];
    switch (ty[0]) {
      default:
        throw "unhandled type kind!";
      case 0: // Unanalyzed
        throw "unanalyzed type!";
      case 1: // Type
      case 2: // Void 
      case 3: //  Bool
      case 4: //  NoReturn
      case 5: //  Int
      case 6: //  Float
        return { kind: ty[0], name: ty[1] };
      case 7: // Pointer
        return {
          kind: ty[0],
          size: ty[1],
          child: ty[2],
          sentinel: ty[3],
          align: ty[4],
          address_space: ty[5],
          bit_start: ty[6],
          host_size: ty[7],
          is_ref: ty[8],
          is_allowzero: ty[9],
          is_mutable: ty[10],
          is_volatile: ty[11],
          has_sentinel: ty[12],
          has_align: ty[13],
          has_addrspace: ty[14],
          has_bit_range: ty[15],
        };
      case 8: // Array
        return {
          kind: ty[0],
          len: ty[1],
          child: ty[2],
          sentinel: ty[3],
        };
      case 9: // Struct
        return {
          kind: ty[0],
          name: ty[1],
          src: ty[2],
          privDecls: ty[3],
          pubDecls: ty[4],
          field_types: ty[5],
          field_defaults: ty[6],
          backing_int: ty[7],
          is_tuple: ty[8],
          line_number: ty[9],
          parent_container: ty[10],
          layout: ty[11],
        };
      case 10: // ComptimeExpr
      case 11: // ComptimeFloat
      case 12: // ComptimeInt
      case 13: // Undefined
      case 14: // Null
        return { kind: ty[0], name: ty[1] };
      case 15: // Optional
        return {
          kind: ty[0],
          name: ty[1],
          child: ty[2],
        };
      case 16: // ErrorUnion
        return {
          kind: ty[0],
          lhs: ty[1],
          rhs: ty[2],
        };
      case 17: // InferredErrorUnion
        return {
          kind: ty[0],
          payload: ty[1],
        };
      case 18: // ErrorSet
        return {
          kind: ty[0],
          name: ty[1],
          fields: ty[2],
        };
      case 19: // Enum
        return {
          kind: ty[0],
          name: ty[1],
          src: ty[2],
          privDecls: ty[3],
          pubDecls: ty[4],
          tag: ty[5],
          values: ty[6],
          nonexhaustive: ty[7],
          parent_container: ty[8],
        };
      case 20: // Union
        return {
          kind: ty[0],
          name: ty[1],
          src: ty[2],
          privDecls: ty[3],
          pubDecls: ty[4],
          field_types: ty[5],
          tag: ty[6],
          auto_tag: ty[7],
          parent_container: ty[8],
          layout: ty[9],
        };
      case 21: // Fn
        return {
          kind: ty[0],
          name: ty[1],
          src: ty[2],
          ret: ty[3],
          generic_ret: ty[4],
          params: ty[5],
          lib_name: ty[6],
          is_var_args: ty[7],
          is_inferred_error: ty[8],
          has_lib_name: ty[9],
          has_cc: ty[10],
          cc: ty[11],
          align: ty[12],
          has_align: ty[13],
          is_test: ty[14],
          is_extern: ty[15],
        };
      case 22: // BoundFn
        return { kind: ty[0], name: ty[1] };
      case 23: // Opaque
        return {
          kind: ty[0],
          name: ty[1],
          src: ty[2],
          privDecls: ty[3],
          pubDecls: ty[4],
          parent_container: ty[5],
        };
      case 24: // Frame
      case 25: // AnyFrame
      case 26: // Vector
      case 27: // EnumLiteral
        return { kind: ty[0], name: ty[1] };
    }
  }

})();

function toggleExpand(event) {
  const parent = event.target.parentElement;
  parent.toggleAttribute("open");

  if (!parent.open && parent.getBoundingClientRect().top < 0) {
    parent.parentElement.parentElement.scrollIntoView(true);
  }
}

function RadixTree() {
  this.root = null;

  RadixTree.prototype.search = function (query) {
    return this.root.search(query);
    
  }

  RadixTree.prototype.add = function (declName, value) {
    if (this.root == null) {
      this.root = new Node(declName.toLowerCase(), null, [value]);
    } else {
      this.root.add(declName.toLowerCase(), value);
    }

    const not_scream_case = declName.toUpperCase() != declName;
    let found_separator = false;
    for (let i = 1; i < declName.length; i +=1) {
      if (declName[i] == '_' || declName[i] == '.') {
        found_separator = true;
        continue;
      }


      if (found_separator || (declName[i].toLowerCase() !== declName[i])) {
        if (declName.length > i+1 
          && declName[i+1].toLowerCase() != declName[i+1]) continue;
        let suffix = declName.slice(i);
        this.root.add(suffix.toLowerCase(), value);
        found_separator = false;
      }
    }
  }
  
  function Node(labels, next, values) {
    this.labels = labels; 
    this.next = next;
    this.values = values;
  }

  Node.prototype.isCompressed = function () {
    return !Array.isArray(this.next);
  }

  Node.prototype.search = function (word) {
    let full_matches = [];
    let partial_matches = [];
    let subtree_root = null;
    
    let cn = this;
    char_loop: for (let i = 0; i < word.length;) {
      if (cn.isCompressed()) {
        for (let j = 0; j < cn.labels.length; j += 1) {
          let current_idx = i+j;

          if (current_idx == word.length) {
            partial_matches = cn.values;
            subtree_root = cn.next;
            break char_loop; 
          }
          
          if (word[current_idx] != cn.labels[j]) return null;
        }

        // the full label matched
        let new_idx = i + cn.labels.length;
        if (new_idx == word.length) {
          full_matches = cn.values;
          subtree_root = cn.next;
          break char_loop;
        }
        
        
        i = new_idx;
        cn = cn.next;
        continue;
      } else {
        for (let j = 0; j < cn.labels.length; j += 1) {
          if (word[i] == cn.labels[j]) {
            if (i == word.length - 1) { 
              full_matches = cn.values[j];
              subtree_root = cn.next[j];
              break char_loop;
            }
              
            let next = cn.next[j];
            if (next == null) return null;
            cn = next;
            i += 1;
            continue char_loop; 
          } 
        }
        
        // didn't find a match
        return null;
      }
    }
    
    // Match was found, let's collect all other 
    // partial matches from the subtree
    let stack = [subtree_root];
    let node;
    while (node = stack.pop()) {
      if (node.isCompressed()) {
        partial_matches = partial_matches.concat(node.values);
        if (node.next != null) {
          stack.push(node.next);
        }
      } else {
        for (let v of node.values) {
          partial_matches = partial_matches.concat(v);
        }
        
        for (let n of node.next) {
          if (n != null) stack.push(n);
        }
      }
    }

    return {full: full_matches, partial: partial_matches};
  }

  Node.prototype.add = function (word, value) {
    let cn = this;
    char_loop: for (let i = 0; i < word.length;) {
      if (cn.isCompressed()) {
        for(let j = 0; j < cn.labels.length; j += 1) {
          let current_idx = i+j;

          if (current_idx == word.length) {
            if (j < cn.labels.length - 1) {
              let node = new Node(cn.labels.slice(j), cn.next, cn.values);
              cn.labels = cn.labels.slice(0, j);
              cn.next = node;
              cn.values = [];
            }
            cn.values.push(value);
            return;
          }
          
          if (word[current_idx] == cn.labels[j]) continue;
          
          // if we're here, a mismatch was found
          if (j != cn.labels.length - 1) {
            // create a suffix node
            const label_suffix = cn.labels.slice(j+1);
            let node = new Node(label_suffix, cn.next, [...cn.values]);
            cn.next = node;
            cn.values = [];
          }

          // turn current node into a split node
          let node = null;
          let word_values = [];
          if (current_idx == word.length - 1) {
            // mismatch happened in the last character of word
            // meaning that the current node should hold its value
            word_values.push(value);
          } else {
             node = new Node(word.slice(current_idx+1), null, [value]);
          }
        
          cn.labels = cn.labels[j] + word[current_idx];
          cn.next = [cn.next, node];          
          cn.values = [cn.values, word_values];

          if (j != 0) {
            // current node must be turned into a prefix node
            let splitNode = new Node(cn.labels, cn.next, cn.values);
            cn.labels = word.slice(i, current_idx);
            cn.next = splitNode;
            cn.values = [];
          }

          return;
        }        
        // label matched fully with word, are there any more chars?
        const new_idx = i + cn.labels.length;
        if (new_idx == word.length) {
          cn.values.push(value);
          return;
        } else {
          if (cn.next == null) {
            let node = new Node(word.slice(new_idx), null, [value]);
            cn.next = node;
            return;
          } else {
            cn = cn.next;
            i = new_idx;
            continue;
          }
        } 
      } else { // node is not compressed
        let letter = word[i];
        for (let j = 0; j < cn.labels.length; j += 1) {
          if (letter == cn.labels[j]) {
            if (i == word.length - 1) {
              cn.values[j].push(value);
              return;
            }
            if (cn.next[j] == null) {
              let node = new Node(word.slice(i+1), null, [value]);
              cn.next[j] = node;
              return;
            } else {
              cn = cn.next[j];
              i += 1;
              continue char_loop;
            }
          }
        }

        // if we're here we didn't find a match
        cn.labels += letter;
        if (i == word.length - 1) {
          cn.next.push(null);
          cn.values.push([value]);
        } else {
          let node = new Node(word.slice(i+1), null, [value]);
          cn.next.push(node);
          cn.values.push([]);
        }
        return;
      }
    }
  }
}

// RADIX TREE:

// apple 
// appliance

// "appl" => [
//   'e', => $
//   'i' => "ance" => $
// ]

// OUR STUFF:

// AutoHashMap
// AutoArrayHashMap

// "Auto" => [
//   'A', => "rrayHashMap" => $
//   'H'  => "ashMap" => $
// ]

// BUT!

// We want to be able to search "Hash", for example!