All files printer.js

96.96% Statements 3006/3100
95.31% Branches 814/854
97.46% Functions 154/158
96.96% Lines 3006/3100

Press n or j to go to the next uncovered block, b, p or k for the previous block.

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 31011x 1x 1x 1x 1x 1x 1x 80x 80x 64x 64x 16x 16x 80x 1x 13635x 13635x 13635x 13635x 13635x 13635x 13635x 5463x 5463x 5463x 5463x 8172x 8172x 13635x 208x 13635x 13635x 13635x 13635x 208x 13635x 13635x 13635x 100x 13635x 13635x 13635x 13635x 13635x 13635x 13635x 13635x 13635x 13635x 13635x 13635x 13635x 54x 13635x 13635x 13635x 13635x 13635x 13635x 13635x 13635x 13635x 13635x 82x 13635x 13635x 13635x 13635x 13635x 13635x 13635x 13635x 13635x 13635x 13635x 13635x 13635x 13635x 13635x 13635x 13635x 133x 13635x 13635x 6x 13635x 13635x 13635x 2x 13635x 13635x 2x 13635x 13635x 3x 13635x 13635x 6x 13635x 13635x 2x 13635x 13635x 1x 13635x 13635x 13635x 13635x 13635x 28x 13635x 13635x 13635x 24x 13635x 13635x 38x 13635x 13635x 15x 13635x 13635x 1x 13635x 13635x 14x 13635x 13635x 5x 13635x 13635x 13635x 13635x 13x 13635x 13635x 6x 13635x 13635x 3x 13635x 13635x 6x 13635x 13635x 5x 13635x 13635x 6x 13635x 13635x 3x 13635x 13635x 2x 13635x 13635x 2x 13635x 13635x 2x 13635x 13635x 13635x 13635x 13635x 13635x 2x 13635x 13635x 2x 13635x 13635x 13635x 13635x 13635x 13635x 29x 13635x 13635x 19x 13635x 13635x 19x 13635x 13635x 16x 13635x 13635x 16x 13635x 13635x 1x 13635x 13635x 1x 13635x 13635x 2x 13635x 13635x 1x 13635x 13635x 1x 13635x 13635x 3x 13635x 13635x 4x 13635x 13635x 4x 13635x 13635x 13635x 18x 13635x 13635x 1x 13635x 13635x 7x 13635x 13635x 8x 13635x 13635x 3x 13635x 13635x 15x 13635x 13635x 25x 13635x 13635x 10x 13635x 13635x 12x 13635x 13635x 20x 13635x 13635x 11x 13635x 13635x 11x 13635x 13635x 6x 13635x 13635x 3x 13635x 13635x 3x 13635x 13635x 2x 13635x 13635x 1x 13635x 13635x 13635x 13635x 13635x 13635x 105x 13635x 13635x 4x 13635x 13635x 13635x 13635x 13635x 13635x 7x 13635x 13635x 1x 13635x 13635x 7x 13635x 13635x 2x 13635x 13635x 13635x 13635x 13635x 13635x 6x 13635x 13635x 7x 13635x 13635x 9x 13635x 13635x 5x 13635x 13635x 13635x 13635x 13635x 13635x 4x 13635x 13635x   13635x 13635x 13635x 13635x 4x 13635x 13635x   13635x 13635x 3x 13635x 13635x 2x 13635x 13635x 13635x 13635x 13635x 13635x 2x 13635x 13635x 13635x 13635x 13635x 13635x 14x 13635x 13635x 10x 13635x 13635x 12x 13635x 13635x 13x 13635x 13635x 13635x 13635x 6x 13635x 13635x 13635x 12x 13635x 13635x 1x 13635x 13635x 13635x 13635x 13635x 13635x 13x 13635x 13635x 5x 13635x 13635x 13635x 10x 13635x 13635x 4x 13635x 13635x 1x 13635x 13635x 3x 13635x 13635x 1x 13635x 13635x 2x 13635x 13635x 5x 13635x 13635x 5x 13635x 13635x 1x 13635x 13635x 13635x 13635x 13635x 13635x 4x 13635x 13635x 2x 13635x 13635x 3x 13635x 13635x 64x 13635x 13635x 38x 13635x 13635x 25x 13635x 13635x 25x 13635x 13635x 67x 13635x 13635x 71x 13635x 13635x 4x 13635x 13635x 15x 13635x 13635x 19x 13635x 13635x 10x 13635x 13635x 14x 13635x 13635x 145x 13635x 13635x 124x 13635x 13635x 70x 13635x 13635x 15x 13635x 13635x 13635x 8x 13635x 13635x 4x 13635x 13635x 2x 13635x 13635x 3x 13635x 13635x 1x 13635x 13635x 57x 13635x 13635x 13635x 13635x 104x 13635x 13635x 13635x 13635x 13635x 13635x 13635x 13635x 13635x 13635x 13635x 13635x 13635x 13x 13635x 13635x 13635x 2x 13635x 1x 13635x 3x 13635x 2x 13635x 3x 13635x 1x 13635x 13635x 9x 13635x 13635x 70x 13635x 13635x 38x 13635x 13635x 13635x 13635x 452x 13635x 13635x   13635x 13635x 12x 13635x 13635x 15x 13635x 13635x 21x 13635x 13635x 13635x 13635x 13635x 13635x 931x 13635x 13635x 2x 13635x 13635x 13635x 13635x 13635x 1694x 13635x 13635x 15x 13635x 13635x 13635x 13635x 2509x 2509x 2509x   13635x 13635x 1x 49x 49x 49x 49x     49x 49x 49x     49x 25x 25x 49x 49x 49x 1x 1x 49x 49x 25x 25x 25x 49x 49x 49x 49x 4x 4x 49x 49x 49x 1x 204x 204x 204x 204x 204x 204x 188x 188x 204x 1x 49x 49x 49x 49x 49x 1x 47x 47x 7x 7x 7x 47x 7x 7x 7x 5x 5x 7x 7x 33x 33x 33x 47x 11x 11x 11x 11x       11x 11x 11x 47x 1x 1034x 1034x 29x 29x 29x 1034x 1034x 1034x 650x 650x 1034x 1x 58x 58x 58x 33x 33x 33x 58x 58x 58x   58x               33x 33x 33x 33x 33x 33x 33x 33x 33x 33x 33x 33x 58x 14x 1x 1x 14x 58x 1x 208x 208x 208x 208x 208x 208x 208x 208x 208x 208x 208x 208x 208x 208x 4x 4x 208x 2x 2x 208x 208x 208x 208x 208x 208x 208x 1x 208x 208x 208x 1x 100x 100x 100x 1x 54x 54x 54x 1x 82x 82x 82x 82x 1x 235x 235x 235x 235x 235x 114x 114x 114x 114x 114x 114x 114x 114x 235x 1x 1x 1x 1x 1x 1x 1x 1x 114x 114x 114x 114x 235x 114x 114x 235x 1x 6x 6x 6x 6x 1x 1x 1x 28x 28x 28x 1x 24x 24x 24x 24x 24x 24x 24x 36x 36x 24x 24x 24x 24x 24x 24x 24x 24x 24x 1x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 38x 12x 12x 38x 38x 38x 38x 12x 12x 26x 26x 16x 16x 10x 10x 10x 26x 38x 38x 38x 1x 15x 15x 15x 15x 1x 6x 6x 6x 6x 6x 6x 6x 6x 1x 5x 5x 5x 5x 5x 5x 1x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 3x 3x 6x 6x 6x 6x 6x 6x 6x 6x 3x 3x 3x 3x 2x 2x 1x 1x 1x 3x 6x 6x 6x 1x 3x 3x 3x 3x 3x 3x 3x 3x 3x 2x 2x 3x 3x 3x 2x 2x 2x 2x 2x 2x 2x 2x 2x 3x 1x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 1x 1x 2x 2x 2x 2x 1x 2x 2x 2x 2x 1x 2x 2x 2x 2x 2x 2x 2x 2x 2x 1x 1x 1x 1x 1x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 1x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 3x 3x 2x 2x 2x 2x 2x 2x                 2x 2x 2x 1x 1x 1x 1x 1x 29x 29x 29x 1x 19x 19x 19x 19x 19x 17x 17x 17x 19x 19x 19x 19x 19x 19x 16x 16x 17x 19x 16x 16x 17x 17x 17x 19x 1x 19x 19x 19x 19x 16x 19x 1x 16x 16x 16x 16x 16x 16x 1x 16x 16x 16x 16x 16x 16x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 2x 2x 2x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 3x 3x 3x 3x 1x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 1x 4x 4x 4x 4x 4x 4x 4x 4x 4x 2x 2x 2x 2x 2x 2x 2x 4x 4x 6x 6x 4x 4x 4x 1x 18x 18x 18x 18x 18x 18x 18x 18x 18x 18x 18x 18x 18x 18x 3x 3x 18x 18x 18x 18x 18x 3x 3x 15x 15x 14x 14x 1x 1x 1x 15x 18x 18x 18x 1x 1x 1x 1x 1x 1x 1x 4x 4x 1x 1x 1x 1x 1x 1x 1x 1x                 1x 1x 1x 1x 7x 7x 7x 7x 1x 8x 8x 8x 8x 1x 3x 3x 3x 3x 3x 3x 1x 1x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 1x 1x 3x 3x 1x 1x 3x 3x 3x 1x 15x 15x 15x 15x 15x 11x 11x 11x 11x 11x 11x 15x 15x 15x 15x 8x 8x 11x 15x 8x 8x 11x 11x 11x 15x 1x 25x 25x 25x 25x 25x 18x 18x 18x 25x 5x 5x 5x 18x 18x 25x 20x 20x 18x 25x 15x 15x 15x 15x 15x 18x 18x 25x 1x 10x 10x 10x 10x 10x 10x 10x 10x 7x 7x 10x 10x 10x 10x 10x 10x 10x 10x 7x 7x 3x 3x 2x 2x 1x 1x 1x 3x 10x 10x 10x 1x 12x 12x 12x 12x 1x 20x 20x 20x 20x 1x 11x 11x 11x 11x 11x 11x 1x 11x 11x 11x 11x 11x 11x 1x 6x 6x 6x 6x 6x 6x 1x 3x 3x 3x 3x 1x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x     3x 3x 3x 3x 3x 3x 1x 1x 3x 3x 3x 1x 1x 1x 1x 1x 14x 14x 14x 1x 5x 5x 5x 5x 5x 8x 8x 5x 5x 5x 1x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 1x 6x 6x 6x 1x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 1x 1x 3x 3x 3x 3x 3x 3x 3x 3x 3x 1x 2x 2x 2x 2x 2x 2x 2x 2x 1x 2x 2x 2x 2x 2x 4x 4x 4x 4x 2x 2x 4x 4x 2x 2x 2x 1x 2x 2x 2x 2x 1x 1x 1x 1x 1x 1x 1x 1x 1x 4x 4x 4x 1x                                           1x 4x 4x 4x 4x 4x 4x 4x 16x 16x 4x 4x 4x 4x 4x 4x 4x 1x                                         1x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 1x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 1x 1x 1x 1x 1x 7x 7x 7x 7x 7x 7x 7x 7x 7x 1x 1x 7x 7x 7x 7x 7x 6x 7x 7x 6x 7x 7x 7x 7x 2x 2x 2x 7x 7x 7x 1x 1x 7x 6x 1x 1x 6x 6x 7x 7x 7x 1x 1x 1x 1x 1x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 1x 2x 2x 2x 2x 1x 1x 1x 1x 1x 105x 105x 105x 1x 4x 4x 4x 4x 4x 4x 8x 8x 8x 4x 4x 8x 4x 4x 4x 1x 1x 1x 1x 1x 6x 6x 6x 1x 7x 7x 7x 1x 9x 9x 9x 9x 9x 9x 9x 9x 9x 27x 27x 9x 9x 9x 9x 9x 18x 18x 9x 9x 9x 9x 9x 9x 9x 9x 9x 9x 9x 9x 9x 9x 9x 9x 9x 9x 9x 9x 9x 9x 9x 1x 5x 5x 5x 5x 5x 5x 5x 5x 9x 9x 9x 9x 9x 9x 9x 9x 9x 9x 4x 4x 9x 5x 5x 5x 5x 1x 1x 1x 1x 1x 2x 2x 2x 1x 1x 1x 1x 1x 14x 14x 14x 1x 12x 12x 12x 1x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 1x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 12x 12x 12x 12x 13x 13x 13x 13x 13x 13x 13x 13x 1x 7x 7x 7x 7x 7x 7x 7x 7x 11x 11x 11x 11x 11x 11x 4x 4x 11x 7x 7x 7x 1x 12x 12x 12x 12x 12x 12x 12x 12x 12x 12x 12x 12x 12x 12x 12x 12x 12x 12x 12x 12x 12x 12x 12x 12x 12x 12x 12x 12x 12x 12x 12x 12x 12x 12x 12x 7x 7x 12x 12x 12x 1x 1x 1x 1x 1x 1x 1x 1x 2x 2x 2x 2x 2x 2x 1x 1x 2x 1x 1x 1x 1x 1x 1x 1x 1x 13x 13x 13x 1x 5x 5x 5x 5x 5x 5x 5x 5x 5x 3x 3x 5x 5x 5x 5x 5x 5x 5x 5x 1x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 9x 9x 10x 10x 10x 6x 6x 10x 10x 10x 10x 1x 4x 4x 4x 1x 3x 3x 3x 3x 3x 3x 3x 5x 5x 5x 5x 3x 3x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 3x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 2x 2x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 1x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 1x 1x 4x 4x 5x 5x 5x 2x 2x 4x 5x 3x 3x 4x 4x 4x 5x 1x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 5x 5x 5x 5x 1x 1x 1x 1x 1x 1x 1x 1x 1x 4x 4x 4x 4x 1x 2x 2x 2x 1x 3x 3x 3x 3x 1x 64x 64x 64x 64x 64x 64x 64x 64x 64x 64x 64x 64x 64x 64x 64x 64x 64x 64x 64x 64x 64x 1x 38x 38x 38x 38x 38x 38x 38x 39x 39x 38x 38x 38x 39x 39x 38x 38x 38x 38x 38x 1x 25x 25x 25x 25x 1x 25x 25x 25x 25x 25x 25x 25x 25x 25x 25x 25x 25x 25x 25x 25x 25x 25x 25x 25x 25x 25x 25x 25x 25x 25x 25x 2x 2x 25x 25x 25x 25x 25x 25x 25x 25x 1x 67x 67x 67x 67x 67x 71x 71x 71x 71x 67x 67x 67x 67x 67x 67x 1x 71x 71x 71x 71x 71x 71x 71x 71x 71x 71x 71x 71x 71x 71x 71x 71x 71x 71x 71x 71x 15x 15x 71x 71x 71x 71x 71x 71x 71x 71x 71x 71x 71x 71x 71x 71x 2x 2x 71x 71x 71x 18x 18x 71x 71x 71x 71x 71x 71x 71x 71x 71x 71x 71x 71x 71x 1x 15x 15x 15x 1x 19x 19x 19x 19x 1x 10x 10x 10x 10x 10x 14x 14x 10x 10x 1x 4x 4x 4x 4x 4x 4x 1x 1x 1x 4x 4x 4x 4x 4x 4x 1x 70x 70x 70x 70x 70x 70x 106x 106x 70x 70x 106x 106x 2x 2x 2x 2x 2x 106x 106x 36x 36x 36x 36x 36x 36x 27x 36x 13x 13x 36x 106x 106x 106x 70x 70x 70x 70x 70x 1x 124x 124x 124x 1x 145x 145x 145x 145x 145x 2x 2x 2x 2x 145x 145x 145x 145x 145x 145x 145x 1x 14x 14x 14x 14x 14x 2x 2x 2x 2x 12x 12x 12x 14x 1x 15x 15x 15x 15x 15x 15x 15x 15x 15x 15x 6x 6x 9x 8x 8x 8x 15x 15x 15x 15x 15x 4x 4x 4x 4x 4x 4x 4x 4x 4x 15x 15x 15x 1x 8x 8x 8x 8x 8x 8x 2x 2x 6x 6x 6x 8x 8x 8x 1x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 3x 2x 2x 1x 1x 1x 3x 4x 4x 4x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x               1x 1x 1x 1x 3x 3x 3x 3x 3x 3x 3x 3x 1x 2x 2x 2x 2x 2x 2x 2x 2x 2x 1x     1x 1x 1x 1x 2x 2x 2x 1x 15x 15x 15x 15x 15x 15x 15x 15x 15x 15x 15x 15x 15x 15x 15x 21x 21x 15x 4x 4x 15x 15x 15x 1x 21x 21x 21x 21x 21x 21x 21x 21x 24x 24x 24x 4x 4x 24x 24x 1x 1x 1x     1x 24x 24x 24x 24x 21x 21x 21x 21x 1x 1x 21x 21x 21x 1x 70x 70x 70x 70x 70x 70x 70x 70x 70x 70x 70x 70x 70x 70x 70x 70x 70x 70x 70x 70x 70x 70x 1x 38x 38x 38x 38x 38x 64x 64x 64x 64x 38x 38x 38x 1x 452x 452x 452x 1x       1x 931x 931x 931x 931x 931x 931x 931x 931x 931x 1x 1694x 1694x 1694x 1694x 1694x 1694x 1704x 1704x 1704x 10x 10x 1704x 1704x 1694x 1694x 1x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 5x 5x 4x 4x 5x 5x 2x 2x 2x 2x 1x 12x 12x 12x 12x 12x 12x 12x 12x 12x 12x 12x 12x 12x 12x 11x 11x 12x 12x 12x 1x 15x 15x 15x 15x 15x 15x 15x 15x 15x 9x 9x 9x 9x 9x 9x 9x 15x 15x 15x 1x 201x 201x 201x 201x 201x 201x 201x 201x 201x 201x 201x 201x 201x 201x 201x 201x 201x 201x 201x 201x 619x 619x 201x 201x 201x 201x 201x 201x 189x 189x 12x 12x 12x 201x 201x 201x 201x 201x 201x 201x 1x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 4x 4x 2x 2x 4x 2x 2x 2x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 5x 5x 5x 5x 3x 3x 1x 1x 2x 2x 2x 2x 2x 3x 1x 2x 2x 2x 2x 2x 1x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 2x 2x 2x 2x 2x 2x 2x 2x 1x 1x 2x 1x 1x 1x 1x 9x 9x 9x 9x 17x 17x 9x 9x 9x 1x 3x 3x 3x 3x 3x 3x 3x 3x 6x 6x 3x 3x 6x 6x 3x 3x 3x 1x 6x 6x 6x 6x 6x 6x 6x 6x 6x 1x 2x 2x 2x 2x 2x 1x 1x 1x 1x 2x 1x 1x 1x 1x 1x 5463x 5463x 5463x 1x 1x 1x 189x 189x 189x 189x 28x 28x 189x 189x 210x 210x 210x 210x 189x 189x 189x 1x 12x 12x 12x 12x 12x 12x 12x 12x 12x 12x 12x 12x 12x 12x 48x 48x 4x 4x 48x 48x 3x 3x 48x 48x 4x 4x 48x 48x 1x 1x 48x 48x     48x 48x 2x 2x 48x 48x 24x 8x 8x 16x 16x 16x 24x 48x 48x 10x 10x 10x 48x 48x 48x 48x 12x 1x 12x 12x 12x 12x 8x 8x 12x 4x 4x 4x 4x 12x 12x 60x 10x 60x 12x 12x 12x 12x 12x 12x 12x 12x 12x 12x 12x 12x 12x 12x 12x 12x 12x 12x 12x 12x 12x 12x 1x 24x 24x 24x 24x 24x 57x 25x 25x 57x 24x 24x 24x 1x 99x 99x 99x 4x 4x 99x 1x 138x 138x 138x 7x 7x 7x 138x 1x 48x 48x 48x 48x 48x 48x 48x 48x 48x 48x 48x 48x 48x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x  
import * as prettier from 'prettier';
import ALParser from '../parser/ALParser.js';
import { isParagraphStatement, isCompoundStatement, shouldAddBlankLineAfter } from "./printerHelpers.js";
import { TokenFormatter } from './tokenFormatter.js';
 
const { hardline, join, indent, group, line, softline } = prettier.doc.builders;
 
function getVisitorKeys(node) {
    if (node && Array.isArray(node.children)) {
        return ['children'];
    }
 
    return [];
}
 
function print(path, options, print, args) {
    const node = path.node;
 
    if (!node) return "";
 
    // Terminal node (ANTLR token)
    if (node.symbol) {
        const text = node.symbol.text;
        if (text === "<EOF>") return "";
        return printToken(node);
    }
 
    switch (node.ruleIndex) {
        case ALParser.RULE_compilationUnit:
            return printCompilationUnit(path, options, print);
 
        //#region Common object elements
 
        case ALParser.RULE_objectDefinition:
            return printObjectDefinition(path, options, print);
 
        case ALParser.RULE_genericObjectProperty:
        case ALParser.RULE_accessProperty:
            return printGenericObjectProperty(path, options, print);
 
        case ALParser.RULE_tablePropertiesList:
        case ALParser.RULE_pagePropertiesList:
        case ALParser.RULE_codeunitPropertiesList:
        case ALParser.RULE_enumPropertiesList:
        case ALParser.RULE_keyPropertiesList:
        case ALParser.RULE_enumPropertiesList:
        case ALParser.RULE_enumValuePropertiesList:
        case ALParser.RULE_groupPropertiesList:
        case ALParser.RULE_queryPropertiesList:
        case ALParser.RULE_queryColumnPropertiesList:
        case ALParser.RULE_reportPropertiesList:
        case ALParser.RULE_reportDataItemPropertiesList:
            return printObjectPropertiesList(path, options, print);
 
        case ALParser.RULE_tablePropertyItem:
        case ALParser.RULE_codeunitPropertyItem:
        case ALParser.RULE_pagePropertyItem:
        case ALParser.RULE_tableFieldPropertyItem:
        case ALParser.RULE_keyPropertyItem:
        case ALParser.RULE_enumPropertyItem:
        case ALParser.RULE_enumValuePropertyItem:
        case ALParser.RULE_queryPropertyItem:
        case ALParser.RULE_queryColumnPropertyItem:
            return printObjectPropertyItem(path, options, print);
 
        case ALParser.RULE_tableProperty:
        case ALParser.RULE_pageProperty:
        case ALParser.RULE_pageFieldProperty:
        case ALParser.RULE_actionProperty:
        case ALParser.RULE_codeunitProperty:
        case ALParser.RULE_tableFieldProperty:
        case ALParser.RULE_keyProperty:
        case ALParser.RULE_groupProperty:
        case ALParser.RULE_partProperty:
        case ALParser.RULE_enumProperty:
        case ALParser.RULE_enumValueProperty:
        case ALParser.RULE_interfaceProperty:
        case ALParser.RULE_queryProperty:
        case ALParser.RULE_queryColumnProperty:
        case ALParser.RULE_reportProperty:
        case ALParser.RULE_reportDataItemProperty:
            return printObjectProperty(path, options, print);
 
        case ALParser.RULE_objectReference:
            return printObjectReference(path, options, print);
 
        case ALParser.RULE_subpageLinkProperty:
        case ALParser.RULE_runPageLinkProperty:
            return printSubPageLinkProperty(path, options, print);
 
        case ALParser.RULE_pageLinkExpression:
            return printPageLinkExpression(path, options, print);
 
        case ALParser.RULE_objectPermissionsList:
            return printObjectPermissionsList(path, options, print);
 
        case ALParser.RULE_permissionsPropertyValue:
            return printPermissionsPropertyValue(path, options, print);
 
        case ALParser.RULE_decimalPlacesPropValue:
            return printDecimalPlacesPropertyValue(path, options, print);
 
        case ALParser.RULE_accessByPermissionProperty:
            return printAccessByPermissionPropertyValue(path, options, print);
 
        //#endregion Common object elements
 
        //#region Table object
        case ALParser.RULE_tableObject:
            return printTableObject(path, options, print);
 
        case ALParser.RULE_tableFieldsList:
        case ALParser.RULE_tableExtFieldsList:
            return printTableFieldsList(path, options, print);
 
        case ALParser.RULE_tableFieldDefinition:
            return printTableFieldDefinition(path, options, print);
 
        case ALParser.RULE_tableFieldPropertiesList:
            return printTableFieldPropertiesList(path, options, print);
 
        case ALParser.RULE_tableRelationExpression:
            return printTableRelationExpression(path, options, print);
 
        case ALParser.RULE_tableFieldReference:
            return printTableFieldReference(path, options, print);
 
        case ALParser.RULE_tableRelationWhereExpression:
            return printTableRelationWhereExpression(path, options, print);
 
        case ALParser.RULE_tableRelationFieldReference:
        case ALParser.RULE_tableRelationConstReference:
        case ALParser.RULE_tableRelationFilter:
            return printTableRelationFilterRef(path, options, print);
 
        case ALParser.RULE_relationFilterExpression:
            return printRelationFilterExpression(path, options, print);
 
        case ALParser.RULE_calcFormulaExpression:
            return printCalcFormulaExpression(path, options, print);
 
        case ALParser.RULE_tableKeysSection:
            return printTableKeysSection(path, options, print);
 
        case ALParser.RULE_keyList:
            return printKeyList(path, options, print);
 
        case ALParser.RULE_keyItem:
            return printKeyItem(path, options, print);
 
        case ALParser.RULE_fieldGroupsList:
            return printFieldGroupsList(path, options, print);
 
        case ALParser.RULE_fieldGroupItem:
            return printFieldGroupItem(path, options, print);
 
        case ALParser.RULE_fieldGroupDefinition:
            return printFieldGroupDefinition(path, options, print);
 
        case ALParser.RULE_fieldGroupFieldsList:
            return printFieldGroupFieldsList(path, options, print);
 
        //#endregion Table object
 
        //#region Table extension object
 
        case ALParser.RULE_tableExtensionObject:
            return printTableExtObject(path, options, print);
 
        case ALParser.RULE_tableExtFieldModification:
            return printTableExtFieldModification(path, node, print);
 
        //#endregion Table extension object
 
        //#region Page object
 
        case ALParser.RULE_pageObject:
            return printPageObject(path, options, print);
 
        case ALParser.RULE_layoutDefinition:
            return printLayoutDefinition(path, options, print);
 
        case ALParser.RULE_layoutElements:
            return printLayoutElements(path, options, print);
 
        case ALParser.RULE_areaDefinition:
            return printAreaDefinition(path, options, print);
 
        case ALParser.RULE_areaElements:
            return printAreaElements(path, options, print);
 
        case ALParser.RULE_groupDefinition:
            return printGroupDefinition(path, options, print);
 
        case ALParser.RULE_groupElements:
            return printGroupElements(path, options, print);
 
        case ALParser.RULE_groupPropertyItem:
            return printGroupPropertyItem(path, options, print);
 
        case ALParser.RULE_partDefinition:
            return printPartDefinition(path, options, print);
 
        case ALParser.RULE_partPropertiesList:
            return printPartPropertiesList(path, options, print);
 
        case ALParser.RULE_partPropertyItem:
            return printPartPropertyItem(path, options, print);
 
        case ALParser.RULE_repeaterDefinition:
            return printRepeaterDefinition(path, options, print);
 
        case ALParser.RULE_repeaterElements:
            return printRepeaterElements(path, options, print);
 
        case ALParser.RULE_pageFieldItem:
        case ALParser.RULE_userControlItem:
            return printPageFieldItem(path, options, print);
 
        case ALParser.RULE_pageLabelItem:
            return printPageLabelItem(path, options, print);
 
        case ALParser.RULE_pageFieldPropertiesList:
            return printPageFieldPropertiesList(path, options, print);
 
        case ALParser.RULE_pageFieldPropertyItem:
            return printPageFieldPropertyItem(path, options, print);
 
        case ALParser.RULE_separatorDefinition:
            return printSeparatorElement(path, options, print);
 
        case ALParser.RULE_actionsDefinition:
            return printActionsDefinition(path, options, print);
 
        case ALParser.RULE_actionElements:
            return printActionElements(path, options, print);
 
        case ALParser.RULE_actionDefinition:
            return printActionDefinition(path, options, print);
 
        case ALParser.RULE_actionPropertiesList:
            return printActionPropertiesList(path, options, print);
 
        case ALParser.RULE_actionPropertyItem:
            return printActionPropertyItem(path, options, print);
 
        case ALParser.RULE_actionAreaDefinition:
            return printActionAreaDefinition(path, options, print);
 
        case ALParser.RULE_actionAreaElements:
            return printActionAreaElements(path, options, print);
 
        case ALParser.RULE_actionGroupDefinition:
            return printActionGroupDefinition(path, options, print);
 
        case ALParser.RULE_actionRefsList:
            return printActionRefsList(path, options, print);
 
        case ALParser.RULE_actionRef:
            return printActionRef(path, options, print);
 
        case ALParser.RULE_tableViewExpression:
            return pintTableViewExpression(path, options, print);
 
        case ALParser.RULE_sourceTableViewProperty:
            return printSourceTableViewExpression(path, options, print);
 
        //#endregion Page object
 
        //#region Codeunit object
 
        case ALParser.RULE_codeunitObject:
            return printCodeunitObject(path, options, print);
 
        case ALParser.RULE_implementsInterfacesList:
            return printImplementsInterfacesList(path, options, print);
 
        //#endregion Codeunit object
 
        //#region Interface object
 
        case ALParser.RULE_interfaceObject:
            return printInterfaceObject(path, options, print);
 
        case ALParser.RULE_interfacePropertiesList:
            return printInterfacePropertiesList(path, options, print);
 
        case ALParser.RULE_procedureDeclaration:
            return printProcedureDeclaration(path, options, print);
 
        case ALParser.RULE_interfacePropertyItem:
            return printInterfacePropertyItem(path, options, print);
 
        //#endregion Interface object
 
        //#region Enum object
 
        case ALParser.RULE_enumObject:
            return printEnumObject(path, options, print);
 
        case ALParser.RULE_enumValuesList:
            return printEnumValuesList(path, options, print);
 
        case ALParser.RULE_enumValueDefinition:
            return printEnumValueDefinition(path, options, print);
 
        case ALParser.RULE_implementationProperty:
            return printImplementationProperty(path, options, print);
 
        //#endregion Enum object
 
        //#region Page extension
 
        case ALParser.RULE_pageExtensionObject:
            return printPageExtensionObject(path, options, print);
 
        case ALParser.RULE_pageExtLayoutDefinition:
            return printPageExtLayoutDefinition(path, options, print);
 
        case ALParser.RULE_pageExtLayoutModification:
        case ALParser.RULE_pageExtActionModification:
        case ALParser.RULE_pageExtActionPropModification:
            return printPageExtLayoutModificationBlock(path, options, print);
 
        case ALParser.RULE_pageExtElementModification:
            return printPageExtElementModificationBlock(path, options, print);
 
        case ALParser.RULE_pageExtActionsBlock:
            return printPageExtensionActions(path, options, print);
 
        case ALParser.RULE_pageExtElementRelocation:
            return printPageExtElementRelocation(path, options, print);
 
        //#endregion Page extension
 
        //#region Enum extension
 
        case ALParser.RULE_enumExtensionObject:
            return printEnumExtensionObject(path, options, print);
 
        //#endregion Enum extension
 
        //#region Query object
 
        case ALParser.RULE_queryObject:
            return printQueryObject(path, options, print);
 
        case ALParser.RULE_queryElements:
            return printQueryElements(path, options, print);
 
        case ALParser.RULE_queryDataItemElementsList:
            return printQueryDataItemElementsList(path, options, print);
 
        case ALParser.RULE_queryDataItemDefinition:
            return printQueryDataItemDefinition(path, options, print);
 
        case ALParser.RULE_queryDataItemLinkProperty:
        case ALParser.RULE_dataItemTableFilterProp:
        case ALParser.RULE_columnFilterProp:
            return printDataItemLinkProperty(path, options, print);
 
        case ALParser.RULE_queryColumnDefinition:
        case ALParser.RULE_queryFilterDefinition:
            return printQueryColumnDefinition(path, options, print);
 
        case ALParser.RULE_orderByProperty:
            return printOrderByProperty(path, options, print);
 
        //#endregion Query object
 
        //#region Report object
 
        case ALParser.RULE_reportObject:
            return printReportObject(path, options, print);
 
        case ALParser.RULE_reportDatasetDefinition:
            return printReportDatasetDefinition(path, options, print);
 
        case ALParser.RULE_reportDataItemDefinition:
        case ALParser.RULE_reportColumnDefinition:
            return printReportDataItemDefinition(path, options, print);
 
        case ALParser.RULE_reportDataItemElementsList:
            return printReportDataItemElementsList(path, options, print);
 
        case ALParser.RULE_reportDataItemLinkProperty:
            return printDataItemLinkProperty(path, options, print);
 
        case ALParser.RULE_requestpageDefinition:
            return printReportRequestPage(path, options, print);
 
        case ALParser.RULE_renderingOptions:
            return printRenderingOptions(path, options, print);
 
        case ALParser.RULE_renderingLayout:
            return printRenderingLayout(path, options, print);
 
        case ALParser.RULE_labelsDefinition:
            return printLabelsDefinition(path, options, () => print(path, args));
 
        case ALParser.RULE_labelDefinition:
            return printLabelDefinition(path, options, print);
 
        case ALParser.RULE_dataItemTableViewProperty:
            return printDataItemTableViewProperty(path, options, print);
 
        //#endregion Report object
 
        //#region Code statements
 
        case ALParser.RULE_namespaceDeclaration:
            return printNamespaceDeclaration(path, options, print);
 
        case ALParser.RULE_usingRefList:
            return printUsingRefList(path, options, print);
 
        case ALParser.RULE_usingReference:
            return printUsingReference(path, options, print);
 
        case ALParser.RULE_variableDeclaration:
            return printVariableDeclaration(path, options, print);
 
        case ALParser.RULE_variablesList:
            return printVariablesList(path, options, print);
 
        case ALParser.RULE_triggersList:
            return printTriggersList(path, options, print);
 
        case ALParser.RULE_triggerDefinition:
            return printTriggerDefinition(path, options, print);
 
        case ALParser.RULE_proceduresList:
            return printProceduresList(path, options, print);
 
        case ALParser.RULE_procedureDefinition:
            return printProcedureDefinition(path, options, print);
 
        case ALParser.RULE_procedureReturnType:
            return printProcReturnType(path, options, print);
 
        case ALParser.RULE_procedureAttributesList:
            return printProcedureAttributes(path, options, print);
 
        case ALParser.RULE_procedureAttribute:
            return printProcedureAttribute(path, options, print);
 
        case ALParser.RULE_parameterList:
            return printParameterList(path, options, print);
 
        case ALParser.RULE_parameter:
            return printParameter(path, options, print);
 
        case ALParser.RULE_statement:
            return printStatement(path, options, print);
 
        case ALParser.RULE_statementWithSeparator:
            return printStatementWithSeparator(path, options, print);
 
        case ALParser.RULE_statementList:
            return printStatementList(path, options, print);
 
        case ALParser.RULE_ifStatement:
            return printIfStatement(path, options, print);
 
        case ALParser.RULE_ifElseStatement:
        case ALParser.RULE_caseElseStatement:
            return printElseStatement(path, options, print);
 
        case ALParser.RULE_forStatement:
            return printForLoopStatement(path, options, print);
 
        case ALParser.RULE_whileStatement:
            return printWhileLoopStatement(path, options, print);
 
        case ALParser.RULE_repeatStatement:
            return printRepeatStatement(path, options, print);
 
        case ALParser.RULE_forEachStatement:
            return printForEachStatement(path, options, print);
 
        case ALParser.RULE_simpleDataType:
            path.call(print, 'children', 0);
 
        // Multi-part type definition concatenate without spaces (e.g. Text[100], Code[20])
        case ALParser.RULE_codeDataType:
        case ALParser.RULE_textDataType:
            return path.map(print, 'children');
 
        // Two-token types (e.g. Record Customer) — join with space
        case ALParser.RULE_codeunitDataType:
        case ALParser.RULE_enumDataType:
        case ALParser.RULE_interfaceDataType:
        case ALParser.RULE_pageDataType:
        case ALParser.RULE_queryDataType:
        case ALParser.RULE_recordDataType:
        case ALParser.RULE_reportDataType:
        case ALParser.RULE_testPageDataType:
        case ALParser.RULE_testRequestPageDataType:
        case ALParser.RULE_xmlPortDataType:
        case ALParser.RULE_dotNetDataType:
            return join(" ", path.map(print, 'children'));
 
        // Other data types that require special formatting
        case ALParser.RULE_arrayDataType:
            return printArrayDataType(path, options, print);
        case ALParser.RULE_dictionaryDataType:
            return printDictionaryDataType(path, options, print);
        case ALParser.RULE_labelDataType:
            return printLabelDataType(path, options, print);
        case ALParser.RULE_listDataType:
            return printListDataType(path, options, print);
        case ALParser.RULE_optionDataType:
            return printOptionDataType(path, options, print);
        case ALParser.RULE_textConstDataType:
            return printTextConst(path, options, print);
 
        case ALParser.RULE_identifiersList:
            return printIdentifiersList(path, options, print);
 
        case ALParser.RULE_procedureCall:
            return printProcedureCall(path, options, print, args);
 
        case ALParser.RULE_argumentList:
            return printArgumentList(path, options, print, args);
 
        case ALParser.RULE_unaryExpression:
        case ALParser.RULE_unaryPlusExpression:
        case ALParser.RULE_unaryMinusExpression:
            return printUnaryExpression(path, options, print, args);
 
        case ALParser.RULE_unaryNotExpression:
            return printUnaryNotExpression(path, options, print);
 
        case ALParser.RULE_compoundBlock:
            return printCompoundBlock(path, options, print);
 
        case ALParser.RULE_caseStatement:
            return printCaseStatement(path, options, print);
 
        case ALParser.RULE_caseBranch:
            return printCaseBranch(path, options, print);
 
        case ALParser.RULE_assignmentStatement:
        case ALParser.RULE_equalityExpression:
        case ALParser.RULE_relationalExpression:
        case ALParser.RULE_tableRelationEqualityExpression:
        case ALParser.RULE_subpageLinkFilter:
            return printBinaryExpression(path, options, print, args);
 
        case ALParser.RULE_logicalInExpression:
            return printLogicalInExpression(path, options, print);
 
        case ALParser.RULE_logicalOrExpression:
        case ALParser.RULE_logicalAndExpression:
        case ALParser.RULE_additiveExpression:
        case ALParser.RULE_multiplicativeExpression:
            return printMultipartExpression(path, options, print, args);
 
        case ALParser.RULE_exitStatement:
            return printExitStatement(path, options, print, args);
 
        //#endregion Code statements
 
        default:
            if (Array.isArray(node.children)) {
                return path.map(() => print(path, args), 'children');
            }
            return "";
    }
}
 
function printComment(path, options) {
    const comment = path.node;
 
    if (!comment?.symbol?.text) {
        return "";
    }
 
    let text = comment.symbol.text.trim();
    const hasPrecedingSiblings = (path) => {
        return path.siblings?.findIndex(sibling => sibling.symbol.startLine < path.node.symbol.startLine) > -1
    }
    const padToOrigin = (symbol) => {
        return symbol.text.trim().padStart(text.length + symbol.startColumn);
    }
 
    const parts = [];
    if (comment.addBlankLineBefore) {
        parts.push(hardline);
    }
 
    if (text.startsWith('#')) {
        text = padToOrigin(comment.symbol);
        parts.push(prettier.doc.builders.trim);
    }
 
    parts.push(text);
 
    if (comment.addBlankLineAfter) {
        parts.push(hardline);
    }
 
    return parts;
}
 
function canAttachComment(node) {
    if (!node) return false;
 
    // Comments cannot be attached to EOF or whitespace-like nodes
    if (node.symbol && node.symbol.text === "<EOF>") return false;
    if (node.hidden) return false;  // Skip hidden tokens themselves
 
    return true;
}
 
function isBlockComment(node) {
    if (!node || !node.symbol) return false;
    const text = node.symbol.text;
    return text && text.trim().startsWith("/*");
}
 
function handleOwnLineComment(comment, text, options, ast, isLastComment) {
    if (comment.value.trimStart().startsWith('#region') && comment.followingNode) {
        prettier.util.addLeadingComment(comment.followingNode, comment);
        return true;
    }
    if (comment.value.trimStart().startsWith('#endregion') && comment.precedingNode) {
        prettier.util.addTrailingComment(comment.precedingNode, comment);
 
        if (isLastComment) {
            insertBlankLinesInNodeComments(ast);
        }
        return true;
    }
 
    // The last comment is attached explicitly to be able to insert blank lines for the complete set of comments
    if (!isLastComment)
        return false;
 
    if (comment.followingNode) {
        prettier.util.addLeadingComment(comment.followingNode, comment);
    }
    else {
        prettier.util.addTrailingComment(comment.precedingNode, comment);
    }
 
    insertBlankLinesInNodeComments(ast);
    return true;
}
 
function insertBlankLinesInNodeComments(node) {
    if (node.comments) {
        insertBlankLinesInComments(node.comments.filter(comment => comment.leading === true && comment.placement === 'ownLine'));
        insertBlankLinesInComments(node.comments.filter(comment => comment.leading === false && comment.placement === 'ownLine'));
    }
 
    if (!node.children)
        return;
 
    node.children.map(child => insertBlankLinesInNodeComments(child));
}
 
function insertBlankLinesInComments(comments) {
    if (!comments || comments.length === 0)
        return;
 
    // Blank line between the preceding node and the first comment
    const firstComment = comments[0];
    if (comments[0].leading &&
        firstComment.precedingNode &&
        !firstComment.followingNode?.ruleIndex === ALParser.RULE_statementWithSeparator &&
        !firstComment.followingNode?.ruleIndex === ALParser.RULE_statement
    ) {
        // Prettier formatter inserts a blank line before the first trailing comment
        // When printing comments inside a statment list, statement printer takes care of the blank lines between
        const precedingNodeEndLine = firstComment.precedingNode.symbol
            ? firstComment.precedingNode.symbol.line
            : firstComment.precedingNode.stop.line;
        firstComment.addBlankLineBefore = firstComment.symbol.startLine > precedingNodeEndLine + 1;
    }
 
    // Blank line between the last comment and the following node
    const lastComment = comments[comments.length - 1];
    if (lastComment.followingNode) {
        const followingNodeStartLine = lastComment.followingNode.symbol
            ? lastComment.followingNode.symbol.line
            : lastComment.followingNode.start.line;
 
        lastComment.addBlankLineAfter = lastComment.symbol.stopLine < followingNodeStartLine - 1;
    }
 
    // Blank lines between comments
    for (let i = 1; i < comments.length; i++) {
        if (comments[i].symbol.startLine > comments[i - 1].symbol.stopLine + 1) {
            comments[i].addBlankLineBefore = true;
        }
    }
}
 
function printCompilationUnit(path, options, print) {
    // Grammar: namespaceDeclaration? usingRefList? objectDefinition* EOF
    const children = path.node.children;
    const namespaceDescIdx = children.findIndex(c => c.ruleIndex === ALParser.RULE_namespaceDeclaration);
    const usingRefListIdx = children.findIndex(c => c.ruleIndex === ALParser.RULE_usingRefList);
    const objectDefinitionIdx = children.findIndex(c => c.ruleIndex === ALParser.RULE_objectDefinition);
 
    const namespace = namespaceDescIdx > -1 ? path.call(print, 'children', namespaceDescIdx) : [];
    const usingRefList = usingRefListIdx > -1 ? path.call(print, 'children', usingRefListIdx) : [];
 
    const objectDef = path.call(print, 'children', objectDefinitionIdx);
 
    const result = [];
    if (namespace.length > 0) {
        result.push(...namespace, hardline, hardline);
    }
    if (usingRefList.length > 0) {
        result.push(...usingRefList, hardline, hardline);
    }
 
    if (objectDef.length > 0) {
        result.push(...objectDef, hardline);
    }
 
    return result;
}
 
function printObjectDefinition(path, options, print) {
    return path.call(print, 'children', 0);
}
 
function printGenericObjectProperty(path, options, print) {
    return printObjectProperty(path, options, print);
}
 
function printObjectPropertiesList(path, options, print) {
    return join(hardline, path.map(print, 'children'));
}
 
function printObjectPropertyItem(path, options, print) {
    // Grammar: tableProperty SEMICOLON (For table. Other object follow the same grammar, only with the respective object type.)
    return [path.call(print, 'children', 0), path.call(print, 'children', 1)];
}
 
function printObjectProperty(path, options, print) {
    // Grammar: identifier EQUAL expression (COMMA identifier EQUAL literal)*;
    const children = path.node.children;
    if (children.length === 1)
        return path.call(print, 'children', 0);
 
    const definition = [];
    definition.push(path.call(print, 'children', 0));  // Property name
    definition.push(path.call(print, 'children', 1));  // Equal sign
    definition.push(path.call(print, 'children', 2));  // Property value
 
    // Comma-separated list of property modifiers (e.g. Caption = 'Caption text', Locked = true)
    const modifiers = [];
    for (let i = 3; i < children.length; i += 4) {
        modifiers.push(
            join(" ", [
                path.call(print, 'children', i),  // Comma
                path.call(print, 'children', i + 1),  // Name
                path.call(print, 'children', i + 2),  // Equal sign
                path.call(print, 'children', i + 3)   // Value
            ]));
    }
 
    const property = [];
    property.push(join(" ", definition));
    if (modifiers.length > 0)
        property.push(modifiers);
 
    return property;
}
 
function printObjectReference(path, options, print) {
    // Grammar: objectTypeName identifier;
    return join(" ", path.map(print, 'children'));
}
 
//#region Table functions
 
function printTableObject(path, options, print) {
    return printALObject(path, options, print, ALParser.TABLE);
}
 
function printTableFieldsList(path, options, print) {
    const children = path.node.children;
    // Invoked for table fields and table extension fields
    // Table fields grammar: FIELDS LBRACE tableFieldDefinition* RBRACE
    // Table extension fields grammar: FIELDS LBRACE (tableFieldDefinition | tableExtFieldModification)* RBRACE;
    const fieldDocs = [];
    for (let i = 2; i < children.length - 1; i++) {
        fieldDocs.push(path.call(print, 'children', i));
    }
    return [
        path.call(print, 'children', 0),  // "fields" keyword
        hardline,
        path.call(print, 'children', 1),  // left brace
        indent([hardline, join(hardline, fieldDocs)]),
        hardline,
        path.call(print, 'children', children.length - 1)  // right brace
    ];
}
 
function printTableFieldDefinition(path, options, print) {
    const children = path.node.children;
    // Grammar: FIELD LPAREN INTEGER_LITERAL SEMICOLON identifier SEMICOLON dataType RPAREN LBRACE tableFieldProperties* triggersList* RBRACE;
    const fieldKeyword = path.call(print, 'children', 0);
    const lparen = path.call(print, 'children', 1);
    const fieldId = path.call(print, 'children', 2);
    const semicolon1 = path.call(print, 'children', 3);
    const fieldName = path.call(print, 'children', 4);  // identifier (non-terminal)
    const semicolon2 = path.call(print, 'children', 5);
    const fieldType = path.call(print, 'children', 6);  // dataType (non-terminal)
    const rparen = path.call(print, 'children', 7);
    const lbrace = path.call(print, 'children', 8);
    const rbrace = path.call(print, 'children', children.length - 1);
 
    // Table field properties and triggers occupy children[9] through children[length-2]; children[length-1] is RBRACE
    const elementDocs = [];
    for (let i = 9; i < children.length - 1; i++) {
        elementDocs.push(path.call(print, 'children', i));
    }
 
    const signature = [fieldKeyword, lparen, fieldId, semicolon1, " ", fieldName, semicolon2, " ", fieldType, rparen];
    let body = [];
    if (elementDocs.length > 0) {
        body = [hardline, lbrace, indent([hardline, join([hardline, hardline], elementDocs)]), hardline, rbrace];
    }
    else {
        if (options?.collapseEmptyBraces) {
            body = [" ", lbrace, rbrace];
        }
        else {
            body = [hardline, lbrace, hardline, rbrace];
        }
    }
 
    return [...signature, ...body];
}
 
function printTableFieldPropertiesList(path, options, print) {
    // Grammar: tableFieldPropertyItem+
    return join(hardline, path.map(print, 'children'));
}
 
function printTableKeysSection(path, options, print) {
    // Grammar: KEYS LBRACE keyList RBRACE
    const keysKeyword = path.call(print, 'children', 0);
    const lbrace = path.call(print, 'children', 1);
    const keyList = path.call(print, 'children', 2);
    const rbrace = path.call(print, 'children', 3);
    return [keysKeyword, hardline, lbrace, indent([hardline, keyList]), hardline, rbrace];
}
 
function printKeyList(path, options, print) {
    // Grammar: (keyItem)*
    const children = path.node.children;
    if (!children || children.length === 0) return "";
    return join(hardline, path.map(print, 'children'));
}
 
function printKeyItem(path, options, print) {
    // Grammar: KEY LPAREN identifier SEMICOLON identifier (COMMA identifier)* RPAREN LBRACE keyPropertiesList? RBRACE
    const children = path.node.children;
    const rparenIdx = children.findIndex(c => c.symbol?.type === ALParser.RPAREN);
 
    const keyName = path.call(print, 'children', 2);
 
    // Field names at indices 4, 6, 8, ... (COMMA tokens at 5, 7, ... are skipped)
    const fieldDocs = [];
    for (let i = 4; i < rparenIdx; i += 2) {
        fieldDocs.push(path.call(print, 'children', i));
    }
 
    const propsListIdx = children.findIndex(c => c.ruleIndex === ALParser.RULE_keyPropertiesList);
    let propsList = [];
    if (propsListIdx > -1) {
        propsList = path.call(print, 'children', propsListIdx);
    }
 
    const lBrace = propsListIdx > -1 
        ? path.call(print, 'children', children.length - 3) 
        : path.call(print, 'children', children.length - 2);
    const rBrace = path.call(print, 'children', children.length - 1);
    const signature = ["key(", keyName, "; ", join(", ", fieldDocs), ")"];
    let body = [];
    if (propsListIdx > -1) {
        body = [hardline, lBrace, indent([hardline, propsList]), hardline, rBrace];
    }
    else {
        if (options.collapseEmptyBraces) {
            body = [" ", lBrace, rBrace];
        }
        else {
            body = [hardline, lBrace, hardline, rBrace];
        }
    }
 
    return [...signature, ...body];
}
 
function printFieldGroupsList(path, options, print) {
    // Grammar: FIELDGROUPS LBRACE fieldGroupItem* RBRACE
    const rBraceIdx = path.node.children.findIndex(c => c.symbol?.type === ALParser.RBRACE);
    const keyword = path.call(print, 'children', 0);
    const lbrace = path.call(print, 'children', 1);
    const rbrace = path.call(print, 'children', rBraceIdx);
    const items = [];
 
    for (let i = 2; i < rBraceIdx; i++) {
        items.push(path.call(print, 'children', 2));
    }
 
    if (options.removeEmptyElements && items.length === 0)
        return [];
 
    const res = [];
    res.push(keyword, hardline, lbrace);
    if (items.length > 0) {
        res.push(indent([hardline, join(hardline, items)]));
    }
    res.push(hardline, rbrace);
 
    return res;
}
 
function printFieldGroupItem(path, options, print) {
    // Grammar: FIELDGROUP LPAREN fieldGroupDefinition RPAREN LBRACE RBRACE
    const fieldgroup = [
        path.call(print, 'children', 0),
        path.call(print, 'children', 1),
        path.call(print, 'children', 2),
        path.call(print, 'children', 3)
    ];
 
    fieldgroup.push(options.collapseEmptyBraces ? " " : hardline);
    fieldgroup.push(path.call(print, 'children', path.node.children.length - 2));
    
    if (!options.collapseEmptyBraces) {
        fieldgroup.push(hardline);
    }
 
    fieldgroup.push(path.call(print, 'children', path.node.children.length - 1));
    return fieldgroup;
}
 
function printFieldGroupDefinition(path, options, print) {
    // Grammar: identifier SEMICOLON fieldGroupFieldsList
    return [path.call(print, 'children', 0), "; ", path.call(print, 'children', 2)];
}
 
function printFieldGroupFieldsList(path, options, print) {
    // Grammar: identifier (COMMA identifier)*
    const fieldNames = [];
    for (let i = 0; i < path.node.children.length; i += 2) {
        fieldNames.push(path.call(print, 'children', i));
    }
 
    return join(", ", fieldNames);
}
 
//#endregion Table functions
 
//#region Table extension functions
 
function printTableExtObject(path, options, print) {
    // Grammar: TABLEEXTENSION INTEGER_LITERAL IDENTIFIER EXTENDS IDENTIFIER LBRACE tableExtPropertiesList? tableExtFieldsList? tableKeysSection? (variablesList | triggersList | proceduresList)* RBRACE;
    const children = path.node.children;
 
    const objectIdx = children.findIndex(c => c.symbol?.type === ALParser.TABLEEXTENSION);
    if (objectIdx === -1) return "";
 
    const objectId = path.call(print, 'children', objectIdx + 1);
    const objectName = path.call(print, 'children', objectIdx + 2);
    const extendedObjectName = path.call(print, 'children', objectIdx + 4);
 
    const elementStart = objectIdx + 6;
    const elementEnd = children.length - 1;
    const elementDocs = [];
    for (let i = elementStart; i < elementEnd; i++) {
        elementDocs.push(path.call(print, 'children', i));
    }
 
    const body = elementDocs.length > 0
        ? [indent([hardline, join([hardline, hardline], elementDocs)]), hardline]
        : [hardline];
 
    return ["tableextension ", objectId, " ", objectName, " extends ", extendedObjectName, hardline, "{", ...body, "}"];
}
 
function printTableExtFieldModification(path, node, print) {
    // Grammar: MODIFY LPAREN identifier RPAREN LBRACE tableFieldPropertiesList? triggersList? RBRACE;
    const children = path.node.children;
    const modifyKeyword = path.call(print, 'children', 0);
    const lparen = path.call(print, 'children', 1);
    const fieldName = path.call(print, 'children', 2);
    const rparen = path.call(print, 'children', 3);
    const lbrace = path.call(print, 'children', 4);
    const rbrace = path.call(print, 'children', children.length - 1);
 
    const elementDocs = [];
    for (let i = 5; i < children.length - 1; i++) {
        elementDocs.push(path.call(print, 'children', i));
    }
 
    const signature = [modifyKeyword, lparen, fieldName, rparen];
    let body = [];
    if (elementDocs.length > 0) {
        body = [hardline, lbrace, indent([hardline, join([hardline, hardline], elementDocs)]), hardline, rbrace];
    }
    else {
        if (options.collapseEmptyBraces) {
            body = [" ", lbrace, rbrace];
        }
        else {
            body = [hardline, lbrace, hardline, rbrace];
        }
    }
 
    return [...signature, ...body];
}
 
//#endregion Table extension functions
 
//#region Page functions
 
function printPageObject(path, options, print) {
    return printALObject(path, options, print, ALParser.PAGE);
}
 
function printLayoutDefinition(path, options, print) {
    // Grammar: LAYOUT LBRACE layoutElements RBRACE
    const elements = path.call(print, 'children', 2);
    if (options.removeEmptyElements && (!Array.isArray(elements) || elements.length === 0))
        return [];
 
    const pageLayout = [path.call(print, 'children', 0)];
    pageLayout.push(
        !options.collapseEmptyBraces || (Array.isArray(elements) && elements.length > 0) 
            ? hardline
            : " ");
    pageLayout.push(path.call(print, 'children', 1));
 
    if (Array.isArray(elements) && elements.length > 0) {
        pageLayout.push(indent([hardline, elements]));
    }
 
    if (!options.collapseEmptyBraces || (Array.isArray(elements) && elements.length > 0)) {
        pageLayout.push(hardline);
    }
 
    pageLayout.push(path.call(print, 'children', 3));
    return pageLayout;
}
 
function printLayoutElements(path, options, print) {
    // Grammar: (areaDefinition | groupDefinition | pageFieldItem | partDefinition | repeaterDefinition)*
    const children = path.node.children;
    if (!children || children.length === 0) return "";
    return join(hardline, path.map(print, 'children'));
}
 
function printAreaDefinition(path, options, print) {
    // Grammar: AREA LPAREN IDENTIFIER RPAREN LBRACE areaElements RBRACE
    const name = path.call(print, 'children', 2);
    const elements = path.call(print, 'children', 5);
    return ["area(", name, ")", hardline, "{", indent([hardline, elements]), hardline, "}"];
}
 
function printAreaElements(path, options, print) {
    // Grammar: (groupDefinition | pageFieldItem | partDefinition | repeaterDefinition)*
    const children = path.node.children;
    if (!children || children.length === 0) return "";
    return join(hardline, path.map(print, 'children'));
}
 
function printGroupDefinition(path, options, print) {
    // Grammar: GROUP LPAREN identifier RPAREN LBRACE groupElements RBRACE
    const name = path.call(print, 'children', 2);
    const elements = path.call(print, 'children', 5);
    return ["group(", name, ")", hardline, "{", indent([hardline, elements]), hardline, "}"];
}
 
function printGroupElements(path, options, print) {
    // Grammar: groupPropertiesList? (pageFieldItem | groupDefinition | partDefinition)*
    const children = path.node.children;
    if (!children || children.length === 0)
        return "";
 
    const docs = [];
    let layoutElementsStartIndex = 0;
 
    // Inserting an empty line after the properties block if there is one
    if (children[0].ruleIndex === ALParser.RULE_groupPropertiesList) {
        layoutElementsStartIndex = 1;
        docs.push([path.call(print, 'children', 0), hardline]);
    }
 
    for (let i = layoutElementsStartIndex; i < children.length; i++) {
        docs.push([path.call(print, 'children', i)]);
    }
 
    return join(hardline, docs);
}
 
function printGroupPropertyItem(path, options, print) {
    return [path.call(print, 'children', 0), ";"];
}
 
function printPartDefinition(path, options, print) {
    // Grammar: PART LPAREN IDENTIFIER SEMICOLON IDENTIFIER RPAREN LBRACE partPropertiesList RBRACE
    const partName = path.call(print, 'children', 2);
    const pageName = path.call(print, 'children', 4);
    const props = path.call(print, 'children', 7);
    const body = props
        ? [hardline, "{", indent([hardline, props]), hardline, "}"]
        : [hardline, "{", hardline, "}"];
    return ["part(", partName, "; ", pageName, ")", ...body];
}
 
function printPartPropertiesList(path, options, print) {
    // Grammar: partPropertyItem+
    return join(hardline, path.map(print, 'children'));
}
 
function printPartPropertyItem(path, options, print) {
    // Grammar: partProperty SEMICOLON
    return [path.call(print, 'children', 0), ";"];
}
 
function printRepeaterDefinition(path, options, print) {
    // Grammar: REPEATER LPAREN identifier RPAREN LBRACE repeaterElements RBRACE
    const repeaterKeyword = path.call(print, 'children', 0);
    const lparen = path.call(print, 'children', 1);
    const repeaterName = path.call(print, 'children', 2);
    const rparen = path.call(print, 'children', 3);
    const lbrace = path.call(print, 'children', 4);
    const elements = path.call(print, 'children', 5);
    const rbrace = path.call(print, 'children', 6);
 
    return [repeaterKeyword, lparen, repeaterName, rparen, hardline, lbrace, indent([hardline, elements]), hardline, rbrace];
}
 
function printRepeaterElements(path, options, print) {
    // Grammar: pageFieldPropertiesList? (pageFieldItem | groupDefinition)*
    const children = path.node.children;
    if (!children || children.length === 0)
        return "";
 
    let firstElementIdx = 0;
    const elements = [];
    if (children[0].ruleIndex === ALParser.RULE_pageFieldPropertiesList) {
        const properties = path.call(print, 'children', 0);
        if (children.length === 1)
            return properties;
 
        elements.push([properties, hardline]);
        firstElementIdx += 1;
    }
 
    for (let i = firstElementIdx; i < children.length; i++) {
        elements.push([path.call(print, 'children', i)]);
    }
 
    return join(hardline, elements);
}
 
function printPageFieldItem(path, options, print) {
    // Grammar: FIELD LPAREN identifier SEMICOLON expression RPAREN LBRACE pageFieldPropertiesList? triggersList? RBRACE;
    const children = path.node.children;
    const keyword = path.call(print, 'children', 0);
    const lparen = path.call(print, 'children', 1);
    const fieldName = path.call(print, 'children', 2);
    const semicolon = path.call(print, 'children', 3);
    const expression = path.call(print, 'children', 4);
    const rparen = path.call(print, 'children', 5);
    const lbrace = path.call(print, 'children', 6);
    const rbrace = path.call(print, 'children', children.length - 1);
 
    const elementDocs = [];
    for (let i = 7; i < children.length - 1; i++) {
        elementDocs.push(path.call(print, 'children', i));
    }
 
    const signature = [keyword, lparen, fieldName, semicolon, " ", expression, rparen];
    const nonEmpty = elementDocs.filter(Boolean);
    let body = [];
    if (nonEmpty.length > 0) {
        body = [hardline, lbrace, indent([hardline, join([hardline, hardline], nonEmpty)]), hardline, rbrace];
    }
    else {
        if (options.collapseEmptyBraces) {
            body = [" ", lbrace, rbrace];
        }
        else {
            body = [hardline, lbrace, hardline, rbrace];
        }
    }
 
    return [...signature, ...body];
}
 
function printPageLabelItem(path, options, print) {
    // Grammar: LABEL LPAREN identifier RPAREN LBRACE pageFieldPropertiesList? RBRACE;
    const children = path.node.children;
 
    const signature = [];
    for (let i = 0; i < 4; i++) {
        signature.push(path.call(print, 'children', i));
    }
 
    const lbrace = path.call(print, 'children', 4);
    const rbrace = path.call(print, 'children', children.length - 1);
    const properties = children[5].ruleIndex === ALParser.RULE_pageFieldPropertiesList ? path.call(print, 'children', 5) : [];
    let body = [];
    if (properties.length > 0) {
        body = [hardline, lbrace, indent([hardline, properties]), hardline, rbrace];
    }
    else {
        if (options.collapseEmptyBraces) {
            body = [" ", lbrace, rbrace];
        }
        else {
            body = [hardline, lbrace, hardline, rbrace];
        }
    }
 
    return [...signature, ...body];
}
 
function printPageFieldPropertiesList(path, options, print) {
    // Grammar: pageFieldPropertyDefinition+
    return join(hardline, path.map(print, 'children'));
}
 
function printPageFieldPropertyItem(path, options, print) {
    // Grammar: pageFieldProperty SEMICOLON
    return [path.call(print, 'children', 0), ";"];
}
 
function printSeparatorElement(path, options, print) {
    // Grammar: SEPARATOR LPAREN identifier RPAREN LBRACE pageFieldPropertiesList? RBRACE;
 
    const children = path.node.children;
    const properties = [];
    if (children[children.length - 2].ruleIndex === ALParser.RULE_pageFieldPropertiesList) {
        properties.push(...path.call(print, 'children', children.length - 2));
    }
 
    const lbrace = children[children.length - 2].ruleIndex === ALParser.RULE_pageFieldPropertiesList
        ? path.call(print, 'children', children.length - 3)
        : path.call(print, 'children', children.length - 2);
    
    const separatorDefinition = [];
    separatorDefinition.push(...path.call(print, 'children', 0));
    separatorDefinition.push(...path.call(print, 'children', 1));
    separatorDefinition.push(...path.call(print, 'children', 2));
    separatorDefinition.push(...path.call(print, 'children', 3));
 
    separatorDefinition.push(properties.length > 0 || !options.collapseEmptyBraces ? hardline : " ");
    separatorDefinition.push(...lbrace);
 
    if (properties.length > 0) {
        separatorDefinition.push(indent([hardline, properties]));
    }
 
    if (properties.length > 0 || !options.collapseEmptyBraces) {
        separatorDefinition.push(hardline);
    }
    separatorDefinition.push(...path.call(print, 'children', children.length - 1));
    return separatorDefinition
}
 
function printActionsDefinition(path, options, print) {
    // Grammar: ACTIONS LBRACE actionElements RBRACE
    const elements = path.call(print, 'children', 2);
    if (options.removeEmptyElements && (!Array.isArray(elements) || elements.length === 0))
        return [];
 
    const keyword = path.call(print, 'children', 0);
    const lbrace = path.call(print, 'children', 1);
    const rbrace = path.call(print, 'children', 3);
 
    const actionsDef = [keyword];
    actionsDef.push(((Array.isArray(elements) && elements.length > 0) || !options.collapseEmptyBraces) ? hardline : " ");
    actionsDef.push(lbrace);
 
    if (Array.isArray(elements) && elements.length > 0) {
        actionsDef.push(indent([hardline, elements]));
    }
 
    if ((Array.isArray(elements) && elements.length > 0) || !options.collapseEmptyBraces) {
        actionsDef.push(hardline);
    }
    actionsDef.push(rbrace);
 
    return actionsDef;
}
 
function printActionElements(path, options, print) {
    // Grammar: actionPropertiesList? (actionDefinition | actionRefsList | actionGroupDefinition | actionAreaDefinition)*;
    const children = path.node.children;
    if (!children || children.length === 0)
        return [];
 
    let actionStartIdx = 0;
    const elements = [];
    if (children[0].ruleIndex === ALParser.RULE_actionPropertiesList) {
        elements.push(path.call(print, 'children', 0));
        actionStartIdx = 1;
    }
 
    const actions = [];
    for (let i = actionStartIdx; i < children.length; i++) {
        actions.push(path.call(print, 'children', i));
    }
 
    if (actions.length > 0) {
        if (elements.length > 0)
            elements.push(hardline, hardline);
 
        elements.push(join(hardline, actions));
    }
 
    return elements;
}
 
function printActionDefinition(path, options, print) {
    // Grammar: ACTION LPAREN IDENTIFIER RPAREN LBRACE actionPropertiesList? triggersList? RBRACE
    const children = path.node.children;
    const name = path.call(print, 'children', 2);
 
    // actionPropertiesList? and triggersList? are collected between LBRACE (index 4) and RBRACE (last)
    const elementDocs = [];
    for (let i = 5; i < children.length - 1; i++) {
        elementDocs.push(path.call(print, 'children', i));
    }
 
    const lbraceIdx = path.node.children.findIndex(c => c.symbol?.type === ALParser.LBRACE);
    const lbrace = path.call(print, 'children', lbraceIdx);
    const rbrace = path.call(print, 'children', children.length - 1);
    const nonEmpty = elementDocs.filter(Boolean);
    let body = [];
    
    if (nonEmpty.length > 0) {
        body = [hardline, lbrace, indent([hardline, join([hardline, hardline], nonEmpty)]), hardline, rbrace]
    }
    else {
        if (options.collapseEmptyBraces) {
            body = [" ", lbrace, rbrace];
        }
        else {
            body = [hardline, lbrace, hardline, rbrace];
        }
    }
 
    return ["action(", name, ")", ...body];
}
 
function printActionPropertiesList(path, options, print) {
    // Grammar: actionPropertyItem+
    return join(hardline, path.map(print, 'children'));
}
 
function printActionPropertyItem(path, options, print) {
    // Grammar: actionProperty SEMICOLON
    return [path.call(print, 'children', 0), ";"];
}
 
function printActionAreaDefinition(path, options, print) {
    // Grammar: AREA LPAREN IDENTIFIER RPAREN LBRACE actionAreaElements RBRACE
    const name = path.call(print, 'children', 2);
    const elements = path.call(print, 'children', 5);
    return ["area(", name, ")", hardline, "{", indent([hardline, elements]), hardline, "}"];
}
 
function printActionAreaElements(path, options, print) {
    // Grammar: actionPropertiesList? (actionDefinition | actionGroupDefinition | actionRefsList)*;
    const children = path.node.children;
    if (!children || children.length === 0) return "";
    return join(hardline, path.map(print, 'children'));
}
 
function printActionGroupDefinition(path, options, print) {
    // Grammar: GROUP LPAREN IDENTIFIER RPAREN LBRACE actionElements RBRACE
    const name = path.call(print, 'children', 2);
    const elements = path.call(print, 'children', 5);
    return ["group(", name, ")", hardline, "{", indent([hardline, elements]), hardline, "}"];
}
 
function printActionRefsList(path, options, print) {
    // Grammar: actionRef+
    return join(hardline, path.map(print, 'children'));
}
 
function printActionRef(path, options, print) {
    // Grammar: ACTIONREF LPAREN identifier SEMICOLON identifier RPAREN LBRACE actionPropertiesList? RBRACE
    const actionRefKeyword = path.call(print, 'children', 0);
    const lparen = path.call(print, 'children', 1);
    const name = path.call(print, 'children', 2);
    const semicolon = path.call(print, 'children', 3);
    const actionName = path.call(print, 'children', 4);
    const rparen = path.call(print, 'children', 5);
    const lbrace = path.call(print, 'children', 6);
    const rbrace = path.call(print, 'children', path.node.children.length - 1);
 
    const actionPropsIdx = path.node.children.findIndex(c => c.ruleIndex === ALParser.RULE_actionPropertiesList);
    const properties = [];
    if (actionPropsIdx > -1) {
        properties.push(indent([hardline, path.call(print, 'children', actionPropsIdx)]));
    }
 
    const actionRef = [actionRefKeyword, lparen, name, semicolon, " ", actionName, rparen];
    actionRef.push(properties.length > 0 || !options.collapseEmptyBraces ? hardline : " ");
    actionRef.push(lbrace, properties);
 
    if (properties.length > 0 || !options.collapseEmptyBraces) {
        actionRef.push(hardline);
    }
    actionRef.push(rbrace);
    return actionRef;
}
 
function printTableRelationExpression(path, options, print) {
    return group(indent(join(line, path.map(print, 'children'))));
}
 
function printTableFieldReference(path, options, print) {
    return path.map(print, 'children');
}
 
function printTableRelationWhereExpression(path, options, print) {
    // Grammar: WHERE LPAREN tableRelationEqualityExpression (COMMA tableRelationEqualityExpression)* RPAREN
    const children = path.node.children;
    const filters = [];
    for (let i = 2; i < children.length; i += 2) {
        filters.push(path.call(print, 'children', i));
    }
 
    return ["where(", indent(join([",", line], filters)), ")"];
}
 
function printTableRelationFilterRef(path, options, print) {
    const rparenIdx = path.node.children.findIndex(c => c.symbol?.type === ALParser.RPAREN);
 
    const func = path.call(print, 'children', 0);
    const lParen = path.call(print, 'children', 1);
    const rParen = path.call(print, 'children', rparenIdx);
    const expression = [];
 
    for (let i = 2; i < rparenIdx; i++)
        expression.push(path.call(print, 'children', i));
 
    return [func, lParen, ...expression, rParen];
}
 
function printRelationFilterExpression(path, options, print) {
    return join(" ", path.map(print, 'children'));
}
 
function printCalcFormulaExpression(path, options, print) {
    // Grammar: (MINUS | PLUS)? identifier LPAREN tableFieldReference (tableRelationWhereExpression)? RPAREN;
    const children = path.node.children;
    const functionIdx = children[0].symbol?.type === ALParser.MINUS || children[0].symbol?.type === ALParser.PLUS ? 1 : 0;
    const whereExprIdx = children.findIndex(c => c.ruleIndex === ALParser.RULE_tableRelationWhereExpression);
    const rparenIdx = children.findIndex(c => c.symbol?.type === ALParser.RPAREN);
    const tableRefIdx = whereExprIdx > 0 ? whereExprIdx - 1 : rparenIdx - 1;
 
    const calcFormulaFunction = [];
    calcFormulaFunction.push(path.call(print, 'children', 0));
    if (functionIdx > 0) {
        calcFormulaFunction.push(path.call(print, 'children', 1));
    }
 
    let whereExpr = [];
    if (whereExprIdx > 0) {
        whereExpr = path.call(print, 'children', whereExprIdx);
    }
 
    const tableRef = path.call(print, 'children', tableRefIdx);
    return group([...calcFormulaFunction, "(", indent([...tableRef, line, ...whereExpr]), ")"]);
}
 
function printSubPageLinkProperty(path, options, print) {
    // Grammar: SUBPAGELINK EQUAL subpageLinkExpression
    const keyword = path.call(print, 'children', 0);
    const equalSign = path.call(print, 'children', 1);
    const expression = path.call(print, 'children', 2);
 
    return [keyword, " ", equalSign, group(indent([line, expression]))];
}
 
function printPageLinkExpression(path, options, print) {
    // Grammar: subpageLinkFilter (COMMA subpageLinkFilter)*;
    const children = path.node.children;
    const filters = [];
    for (let i = 0; i < children.length; i += 2) {
        const filter = [];
        filter.push(path.call(print, 'children', i));
 
        if (children.length > i + 1 && children[i + 1].symbol?.type === ALParser.COMMA) {
            filter.push([path.call(print, 'children', i + 1), line]);
        }
        filters.push(filter);
    }
 
    return filters;
}
 
function pintTableViewExpression(path, options, print) {
    // Grammar: sourceTableSortingExpr? sourceTableOrderExpr? tableRelationWhereExpression?;
    return group(indent(join(line, path.map(print, 'children'))));
}
 
function printSourceTableViewExpression(path, options, print) {
    return printObjectProperty(path, options, print);
}
 
//#endregion Page functions
 
//#region  Page extension functions
 
function printPageExtensionObject(path, options, print) {
    return printALObject(path, options, print, ALParser.PAGEEXTENSION);
}
 
function printPageExtLayoutDefinition(path, options, print) {
    // Grammar: LAYOUT LBRACE (pageExtLayoutModification | pageExtElementModification)* RBRACE
    const children = path.node.children;
    const lBraceIdx = children.findIndex(c => c.symbol?.type === ALParser.LBRACE);
    const rBraceIdx = children.findIndex(c => c.symbol?.type === ALParser.RBRACE);

    const layoutElements = [];
    for (let i = lBraceIdx + 1; i < rBraceIdx; i++) {
        layoutElements.push(path.call(print, "children", i));
    }

    const layout = [];
    layout.push(path.call(print, "children", 0), hardline, path.call(print, "children", lBraceIdx));

    if (layoutElements.length > 0) {
        layout.push(indent([hardline, join(hardline, layoutElements)]));
    }
    layout.push(hardline, path.call(print, "children", rBraceIdx));

    return layout;
}
 
function printPageExtLayoutModificationBlock(path, options, print) {
    // Grammar: pageExtLayoutMod LPAREN identifier RPAREN LBRACE layoutElements RBRACE
    const children = path.node.children;
    const lBraceIdx = children.findIndex(c => c.symbol?.type === ALParser.LBRACE);
 
    const anchor = [];
    for (let i = 0; i < lBraceIdx; i++) {
        anchor.push(path.call(print, 'children', i));
    }
 
    const layoutElements = path.call(print, 'children', lBraceIdx + 1);
    const lBrace = path.call(print, 'children', lBraceIdx);
    const rBrace = path.call(print, 'children', children.length - 1);
 
    return [anchor, hardline, lBrace, indent([hardline, layoutElements]), hardline, rBrace];
}
 
function printPageExtElementModificationBlock(path, options, print) {
    // Grammar: MODIFY LPAREN identifier RPAREN LBRACE (pageFieldPropertiesList | actionPropertiesList | triggersList)* RBRACE
    const children = path.node.children;
    const lBraceIdx = children.findIndex(c => c.symbol?.type === ALParser.LBRACE);

    const anchor = [];
    for (let i = 0; i < lBraceIdx; i++) {
        anchor.push(path.call(print, 'children', i));
    }

    const layoutElements = [];
    for (let i = lBraceIdx + 1; i < children.length - 1; i++) {
        layoutElements.push(path.call(print, 'children', i));
    }
    path.call(print, 'children', lBraceIdx + 1);
    const lBrace = path.call(print, 'children', lBraceIdx);
    const rBrace = path.call(print, 'children', children.length - 1);

    return [...anchor, hardline, lBrace, indent([hardline, join(hardline, layoutElements)]), hardline, rBrace];
}
 
function printPageExtensionActions(path, options, print) {
    // Grammar: ACTIONS LBRACE (pageExtActionModification | pageExtActionPropModification)* RBRACE
    const children = path.node.children;
    const lBraceIdx = children.findIndex(c => c.symbol?.type === ALParser.LBRACE);
    const rBraceIdx = children.findIndex(c => c.symbol?.type === ALParser.RBRACE);
    const mods = [];
 
    for (let i = lBraceIdx + 1; i < rBraceIdx; i++)
        mods.push(path.call(print, "children", i));
 
    const result = [];
    result.push(path.call(print, "children", 0), hardline, path.call(print, "children", lBraceIdx));
 
    if (mods.length > 0) {
        result.push(indent([hardline, join(hardline, mods)]));
    }
    result.push(hardline, path.call(print, "children", rBraceIdx));
 
    return result;
}
 
function printPageExtElementRelocation(path, options, print) {
    // Grammar: pageExtElementRelocationKeyword LPAREN identifier SEMICOLON identifiersList RPAREN;
    const keyword = path.call(print, 'children', 0);
    const lparen = path.call(print, 'children', 1);
    const identifier = path.call(print, 'children', 2);
    const semicolon = path.call(print, 'children', 3);
    const idList = path.call(print, 'children', 4);
    const rparen = path.call(print, 'children', 5);
    return [keyword, lparen, identifier, semicolon, " ", idList, rparen];
}
 
//#endregion Page extension functions
 
//#region Interface functions
 
function printInterfaceObject(path, options, print) {
    const children = path.node.children;
    // Grammar: INTERFACE identifier (EXTENDS identifierWithNamespace)? LBRACE interfacePropertiesList? procedureDeclaration* RBRACE
    const keyword = path.call(print, 'children', 0);
    const objectName = path.call(print, 'children', 1);
 
    let properties = [];
    const propsListIdx = children.findIndex(c => c.ruleIndex === ALParser.RULE_interfacePropertiesList);
    if (propsListIdx > -1) {
        properties = path.call(print, 'children', propsListIdx);
    }
 
    const procListStart = children.findIndex(c => c.ruleIndex === ALParser.RULE_procedureDeclaration);
    const procListEnd = children.length - 1;
    const procDeclDocs = [];
    if (procListStart > -1) {
        for (let i = procListStart; i < procListEnd; i++) {
            procDeclDocs.push(path.call(print, 'children', i));
        }
    }
 
    const declaration = [keyword, " ", objectName];
    const extendsIdx = children.findIndex(c => c.symbol?.type === ALParser.EXTENDS);
    if (extendsIdx > -1) {
        declaration.push([" ", path.call(print, 'children', extendsIdx)]);
        declaration.push([" ", path.call(print, 'children', extendsIdx + 1)]);
    }
 
    const body = [];
    if (properties.length > 0) {
        body.push(hardline, ...properties);
    }
    if (procDeclDocs.length > 0) {
        if (body.length > 0) {
            body.push(hardline);
        }
        body.push(hardline, join([hardline], procDeclDocs));
    }
 
    return [...declaration, hardline, "{", indent([...body]), hardline, "}"];
}
 
function printInterfacePropertiesList(path, options, print) {
    return join(hardline, path.map(print, 'children'));
}
 
function printProcedureDeclaration(path, options, print) {
    // Grammar: PROCEDURE identifier LPAREN parameterList? RPAREN procedureReturnType? SEMICOLON?
 
    const children = path.node.children;
    const rParenIdx = children.findIndex(c => c.symbol?.type === ALParser.RPAREN);
    const returnTypeIdx = children.findIndex(c => c.ruleIndex === ALParser.RULE_procedureReturnType);
 
    const name = path.call(print, 'children', 1);
    const paramDoc = rParenIdx > 3 ? path.call(print, 'children', 3) : "";
 
    let signature =
        [path.call(print, 'children', 0), " ", name, path.call(print, 'children', 2), softline, paramDoc, path.call(print, 'children', rParenIdx)];
 
    if (returnTypeIdx) {
        signature = [...signature, path.call(print, 'children', returnTypeIdx)];
    }
 
    const semicolon =
        children[children.length - 1].symbol?.type === ALParser.SEMICOLON
            ? path.call(print, 'children', children.length - 1)
            : ";";
    signature = group(indent([...signature, semicolon]));
 
    return signature;
}
 
function printInterfacePropertyItem(path, options, print) {
    // Grammar: interfaceProperty SEMICOLON
    return path.map(print, 'children');
}
 
//#endregion Interface functions
 
//#region Codeunit functions
 
function printCodeunitObject(path, options, print) {
    return printALObject(path, options, print, ALParser.CODEUNIT);
}
 
function printImplementsInterfacesList(path, options, print) {
    // Grammar: IMPLEMENTS identifierWithNamespace (COMMA identifierWithNamespace)*
    const children = path.node.children;
    const implementsKeyword = path.call(print, 'children', 0);
    const interfaces = [];
    for (let i = 1; i < children.length; i += 2) {
        interfaces.push(path.call(print, 'children', i));  // Name of the implemented interface
 
        if (i < children.length - 1) {
            interfaces.push([path.call(print, 'children', i + 1), " "]);  // Comma
        }
    }
 
    return [implementsKeyword, " ", interfaces];
}
 
//#endregion Codeunit functions
 
//#region Enum functions
 
function printEnumObject(path, options, print) {
    return printALObject(path, options, print, ALParser.ENUM);
}
 
function printEnumValuesList(path, options, print) {
    return join(hardline, path.map(print, 'children'));
}
 
function printEnumValueDefinition(path, options, print) {
    // Grammar: VALUE LPAREN INTEGER_LITERAL SEMICOLON identifier RPAREN LBRACE enumValuePropertiesList? RBRACE
    const children = path.node.children;
    const semicolonIdx = children.findIndex(c => c.symbol?.type === ALParser.SEMICOLON);
    const lBraceIdx = children.findIndex(c => c.symbol?.type === ALParser.LBRACE);
    const rBraceIdx = children.findIndex(c => c.symbol?.type === ALParser.RBRACE);
 
    const decl = [];
    for (let i = 0; i < semicolonIdx; i++) {
        decl.push(path.call(print, 'children', i));
    }
 
    decl.push(path.call(print, 'children', semicolonIdx));
    decl.push(" ");
 
    for (let i = semicolonIdx + 1; i < lBraceIdx; i++) {
        decl.push(path.call(print, 'children', i));
    }
 
    const props = [];
    if (rBraceIdx > lBraceIdx + 1) {
        props.push(path.call(print, 'children', lBraceIdx + 1));
    }
 
    const result = [];
    result.push(
        decl,
        hardline,
        path.call(print, 'children', lBraceIdx));
 
    if (props.length > 0) {
        result.push(indent([hardline, props]));
    }
 
    result.push(
        hardline,
        path.call(print, 'children', rBraceIdx)
    );
 
    return result;
}
 
function printImplementationProperty(path, options, print) {
    // Grammar: identifier EQUAL identifierWithNamespace EQUAL identifierWithNamespace (COMMA identifierWithNamespace EQUAL identifierWithNamespace)*;
    const children = path.node.children;
    const stmt = [];
    stmt.push(path.call(print, 'children', 0), " ", path.call(print, 'children', 1));
 
    const implementations = [];
    for (let impl = 2; impl <= children.length - 3; impl += 4) {
        implementations.push(
            line,
            path.call(print, 'children', impl),     // Interface name
            " ",
            path.call(print, 'children', impl + 1), // Equal sign
            " ",
            path.call(print, 'children', impl + 2)  // Implementation name
        );
 
        if (impl < children.length - 4) {
            implementations.push(path.call(print, 'children', impl + 3));  // Comma before the next implementation
        }
    }
 
    stmt.push(group(indent(implementations)));
    return stmt;
}
 
//#endregion Enum functions
 
//#region Enum extension functions
 
function printEnumExtensionObject(path, options, print) {
    return printALObject(path, options, print, ALParser.ENUMEXTENSION);
}
 
//#endregion Enum extension functions
 
//#region  Query functions
 
function printQueryObject(path, options, print) {
    return printALObject(path, options, print, ALParser.QUERY);
}
 
function printQueryDataItemElementsList(path, options, print) {
    return join(hardline, path.map(print, 'children'));
}
 
function printQueryElements(path, options, print) {
    // Grammar: ELEMENTS LBRACE queryDataItemDefinition* RBRACE;
    const keyword = path.call(print, 'children', 0);
    const lbrace = path.call(print, 'children', 1);
    const rbrace = path.call(print, 'children', path.node.children.length - 1);
 
    const dataItems = [];
    for (let i = 2; i < path.node.children.length - 1; i++) {
        dataItems.push(path.call(print, 'children', i));
    }
 
    return [keyword, hardline, lbrace, indent([hardline, join(hardline, dataItems)]), hardline, rbrace];
}
 
function printQueryDataItemDefinition(path, options, print) {
    // Grammar: DATAITEM LPAREN identifier SEMICOLON expression RPAREN LBRACE queryPropertiesList? queryDataItemElementsList? RBRACE;
    const children = path.node.children;
    const keyword = path.call(print, 'children', 0);
    const lparen = path.call(print, 'children', 1);
    const dataItemId = path.call(print, 'children', 2);
    const semicolon = path.call(print, 'children', 3);
    const refExpression = path.call(print, 'children', 4);
    const rparen = path.call(print, 'children', 5);
    const lbrace = path.call(print, 'children', 6);
    const rbrace = path.call(print, 'children', children.length - 1);
 
    const content = [];
    const propsIdx = children.findIndex(c => c.ruleIndex === ALParser.RULE_queryPropertiesList);
    if (propsIdx > -1)
        content.push(path.call(print, 'children', propsIdx));
 
    const elementsIdx = children.findIndex(c => c.ruleIndex === ALParser.RULE_queryDataItemElementsList);
    if (elementsIdx > -1) {
        if (content.length > 0)
            content.push(hardline, hardline);
        content.push(path.call(print, 'children', elementsIdx));
    }
 
    const dataItem = [keyword, lparen, dataItemId, semicolon, " ", refExpression, rparen, hardline, lbrace];
    if (content.length > 0)
        dataItem.push(indent([hardline, ...content]));
 
    dataItem.push(hardline, rbrace);
    return dataItem;
}
 
function printDataItemLinkProperty(path, options, print) {
    // Grammar: DATAITEMLINK EQUAL identifier EQUAL tableFieldReference (COMMA identifier EQUAL tableFieldReference)*;
 
    const propertyName = path.call(print, 'children', 0);
    const equalSign = path.call(print, 'children', 1);
 
    const colRefs = [];
    for (let i = 2; i <= path.node.children.length - 3; i += 4) {
        const colName = path.call(print, 'children', i);
        const refEqualSign = path.call(print, 'children', i + 1);
        const referencedColumn = path.call(print, 'children', i + 2);
        colRefs.push(colName, " ", refEqualSign, " ", referencedColumn);
 
        if (i < path.node.children.length - 3) {
            colRefs.push(path.call(print, 'children', i + 3), line);  // Comma
        }
    }
 
    return [propertyName, " ", equalSign, group(indent([line, ...colRefs]))];
}
 
function printQueryColumnDefinition(path, options, print) {
    // Grammar: COLUMN LPAREN identifier (SEMICOLON expression)? RPAREN LBRACE queryColumnPropertiesList? RBRACE;
    const children = path.node.children;
    const keyword = path.call(print, 'children', 0);
    const lparen = path.call(print, 'children', 1);
    const colId = path.call(print, 'children', 2);
 
    const semicolonIdx = children.findIndex(c => c.symbol?.type === ALParser.SEMICOLON);
    const refExpIdx = semicolonIdx > -1 ? semicolonIdx + 1 : -1;
    const rparenIdx = semicolonIdx > -1 ? 5 : 3;
    const lbraceIdx = rparenIdx + 1;
    const propsListIdx = children.findIndex(c => c.ruleIndex === ALParser.RULE_queryColumnPropertiesList);
    const rbraceIdx = children.length - 1;
 
    const semicolon = semicolonIdx > -1 ? path.call(print, 'children', semicolonIdx) : [];
    const refExpression = refExpIdx > -1 ? path.call(print, 'children', refExpIdx) : [];
    const rparen = path.call(print, 'children', rparenIdx);
    const lbrace = path.call(print, 'children', lbraceIdx);
    const rbrace = path.call(print, 'children', rbraceIdx);
    const properties =
        propsListIdx > -1
            ? path.call(print, 'children', propsListIdx)
            : [];
 
    const content = [keyword, lparen, colId];
    if (semicolonIdx > -1)
        content.push(semicolon, " ", refExpression);
 
    content.push(rparen)
    content.push(properties.length > 0 || !options.collapseEmptyBraces ? hardline : " ");
    content.push(lbrace);
    if (properties.length > 0)
        content.push(indent([hardline, ...properties]));
 
    if (properties.length > 0 || !options.collapseEmptyBraces) {
        content.push(hardline)
    }
    content.push(rbrace);
    return content;
}
 
function printOrderByProperty(path, options, print) {
    // Grammar: ORDERBY EQUAL IDENTIFIER LPAREN identifier RPAREN (COMMA IDENTIFIER LPAREN identifier RPAREN)*;
    const keyword = path.call(print, 'children', 0);
    const equalSign = path.call(print, 'children', 1);
    const expression = [];
 
    for (let i = 2; i < path.node.children.length; i += 5) {
        expression.push(path.call(print, 'children', i));  // Order direction: ascending / descending
        expression.push(path.call(print, 'children', i + 1));  // Left parenthesis
        expression.push(path.call(print, 'children', i + 2)); // Ordergin column name
        expression.push(path.call(print, 'children', i + 3));  // Right parenthesis
 
        if (i < path.node.children.length - 4) {
            expression.push([path.call(print, 'children', i + 4), " "]);  // Comma separating the next ordering clause
        }
    }
 
    return [keyword, " ", equalSign, " ", ...expression];
}
 
//#endregion Query functions
 
//#region Report functions
 
function printReportObject(path, options, print) {
    return printALObject(path, options, print, ALParser.REPORT);
}
 
function printReportDatasetDefinition(path, options, print) {
    // Grammar: DATASET LBRACE reportDataItemDefinition* RBRACE;
    const children = path.node.children;
    const keyword = path.call(print, 'children', 0);
    const lbrace = path.call(print, 'children', 1);
    const rbrace = path.call(print, 'children', children.length - 1);
 
    const dataItems = [];
    for (let i = 2; i < children.length - 1; i++) {
        dataItems.push(path.call(print, 'children', i));
    }
 
    const dataset = [keyword, hardline, lbrace];
    if (dataItems.length > 0)
        dataset.push(indent([hardline, ...dataItems]));
 
    dataset.push(hardline, rbrace);
    return dataset;
}
 
function printReportDataItemDefinition(path, options, print) {
    // Grammar: DATAITEM LPAREN identifier SEMICOLON expression RPAREN LBRACE reportDataItemPropertiesList? reportDataItemElementsList? triggersList? RBRACE;
    const children = path.node.children;
    const keyword = path.call(print, 'children', 0);
    const lparen = path.call(print, 'children', 1);
    const dataItemName = path.call(print, 'children', 2);
    const semicolon = path.call(print, 'children', 3);
    const sourceExpression = path.call(print, 'children', 4);
    const rparen = path.call(print, 'children', 5);
    const lbrace = path.call(print, 'children', 6);
    const rbrace = path.call(print, 'children', children.length - 1);
 
    const elements = [];
    for (let i = 7; i < children.length - 1; i++) {  // All elements between lbrace and rbrace
        elements.push(path.call(print, 'children', i));
    }
 
    const dataItem = [keyword, lparen, dataItemName, semicolon, " ", sourceExpression, rparen, hardline, lbrace];
    if (elements.length > 0) {
        dataItem.push(indent([hardline, join([hardline, hardline], elements)]));
    }
 
    dataItem.push(hardline, rbrace);
    return dataItem;
}
 
function printReportDataItemElementsList(path, options, print) {
    return join(hardline, path.map(print, 'children'));
}
 
function printReportRequestPage(path, options, print) {
    // Grammar: REQUESTPAGE LBRACE pagePropertiesList? layoutDefinition? (triggersList | variablesList | proceduresList | actionsDefinition)* RBRACE;
 
    const children = path.node.children;
 
    const elements = [];
    for (let i = 2; i < children.length - 1; i++) {
        const el = path.call(print, 'children', i);
        if (Array.isArray(el) && el.length > 0)
            elements.push(el);
    }
    if (options.removeEmptyElements && elements.length === 0)
        return [];
 
    const keyword = path.call(print, 'children', 0);
    const lbrace = path.call(print, 'children', 1);
    const rbrace = path.call(print, 'children', children.length - 1);
 
    const pageDocs = [keyword, hardline, lbrace];
    if (elements.length > 0) {
        pageDocs.push(indent([hardline, join([hardline, hardline], elements)]));
    }
 
    pageDocs.push(hardline, rbrace);
    return pageDocs;
}
 
function printRenderingOptions(path, options, print) {
    // Grammar: RENDERING LBRACE renderingLayout* RBRACE
    const children = path.node.children;
    const keyword = path.call(print, 'children', 0);
    const lbrace = path.call(print, 'children', 1);
    const rbrace = path.call(print, 'children', children.length - 1);
 
    const layouts = [];
    for (let i = 2; i < children.length - 1; i++) {
        layouts.push(path.call(print, 'children', i));
    }
 
    const renderingDocs = [keyword, hardline, lbrace];
    if (layouts.length > 0) {
        renderingDocs.push(indent([hardline, join(hardline, layouts)]));
    }
 
    renderingDocs.push(hardline, rbrace);
    return renderingDocs;
}
 
function printRenderingLayout(path, options, print) {
    // Grammar: LAYOUT LPAREN identifier RPAREN LBRACE reportDataItemPropertiesList RBRACE
    const keyword = path.call(print, 'children', 0);
    const lparen = path.call(print, 'children', 1);
    const layoutName = path.call(print, 'children', 2);
    const rparen = path.call(print, 'children', 3);
    const lbrace = path.call(print, 'children', 4);
    const props = path.call(print, 'children', 5);
    const rbrace = path.call(print, 'children', 6);
 
    const body = props
        ? [hardline, lbrace, indent([hardline, props]), hardline, rbrace]
        : [hardline, lbrace, hardline, rbrace];
 
    return [keyword, lparen, layoutName, rparen, ...body];
}
 
function printLabelsDefinition(path, options, print) {
    // Grammar: LABELS LBRACE labelDefinition* RBRACE
    const children = path.node.children;
    const keyword = path.call(print, 'children', 0);
    const lbrace = path.call(print, 'children', 1);
    const rbrace = path.call(print, 'children', children.length - 1);
 
    const labels = [];
    for (let i = 2; i < children.length - 1; i++) {
        labels.push(path.call(print, 'children', i));
    }
 
    if (options.removeEmptyElements && labels.length === 0) {
        return [];
    }
 
    const labelsDocs = [keyword];
    labelsDocs.push(labels.length > 0 || !options.collapseEmptyBraces ? hardline : " ");
    labelsDocs.push(lbrace);
    if (labels.length > 0) {
        labelsDocs.push(indent([hardline, join(hardline, labels)]));
    }
 
    if (labels.length > 0 || !options.collapseEmptyBraces) {
        labelsDocs.push(hardline);
    }
 
    labelsDocs.push(rbrace);
    return labelsDocs;
}
 
function printLabelDefinition(path, options, print) {
    // Grammar: identifier EQUAL STRING_LITERAL (COMMA identifier EQUAL literal)* SEMICOLON
    const children = path.node.children;
    const labelName = path.call(print, 'children', 0);
    const equal = path.call(print, 'children', 1);
    const labelValue = path.call(print, 'children', 2);
 
    const parts = [labelName, " ", equal, " ", labelValue];
 
    // Add additional identifier = value pairs if present
    for (let i = 3; i < children.length - 1; i += 4) {
        if (children[i].symbol?.type === ALParser.COMMA) {
            parts.push(path.call(print, 'children', i)); // comma
            parts.push(line);
            parts.push(path.call(print, 'children', i + 1)); // identifier
            parts.push(" ");
            parts.push(path.call(print, 'children', i + 2)); // equal
            parts.push(" ");
            parts.push(path.call(print, 'children', i + 3)); // value
        }
    }
 
    parts.push(path.call(print, 'children', children.length - 1)); // semicolon
    return group(indent(parts));
}
 
function printDataItemTableViewProperty(path, options, print) {
    return printObjectProperty(path, options, print);
}
 
//#endregion Report functions
 
//#region Code statements
 
function printNamespaceDeclaration(path, options, print) {
    // Grammar: NAMESPACE namespaceName SEMICOLON;
    return [path.call(print, 'children', 0), " ", ...path.call(print, 'children', 1), path.call(print, 'children', 2)];
}
 
function printUsingRefList(path, options, print) {
    return join(hardline, path.map(print, 'children'));
}
 
function printUsingReference(path, options, print) {
    // Grammar: USING namespaceName SEMICOLON;
    return [path.call(print, 'children', 0), " ", ...path.call(print, 'children', 1), path.call(print, 'children', 2)];
}
 
function printVariableDeclaration(path, options, print) {
    // Grammar: variableAttributesList? identifier (COMMA identifier)* COLON dataType SEMICOLON
    const children = path.node.children;
    const colonIdx = children.findIndex(c => c.symbol?.type === ALParser.COLON);
    const attrListIdx = children.findIndex(c => c.ruleIndex === ALParser.RULE_variableAttributesList);
    const attributes = attrListIdx > -1 ? [path.call(print, 'children', attrListIdx), hardline] : [];
 
    const varNames = [];
    for (let varIdx = attrListIdx + 1; varIdx < colonIdx; varIdx += 2)
        varNames.push(path.call(print, 'children', varIdx));
 
    const type = path.call(print, 'children', colonIdx + 1);
    return [
        ...attributes,
        join(", ", varNames),
        path.call(print, 'children', colonIdx),
        " ",
        type,
        path.call(print, 'children', children.length - 1)
    ];
}
 
function printVariablesList(path, options, print) {
    // Grammar: PROTECTED? VAR variableDeclaration+;
    const children = path.node.children;
    const varIdx = children.findIndex(c => c.symbol?.type === ALParser.VAR);
 
    const keywords = [];
    for (let i = 0; i <= varIdx; i++) {
        keywords.push(path.call(print, 'children', i));
    }
 
    const varDocs = [];
    for (let i = varIdx + 1; i < children.length; i++) {
        varDocs.push(path.call(print, 'children', i));
    }
 
    return varDocs.length > 0
        ? [join(" ", keywords), indent([hardline, join(hardline, varDocs)])]
        : [];
}
 
function printTriggersList(path, options, print) {
    // Grammar: triggerDefinition+
    return join([hardline, hardline], path.map(print, 'children'));
}
 
function printTriggerDefinition(path, options, print) {
    // Grammar: TRIGGER IDENTIFIER LPAREN parameterList? RPAREN procedureReturnType? variablesList? BEGIN statementList? END SEMICOLON
    const children = path.node.children;
    const paramsListIdx = children.findIndex(c => c.ruleIndex === ALParser.RULE_parameterList);
    const beginIdx = children.findIndex(c => c.symbol?.type === ALParser.BEGIN);
    const endIdx = children.findIndex(c => c.symbol?.type === ALParser.END);
    const returnTypeIdx = children.findIndex(c => c.ruleIndex === ALParser.RULE_procedureReturnType);
    const varsIdx = children.findIndex(c => c.ruleIndex === ALParser.RULE_variablesList);
    const statementListId = endIdx > beginIdx + 1 ? beginIdx + 1 : -1;
 
    const triggerKeyword = path.call(print, 'children', 0);
    const name = path.call(print, 'children', 1);
    const lParen = path.call(print, 'children', 2);
    const rParen = path.call(print, 'children', paramsListIdx > -1 ? paramsListIdx + 1 : 3);
    const beginKeyword = path.call(print, 'children', beginIdx);
    const endKeyword = path.call(print, 'children', endIdx);
    const semicolon = path.call(print, 'children', children.length - 1);
 
    const paramDoc = paramsListIdx > -1 ? path.call(print, 'children', paramsListIdx) : "";
    const returnType = returnTypeIdx > -1 ? path.call(print, 'children', returnTypeIdx) : [];
 
    // variablesList: any rule context between RPAREN and BEGIN
    const varDocs = path.call(print, 'children', varsIdx);
 
    const signature = [triggerKeyword, " ", name, lParen, paramDoc, rParen];
    if (returnType.length > 0) {
        signature.push(...returnType);
    }
 
    const vars = varDocs.length > 0 ? [hardline, ...varDocs] : [];
    const body = statementListId > 0
        ? [hardline, beginKeyword, indent([hardline, path.call(print, 'children', statementListId)]), hardline, endKeyword, semicolon]
        : [hardline, beginKeyword, hardline, endKeyword, semicolon];
 
    return [...signature, ...vars, ...body];
}
 
function printProceduresList(path, options, print) {
    // Grammar: procedureDefinition+
    const children = path.node.children;
    const procedures = [];
    for (let i = 0; i < children.length; i++) {
        removeBlankLineBeforeLeadingComment(children[i]);
        removeBlankLineAroundTrailingComment(children[i]);
        procedures.push(path.call(print, 'children', i));
    }
 
    // To avoid inserting redundant line breaks after the trailing comment attached to the procedures list node
    removeBlankLineAroundTrailingComment(path.node);
 
    return join([hardline, hardline], procedures);
}
 
function printProcedureDefinition(path, options, print) {
    // Grammar: procedureAttributesList? (LOCAL | INTERNAL)? PROCEDURE IDENTIFIER LPAREN parameterList? RPAREN procedureReturnType? variablesList? BEGIN statementList? END SEMICOLON
    const children = path.node.children;
 
    const accessModifierIdx = children.findIndex(c => c.ruleIndex === ALParser.RULE_procedureAccessModifier);
    const procKeywordIdx = children.findIndex(c => c.symbol?.type === ALParser.PROCEDURE);
    const varListIdx = children.findIndex(c => c.ruleIndex === ALParser.RULE_variablesList);
    const lParenIdx = children.findIndex(c => c.symbol?.type === ALParser.LPAREN);
    const rParenIdx = children.findIndex(c => c.symbol?.type === ALParser.RPAREN);
    const returnTypeIdx = children.findIndex(c => c.ruleIndex === ALParser.RULE_procedureReturnType);
    const beginIdx = children.findIndex(c => c.symbol?.type === ALParser.BEGIN);
    const endIdx = children.findIndex(c => c.symbol?.type === ALParser.END);
    const statementListId = endIdx > beginIdx + 1 ? beginIdx + 1 : -1;
 
    const proc = path.call(print, 'children', procKeywordIdx);
    const begin = path.call(print, 'children', beginIdx);
    const end = path.call(print, 'children', endIdx);
 
    let attributes = [];
    if (children[0].ruleIndex === ALParser.RULE_procedureAttributesList) {
        attributes = [...path.call(print, "children", 0), hardline];
    }
 
    const name = path.call(print, 'children', procKeywordIdx + 1);
 
    // parameterList is at index procKeywordIdx + 3 only when RPAREN is not immediately after LPAREN (index procKeywordIdx + 2)
    const paramDoc = rParenIdx > procKeywordIdx + 3 ? path.call(print, 'children', procKeywordIdx + 3) : "";
 
    // variablesList: any rule context between RPAREN and BEGIN
    const varDocs = varListIdx > 0 ? path.call(print, 'children', varListIdx) : [];
 
    let signature = [proc, " ", name, path.call(print, 'children', lParenIdx), group(indent([softline, paramDoc])), path.call(print, 'children', rParenIdx)];
 
    // If the procedure return type is not defined, returnTypeIdx = -1
    let returnType = [];
    if (returnTypeIdx > 0) {
        returnType = path.call(print, 'children', returnTypeIdx);
    }
 
    let accessModifier = [];
    if (accessModifierIdx >= 0) {
        accessModifier = [path.call(print, 'children', accessModifierIdx), " "];
    }
 
    const vars = varDocs.length > 0 ? [hardline, varDocs] : [];
    const semicolon = children[children.length - 1].symbol?.type === ALParser.SEMICOLON
        ? path.call(print, 'children', children.length - 1)
        : ";";  // Adding the trailing semicolon after the "end" if it is missing.
                // TODO: This may break comment allocation if a comment is placed after the keyword. Need to reattach the comment in this case.
 
    const body = statementListId > 0
        ? [hardline, begin, indent([hardline, path.call(print, 'children', statementListId)]), hardline, end, semicolon]
        : [hardline, begin, hardline, end, semicolon];
 
    return [...attributes, ...accessModifier, ...signature, ...returnType, ...vars, ...body];
}
 
function printProcedureAttributes(path, options, print) {
    return join(hardline, path.map(print, 'children'));
}
 
function printProcedureAttribute(path, options, print) {
    // Grammar: LBRACKET expression RBRACKET
    return path.map(() => print(path, { suppressLineBreaks: options.noLineBreaksInAttributes || false }), 'children');
}
 
function printParameterList(path, options, print) {
    // Grammar: parameter (SEMICOLON parameter)* — SEMICOLON tokens at indices 1, 3, 5, ... are skipped
    const children = path.node.children;
    const paramDocs = [];
    for (let i = 0; i < children.length; i += 2) {
        paramDocs.push(path.call(print, 'children', i));
    }
    return join([";", line], paramDocs);
}
 
function printProcReturnType(path, options, print) {
    // Grammar: identifier? COLON dataType;
    const elements = [];
    let nextElNo = 0;
 
    if (path.node.children[0].symbol?.type !== ALParser.COLON) {
        elements.push(" ", path.call(print, 'children', 0));
        nextElNo += 1;
    }
 
    elements.push(path.call(print, 'children', nextElNo), " ");  // Colon
    elements.push(path.call(print, 'children', nextElNo + 1));
 
    return elements;
}
 
function printStatementList(path, options, print) {
    const children = path.node.children;
    const stmtDocs = [];
    const paragraphs = [];
 
    for (let i = 0; i < children.length; i++) {
        paragraphs.push(isParagraphStatement(children[i]));
    }
 
    for (let i = 0; i < children.length; i++) {
        let doc = path.call(print, 'children', i);
        if (i === children.length - 1 && children[i].ruleIndex === ALParser.RULE_statement) {
            // The last statement in the list can end without the terminating semicolon. Printer will add it.
            // To determine whether the semicolon is present or not, we check the parser rule for the node.
            // Elements of the statement list can be either "statment" or "statementWithSeparator".
            doc = [doc, ";"];
        }
 
        if (i > 0) {
            stmtDocs.push(hardline);
 
            if (
                paragraphs[i - 1] ||
                paragraphs[i] ||
                children[i].start.line > children[i - 1].stop.line + 1 ||
                shouldAddBlankLineAfter(children[i - 1])
            ) {
                stmtDocs.push(hardline);
            }
        }
        
        stmtDocs.push(doc);
    }
 
    return stmtDocs.length > 0
        ? stmtDocs
        : "";
}
 
function printStatementWithSeparator(path, options, print) {
    return path.map(print, 'children');
}
 
function printStatement(path, options, print) {
    // Statement can be prefixed with an error assertion "asserterror"
    const statement = [];
    let stmtStartIdx = 0;
    if (path.node.children[0].symbol?.type == ALParser.ASSERTERROR) {
        statement.push(path.call(print, 'children', 0));
        statement.push(" ");
        stmtStartIdx++;
    }
 
    for (let i = stmtStartIdx; i < path.node.children.length; i++) {
        statement.push(path.call(print, 'children', i));
    }
 
    return statement;
}
 
function printParameter(path, options, print) {
    // Grammar: VAR? IDENTIFIER COLON dataType
    const children = path.node.children;
    const hasVar = children[0]?.symbol?.type === ALParser.VAR;
    if (hasVar) {
        const name = path.call(print, 'children', 1);
        const type = path.call(print, 'children', 3);
        return ["var ", name, ": ", type];
    }
    const name = path.call(print, 'children', 0);
    const type = path.call(print, 'children', 2);
    return [name, ": ", type];
}
 
function printIfStatement(path, options, print) {
    // Grammar: IF expression THEN statement elseStatement?
    const children = path.node.children;
    const ifKeyword = path.call(print, 'children', 0);
    const condition = path.call(print, 'children', 1);  // expression
    const thenKeyword = path.call(print, 'children', 2);
    let thenStmt = path.call(print, 'children', 3);   // statement
 
    // Statement following "then". If it's a compound statement "begin..end", do not insert a hardline before the statement.
    if (children[3]?.children[0]?.ruleIndex === ALParser.RULE_compoundBlock) {
        thenStmt = [" ", thenStmt];
    }
    else if (thenStmt.length > 0) {
        // If the statement body is missing ("if condition then;"), do not insert the line break: the terminating semicolon sticks to the "then" keyword.
        thenStmt = indent([hardline, thenStmt]);
    }
 
    const result = [group([ifKeyword, " ", condition, line, thenKeyword]), thenStmt];
 
    // ELSE and its statement are optional — present when children.length > 4
    if (children.length > 4) {
        let elseStmt = path.call(print, 'children', 4);
 
        result.push(
            children[3]?.children[0]?.ruleIndex === ALParser.RULE_compoundBlock
                ? " "
                : hardline
        );
        result.push(elseStmt);
    }
 
    return result;
}
 
function printElseStatement(path, options, print) {
    // Grammar: ELSE statementList;
    // Similar to "then begin" in the if statement above, "else begin" must not break the line.
    const elseKeyword = path.call(print, 'children', 0);
    let elseStmt = path.call(print, 'children', 1);
    if (isCompoundStatement(path.node.children[1]?.children[0])) {
        elseStmt = [" ", elseStmt];
    }
    else {
        elseStmt = indent([hardline, elseStmt]);
    }
 
    return [elseKeyword, elseStmt];
}
 
function printForLoopStatement(path, options, print) {
    // Grammar: FOR identifier ASSIGN expression TO expression DO statement
    //        | FOR identifier ASSIGN expression DOWNTO expression DO statement;
 
    const children = path.node.children;
    const iterator = path.call(print, 'children', 1);
    const initialization = path.call(print, 'children', 3);
    const increment = path.call(print, 'children', 4);  // "to" or "downto" keyword
    const condition = path.call(print, 'children', 5);
    let statement = (children.length > 7) ? path.call(print, 'children', 7) : [];
 
    // Statement executed inside the loop. If it's a compond statement "begin..end", do not insert a hardline before the statement.
    if (children.length > 7) {
        if (children[7].children && children[7].children[0].ruleIndex === ALParser.RULE_compoundBlock) {
            statement = [" ", statement];
        }
        else {
            statement = indent([hardline, statement]);
        }
    }
 
    return ["for ", iterator, " := ", initialization, ` ${increment} `, condition, " do", statement];
}
 
function printForEachStatement(path, options, print) {
    // Grammar: FOREACH identifier IN expression DO statement
 
    const children = path.node.children;
    const iterator = path.call(print, 'children', 1);
    const condition = path.call(print, 'children', 3);
    let statement = (children.length > 5) ? path.call(print, 'children', 5) : [];
 
    // Statement executed inside the loop. If it's a compond statement "begin..end", do not insert a hardline before the statement.
    if (children.length > 5) {
        if (children[5].children[0].ruleIndex === ALParser.RULE_compoundBlock) {
            statement = [" ", statement];
        }
        else {
            statement = indent([hardline, statement]);
        }
    }
 
    return ["foreach ", iterator, " in ", condition, " do", statement];
}
 
function printRepeatStatement(path, options, print) {
    // Grammar: REPEAT statementList UNTIL expression;
 
    const statementList = path.call(print, 'children', 1);
    const condition = path.call(print, 'children', 3);
 
    return ["repeat", indent([hardline, statementList]), [hardline, "until ", condition]];
}
 
function printWhileLoopStatement(path, options, print) {
    // Grammar: WHILE expression DO statement?
 
    const children = path.node.children;
    const condition = path.call(print, 'children', 1);
    let statement = children.length > 3 ? path.call(print, 'children', 3) : [];
 
    // Statement executed inside the loop. If it's a compond statement "begin..end", do not insert a hardline before the statement.
    if (children.length > 3) {
        if (children[3].children[0].ruleIndex === ALParser.RULE_compoundBlock) {
            statement = [" ", statement];
        }
        else {
            statement = indent([hardline, statement]);
        }
    }
 
    return ["while ", condition, " do", statement];
}
 
function printCaseStatement(path, options, print) {
    // Grammar: CASE expression OF caseBranch+ (elseStatement SEMICOLON?)? END
    const children = path.node.children;
    const caseKeyword = path.call(print, 'children', 0);
    const ofKeyword = path.call(print, 'children', 2);
    const endKeyword = path.call(print, 'children', path.node.children.length - 1);
 
    const elseIdx = path.node.children.findIndex(c => c.ruleIndex === ALParser.RULE_caseElseStatement);
    let elseBranch = elseIdx > -1 ? path.call(print, 'children', elseIdx) : [];
 
    const switchExpr = path.call(print, 'children', 1);
    const branches = [];
 
    const lastBranchIdx = elseIdx > -1 ? elseIdx - 1 : children.length - 2;
    for (let i = 3; i <= lastBranchIdx; i++) {
        branches.push(path.call(print, 'children', i));
    }
    if (elseIdx > -1) {
        branches.push(elseBranch);
    }
 
    return [caseKeyword, " ", switchExpr, " ", ofKeyword, indent([hardline, join(hardline, branches)]), hardline, endKeyword];
}
 
function printCaseBranch(path, options, print) {
    // Grammar: expression ((COMMA | RANGE_OP) expression)* COLON (statement | statementWithSeparator | SEMICOLON);
 
    const colonIdx = path.node.children.findIndex(c => c.symbol?.type === ALParser.COLON);
 
    const conditions = [];
    let i = 0;
    while (i < colonIdx) {
        // for (let i = 0; i < colonIdx; i += 2) {
        let condition = path.call(print, 'children', i);
        if (i < colonIdx - 1) {
            condition = [condition, path.call(print, 'children', i + 1)];  // Print the comma or range operator separating the conditions
        }
 
        if (path.node.children[i + 1].symbol.type === ALParser.RANGE_OP) {
            i += 2;
            condition.push(path.call(print, 'children', i));
            if (i < colonIdx - 1) {
                condition = [condition, path.call(print, 'children', i + 1)];
            }
        }
        i += 2;
 
        conditions.push(condition);
    }
 
    const colon = path.call(print, 'children', colonIdx);
    const statement = path.call(print, 'children', colonIdx + 1);
    if (path.node.children[colonIdx + 1].ruleIndex === ALParser.RULE_statement) {  // If the statement in a case branch ends with semicolon, its type must be statementWithSeparator
        statement.push(";");
    }
 
    return [join(hardline, conditions), colon, indent([hardline, statement])];
}
 
function printProcedureCall(path, options, print, args) {
    // Grammar: identifier (DOT identifier)* LPAREN argumentList? RPAREN
    const children = path.node.children;
    const lParenIdx = children.findIndex(c => c.symbol?.type === ALParser.LPAREN);
    const rParenIdx = children.findIndex(c => c.symbol?.type === ALParser.RPAREN);
 
    // Name chain before LPAREN: joined without spaces to produce e.g. "Foo.Bar.Baz"
    const nameDocs = [];
    for (let i = 0; i < lParenIdx; i++) {
        nameDocs.push(path.call(print, 'children', i));
    }
 
    // argumentList is present when there is a child between LPAREN and RPAREN
    const argDoc = rParenIdx > lParenIdx + 1 ? path.call(() => print(path, args), 'children', lParenIdx + 1) : "";
 
    const result = [...nameDocs, path.call(print, 'children', lParenIdx)];
    if (argDoc.length > 0 && !args?.suppressLineBreaks)
        result.push(softline);
 
    result.push(argDoc, path.call(print, 'children', rParenIdx));
    return group(indent(result));
}
 
function printArgumentList(path, options, print, args) {
    // Grammar: expression (COMMA expression)*
    const children = path.node.children;
    const argDocs = [];
    for (let i = 0; i < children.length; i += 2) {
        const argument = path.call(print, 'children', i);
        const comma = i < children.length - 2 ? [path.call(print, 'children', i + 1), args?.suppressLineBreaks ? " " : line] : [];
        argDocs.push([...argument, ...comma]);
    }
 
    return argDocs;
}
 
function printUnaryExpression(path, options, print, args) {
    return path.map(() => print(path, args), 'children');
}
 
function printUnaryNotExpression(path, options, print) {
    return join(" ", path.map(print, 'children'));
}
 
function printBinaryExpression(path, options, print, args) {
    // All binary expressions follow the structure: "operand operator operand".
    // If the line does not fit in the print width, the second operand will be moved to the next line with indent.
    const printWithArguments = () => print(path, args);
 
    return path.node?.children?.length > 1
        ? group(indent([path.call(printWithArguments, 'children', 0), " ", path.call(printWithArguments, 'children', 1), line, path.call(printWithArguments, 'children', 2)]))
        : join(" ", path.map(printWithArguments, 'children'));
}
 
function printMultipartExpression(path, options, print, args) {
    // Grammar: unaryExpression ((MULTIPLY | DIVIDE | DIV | MOD) unaryExpression)*;
    const children = path.node.children;
 
    const parts = [];
    for (let i = 0; i < children.length; i += 2) {
        const operand = path.call(() => print(path, args), 'children', i);
        parts.length === 0 ? parts.push(operand) : parts.push([line, operand]);
        if (i + 1 < children.length) {
            parts.push([" ", path.call(() => print(path, args), 'children', i + 1)]);
        }
    }
 
    return children.length > 1 ? group(indent(parts)) : parts;
}
 
function printLogicalInExpression(path, options, print) {
    // Grammar: logicalAndExpression IN LBRACKET logicalAndExpression ((COMMA|RANGE_OP) logicalAndExpression)* RBRACKET;
    const children = path.node.children;
    const components = [];
    components.push(path.call(print, 'children', 0));  // Left expression
    components.push([" ", path.call(print, 'children', 1), " "]);  // "in" keyword
    components.push(path.call(print, 'children', 2));  // Left bracket
    components.push(path.call(print, 'children', 3));  // First condition - always present
 
    for (let i = 4; i < children.length - 1; i += 2) {
        components.push(path.call(print, 'children', i));  // Operator - comma or range
        if (children[i].symbol.type === ALParser.COMMA) {
            components.push(" ");
        }
        components.push(path.call(print, 'children', i + 1));  // Condition following the operator
    }
 
    components.push(path.call(print, 'children', children.length - 1));  // Right bracket
    return components;
}
 
function printCompoundBlock(path, options, print) {
    // Grammar: BEGIN statementList? END
    const statementListIdx = path.node.children.findIndex(c => c.ruleIndex === ALParser.RULE_statementList);
    const endIdx = path.node.children.findIndex(c => c.symbol?.type === ALParser.END);
 
    const beginKeyword = path.call(print, 'children', 0);
    const statementList = statementListIdx > -1
        ? path.call(print, 'children', 1)
        : [];
    const endKeyword = path.call(print, 'children', endIdx);
 
    const compoundBlock = [];
    compoundBlock.push(beginKeyword);
    if (statementListIdx > -1) {
        compoundBlock.push(indent([hardline, statementList]));
    }
    compoundBlock.push([hardline, endKeyword]);
    return compoundBlock;
}
 
function printExitStatement(path, options, print, args) {
    // Grammar: EXIT (LPAREN expression RPAREN)?;
    const children = path.node.children;
    const stmt = [];
    const expressionIdx = children.findIndex(c => c.ruleIndex === ALParser.RULE_expression);
 
    stmt.push(path.call(print, 'children', 0));
 
    if (children.length > 1) {
        stmt.push(path.call(print, 'children', 1));
 
        if (expressionIdx > -1) {
            stmt.push(group(indent([softline, path.call(print, 'children', expressionIdx)])));
        }
        stmt.push(path.call(print, 'children', children.length - 1));
    }
 
    return stmt;
}
 
function printALObject(path, options, print, objectType) {
    const children = path.node.children;
    // Grammar is similar for most objects.
    // For example, table grammar: TABLE INTEGER_LITERAL identifier LBRACE
    //              tablePropertyList? variablesList? tableFieldsList? tableKeysSection?
    //              variablesList? triggersList? variablesList? proceduresList? variablesList?
    //          RBRACE
 
    // Codeunit and Enum objects can implement interfaces and therefore additonally have an optional IMPLEMENTS block
    // ENUM INTEGER_LITERAL IDENTIFIER (IMPLEMENTS identifierWithNamespace)? LBRACE enumPropertiesList? enumValuesList? RBRACE
 
    // Optional prefix rules are omitted from children when absent, so find the object type token (TABLE, PAGE, CODEUNIT, etc) dynamically
    const objectIdx = children.findIndex(c => c.symbol?.type === objectType);
    if (objectIdx === -1) return "";
 
    const lBraceIdx = children.findIndex(c => c.symbol?.type === ALParser.LBRACE);
    const rBraceIdx = children.findIndex(c => c.symbol?.type === ALParser.RBRACE);
 
    const objectDeclaration = [];
    for (let i = 0; i < lBraceIdx; i++) {
        objectDeclaration.push(path.call(print, 'children', i));
    }
 
    const elementStart = lBraceIdx + 1;
    const elementEnd = children.length - 1;
    let elementDocs = [];
 
    if (!options || options.groupGlobalVars === "none") {
        elementDocs = printAllElements(path, options, print, elementStart, elementEnd);
    }
    else {
        elementDocs = printElementsInGroups(path, options, print, elementStart, elementEnd);
    }
 
    const body = elementDocs.length > 0
        ? [indent([hardline, join([hardline, hardline], elementDocs)]), hardline]
        : [hardline];
 
    return [join(" ", objectDeclaration), hardline, path.call(print, 'children', lBraceIdx), ...body, path.call(print, 'children', rBraceIdx)];
}
 
function printArrayDataType(path, options, print) {
    // Grammar: ARRAY LBRACKET INTEGER_LITERAL (COMMA INTEGER_LITERAL)* RBRACKET OF dataType;
    const children = path.node.children;
    const arrayKeyword = path.call(print, 'children', 0);
    const lbracket = path.call(print, 'children', 1);
    const rbracket = path.call(print, 'children', children.length - 3);
    const ofKeyword = path.call(print, 'children', children.length - 2);
    const dataType = path.call(print, 'children', children.length - 1);
 
    const dimensions = [];
    for (let i = 2; i < children.length - 3; i += 2) {
        dimensions.push(path.call(print, 'children', i));
        if (children[i + 1].symbol?.type === ALParser.COMMA) {
            dimensions.push([path.call(print, 'children', i + 1), " "]);
        }
    }
 
    return [arrayKeyword, lbracket, ...dimensions, rbracket, " ", ofKeyword, " ", dataType];
}
 
function printDictionaryDataType(path, options, print) {
    // Grammar: DICTIONARY OF LBRACKET dataType COMMA dataType RBRACKET;
    const dictTypeName = path.call(print, 'children', 0);
    const ofKeyword = path.call(print, 'children', 1);
    const lbracket = path.call(print, 'children', 2);
    const type1 = path.call(print, 'children', 3);
    const comma = path.call(print, 'children', 4);
    const type2 = path.call(print, 'children', 5);
    const rbracket = path.call(print, 'children', 6);
    return [dictTypeName, " ", ofKeyword, " ", lbracket, type1, comma, " ", type2, rbracket];
}
 
function printLabelDataType(path, options, print) {
    // Grammar: LABEL STRING_LITERAL ((COMMA COMMENT EQUAL STRING_LITERAL)? | (COMMA LOCKED EQUAL BOOLEAN_LITERAL)? )*
    // Flat:    Label 'text', Comment = 'value', Locked = true
    // Broken:  Label 'text',
    //              Comment = 'value',
    //              Locked = true
    const children = path.node.children;
    const labelText = path.call(print, 'children', 1);
    const properties = [];
 
    for (let index = 3; index < children.length; index += 4) {
        const name = path.call(print, 'children', index);
        const value = path.call(print, 'children', index + 2);
        properties.push([name, " = ", value]);
    }
 
    if (properties.length === 0) {
        return ["Label ", labelText];
    }
 
    return group([
        "Label ", labelText,
        indent(properties.map(prop => [",", line, prop]))
    ]);
}
 
function printListDataType(path, options, print) {
    // Grammar: LIST OF LBRACKET dataType RBRACKET
    const type = path.call(print, 'children', 3);
    return ["List of [", type, "]"];
}
 
function printOptionDataType(path, options, print) {
    // Grammar: OPTION COMMA? identifiersList?;
    const typeName = path.call(print, 'children', 0);
 
    const optionValues = [];
    for (let i = 1; i < path.node.children.length; i++) {
        optionValues.push(path.call(print, 'children', i));
    }
 
    return optionValues.length > 0
        ? [typeName, " ", optionValues]
        : [typeName];
}
 
function printTextConst(path, options, print) {
    // Grammar: TEXTCONST IDENTIFIER EQUAL STRING_LITERAL (COMMA IDENTIFIER EQUAL STRING_LITERAL)*;
    const children = path.node.children;
    const decl = [];
 
 
    decl.push(path.call(print, 'children', 0), " ");
 
    for (let i = 1; i <= children.length - 3; i += 4) {
        decl.push(
            path.call(print, 'children', i),
            " ",
            path.call(print, 'children', i + 1),
            " ",
            path.call(print, 'children', i + 2));
 
        if (i < children.length - 4) {
            decl.push(path.call(print, 'children', i + 3), " "); // Comma before the next language constant
        }
    }
 
    return decl;
}
 
function printIdentifiersList(path, options, print) {
    // Grammar: identifier (COMMA identifier)*
    const optionValues = [];
    for (let i = 0; i < path.node.children.length; i += 2) {
        optionValues.push(path.call(print, 'children', i));
    }
 
    return join(", ", optionValues);
}
 
function printObjectPermissionsList(path, options, print) {
    // Grammar: PERMISSIONS EQUAL permissionsPropertyValue (COMMA permissionsPropertyValue)*
    const children = path.node.children;
    const permissionsKeyword = path.call(print, 'children', 0);
    const equalSign = path.call(print, 'children', 1);
 
    const propValues = [];
    for (let i = 2; i < children.length; i += 2) {
        let value = path.call(print, 'children', i);
        if (i < children.length - 1) {
            value.push(path.call(print, 'children', i + 1));  // Print comma
        }
        propValues.push(value);
    }
 
    return group(indent([permissionsKeyword, " ", equalSign, line, join(line, propValues)]));
}
 
function printPermissionsPropertyValue(path, options, print) {
    // Grammar: identifier identifier EQUAL PERMISSION_VALUES
    const objectType = path.call(print, 'children', 0);
    const objectName = path.call(print, 'children', 1);
    const equalSign = path.call(print, 'children', 2);
    const permissions = path.call(print, 'children', 3);
 
    return join(" ", [objectType, objectName, equalSign, permissions]);
}
 
function printDecimalPlacesPropertyValue(path, options, print) {
    // Grammar: INTEGER_LITERAL (COLON INTEGER_LITERAL)?;
    const intPart = path.call(print, 'children', 0);
    if (path.node.children.length === 1)
        return intPart;
 
    const colon = path.call(print, 'children', 1);
    const decPart = path.call(print, 'children', 2);
    return [intPart, " ", colon, " ", decPart];
}
 
function printAccessByPermissionPropertyValue(path, options, print) {
    return join(" ", path.map(print, 'children'));
}
 
function printToken(token) {
    return TokenFormatter.format(token);
}
 
//#endregion Code statements
 
function printAllElements(path, options, print, elementStart, elementEnd) {
    const elementDocs = [];
 
    for (let i = elementStart + 1; i < elementEnd; i++) {
        removeBlankLineBeforeLeadingComment(path.node.children[i]);
    }
 
    for (let i = elementStart; i < elementEnd; i++) {
        const el = path.call(print, 'children', i);
        if (Array.isArray(el) && el.length > 0)
            elementDocs.push(el);
    }
 
    return elementDocs;
}
 
function printElementsInGroups(path, options, print, elementStart, elementEnd) {
    const objectElements = {
        properties: [],
        vars: [],
        protectedVars: [],
        procedures: [],
        fields: [],
        keys: [],
        layout: [],
        actions: [],
        otherElements: []
    }
 
    for (let i = elementStart; i < elementEnd; i++) {
        switch (true) {
            case isALObjectPropertiesList(path.node.children[i]):
                objectElements.properties = path.call(print, 'children', i);
                break;
 
            case path.node.children[i].ruleIndex === ALParser.RULE_proceduresList:
                objectElements.procedures.push(path.call(print, 'children', i));
                break;
 
            case path.node.children[i].ruleIndex === ALParser.RULE_layoutDefinition:
                objectElements.layout = path.call(print, 'children', i);
                break;
 
            case path.node.children[i].ruleIndex === ALParser.RULE_tableFieldsList:
                objectElements.fields = path.call(print, 'children', i);
                break;
 
            case path.node.children[i].ruleIndex === ALParser.RULE_tableKeysSection:
                objectElements.keys = path.call(print, 'children', i);
                break;
 
            case path.node.children[i].ruleIndex === ALParser.RULE_actionsDefinition:
                objectElements.actions = path.call(print, 'children', i);
                break;
 
            case path.node.children[i].ruleIndex === ALParser.RULE_variablesList:
                if (path.node.children[i]?.children[0]?.symbol?.type === ALParser.PROTECTED) {
                    objectElements.protectedVars.push(path.call(() => printVariablesListExcludingKeywords(path, options, print), 'children', i));
                }
                else {
                    objectElements.vars.push(path.call(() => printVariablesListExcludingKeywords(path, options, print), 'children', i));
                }
                break;
 
            default:
                const el = path.call(print, 'children', i);
                if (el !== "")
                    objectElements.otherElements.push(el);
        }
    }
 
    return buildObjectFromElementGroups(objectElements, options);
}
 
function buildObjectFromElementGroups(objectElements, options) {
    const elementDocs = [];
 
    if (objectElements.vars.length > 0) {
        objectElements.vars = ["var", indent([hardline, join(hardline, objectElements.vars)])];
    }
    if (objectElements.protectedVars.length > 0) {
        if (objectElements.vars.length > 0)
            objectElements.vars.push(hardline, hardline);
        objectElements.vars.push("protected var", indent([hardline, join(hardline, objectElements.protectedVars)]));
    }
 
    const pushNonEmpty = (arr, el) => {
        if (!Array.isArray(el) || el.length > 0) {
            arr.push(el);
        };
    };
 
    pushNonEmpty(elementDocs, objectElements.properties);
    pushNonEmpty(elementDocs, objectElements.fields);
    pushNonEmpty(elementDocs, objectElements.keys);
    pushNonEmpty(elementDocs, objectElements.layout);
    pushNonEmpty(elementDocs, objectElements.actions);
    if (options.groupGlobalVars === "top" && objectElements.vars.length > 0)
        elementDocs.push(objectElements.vars);
 
    elementDocs.push(...objectElements.otherElements)
    if (options.groupGlobalVars === "beforeCode" && objectElements.vars.length > 0)
        elementDocs.push(objectElements.vars);
 
    if (objectElements.procedures.length > 0)
        elementDocs.push(objectElements.procedures);
 
    if (options.groupGlobalVars === "bottom" && objectElements.vars.length > 0)
        elementDocs.push(objectElements.vars);
 
    return elementDocs;
}
 
function printVariablesListExcludingKeywords(path, options, print) {
    const children = path.node.children;
    const vars = [];
 
    for (let i = 0; i < children.length; i++) {
        if (children[i].ruleIndex === ALParser.RULE_variableDeclaration) {
            vars.push(path.call(print, 'children', i));
        }
    }
 
    return join(hardline, vars);
}
 
function removeBlankLineBeforeLeadingComment(node) {
    const leadingCommentIndex = node.comments?.findIndex(el => el.leading === true);
    if (leadingCommentIndex > -1) {
        node.comments[leadingCommentIndex].addBlankLineBefore = false;
    }
}
 
function removeBlankLineAroundTrailingComment(node) {
    const trailingCommentIndex = node.comments?.findIndex(el => el.leading === false);
    if (trailingCommentIndex > -1) {
        node.comments[trailingCommentIndex].addBlankLineBefore = false;
        node.comments[trailingCommentIndex].addBlankLineAfter = false;
    }
}
 
function isALObjectPropertiesList(node) {
    if (typeof node.ruleIndex === "undefined")
        return false;
 
    return [
        ALParser.RULE_tablePropertiesList,
        ALParser.RULE_pagePropertiesList,
        ALParser.RULE_codeunitPropertiesList,
        ALParser.RULE_reportPropertiesList,
        ALParser.RULE_queryPropertiesList,
        ALParser.RULE_tableExtPropertiesList
    ].includes(node.ruleIndex);
}
 
export default {
    print,
    getVisitorKeys,
    printComment,
    canAttachComment,
    isBlockComment,
    handleComments: {
        ownLine: handleOwnLineComment
    }
}