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
|
// Scintilla source code edit control
/** @file LexHTML.cxx
** Lexer for HTML.
**/
// Copyright 1998-2005 by Neil Hodgson <neilh@scintilla.org>
// The License.txt file describes the conditions under which this software may be distributed.
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <stdarg.h>
#include <assert.h>
#include <ctype.h>
#include <string>
#include <map>
#include <set>
#include "ILexer.h"
#include "Scintilla.h"
#include "SciLexer.h"
#include "StringCopy.h"
#include "WordList.h"
#include "LexAccessor.h"
#include "Accessor.h"
#include "StyleContext.h"
#include "CharacterSet.h"
#include "LexerModule.h"
#include "OptionSet.h"
#include "DefaultLexer.h"
using namespace Scintilla;
namespace {
#define SCE_HA_JS (SCE_HJA_START - SCE_HJ_START)
#define SCE_HA_VBS (SCE_HBA_START - SCE_HB_START)
#define SCE_HA_PYTHON (SCE_HPA_START - SCE_HP_START)
enum script_type { eScriptNone = 0, eScriptJS, eScriptVBS, eScriptPython, eScriptPHP, eScriptXML, eScriptSGML, eScriptSGMLblock, eScriptComment };
enum script_mode { eHtml = 0, eNonHtmlScript, eNonHtmlPreProc, eNonHtmlScriptPreProc };
inline bool IsAWordChar(const int ch) {
return (ch < 0x80) && (isalnum(ch) || ch == '.' || ch == '_');
}
inline bool IsAWordStart(const int ch) {
return (ch < 0x80) && (isalnum(ch) || ch == '_');
}
inline bool IsOperator(int ch) {
if (IsASCII(ch) && isalnum(ch))
return false;
// '.' left out as it is used to make up numbers
if (ch == '%' || ch == '^' || ch == '&' || ch == '*' ||
ch == '(' || ch == ')' || ch == '-' || ch == '+' ||
ch == '=' || ch == '|' || ch == '{' || ch == '}' ||
ch == '[' || ch == ']' || ch == ':' || ch == ';' ||
ch == '<' || ch == '>' || ch == ',' || ch == '/' ||
ch == '?' || ch == '!' || ch == '.' || ch == '~')
return true;
return false;
}
void GetTextSegment(Accessor &styler, Sci_PositionU start, Sci_PositionU end, char *s, size_t len) {
Sci_PositionU i = 0;
for (; (i < end - start + 1) && (i < len-1); i++) {
s[i] = MakeLowerCase(styler[start + i]);
}
s[i] = '\0';
}
std::string GetStringSegment(Accessor &styler, Sci_PositionU start, Sci_PositionU end) {
std::string s;
Sci_PositionU i = 0;
for (; (i < end - start + 1); i++) {
s.push_back(MakeLowerCase(styler[start + i]));
}
return s;
}
std::string GetNextWord(Accessor &styler, Sci_PositionU start) {
std::string ret;
Sci_PositionU i = 0;
for (; i < 200; i++) { // Put an upper limit to bound time taken for unexpected text.
const char ch = styler.SafeGetCharAt(start + i);
if ((i == 0) && !IsAWordStart(ch))
break;
if ((i > 0) && !IsAWordChar(ch))
break;
ret.push_back(ch);
}
return ret;
}
script_type segIsScriptingIndicator(Accessor &styler, Sci_PositionU start, Sci_PositionU end, script_type prevValue) {
char s[100];
GetTextSegment(styler, start, end, s, sizeof(s));
//Platform::DebugPrintf("Scripting indicator [%s]\n", s);
if (strstr(s, "src")) // External script
return eScriptNone;
if (strstr(s, "vbs"))
return eScriptVBS;
if (strstr(s, "pyth"))
return eScriptPython;
if (strstr(s, "javas"))
return eScriptJS;
if (strstr(s, "jscr"))
return eScriptJS;
if (strstr(s, "php"))
return eScriptPHP;
if (strstr(s, "xml")) {
const char *xml = strstr(s, "xml");
for (const char *t=s; t<xml; t++) {
if (!IsASpace(*t)) {
return prevValue;
}
}
return eScriptXML;
}
return prevValue;
}
int PrintScriptingIndicatorOffset(Accessor &styler, Sci_PositionU start, Sci_PositionU end) {
int iResult = 0;
std::string s = GetStringSegment(styler, start, end);
if (0 == strncmp(s.c_str(), "php", 3)) {
iResult = 3;
}
return iResult;
}
script_type ScriptOfState(int state) {
if ((state >= SCE_HP_START) && (state <= SCE_HP_IDENTIFIER)) {
return eScriptPython;
} else if ((state >= SCE_HB_START) && (state <= SCE_HB_STRINGEOL)) {
return eScriptVBS;
} else if ((state >= SCE_HJ_START) && (state <= SCE_HJ_REGEX)) {
return eScriptJS;
} else if ((state >= SCE_HPHP_DEFAULT) && (state <= SCE_HPHP_COMMENTLINE)) {
return eScriptPHP;
} else if ((state >= SCE_H_SGML_DEFAULT) && (state < SCE_H_SGML_BLOCK_DEFAULT)) {
return eScriptSGML;
} else if (state == SCE_H_SGML_BLOCK_DEFAULT) {
return eScriptSGMLblock;
} else {
return eScriptNone;
}
}
int statePrintForState(int state, script_mode inScriptType) {
int StateToPrint = state;
if (state >= SCE_HJ_START) {
if ((state >= SCE_HP_START) && (state <= SCE_HP_IDENTIFIER)) {
StateToPrint = state + ((inScriptType == eNonHtmlScript) ? 0 : SCE_HA_PYTHON);
} else if ((state >= SCE_HB_START) && (state <= SCE_HB_STRINGEOL)) {
StateToPrint = state + ((inScriptType == eNonHtmlScript) ? 0 : SCE_HA_VBS);
} else if ((state >= SCE_HJ_START) && (state <= SCE_HJ_REGEX)) {
StateToPrint = state + ((inScriptType == eNonHtmlScript) ? 0 : SCE_HA_JS);
}
}
return StateToPrint;
}
int stateForPrintState(int StateToPrint) {
int state;
if ((StateToPrint >= SCE_HPA_START) && (StateToPrint <= SCE_HPA_IDENTIFIER)) {
state = StateToPrint - SCE_HA_PYTHON;
} else if ((StateToPrint >= SCE_HBA_START) && (StateToPrint <= SCE_HBA_STRINGEOL)) {
state = StateToPrint - SCE_HA_VBS;
} else if ((StateToPrint >= SCE_HJA_START) && (StateToPrint <= SCE_HJA_REGEX)) {
state = StateToPrint - SCE_HA_JS;
} else {
state = StateToPrint;
}
return state;
}
inline bool IsNumber(Sci_PositionU start, Accessor &styler) {
return IsADigit(styler[start]) || (styler[start] == '.') ||
(styler[start] == '-') || (styler[start] == '#');
}
inline bool isStringState(int state) {
bool bResult;
switch (state) {
case SCE_HJ_DOUBLESTRING:
case SCE_HJ_SINGLESTRING:
case SCE_HJA_DOUBLESTRING:
case SCE_HJA_SINGLESTRING:
case SCE_HB_STRING:
case SCE_HBA_STRING:
case SCE_HP_STRING:
case SCE_HP_CHARACTER:
case SCE_HP_TRIPLE:
case SCE_HP_TRIPLEDOUBLE:
case SCE_HPA_STRING:
case SCE_HPA_CHARACTER:
case SCE_HPA_TRIPLE:
case SCE_HPA_TRIPLEDOUBLE:
case SCE_HPHP_HSTRING:
case SCE_HPHP_SIMPLESTRING:
case SCE_HPHP_HSTRING_VARIABLE:
case SCE_HPHP_COMPLEX_VARIABLE:
bResult = true;
break;
default :
bResult = false;
break;
}
return bResult;
}
inline bool stateAllowsTermination(int state) {
bool allowTermination = !isStringState(state);
if (allowTermination) {
switch (state) {
case SCE_HB_COMMENTLINE:
case SCE_HPHP_COMMENT:
case SCE_HP_COMMENTLINE:
case SCE_HPA_COMMENTLINE:
allowTermination = false;
}
}
return allowTermination;
}
// not really well done, since it's only comments that should lex the %> and <%
inline bool isCommentASPState(int state) {
bool bResult;
switch (state) {
case SCE_HJ_COMMENT:
case SCE_HJ_COMMENTLINE:
case SCE_HJ_COMMENTDOC:
case SCE_HB_COMMENTLINE:
case SCE_HP_COMMENTLINE:
case SCE_HPHP_COMMENT:
case SCE_HPHP_COMMENTLINE:
bResult = true;
break;
default :
bResult = false;
break;
}
return bResult;
}
void classifyAttribHTML(Sci_PositionU start, Sci_PositionU end, const WordList &keywords, Accessor &styler) {
const bool wordIsNumber = IsNumber(start, styler);
char chAttr = SCE_H_ATTRIBUTEUNKNOWN;
if (wordIsNumber) {
chAttr = SCE_H_NUMBER;
} else {
std::string s = GetStringSegment(styler, start, end);
if (keywords.InList(s.c_str()))
chAttr = SCE_H_ATTRIBUTE;
}
if ((chAttr == SCE_H_ATTRIBUTEUNKNOWN) && !keywords)
// No keywords -> all are known
chAttr = SCE_H_ATTRIBUTE;
styler.ColourTo(end, chAttr);
}
// https://html.spec.whatwg.org/multipage/custom-elements.html#custom-elements-core-concepts
bool isHTMLCustomElement(const std::string &tag) {
// check valid HTML custom element name: starts with an ASCII lower alpha and contains hyphen.
// IsUpperOrLowerCase() is used for `html.tags.case.sensitive=1`.
if (tag.length() < 2 || !IsUpperOrLowerCase(tag[0])) {
return false;
}
if (tag.find('-') == std::string::npos) {
return false;
}
return true;
}
int classifyTagHTML(Sci_PositionU start, Sci_PositionU end,
const WordList &keywords, Accessor &styler, bool &tagDontFold,
bool caseSensitive, bool isXml, bool allowScripts,
const std::set<std::string> &nonFoldingTags) {
std::string tag;
// Copy after the '<' and stop before ' '
for (Sci_PositionU cPos = start; cPos <= end; cPos++) {
const char ch = styler[cPos];
if (IsASpace(ch)) {
break;
}
if ((ch != '<') && (ch != '/')) {
tag.push_back(caseSensitive ? ch : MakeLowerCase(ch));
}
}
// if the current language is XML, I can fold any tag
// if the current language is HTML, I don't want to fold certain tags (input, meta, etc.)
//...to find it in the list of no-container-tags
tagDontFold = (!isXml) && (nonFoldingTags.count(tag) > 0);
// No keywords -> all are known
char chAttr = SCE_H_TAGUNKNOWN;
if (!tag.empty() && (tag[0] == '!')) {
chAttr = SCE_H_SGML_DEFAULT;
} else if (!keywords || keywords.InList(tag.c_str())) {
chAttr = SCE_H_TAG;
} else if (!isXml && isHTMLCustomElement(tag)) {
chAttr = SCE_H_TAG;
}
if (chAttr != SCE_H_TAGUNKNOWN) {
styler.ColourTo(end, chAttr);
}
if (chAttr == SCE_H_TAG) {
if (allowScripts && (tag == "script")) {
// check to see if this is a self-closing tag by sniffing ahead
bool isSelfClose = false;
for (Sci_PositionU cPos = end; cPos <= end + 200; cPos++) {
const char ch = styler.SafeGetCharAt(cPos, '\0');
if (ch == '\0' || ch == '>')
break;
else if (ch == '/' && styler.SafeGetCharAt(cPos + 1, '\0') == '>') {
isSelfClose = true;
break;
}
}
// do not enter a script state if the tag self-closed
if (!isSelfClose)
chAttr = SCE_H_SCRIPT;
} else if (!isXml && (tag == "comment")) {
chAttr = SCE_H_COMMENT;
}
}
return chAttr;
}
void classifyWordHTJS(Sci_PositionU start, Sci_PositionU end,
const WordList &keywords, Accessor &styler, script_mode inScriptType) {
char s[30 + 1];
Sci_PositionU i = 0;
for (; i < end - start + 1 && i < 30; i++) {
s[i] = styler[start + i];
}
s[i] = '\0';
char chAttr = SCE_HJ_WORD;
const bool wordIsNumber = IsADigit(s[0]) || ((s[0] == '.') && IsADigit(s[1]));
if (wordIsNumber) {
chAttr = SCE_HJ_NUMBER;
} else if (keywords.InList(s)) {
chAttr = SCE_HJ_KEYWORD;
}
styler.ColourTo(end, statePrintForState(chAttr, inScriptType));
}
int classifyWordHTVB(Sci_PositionU start, Sci_PositionU end, const WordList &keywords, Accessor &styler, script_mode inScriptType) {
char chAttr = SCE_HB_IDENTIFIER;
const bool wordIsNumber = IsADigit(styler[start]) || (styler[start] == '.');
if (wordIsNumber) {
chAttr = SCE_HB_NUMBER;
} else {
std::string s = GetStringSegment(styler, start, end);
if (keywords.InList(s.c_str())) {
chAttr = SCE_HB_WORD;
if (s == "rem")
chAttr = SCE_HB_COMMENTLINE;
}
}
styler.ColourTo(end, statePrintForState(chAttr, inScriptType));
if (chAttr == SCE_HB_COMMENTLINE)
return SCE_HB_COMMENTLINE;
else
return SCE_HB_DEFAULT;
}
void classifyWordHTPy(Sci_PositionU start, Sci_PositionU end, const WordList &keywords, Accessor &styler, std::string &prevWord, script_mode inScriptType, bool isMako) {
const bool wordIsNumber = IsADigit(styler[start]);
std::string s;
for (Sci_PositionU i = 0; i < end - start + 1 && i < 30; i++) {
s.push_back(styler[start + i]);
}
char chAttr = SCE_HP_IDENTIFIER;
if (prevWord == "class")
chAttr = SCE_HP_CLASSNAME;
else if (prevWord == "def")
chAttr = SCE_HP_DEFNAME;
else if (wordIsNumber)
chAttr = SCE_HP_NUMBER;
else if (keywords.InList(s.c_str()))
chAttr = SCE_HP_WORD;
else if (isMako && (s == "block"))
chAttr = SCE_HP_WORD;
styler.ColourTo(end, statePrintForState(chAttr, inScriptType));
prevWord = s;
}
// Update the word colour to default or keyword
// Called when in a PHP word
void classifyWordHTPHP(Sci_PositionU start, Sci_PositionU end, const WordList &keywords, Accessor &styler) {
char chAttr = SCE_HPHP_DEFAULT;
const bool wordIsNumber = IsADigit(styler[start]) || (styler[start] == '.' && start+1 <= end && IsADigit(styler[start+1]));
if (wordIsNumber) {
chAttr = SCE_HPHP_NUMBER;
} else {
std::string s = GetStringSegment(styler, start, end);
if (keywords.InList(s.c_str()))
chAttr = SCE_HPHP_WORD;
}
styler.ColourTo(end, chAttr);
}
bool isWordHSGML(Sci_PositionU start, Sci_PositionU end, const WordList &keywords, Accessor &styler) {
std::string s;
for (Sci_PositionU i = 0; i < end - start + 1 && i < 30; i++) {
s.push_back(styler[start + i]);
}
return keywords.InList(s.c_str());
}
bool isWordCdata(Sci_PositionU start, Sci_PositionU end, Accessor &styler) {
std::string s;
for (Sci_PositionU i = 0; i < end - start + 1 && i < 30; i++) {
s.push_back(styler[start + i]);
}
return s == "[CDATA[";
}
// Return the first state to reach when entering a scripting language
int StateForScript(script_type scriptLanguage) {
int Result;
switch (scriptLanguage) {
case eScriptVBS:
Result = SCE_HB_START;
break;
case eScriptPython:
Result = SCE_HP_START;
break;
case eScriptPHP:
Result = SCE_HPHP_DEFAULT;
break;
case eScriptXML:
Result = SCE_H_TAGUNKNOWN;
break;
case eScriptSGML:
Result = SCE_H_SGML_DEFAULT;
break;
case eScriptComment:
Result = SCE_H_COMMENT;
break;
default :
Result = SCE_HJ_START;
break;
}
return Result;
}
inline bool issgmlwordchar(int ch) {
return !IsASCII(ch) ||
(isalnum(ch) || ch == '.' || ch == '_' || ch == ':' || ch == '!' || ch == '#' || ch == '[');
}
inline bool IsPhpWordStart(int ch) {
return (IsASCII(ch) && (isalpha(ch) || (ch == '_'))) || (ch >= 0x7f);
}
inline bool IsPhpWordChar(int ch) {
return IsADigit(ch) || IsPhpWordStart(ch);
}
bool InTagState(int state) {
return state == SCE_H_TAG || state == SCE_H_TAGUNKNOWN ||
state == SCE_H_SCRIPT ||
state == SCE_H_ATTRIBUTE || state == SCE_H_ATTRIBUTEUNKNOWN ||
state == SCE_H_NUMBER || state == SCE_H_OTHER ||
state == SCE_H_DOUBLESTRING || state == SCE_H_SINGLESTRING;
}
bool IsCommentState(const int state) {
return state == SCE_H_COMMENT || state == SCE_H_SGML_COMMENT;
}
bool IsScriptCommentState(const int state) {
return state == SCE_HJ_COMMENT || state == SCE_HJ_COMMENTLINE || state == SCE_HJA_COMMENT ||
state == SCE_HJA_COMMENTLINE || state == SCE_HB_COMMENTLINE || state == SCE_HBA_COMMENTLINE;
}
bool isLineEnd(int ch) {
return ch == '\r' || ch == '\n';
}
bool isMakoBlockEnd(const int ch, const int chNext, const std::string &blockType) {
if (blockType.empty()) {
return ((ch == '%') && (chNext == '>'));
} else if ((blockType == "inherit") ||
(blockType == "namespace") ||
(blockType == "include") ||
(blockType == "page")) {
return ((ch == '/') && (chNext == '>'));
} else if (blockType == "%") {
if (ch == '/' && isLineEnd(chNext))
return true;
else
return isLineEnd(ch);
} else if (blockType == "{") {
return ch == '}';
} else {
return (ch == '>');
}
}
bool isDjangoBlockEnd(const int ch, const int chNext, const std::string &blockType) {
if (blockType.empty()) {
return false;
} else if (blockType == "%") {
return ((ch == '%') && (chNext == '}'));
} else if (blockType == "{") {
return ((ch == '}') && (chNext == '}'));
} else {
return false;
}
}
bool isPHPStringState(int state) {
return
(state == SCE_HPHP_HSTRING) ||
(state == SCE_HPHP_SIMPLESTRING) ||
(state == SCE_HPHP_HSTRING_VARIABLE) ||
(state == SCE_HPHP_COMPLEX_VARIABLE);
}
Sci_Position FindPhpStringDelimiter(std::string &phpStringDelimiter, Sci_Position i, const Sci_Position lengthDoc, Accessor &styler, bool &isSimpleString) {
Sci_Position j;
const Sci_Position beginning = i - 1;
bool isValidSimpleString = false;
while (i < lengthDoc && (styler[i] == ' ' || styler[i] == '\t'))
i++;
char ch = styler.SafeGetCharAt(i);
const char chNext = styler.SafeGetCharAt(i + 1);
phpStringDelimiter.clear();
if (!IsPhpWordStart(ch)) {
if (ch == '\'' && IsPhpWordStart(chNext)) {
i++;
ch = chNext;
isSimpleString = true;
} else {
return beginning;
}
}
phpStringDelimiter.push_back(ch);
i++;
for (j = i; j < lengthDoc && !isLineEnd(styler[j]); j++) {
if (!IsPhpWordChar(styler[j])) {
if (isSimpleString && (styler[j] == '\'') && isLineEnd(styler.SafeGetCharAt(j + 1))) {
isValidSimpleString = true;
j++;
break;
} else {
phpStringDelimiter.clear();
return beginning;
}
}
phpStringDelimiter.push_back(styler[j]);
}
if (isSimpleString && !isValidSimpleString) {
phpStringDelimiter.clear();
return beginning;
}
return j - 1;
}
// Options used for LexerHTML
struct OptionsHTML {
int aspDefaultLanguage = eScriptJS;
bool caseSensitive = false;
bool allowScripts = true;
bool isMako = false;
bool isDjango = false;
bool fold = false;
bool foldHTML = false;
bool foldHTMLPreprocessor = true;
bool foldCompact = true;
bool foldComment = false;
bool foldHeredoc = false;
bool foldXmlAtTagOpen = false;
OptionsHTML() noexcept {
}
};
const char * const htmlWordListDesc[] = {
"HTML elements and attributes",
"JavaScript keywords",
"VBScript keywords",
"Python keywords",
"PHP keywords",
"SGML and DTD keywords",
0,
};
const char * const phpscriptWordListDesc[] = {
"", //Unused
"", //Unused
"", //Unused
"", //Unused
"PHP keywords",
"", //Unused
0,
};
struct OptionSetHTML : public OptionSet<OptionsHTML> {
OptionSetHTML(bool isPHPScript_) {
DefineProperty("asp.default.language", &OptionsHTML::aspDefaultLanguage,
"Script in ASP code is initially assumed to be in JavaScript. "
"To change this to VBScript set asp.default.language to 2. Python is 3.");
DefineProperty("html.tags.case.sensitive", &OptionsHTML::caseSensitive,
"For XML and HTML, setting this property to 1 will make tags match in a case "
"sensitive way which is the expected behaviour for XML and XHTML.");
DefineProperty("lexer.xml.allow.scripts", &OptionsHTML::allowScripts,
"Set to 0 to disable scripts in XML.");
DefineProperty("lexer.html.mako", &OptionsHTML::isMako,
"Set to 1 to enable the mako template language.");
DefineProperty("lexer.html.django", &OptionsHTML::isDjango,
"Set to 1 to enable the django template language.");
DefineProperty("fold", &OptionsHTML::fold);
DefineProperty("fold.html", &OptionsHTML::foldHTML,
"Folding is turned on or off for HTML and XML files with this option. "
"The fold option must also be on for folding to occur.");
DefineProperty("fold.html.preprocessor", &OptionsHTML::foldHTMLPreprocessor,
"Folding is turned on or off for scripts embedded in HTML files with this option. "
"The default is on.");
DefineProperty("fold.compact", &OptionsHTML::foldCompact);
DefineProperty("fold.hypertext.comment", &OptionsHTML::foldComment,
"Allow folding for comments in scripts embedded in HTML. "
"The default is off.");
DefineProperty("fold.hypertext.heredoc", &OptionsHTML::foldHeredoc,
"Allow folding for heredocs in scripts embedded in HTML. "
"The default is off.");
DefineProperty("fold.xml.at.tag.open", &OptionsHTML::foldXmlAtTagOpen,
"Enable folding for XML at the start of open tag. "
"The default is off.");
DefineWordListSets(isPHPScript_ ? phpscriptWordListDesc : htmlWordListDesc);
}
};
LexicalClass lexicalClassesHTML[] = {
// Lexer HTML SCLEX_HTML SCE_H_ SCE_HJ_ SCE_HJA_ SCE_HB_ SCE_HBA_ SCE_HP_ SCE_HPHP_ SCE_HPA_:
0, "SCE_H_DEFAULT", "default", "Text",
1, "SCE_H_TAG", "tag", "Tags",
2, "SCE_H_ERRORTAGUNKNOWN", "error tag", "Unknown Tags",
3, "SCE_H_ATTRIBUTE", "attribute", "Attributes",
4, "SCE_H_ATTRIBUTEUNKNOWN", "error attribute", "Unknown Attributes",
5, "SCE_H_NUMBER", "literal numeric", "Numbers",
6, "SCE_H_DOUBLESTRING", "literal string", "Double quoted strings",
7, "SCE_H_SINGLESTRING", "literal string", "Single quoted strings",
8, "SCE_H_OTHER", "tag operator", "Other inside tag, including space and '='",
9, "SCE_H_COMMENT", "comment", "Comment",
10, "SCE_H_ENTITY", "literal", "Entities",
11, "SCE_H_TAGEND", "tag", "XML style tag ends '/>'",
12, "SCE_H_XMLSTART", "identifier", "XML identifier start '<?'",
13, "SCE_H_XMLEND", "identifier", "XML identifier end '?>'",
14, "SCE_H_SCRIPT", "error", "Internal state which should never be visible",
15, "SCE_H_ASP", "preprocessor", "ASP <% ... %>",
16, "SCE_H_ASPAT", "preprocessor", "ASP <% ... %>",
17, "SCE_H_CDATA", "literal", "CDATA",
18, "SCE_H_QUESTION", "preprocessor", "PHP",
19, "SCE_H_VALUE", "literal string", "Unquoted values",
20, "SCE_H_XCCOMMENT", "comment", "JSP Comment <%-- ... --%>",
21, "SCE_H_SGML_DEFAULT", "default", "SGML tags <! ... >",
22, "SCE_H_SGML_COMMAND", "preprocessor", "SGML command",
23, "SCE_H_SGML_1ST_PARAM", "preprocessor", "SGML 1st param",
24, "SCE_H_SGML_DOUBLESTRING", "literal string", "SGML double string",
25, "SCE_H_SGML_SIMPLESTRING", "literal string", "SGML single string",
26, "SCE_H_SGML_ERROR", "error", "SGML error",
27, "SCE_H_SGML_SPECIAL", "literal", "SGML special (#XXXX type)",
28, "SCE_H_SGML_ENTITY", "literal", "SGML entity",
29, "SCE_H_SGML_COMMENT", "comment", "SGML comment",
30, "SCE_H_SGML_1ST_PARAM_COMMENT", "error comment", "SGML first parameter - lexer internal. It is an error if any text is in this style.",
31, "SCE_H_SGML_BLOCK_DEFAULT", "default", "SGML block",
32, "", "predefined", "",
33, "", "predefined", "",
34, "", "predefined", "",
35, "", "predefined", "",
36, "", "predefined", "",
37, "", "predefined", "",
38, "", "predefined", "",
39, "", "predefined", "",
40, "SCE_HJ_START", "client javascript default", "JS Start - allows eol filled background to not start on same line as SCRIPT tag",
41, "SCE_HJ_DEFAULT", "client javascript default", "JS Default",
42, "SCE_HJ_COMMENT", "client javascript comment", "JS Comment",
43, "SCE_HJ_COMMENTLINE", "client javascript comment line", "JS Line Comment",
44, "SCE_HJ_COMMENTDOC", "client javascript comment documentation", "JS Doc comment",
45, "SCE_HJ_NUMBER", "client javascript literal numeric", "JS Number",
46, "SCE_HJ_WORD", "client javascript identifier", "JS Word",
47, "SCE_HJ_KEYWORD", "client javascript keyword", "JS Keyword",
48, "SCE_HJ_DOUBLESTRING", "client javascript literal string", "JS Double quoted string",
49, "SCE_HJ_SINGLESTRING", "client javascript literal string", "JS Single quoted string",
50, "SCE_HJ_SYMBOLS", "client javascript operator", "JS Symbols",
51, "SCE_HJ_STRINGEOL", "client javascript error literal string", "JavaScript EOL",
52, "SCE_HJ_REGEX", "client javascript literal regex", "JavaScript RegEx",
53, "", "unused", "",
54, "", "unused", "",
55, "SCE_HJA_START", "server javascript default", "JS Start - allows eol filled background to not start on same line as SCRIPT tag",
56, "SCE_HJA_DEFAULT", "server javascript default", "JS Default",
57, "SCE_HJA_COMMENT", "server javascript comment", "JS Comment",
58, "SCE_HJA_COMMENTLINE", "server javascript comment line", "JS Line Comment",
59, "SCE_HJA_COMMENTDOC", "server javascript comment documentation", "JS Doc comment",
60, "SCE_HJA_NUMBER", "server javascript literal numeric", "JS Number",
61, "SCE_HJA_WORD", "server javascript identifier", "JS Word",
62, "SCE_HJA_KEYWORD", "server javascript keyword", "JS Keyword",
63, "SCE_HJA_DOUBLESTRING", "server javascript literal string", "JS Double quoted string",
64, "SCE_HJA_SINGLESTRING", "server javascript literal string", "JS Single quoted string",
65, "SCE_HJA_SYMBOLS", "server javascript operator", "JS Symbols",
66, "SCE_HJA_STRINGEOL", "server javascript error literal string", "JavaScript EOL",
67, "SCE_HJA_REGEX", "server javascript literal regex", "JavaScript RegEx",
68, "", "unused", "",
69, "", "unused", "",
70, "SCE_HB_START", "client basic default", "Start",
71, "SCE_HB_DEFAULT", "client basic default", "Default",
72, "SCE_HB_COMMENTLINE", "client basic comment line", "Comment",
73, "SCE_HB_NUMBER", "client basic literal numeric", "Number",
74, "SCE_HB_WORD", "client basic keyword", "KeyWord",
75, "SCE_HB_STRING", "client basic literal string", "String",
76, "SCE_HB_IDENTIFIER", "client basic identifier", "Identifier",
77, "SCE_HB_STRINGEOL", "client basic literal string", "Unterminated string",
78, "", "unused", "",
79, "", "unused", "",
80, "SCE_HBA_START", "server basic default", "Start",
81, "SCE_HBA_DEFAULT", "server basic default", "Default",
82, "SCE_HBA_COMMENTLINE", "server basic comment line", "Comment",
83, "SCE_HBA_NUMBER", "server basic literal numeric", "Number",
84, "SCE_HBA_WORD", "server basic keyword", "KeyWord",
85, "SCE_HBA_STRING", "server basic literal string", "String",
86, "SCE_HBA_IDENTIFIER", "server basic identifier", "Identifier",
87, "SCE_HBA_STRINGEOL", "server basic literal string", "Unterminated string",
88, "", "unused", "",
89, "", "unused", "",
90, "SCE_HP_START", "client python default", "Embedded Python",
91, "SCE_HP_DEFAULT", "client python default", "Embedded Python",
92, "SCE_HP_COMMENTLINE", "client python comment line", "Comment",
93, "SCE_HP_NUMBER", "client python literal numeric", "Number",
94, "SCE_HP_STRING", "client python literal string", "String",
95, "SCE_HP_CHARACTER", "client python literal string character", "Single quoted string",
96, "SCE_HP_WORD", "client python keyword", "Keyword",
97, "SCE_HP_TRIPLE", "client python literal string", "Triple quotes",
98, "SCE_HP_TRIPLEDOUBLE", "client python literal string", "Triple double quotes",
99, "SCE_HP_CLASSNAME", "client python identifier", "Class name definition",
100, "SCE_HP_DEFNAME", "client python identifier", "Function or method name definition",
101, "SCE_HP_OPERATOR", "client python operator", "Operators",
102, "SCE_HP_IDENTIFIER", "client python identifier", "Identifiers",
103, "", "unused", "",
104, "SCE_HPHP_COMPLEX_VARIABLE", "server php identifier", "PHP complex variable",
105, "SCE_HPA_START", "server python default", "ASP Python",
106, "SCE_HPA_DEFAULT", "server python default", "ASP Python",
107, "SCE_HPA_COMMENTLINE", "server python comment line", "Comment",
108, "SCE_HPA_NUMBER", "server python literal numeric", "Number",
109, "SCE_HPA_STRING", "server python literal string", "String",
110, "SCE_HPA_CHARACTER", "server python literal string character", "Single quoted string",
111, "SCE_HPA_WORD", "server python keyword", "Keyword",
112, "SCE_HPA_TRIPLE", "server python literal string", "Triple quotes",
113, "SCE_HPA_TRIPLEDOUBLE", "server python literal string", "Triple double quotes",
114, "SCE_HPA_CLASSNAME", "server python identifier", "Class name definition",
115, "SCE_HPA_DEFNAME", "server python identifier", "Function or method name definition",
116, "SCE_HPA_OPERATOR", "server python operator", "Operators",
117, "SCE_HPA_IDENTIFIER", "server python identifier", "Identifiers",
118, "SCE_HPHP_DEFAULT", "server php default", "Default",
119, "SCE_HPHP_HSTRING", "server php literal string", "Double quoted String",
120, "SCE_HPHP_SIMPLESTRING", "server php literal string", "Single quoted string",
121, "SCE_HPHP_WORD", "server php keyword", "Keyword",
122, "SCE_HPHP_NUMBER", "server php literal numeric", "Number",
123, "SCE_HPHP_VARIABLE", "server php identifier", "Variable",
124, "SCE_HPHP_COMMENT", "server php comment", "Comment",
125, "SCE_HPHP_COMMENTLINE", "server php comment line", "One line comment",
126, "SCE_HPHP_HSTRING_VARIABLE", "server php literal string identifier", "PHP variable in double quoted string",
127, "SCE_HPHP_OPERATOR", "server php operator", "PHP operator",
};
LexicalClass lexicalClassesXML[] = {
// Lexer.Secondary XML SCLEX_XML SCE_H_:
0, "SCE_H_DEFAULT", "default", "Default",
1, "SCE_H_TAG", "tag", "Tags",
2, "SCE_H_TAGUNKNOWN", "error tag", "Unknown Tags",
3, "SCE_H_ATTRIBUTE", "attribute", "Attributes",
4, "SCE_H_ERRORATTRIBUTEUNKNOWN", "error attribute", "Unknown Attributes",
5, "SCE_H_NUMBER", "literal numeric", "Numbers",
6, "SCE_H_DOUBLESTRING", "literal string", "Double quoted strings",
7, "SCE_H_SINGLESTRING", "literal string", "Single quoted strings",
8, "SCE_H_OTHER", "tag operator", "Other inside tag, including space and '='",
9, "SCE_H_COMMENT", "comment", "Comment",
10, "SCE_H_ENTITY", "literal", "Entities",
11, "SCE_H_TAGEND", "tag", "XML style tag ends '/>'",
12, "SCE_H_XMLSTART", "identifier", "XML identifier start '<?'",
13, "SCE_H_XMLEND", "identifier", "XML identifier end '?>'",
14, "", "unused", "",
15, "", "unused", "",
16, "", "unused", "",
17, "SCE_H_CDATA", "literal", "CDATA",
18, "SCE_H_QUESTION", "preprocessor", "Question",
19, "SCE_H_VALUE", "literal string", "Unquoted Value",
20, "", "unused", "",
21, "SCE_H_SGML_DEFAULT", "default", "SGML tags <! ... >",
22, "SCE_H_SGML_COMMAND", "preprocessor", "SGML command",
23, "SCE_H_SGML_1ST_PARAM", "preprocessor", "SGML 1st param",
24, "SCE_H_SGML_DOUBLESTRING", "literal string", "SGML double string",
25, "SCE_H_SGML_SIMPLESTRING", "literal string", "SGML single string",
26, "SCE_H_SGML_ERROR", "error", "SGML error",
27, "SCE_H_SGML_SPECIAL", "literal", "SGML special (#XXXX type)",
28, "SCE_H_SGML_ENTITY", "literal", "SGML entity",
29, "SCE_H_SGML_COMMENT", "comment", "SGML comment",
30, "", "unused", "",
31, "SCE_H_SGML_BLOCK_DEFAULT", "default", "SGML block",
};
const char *tagsThatDoNotFold[] = {
"area",
"base",
"basefont",
"br",
"col",
"command",
"embed",
"frame",
"hr",
"img",
"input",
"isindex",
"keygen",
"link",
"meta",
"param",
"source",
"track",
"wbr"
};
}
class LexerHTML : public DefaultLexer {
bool isXml;
bool isPHPScript;
WordList keywords;
WordList keywords2;
WordList keywords3;
WordList keywords4;
WordList keywords5;
WordList keywords6; // SGML (DTD) keywords
OptionsHTML options;
OptionSetHTML osHTML;
std::set<std::string> nonFoldingTags;
public:
explicit LexerHTML(bool isXml_, bool isPHPScript_) :
DefaultLexer(
isXml_ ? "xml" : (isPHPScript_ ? "phpscript" : "hypertext"),
isXml_ ? SCLEX_XML : (isPHPScript_ ? SCLEX_PHPSCRIPT : SCLEX_HTML),
isXml_ ? lexicalClassesHTML : lexicalClassesXML,
isXml_ ? Sci::size(lexicalClassesHTML) : Sci::size(lexicalClassesXML)),
isXml(isXml_),
isPHPScript(isPHPScript_),
osHTML(isPHPScript_),
nonFoldingTags(std::begin(tagsThatDoNotFold), std::end(tagsThatDoNotFold)) {
}
~LexerHTML() override {
}
void SCI_METHOD Release() override {
delete this;
}
const char *SCI_METHOD PropertyNames() override {
return osHTML.PropertyNames();
}
int SCI_METHOD PropertyType(const char *name) override {
return osHTML.PropertyType(name);
}
const char *SCI_METHOD DescribeProperty(const char *name) override {
return osHTML.DescribeProperty(name);
}
Sci_Position SCI_METHOD PropertySet(const char *key, const char *val) override;
const char * SCI_METHOD PropertyGet(const char *key) override {
return osHTML.PropertyGet(key);
}
const char *SCI_METHOD DescribeWordListSets() override {
return osHTML.DescribeWordListSets();
}
Sci_Position SCI_METHOD WordListSet(int n, const char *wl) override;
void SCI_METHOD Lex(Sci_PositionU startPos, Sci_Position length, int initStyle, IDocument *pAccess) override;
// No Fold as all folding performs in Lex.
static ILexer *LexerFactoryHTML() {
return new LexerHTML(false, false);
}
static ILexer *LexerFactoryXML() {
return new LexerHTML(true, false);
}
static ILexer *LexerFactoryPHPScript() {
return new LexerHTML(false, true);
}
};
Sci_Position SCI_METHOD LexerHTML::PropertySet(const char *key, const char *val) {
if (osHTML.PropertySet(&options, key, val)) {
return 0;
}
return -1;
}
Sci_Position SCI_METHOD LexerHTML::WordListSet(int n, const char *wl) {
WordList *wordListN = 0;
switch (n) {
case 0:
wordListN = &keywords;
break;
case 1:
wordListN = &keywords2;
break;
case 2:
wordListN = &keywords3;
break;
case 3:
wordListN = &keywords4;
break;
case 4:
wordListN = &keywords5;
break;
case 5:
wordListN = &keywords6;
break;
}
Sci_Position firstModification = -1;
if (wordListN) {
WordList wlNew;
wlNew.Set(wl);
if (*wordListN != wlNew) {
wordListN->Set(wl);
firstModification = 0;
}
}
return firstModification;
}
void SCI_METHOD LexerHTML::Lex(Sci_PositionU startPos, Sci_Position length, int initStyle, IDocument *pAccess) {
Accessor styler(pAccess, nullptr);
if (isPHPScript && (startPos == 0)) {
initStyle = SCE_HPHP_DEFAULT;
}
styler.StartAt(startPos);
std::string prevWord;
std::string phpStringDelimiter;
int StateToPrint = initStyle;
int state = stateForPrintState(StateToPrint);
std::string makoBlockType;
int makoComment = 0;
std::string djangoBlockType;
// If inside a tag, it may be a script tag, so reread from the start of line starting tag to ensure any language tags are seen
if (InTagState(state)) {
while ((startPos > 0) && (InTagState(styler.StyleAt(startPos - 1)))) {
const Sci_Position backLineStart = styler.LineStart(styler.GetLine(startPos-1));
length += startPos - backLineStart;
startPos = backLineStart;
}
state = SCE_H_DEFAULT;
}
// String can be heredoc, must find a delimiter first. Reread from beginning of line containing the string, to get the correct lineState
if (isPHPStringState(state)) {
while (startPos > 0 && (isPHPStringState(state) || !isLineEnd(styler[startPos - 1]))) {
startPos--;
length++;
state = styler.StyleAt(startPos);
}
if (startPos == 0)
state = SCE_H_DEFAULT;
}
styler.StartAt(startPos);
/* Nothing handles getting out of these, so we need not start in any of them.
* As we're at line start and they can't span lines, we'll re-detect them anyway */
switch (state) {
case SCE_H_QUESTION:
case SCE_H_XMLSTART:
case SCE_H_XMLEND:
case SCE_H_ASP:
state = SCE_H_DEFAULT;
break;
}
Sci_Position lineCurrent = styler.GetLine(startPos);
int lineState;
if (lineCurrent > 0) {
lineState = styler.GetLineState(lineCurrent-1);
} else {
// Default client and ASP scripting language is JavaScript
lineState = eScriptJS << 8;
lineState |= options.aspDefaultLanguage << 4;
}
script_mode inScriptType = static_cast<script_mode>((lineState >> 0) & 0x03); // 2 bits of scripting mode
bool tagOpened = (lineState >> 2) & 0x01; // 1 bit to know if we are in an opened tag
bool tagClosing = (lineState >> 3) & 0x01; // 1 bit to know if we are in a closing tag
bool tagDontFold = false; //some HTML tags should not be folded
script_type aspScript = static_cast<script_type>((lineState >> 4) & 0x0F); // 4 bits of script name
script_type clientScript = static_cast<script_type>((lineState >> 8) & 0x0F); // 4 bits of script name
int beforePreProc = (lineState >> 12) & 0xFF; // 8 bits of state
script_type scriptLanguage = ScriptOfState(state);
// If eNonHtmlScript coincides with SCE_H_COMMENT, assume eScriptComment
if (inScriptType == eNonHtmlScript && state == SCE_H_COMMENT) {
scriptLanguage = eScriptComment;
}
script_type beforeLanguage = ScriptOfState(beforePreProc);
const bool foldHTML = options.foldHTML;
const bool fold = foldHTML && options.fold;
const bool foldHTMLPreprocessor = foldHTML && options.foldHTMLPreprocessor;
const bool foldCompact = options.foldCompact;
const bool foldComment = fold && options.foldComment;
const bool foldHeredoc = fold && options.foldHeredoc;
const bool foldXmlAtTagOpen = isXml && fold && options.foldXmlAtTagOpen;
const bool caseSensitive = options.caseSensitive;
const bool allowScripts = options.allowScripts;
const bool isMako = options.isMako;
const bool isDjango = options.isDjango;
const CharacterSet setHTMLWord(CharacterSet::setAlphaNum, ".-_:!#", 0x80, true);
const CharacterSet setTagContinue(CharacterSet::setAlphaNum, ".-_:!#[", 0x80, true);
const CharacterSet setAttributeContinue(CharacterSet::setAlphaNum, ".-_:!#/", 0x80, true);
// TODO: also handle + and - (except if they're part of ++ or --) and return keywords
const CharacterSet setOKBeforeJSRE(CharacterSet::setNone, "([{=,:;!%^&*|?~");
int levelPrev = styler.LevelAt(lineCurrent) & SC_FOLDLEVELNUMBERMASK;
int levelCurrent = levelPrev;
int visibleChars = 0;
int lineStartVisibleChars = 0;
int chPrev = ' ';
int ch = ' ';
int chPrevNonWhite = ' ';
// look back to set chPrevNonWhite properly for better regex colouring
if (scriptLanguage == eScriptJS && startPos > 0) {
Sci_Position back = startPos;
int style = 0;
while (--back) {
style = styler.StyleAt(back);
if (style < SCE_HJ_DEFAULT || style > SCE_HJ_COMMENTDOC)
// includes SCE_HJ_COMMENT & SCE_HJ_COMMENTLINE
break;
}
if (style == SCE_HJ_SYMBOLS) {
chPrevNonWhite = static_cast<unsigned char>(styler.SafeGetCharAt(back));
}
}
styler.StartSegment(startPos);
const Sci_Position lengthDoc = startPos + length;
for (Sci_Position i = startPos; i < lengthDoc; i++) {
const int chPrev2 = chPrev;
chPrev = ch;
if (!IsASpace(ch) && state != SCE_HJ_COMMENT &&
state != SCE_HJ_COMMENTLINE && state != SCE_HJ_COMMENTDOC)
chPrevNonWhite = ch;
ch = static_cast<unsigned char>(styler[i]);
int chNext = static_cast<unsigned char>(styler.SafeGetCharAt(i + 1));
const int chNext2 = static_cast<unsigned char>(styler.SafeGetCharAt(i + 2));
// Handle DBCS codepages
if (styler.IsLeadByte(static_cast<char>(ch))) {
chPrev = ' ';
i += 1;
continue;
}
if ((!IsASpace(ch) || !foldCompact) && fold)
visibleChars++;
if (!IsASpace(ch))
lineStartVisibleChars++;
// decide what is the current state to print (depending of the script tag)
StateToPrint = statePrintForState(state, inScriptType);
// handle script folding
if (fold) {
switch (scriptLanguage) {
case eScriptJS:
case eScriptPHP:
//not currently supported case eScriptVBS:
if ((state != SCE_HPHP_COMMENT) && (state != SCE_HPHP_COMMENTLINE) && (state != SCE_HJ_COMMENT) && (state != SCE_HJ_COMMENTLINE) && (state != SCE_HJ_COMMENTDOC) && (!isStringState(state))) {
//Platform::DebugPrintf("state=%d, StateToPrint=%d, initStyle=%d\n", state, StateToPrint, initStyle);
//if ((state == SCE_HPHP_OPERATOR) || (state == SCE_HPHP_DEFAULT) || (state == SCE_HJ_SYMBOLS) || (state == SCE_HJ_START) || (state == SCE_HJ_DEFAULT)) {
if (ch == '#') {
Sci_Position j = i + 1;
while ((j < lengthDoc) && IsASpaceOrTab(styler.SafeGetCharAt(j))) {
j++;
}
if (styler.Match(j, "region") || styler.Match(j, "if")) {
levelCurrent++;
} else if (styler.Match(j, "end")) {
levelCurrent--;
}
} else if ((ch == '{') || (ch == '}') || (foldComment && (ch == '/') && (chNext == '*'))) {
levelCurrent += (((ch == '{') || (ch == '/')) ? 1 : -1);
}
} else if (((state == SCE_HPHP_COMMENT) || (state == SCE_HJ_COMMENT)) && foldComment && (ch == '*') && (chNext == '/')) {
levelCurrent--;
}
break;
case eScriptPython:
if (state != SCE_HP_COMMENTLINE && !isMako) {
if ((ch == ':') && ((chNext == '\n') || (chNext == '\r' && chNext2 == '\n'))) {
levelCurrent++;
} else if ((ch == '\n') && !((chNext == '\r') && (chNext2 == '\n')) && (chNext != '\n')) {
// check if the number of tabs is lower than the level
int Findlevel = (levelCurrent & ~SC_FOLDLEVELBASE) * 8;
for (Sci_Position j = 0; Findlevel > 0; j++) {
const char chTmp = styler.SafeGetCharAt(i + j + 1);
if (chTmp == '\t') {
Findlevel -= 8;
} else if (chTmp == ' ') {
Findlevel--;
} else {
break;
}
}
if (Findlevel > 0) {
levelCurrent -= Findlevel / 8;
if (Findlevel % 8)
levelCurrent--;
}
}
}
break;
default:
break;
}
}
if ((ch == '\r' && chNext != '\n') || (ch == '\n')) {
// Trigger on CR only (Mac style) or either on LF from CR+LF (Dos/Win) or on LF alone (Unix)
// Avoid triggering two times on Dos/Win
// New line -> record any line state onto /next/ line
if (fold) {
int lev = levelPrev;
if (visibleChars == 0)
lev |= SC_FOLDLEVELWHITEFLAG;
if ((levelCurrent > levelPrev) && (visibleChars > 0))
lev |= SC_FOLDLEVELHEADERFLAG;
styler.SetLevel(lineCurrent, lev);
visibleChars = 0;
levelPrev = levelCurrent;
}
styler.SetLineState(lineCurrent,
((inScriptType & 0x03) << 0) |
((tagOpened ? 1 : 0) << 2) |
((tagClosing ? 1 : 0) << 3) |
((aspScript & 0x0F) << 4) |
((clientScript & 0x0F) << 8) |
((beforePreProc & 0xFF) << 12));
lineCurrent++;
lineStartVisibleChars = 0;
}
// handle start of Mako comment line
if (isMako && ch == '#' && chNext == '#') {
makoComment = 1;
state = SCE_HP_COMMENTLINE;
}
// handle end of Mako comment line
else if (isMako && makoComment && (ch == '\r' || ch == '\n')) {
makoComment = 0;
styler.ColourTo(i - 1, StateToPrint);
if (scriptLanguage == eScriptPython) {
state = SCE_HP_DEFAULT;
} else {
state = SCE_H_DEFAULT;
}
}
// Allow falling through to mako handling code if newline is going to end a block
if (((ch == '\r' && chNext != '\n') || (ch == '\n')) &&
(!isMako || (makoBlockType != "%"))) {
}
// Ignore everything in mako comment until the line ends
else if (isMako && makoComment) {
}
// generic end of script processing
else if ((inScriptType == eNonHtmlScript) && (ch == '<') && (chNext == '/')) {
// Check if it's the end of the script tag (or any other HTML tag)
switch (state) {
// in these cases, you can embed HTML tags (to confirm !!!!!!!!!!!!!!!!!!!!!!)
case SCE_H_DOUBLESTRING:
case SCE_H_SINGLESTRING:
case SCE_HJ_COMMENT:
case SCE_HJ_COMMENTDOC:
//case SCE_HJ_COMMENTLINE: // removed as this is a common thing done to hide
// the end of script marker from some JS interpreters.
case SCE_HB_COMMENTLINE:
case SCE_HBA_COMMENTLINE:
case SCE_HJ_DOUBLESTRING:
case SCE_HJ_SINGLESTRING:
case SCE_HJ_REGEX:
case SCE_HB_STRING:
case SCE_HBA_STRING:
case SCE_HP_STRING:
case SCE_HP_TRIPLE:
case SCE_HP_TRIPLEDOUBLE:
case SCE_HPHP_HSTRING:
case SCE_HPHP_SIMPLESTRING:
case SCE_HPHP_COMMENT:
case SCE_HPHP_COMMENTLINE:
break;
default :
// check if the closing tag is a script tag
if (const char *tag =
state == SCE_HJ_COMMENTLINE || isXml ? "script" :
state == SCE_H_COMMENT ? "comment" : 0) {
Sci_Position j = i + 2;
int chr;
do {
chr = static_cast<int>(*tag++);
} while (chr != 0 && chr == MakeLowerCase(styler.SafeGetCharAt(j++)));
if (chr != 0) break;
}
// closing tag of the script (it's a closing HTML tag anyway)
styler.ColourTo(i - 1, StateToPrint);
state = SCE_H_TAGUNKNOWN;
inScriptType = eHtml;
scriptLanguage = eScriptNone;
clientScript = eScriptJS;
i += 2;
visibleChars += 2;
tagClosing = true;
if (foldXmlAtTagOpen) {
levelCurrent--;
}
continue;
}
}
/////////////////////////////////////
// handle the start of PHP pre-processor = Non-HTML
else if ((state != SCE_H_ASPAT) &&
!isStringState(state) &&
(state != SCE_HPHP_COMMENT) &&
(state != SCE_HPHP_COMMENTLINE) &&
(ch == '<') &&
(chNext == '?') &&
!IsScriptCommentState(state)) {
beforeLanguage = scriptLanguage;
scriptLanguage = segIsScriptingIndicator(styler, i + 2, i + 6, isXml ? eScriptXML : eScriptPHP);
if ((scriptLanguage != eScriptPHP) && (isStringState(state) || (state==SCE_H_COMMENT))) continue;
styler.ColourTo(i - 1, StateToPrint);
beforePreProc = state;
i++;
visibleChars++;
i += PrintScriptingIndicatorOffset(styler, styler.GetStartSegment() + 2, i + 6);
if (scriptLanguage == eScriptXML)
styler.ColourTo(i, SCE_H_XMLSTART);
else
styler.ColourTo(i, SCE_H_QUESTION);
state = StateForScript(scriptLanguage);
if (inScriptType == eNonHtmlScript)
inScriptType = eNonHtmlScriptPreProc;
else
inScriptType = eNonHtmlPreProc;
// Fold whole script, but not if the XML first tag (all XML-like tags in this case)
if (foldHTMLPreprocessor && (scriptLanguage != eScriptXML)) {
levelCurrent++;
}
// should be better
ch = static_cast<unsigned char>(styler.SafeGetCharAt(i));
continue;
}
// handle the start Mako template Python code
else if (isMako && scriptLanguage == eScriptNone && ((ch == '<' && chNext == '%') ||
(lineStartVisibleChars == 1 && ch == '%') ||
(lineStartVisibleChars == 1 && ch == '/' && chNext == '%') ||
(ch == '$' && chNext == '{') ||
(ch == '<' && chNext == '/' && chNext2 == '%'))) {
if (ch == '%' || ch == '/')
makoBlockType = "%";
else if (ch == '$')
makoBlockType = "{";
else if (chNext == '/')
makoBlockType = GetNextWord(styler, i+3);
else
makoBlockType = GetNextWord(styler, i+2);
styler.ColourTo(i - 1, StateToPrint);
beforePreProc = state;
if (inScriptType == eNonHtmlScript)
inScriptType = eNonHtmlScriptPreProc;
else
inScriptType = eNonHtmlPreProc;
if (chNext == '/') {
i += 2;
visibleChars += 2;
} else if (ch != '%') {
i++;
visibleChars++;
}
state = SCE_HP_START;
scriptLanguage = eScriptPython;
styler.ColourTo(i, SCE_H_ASP);
if (ch != '%' && ch != '$' && ch != '/') {
i += makoBlockType.length();
visibleChars += static_cast<int>(makoBlockType.length());
if (keywords4.InList(makoBlockType.c_str()))
styler.ColourTo(i, SCE_HP_WORD);
else
styler.ColourTo(i, SCE_H_TAGUNKNOWN);
}
ch = static_cast<unsigned char>(styler.SafeGetCharAt(i));
continue;
}
// handle the start/end of Django comment
else if (isDjango && state != SCE_H_COMMENT && (ch == '{' && chNext == '#')) {
styler.ColourTo(i - 1, StateToPrint);
beforePreProc = state;
beforeLanguage = scriptLanguage;
if (inScriptType == eNonHtmlScript)
inScriptType = eNonHtmlScriptPreProc;
else
inScriptType = eNonHtmlPreProc;
i += 1;
visibleChars += 1;
scriptLanguage = eScriptComment;
state = SCE_H_COMMENT;
styler.ColourTo(i, SCE_H_ASP);
ch = static_cast<unsigned char>(styler.SafeGetCharAt(i));
continue;
} else if (isDjango && state == SCE_H_COMMENT && (ch == '#' && chNext == '}')) {
styler.ColourTo(i - 1, StateToPrint);
i += 1;
visibleChars += 1;
styler.ColourTo(i, SCE_H_ASP);
state = beforePreProc;
if (inScriptType == eNonHtmlScriptPreProc)
inScriptType = eNonHtmlScript;
else
inScriptType = eHtml;
scriptLanguage = beforeLanguage;
continue;
}
// handle the start Django template code
else if (isDjango && scriptLanguage != eScriptPython && scriptLanguage != eScriptComment && (ch == '{' && (chNext == '%' || chNext == '{'))) {
if (chNext == '%')
djangoBlockType = "%";
else
djangoBlockType = "{";
styler.ColourTo(i - 1, StateToPrint);
beforePreProc = state;
if (inScriptType == eNonHtmlScript)
inScriptType = eNonHtmlScriptPreProc;
else
inScriptType = eNonHtmlPreProc;
i += 1;
visibleChars += 1;
state = SCE_HP_START;
beforeLanguage = scriptLanguage;
scriptLanguage = eScriptPython;
styler.ColourTo(i, SCE_H_ASP);
ch = static_cast<unsigned char>(styler.SafeGetCharAt(i));
continue;
}
// handle the start of ASP pre-processor = Non-HTML
else if (!isMako && !isDjango && !isCommentASPState(state) && (ch == '<') && (chNext == '%') && !isPHPStringState(state)) {
styler.ColourTo(i - 1, StateToPrint);
beforePreProc = state;
if (inScriptType == eNonHtmlScript)
inScriptType = eNonHtmlScriptPreProc;
else
inScriptType = eNonHtmlPreProc;
if (chNext2 == '@') {
i += 2; // place as if it was the second next char treated
visibleChars += 2;
state = SCE_H_ASPAT;
} else if ((chNext2 == '-') && (styler.SafeGetCharAt(i + 3) == '-')) {
styler.ColourTo(i + 3, SCE_H_ASP);
state = SCE_H_XCCOMMENT;
scriptLanguage = eScriptVBS;
continue;
} else {
if (chNext2 == '=') {
i += 2; // place as if it was the second next char treated
visibleChars += 2;
} else {
i++; // place as if it was the next char treated
visibleChars++;
}
state = StateForScript(aspScript);
}
scriptLanguage = eScriptVBS;
styler.ColourTo(i, SCE_H_ASP);
// fold whole script
if (foldHTMLPreprocessor)
levelCurrent++;
// should be better
ch = static_cast<unsigned char>(styler.SafeGetCharAt(i));
continue;
}
/////////////////////////////////////
// handle the start of SGML language (DTD)
else if (((scriptLanguage == eScriptNone) || (scriptLanguage == eScriptXML)) &&
(chPrev == '<') &&
(ch == '!') &&
(StateToPrint != SCE_H_CDATA) &&
(!IsCommentState(StateToPrint)) &&
(!IsScriptCommentState(StateToPrint))) {
beforePreProc = state;
styler.ColourTo(i - 2, StateToPrint);
if ((chNext == '-') && (chNext2 == '-')) {
state = SCE_H_COMMENT; // wait for a pending command
styler.ColourTo(i + 2, SCE_H_COMMENT);
i += 2; // follow styling after the --
} else if (isWordCdata(i + 1, i + 7, styler)) {
state = SCE_H_CDATA;
} else {
styler.ColourTo(i, SCE_H_SGML_DEFAULT); // <! is default
scriptLanguage = eScriptSGML;
state = SCE_H_SGML_COMMAND; // wait for a pending command
}
// fold whole tag (-- when closing the tag)
if (foldHTMLPreprocessor || state == SCE_H_COMMENT || state == SCE_H_CDATA)
levelCurrent++;
continue;
}
// handle the end of Mako Python code
else if (isMako &&
((inScriptType == eNonHtmlPreProc) || (inScriptType == eNonHtmlScriptPreProc)) &&
(scriptLanguage != eScriptNone) && stateAllowsTermination(state) &&
isMakoBlockEnd(ch, chNext, makoBlockType)) {
if (state == SCE_H_ASPAT) {
aspScript = segIsScriptingIndicator(styler,
styler.GetStartSegment(), i - 1, aspScript);
}
if (state == SCE_HP_WORD) {
classifyWordHTPy(styler.GetStartSegment(), i - 1, keywords4, styler, prevWord, inScriptType, isMako);
} else {
styler.ColourTo(i - 1, StateToPrint);
}
if ((makoBlockType != "%") && (makoBlockType != "{") && ch != '>') {
i++;
visibleChars++;
}
else if ((makoBlockType == "%") && ch == '/') {
i++;
visibleChars++;
}
if ((makoBlockType != "%") || ch == '/') {
styler.ColourTo(i, SCE_H_ASP);
}
state = beforePreProc;
if (inScriptType == eNonHtmlScriptPreProc)
inScriptType = eNonHtmlScript;
else
inScriptType = eHtml;
scriptLanguage = eScriptNone;
continue;
}
// handle the end of Django template code
else if (isDjango &&
((inScriptType == eNonHtmlPreProc) || (inScriptType == eNonHtmlScriptPreProc)) &&
(scriptLanguage != eScriptNone) && stateAllowsTermination(state) &&
isDjangoBlockEnd(ch, chNext, djangoBlockType)) {
if (state == SCE_H_ASPAT) {
aspScript = segIsScriptingIndicator(styler,
styler.GetStartSegment(), i - 1, aspScript);
}
if (state == SCE_HP_WORD) {
classifyWordHTPy(styler.GetStartSegment(), i - 1, keywords4, styler, prevWord, inScriptType, isMako);
} else {
styler.ColourTo(i - 1, StateToPrint);
}
i += 1;
visibleChars += 1;
styler.ColourTo(i, SCE_H_ASP);
state = beforePreProc;
if (inScriptType == eNonHtmlScriptPreProc)
inScriptType = eNonHtmlScript;
else
inScriptType = eHtml;
scriptLanguage = beforeLanguage;
continue;
}
// handle the end of a pre-processor = Non-HTML
else if ((!isMako && !isDjango && ((inScriptType == eNonHtmlPreProc) || (inScriptType == eNonHtmlScriptPreProc)) &&
(((scriptLanguage != eScriptNone) && stateAllowsTermination(state))) &&
(((ch == '%') || (ch == '?')) && (chNext == '>'))) ||
((scriptLanguage == eScriptSGML) && (ch == '>') && (state != SCE_H_SGML_COMMENT))) {
if (state == SCE_H_ASPAT) {
aspScript = segIsScriptingIndicator(styler,
styler.GetStartSegment(), i - 1, aspScript);
}
// Bounce out of any ASP mode
switch (state) {
case SCE_HJ_WORD:
classifyWordHTJS(styler.GetStartSegment(), i - 1, keywords2, styler, inScriptType);
break;
case SCE_HB_WORD:
classifyWordHTVB(styler.GetStartSegment(), i - 1, keywords3, styler, inScriptType);
break;
case SCE_HP_WORD:
classifyWordHTPy(styler.GetStartSegment(), i - 1, keywords4, styler, prevWord, inScriptType, isMako);
break;
case SCE_HPHP_WORD:
classifyWordHTPHP(styler.GetStartSegment(), i - 1, keywords5, styler);
break;
case SCE_H_XCCOMMENT:
styler.ColourTo(i - 1, state);
break;
default :
styler.ColourTo(i - 1, StateToPrint);
break;
}
if (scriptLanguage != eScriptSGML) {
i++;
visibleChars++;
}
if (ch == '%')
styler.ColourTo(i, SCE_H_ASP);
else if (scriptLanguage == eScriptXML)
styler.ColourTo(i, SCE_H_XMLEND);
else if (scriptLanguage == eScriptSGML)
styler.ColourTo(i, SCE_H_SGML_DEFAULT);
else
styler.ColourTo(i, SCE_H_QUESTION);
state = beforePreProc;
if (inScriptType == eNonHtmlScriptPreProc)
inScriptType = eNonHtmlScript;
else
inScriptType = eHtml;
// Unfold all scripting languages, except for XML tag
if (foldHTMLPreprocessor && (scriptLanguage != eScriptXML)) {
levelCurrent--;
}
scriptLanguage = beforeLanguage;
continue;
}
/////////////////////////////////////
switch (state) {
case SCE_H_DEFAULT:
if (ch == '<') {
// in HTML, fold on tag open and unfold on tag close
tagOpened = true;
tagClosing = (chNext == '/');
if (foldXmlAtTagOpen && !(chNext == '/' || chNext == '?' || chNext == '!' || chNext == '-' || chNext == '%')) {
levelCurrent++;
}
if (foldXmlAtTagOpen && chNext == '/') {
levelCurrent--;
}
styler.ColourTo(i - 1, StateToPrint);
if (chNext != '!')
state = SCE_H_TAGUNKNOWN;
} else if (ch == '&') {
styler.ColourTo(i - 1, SCE_H_DEFAULT);
state = SCE_H_ENTITY;
}
break;
case SCE_H_SGML_DEFAULT:
case SCE_H_SGML_BLOCK_DEFAULT:
// if (scriptLanguage == eScriptSGMLblock)
// StateToPrint = SCE_H_SGML_BLOCK_DEFAULT;
if (ch == '\"') {
styler.ColourTo(i - 1, StateToPrint);
state = SCE_H_SGML_DOUBLESTRING;
} else if (ch == '\'') {
styler.ColourTo(i - 1, StateToPrint);
state = SCE_H_SGML_SIMPLESTRING;
} else if ((ch == '-') && (chPrev == '-')) {
if (static_cast<Sci_Position>(styler.GetStartSegment()) <= (i - 2)) {
styler.ColourTo(i - 2, StateToPrint);
}
state = SCE_H_SGML_COMMENT;
} else if (IsASCII(ch) && isalpha(ch) && (chPrev == '%')) {
styler.ColourTo(i - 2, StateToPrint);
state = SCE_H_SGML_ENTITY;
} else if (ch == '#') {
styler.ColourTo(i - 1, StateToPrint);
state = SCE_H_SGML_SPECIAL;
} else if (ch == '[') {
styler.ColourTo(i - 1, StateToPrint);
scriptLanguage = eScriptSGMLblock;
state = SCE_H_SGML_BLOCK_DEFAULT;
} else if (ch == ']') {
if (scriptLanguage == eScriptSGMLblock) {
styler.ColourTo(i, StateToPrint);
scriptLanguage = eScriptSGML;
} else {
styler.ColourTo(i - 1, StateToPrint);
styler.ColourTo(i, SCE_H_SGML_ERROR);
}
state = SCE_H_SGML_DEFAULT;
} else if (scriptLanguage == eScriptSGMLblock) {
if ((ch == '!') && (chPrev == '<')) {
styler.ColourTo(i - 2, StateToPrint);
styler.ColourTo(i, SCE_H_SGML_DEFAULT);
state = SCE_H_SGML_COMMAND;
} else if (ch == '>') {
styler.ColourTo(i - 1, StateToPrint);
styler.ColourTo(i, SCE_H_SGML_DEFAULT);
}
}
break;
case SCE_H_SGML_COMMAND:
if ((ch == '-') && (chPrev == '-')) {
styler.ColourTo(i - 2, StateToPrint);
state = SCE_H_SGML_COMMENT;
} else if (!issgmlwordchar(ch)) {
if (isWordHSGML(styler.GetStartSegment(), i - 1, keywords6, styler)) {
styler.ColourTo(i - 1, StateToPrint);
state = SCE_H_SGML_1ST_PARAM;
} else {
state = SCE_H_SGML_ERROR;
}
}
break;
case SCE_H_SGML_1ST_PARAM:
// wait for the beginning of the word
if ((ch == '-') && (chPrev == '-')) {
if (scriptLanguage == eScriptSGMLblock) {
styler.ColourTo(i - 2, SCE_H_SGML_BLOCK_DEFAULT);
} else {
styler.ColourTo(i - 2, SCE_H_SGML_DEFAULT);
}
state = SCE_H_SGML_1ST_PARAM_COMMENT;
} else if (issgmlwordchar(ch)) {
if (scriptLanguage == eScriptSGMLblock) {
styler.ColourTo(i - 1, SCE_H_SGML_BLOCK_DEFAULT);
} else {
styler.ColourTo(i - 1, SCE_H_SGML_DEFAULT);
}
// find the length of the word
int size = 1;
while (setHTMLWord.Contains(static_cast<unsigned char>(styler.SafeGetCharAt(i + size))))
size++;
styler.ColourTo(i + size - 1, StateToPrint);
i += size - 1;
visibleChars += size - 1;
ch = static_cast<unsigned char>(styler.SafeGetCharAt(i));
if (scriptLanguage == eScriptSGMLblock) {
state = SCE_H_SGML_BLOCK_DEFAULT;
} else {
state = SCE_H_SGML_DEFAULT;
}
continue;
}
break;
case SCE_H_SGML_ERROR:
if ((ch == '-') && (chPrev == '-')) {
styler.ColourTo(i - 2, StateToPrint);
state = SCE_H_SGML_COMMENT;
}
break;
case SCE_H_SGML_DOUBLESTRING:
if (ch == '\"') {
styler.ColourTo(i, StateToPrint);
state = SCE_H_SGML_DEFAULT;
}
break;
case SCE_H_SGML_SIMPLESTRING:
if (ch == '\'') {
styler.ColourTo(i, StateToPrint);
state = SCE_H_SGML_DEFAULT;
}
break;
case SCE_H_SGML_COMMENT:
if ((ch == '-') && (chPrev == '-')) {
styler.ColourTo(i, StateToPrint);
state = SCE_H_SGML_DEFAULT;
}
break;
case SCE_H_CDATA:
if ((chPrev2 == ']') && (chPrev == ']') && (ch == '>')) {
styler.ColourTo(i, StateToPrint);
state = SCE_H_DEFAULT;
levelCurrent--;
}
break;
case SCE_H_COMMENT:
if ((scriptLanguage != eScriptComment) && (chPrev2 == '-') && (chPrev == '-') && (ch == '>')) {
styler.ColourTo(i, StateToPrint);
state = SCE_H_DEFAULT;
levelCurrent--;
}
break;
case SCE_H_SGML_1ST_PARAM_COMMENT:
if ((ch == '-') && (chPrev == '-')) {
styler.ColourTo(i, SCE_H_SGML_COMMENT);
state = SCE_H_SGML_1ST_PARAM;
}
break;
case SCE_H_SGML_SPECIAL:
if (!(IsASCII(ch) && isupper(ch))) {
styler.ColourTo(i - 1, StateToPrint);
if (isalnum(ch)) {
state = SCE_H_SGML_ERROR;
} else {
state = SCE_H_SGML_DEFAULT;
}
}
break;
case SCE_H_SGML_ENTITY:
if (ch == ';') {
styler.ColourTo(i, StateToPrint);
state = SCE_H_SGML_DEFAULT;
} else if (!(IsASCII(ch) && isalnum(ch)) && ch != '-' && ch != '.') {
styler.ColourTo(i, SCE_H_SGML_ERROR);
state = SCE_H_SGML_DEFAULT;
}
break;
case SCE_H_ENTITY:
if (ch == ';') {
styler.ColourTo(i, StateToPrint);
state = SCE_H_DEFAULT;
}
if (ch != '#' && !(IsASCII(ch) && isalnum(ch)) // Should check that '#' follows '&', but it is unlikely anyway...
&& ch != '.' && ch != '-' && ch != '_' && ch != ':') { // valid in XML
if (!IsASCII(ch)) // Possibly start of a multibyte character so don't allow this byte to be in entity style
styler.ColourTo(i-1, SCE_H_TAGUNKNOWN);
else
styler.ColourTo(i, SCE_H_TAGUNKNOWN);
state = SCE_H_DEFAULT;
}
break;
case SCE_H_TAGUNKNOWN:
if (!setTagContinue.Contains(ch) && !((ch == '/') && (chPrev == '<'))) {
int eClass = classifyTagHTML(styler.GetStartSegment(),
i - 1, keywords, styler, tagDontFold, caseSensitive, isXml, allowScripts, nonFoldingTags);
if (eClass == SCE_H_SCRIPT || eClass == SCE_H_COMMENT) {
if (!tagClosing) {
inScriptType = eNonHtmlScript;
scriptLanguage = eClass == SCE_H_SCRIPT ? clientScript : eScriptComment;
} else {
scriptLanguage = eScriptNone;
}
eClass = SCE_H_TAG;
}
if (ch == '>') {
styler.ColourTo(i, eClass);
if (inScriptType == eNonHtmlScript) {
state = StateForScript(scriptLanguage);
} else {
state = SCE_H_DEFAULT;
}
tagOpened = false;
if (!(foldXmlAtTagOpen || tagDontFold)) {
if (tagClosing) {
levelCurrent--;
} else {
levelCurrent++;
}
}
tagClosing = false;
} else if (ch == '/' && chNext == '>') {
if (eClass == SCE_H_TAGUNKNOWN) {
styler.ColourTo(i + 1, SCE_H_TAGUNKNOWN);
} else {
styler.ColourTo(i - 1, StateToPrint);
styler.ColourTo(i + 1, SCE_H_TAGEND);
}
i++;
ch = chNext;
state = SCE_H_DEFAULT;
tagOpened = false;
if (foldXmlAtTagOpen) {
levelCurrent--;
}
} else {
if (eClass != SCE_H_TAGUNKNOWN) {
if (eClass == SCE_H_SGML_DEFAULT) {
state = SCE_H_SGML_DEFAULT;
} else {
state = SCE_H_OTHER;
}
}
}
}
break;
case SCE_H_ATTRIBUTE:
if (!setAttributeContinue.Contains(ch)) {
if (inScriptType == eNonHtmlScript) {
const int scriptLanguagePrev = scriptLanguage;
clientScript = segIsScriptingIndicator(styler, styler.GetStartSegment(), i - 1, scriptLanguage);
scriptLanguage = clientScript;
if ((scriptLanguagePrev != scriptLanguage) && (scriptLanguage == eScriptNone))
inScriptType = eHtml;
}
classifyAttribHTML(styler.GetStartSegment(), i - 1, keywords, styler);
if (ch == '>') {
styler.ColourTo(i, SCE_H_TAG);
if (inScriptType == eNonHtmlScript) {
state = StateForScript(scriptLanguage);
} else {
state = SCE_H_DEFAULT;
}
tagOpened = false;
if (!(foldXmlAtTagOpen || tagDontFold)) {
if (tagClosing) {
levelCurrent--;
} else {
levelCurrent++;
}
}
tagClosing = false;
} else if (ch == '=') {
styler.ColourTo(i, SCE_H_OTHER);
state = SCE_H_VALUE;
} else {
state = SCE_H_OTHER;
}
}
break;
case SCE_H_OTHER:
if (ch == '>') {
styler.ColourTo(i - 1, StateToPrint);
styler.ColourTo(i, SCE_H_TAG);
if (inScriptType == eNonHtmlScript) {
state = StateForScript(scriptLanguage);
} else {
state = SCE_H_DEFAULT;
}
tagOpened = false;
if (!(foldXmlAtTagOpen || tagDontFold)) {
if (tagClosing) {
levelCurrent--;
} else {
levelCurrent++;
}
}
tagClosing = false;
} else if (ch == '\"') {
styler.ColourTo(i - 1, StateToPrint);
state = SCE_H_DOUBLESTRING;
} else if (ch == '\'') {
styler.ColourTo(i - 1, StateToPrint);
state = SCE_H_SINGLESTRING;
} else if (ch == '=') {
styler.ColourTo(i, StateToPrint);
state = SCE_H_VALUE;
} else if (ch == '/' && chNext == '>') {
styler.ColourTo(i - 1, StateToPrint);
styler.ColourTo(i + 1, SCE_H_TAGEND);
i++;
ch = chNext;
state = SCE_H_DEFAULT;
tagOpened = false;
if (foldXmlAtTagOpen) {
levelCurrent--;
}
} else if (ch == '?' && chNext == '>') {
styler.ColourTo(i - 1, StateToPrint);
styler.ColourTo(i + 1, SCE_H_XMLEND);
i++;
ch = chNext;
state = SCE_H_DEFAULT;
} else if (setHTMLWord.Contains(ch)) {
styler.ColourTo(i - 1, StateToPrint);
state = SCE_H_ATTRIBUTE;
}
break;
case SCE_H_DOUBLESTRING:
if (ch == '\"') {
if (inScriptType == eNonHtmlScript) {
scriptLanguage = segIsScriptingIndicator(styler, styler.GetStartSegment(), i, scriptLanguage);
}
styler.ColourTo(i, SCE_H_DOUBLESTRING);
state = SCE_H_OTHER;
}
break;
case SCE_H_SINGLESTRING:
if (ch == '\'') {
if (inScriptType == eNonHtmlScript) {
scriptLanguage = segIsScriptingIndicator(styler, styler.GetStartSegment(), i, scriptLanguage);
}
styler.ColourTo(i, SCE_H_SINGLESTRING);
state = SCE_H_OTHER;
}
break;
case SCE_H_VALUE:
if (!setHTMLWord.Contains(ch)) {
if (ch == '\"' && chPrev == '=') {
// Should really test for being first character
state = SCE_H_DOUBLESTRING;
} else if (ch == '\'' && chPrev == '=') {
state = SCE_H_SINGLESTRING;
} else {
if (IsNumber(styler.GetStartSegment(), styler)) {
styler.ColourTo(i - 1, SCE_H_NUMBER);
} else {
styler.ColourTo(i - 1, StateToPrint);
}
if (ch == '>') {
styler.ColourTo(i, SCE_H_TAG);
if (inScriptType == eNonHtmlScript) {
state = StateForScript(scriptLanguage);
} else {
state = SCE_H_DEFAULT;
}
tagOpened = false;
if (!tagDontFold) {
if (tagClosing) {
levelCurrent--;
} else {
levelCurrent++;
}
}
tagClosing = false;
} else {
state = SCE_H_OTHER;
}
}
}
break;
case SCE_HJ_DEFAULT:
case SCE_HJ_START:
case SCE_HJ_SYMBOLS:
if (IsAWordStart(ch)) {
styler.ColourTo(i - 1, StateToPrint);
state = SCE_HJ_WORD;
} else if (ch == '/' && chNext == '*') {
styler.ColourTo(i - 1, StateToPrint);
if (chNext2 == '*')
state = SCE_HJ_COMMENTDOC;
else
state = SCE_HJ_COMMENT;
if (chNext2 == '/') {
// Eat the * so it isn't used for the end of the comment
i++;
}
} else if (ch == '/' && chNext == '/') {
styler.ColourTo(i - 1, StateToPrint);
state = SCE_HJ_COMMENTLINE;
} else if (ch == '/' && setOKBeforeJSRE.Contains(chPrevNonWhite)) {
styler.ColourTo(i - 1, StateToPrint);
state = SCE_HJ_REGEX;
} else if (ch == '\"') {
styler.ColourTo(i - 1, StateToPrint);
state = SCE_HJ_DOUBLESTRING;
} else if (ch == '\'') {
styler.ColourTo(i - 1, StateToPrint);
state = SCE_HJ_SINGLESTRING;
} else if ((ch == '<') && (chNext == '!') && (chNext2 == '-') &&
styler.SafeGetCharAt(i + 3) == '-') {
styler.ColourTo(i - 1, StateToPrint);
state = SCE_HJ_COMMENTLINE;
} else if ((ch == '-') && (chNext == '-') && (chNext2 == '>')) {
styler.ColourTo(i - 1, StateToPrint);
state = SCE_HJ_COMMENTLINE;
i += 2;
} else if (IsOperator(ch)) {
styler.ColourTo(i - 1, StateToPrint);
styler.ColourTo(i, statePrintForState(SCE_HJ_SYMBOLS, inScriptType));
state = SCE_HJ_DEFAULT;
} else if ((ch == ' ') || (ch == '\t')) {
if (state == SCE_HJ_START) {
styler.ColourTo(i - 1, StateToPrint);
state = SCE_HJ_DEFAULT;
}
}
break;
case SCE_HJ_WORD:
if (!IsAWordChar(ch)) {
classifyWordHTJS(styler.GetStartSegment(), i - 1, keywords2, styler, inScriptType);
//styler.ColourTo(i - 1, eHTJSKeyword);
state = SCE_HJ_DEFAULT;
if (ch == '/' && chNext == '*') {
if (chNext2 == '*')
state = SCE_HJ_COMMENTDOC;
else
state = SCE_HJ_COMMENT;
} else if (ch == '/' && chNext == '/') {
state = SCE_HJ_COMMENTLINE;
} else if (ch == '\"') {
state = SCE_HJ_DOUBLESTRING;
} else if (ch == '\'') {
state = SCE_HJ_SINGLESTRING;
} else if ((ch == '-') && (chNext == '-') && (chNext2 == '>')) {
styler.ColourTo(i - 1, StateToPrint);
state = SCE_HJ_COMMENTLINE;
i += 2;
} else if (IsOperator(ch)) {
styler.ColourTo(i, statePrintForState(SCE_HJ_SYMBOLS, inScriptType));
state = SCE_HJ_DEFAULT;
}
}
break;
case SCE_HJ_COMMENT:
case SCE_HJ_COMMENTDOC:
if (ch == '/' && chPrev == '*') {
styler.ColourTo(i, StateToPrint);
state = SCE_HJ_DEFAULT;
ch = ' ';
}
break;
case SCE_HJ_COMMENTLINE:
if (ch == '\r' || ch == '\n') {
styler.ColourTo(i - 1, statePrintForState(SCE_HJ_COMMENTLINE, inScriptType));
state = SCE_HJ_DEFAULT;
ch = ' ';
}
break;
case SCE_HJ_DOUBLESTRING:
if (ch == '\\') {
if (chNext == '\"' || chNext == '\'' || chNext == '\\') {
i++;
}
} else if (ch == '\"') {
styler.ColourTo(i, statePrintForState(SCE_HJ_DOUBLESTRING, inScriptType));
state = SCE_HJ_DEFAULT;
} else if ((inScriptType == eNonHtmlScript) && (ch == '-') && (chNext == '-') && (chNext2 == '>')) {
styler.ColourTo(i - 1, StateToPrint);
state = SCE_HJ_COMMENTLINE;
i += 2;
} else if (isLineEnd(ch)) {
styler.ColourTo(i - 1, StateToPrint);
state = SCE_HJ_STRINGEOL;
}
break;
case SCE_HJ_SINGLESTRING:
if (ch == '\\') {
if (chNext == '\"' || chNext == '\'' || chNext == '\\') {
i++;
}
} else if (ch == '\'') {
styler.ColourTo(i, statePrintForState(SCE_HJ_SINGLESTRING, inScriptType));
state = SCE_HJ_DEFAULT;
} else if ((inScriptType == eNonHtmlScript) && (ch == '-') && (chNext == '-') && (chNext2 == '>')) {
styler.ColourTo(i - 1, StateToPrint);
state = SCE_HJ_COMMENTLINE;
i += 2;
} else if (isLineEnd(ch)) {
styler.ColourTo(i - 1, StateToPrint);
if (chPrev != '\\' && (chPrev2 != '\\' || chPrev != '\r' || ch != '\n')) {
state = SCE_HJ_STRINGEOL;
}
}
break;
case SCE_HJ_STRINGEOL:
if (!isLineEnd(ch)) {
styler.ColourTo(i - 1, StateToPrint);
state = SCE_HJ_DEFAULT;
} else if (!isLineEnd(chNext)) {
styler.ColourTo(i, StateToPrint);
state = SCE_HJ_DEFAULT;
}
break;
case SCE_HJ_REGEX:
if (ch == '\r' || ch == '\n' || ch == '/') {
if (ch == '/') {
while (IsASCII(chNext) && islower(chNext)) { // gobble regex flags
i++;
ch = chNext;
chNext = static_cast<unsigned char>(styler.SafeGetCharAt(i + 1));
}
}
styler.ColourTo(i, StateToPrint);
state = SCE_HJ_DEFAULT;
} else if (ch == '\\') {
// Gobble up the quoted character
if (chNext == '\\' || chNext == '/') {
i++;
ch = chNext;
chNext = static_cast<unsigned char>(styler.SafeGetCharAt(i + 1));
}
}
break;
case SCE_HB_DEFAULT:
case SCE_HB_START:
if (IsAWordStart(ch)) {
styler.ColourTo(i - 1, StateToPrint);
state = SCE_HB_WORD;
} else if (ch == '\'') {
styler.ColourTo(i - 1, StateToPrint);
state = SCE_HB_COMMENTLINE;
} else if (ch == '\"') {
styler.ColourTo(i - 1, StateToPrint);
state = SCE_HB_STRING;
} else if ((ch == '<') && (chNext == '!') && (chNext2 == '-') &&
styler.SafeGetCharAt(i + 3) == '-') {
styler.ColourTo(i - 1, StateToPrint);
state = SCE_HB_COMMENTLINE;
} else if (IsOperator(ch)) {
styler.ColourTo(i - 1, StateToPrint);
styler.ColourTo(i, statePrintForState(SCE_HB_DEFAULT, inScriptType));
state = SCE_HB_DEFAULT;
} else if ((ch == ' ') || (ch == '\t')) {
if (state == SCE_HB_START) {
styler.ColourTo(i - 1, StateToPrint);
state = SCE_HB_DEFAULT;
}
}
break;
case SCE_HB_WORD:
if (!IsAWordChar(ch)) {
state = classifyWordHTVB(styler.GetStartSegment(), i - 1, keywords3, styler, inScriptType);
if (state == SCE_HB_DEFAULT) {
if (ch == '\"') {
state = SCE_HB_STRING;
} else if (ch == '\'') {
state = SCE_HB_COMMENTLINE;
} else if (IsOperator(ch)) {
styler.ColourTo(i, statePrintForState(SCE_HB_DEFAULT, inScriptType));
state = SCE_HB_DEFAULT;
}
}
}
break;
case SCE_HB_STRING:
if (ch == '\"') {
styler.ColourTo(i, StateToPrint);
state = SCE_HB_DEFAULT;
} else if (ch == '\r' || ch == '\n') {
styler.ColourTo(i - 1, StateToPrint);
state = SCE_HB_STRINGEOL;
}
break;
case SCE_HB_COMMENTLINE:
if (ch == '\r' || ch == '\n') {
styler.ColourTo(i - 1, StateToPrint);
state = SCE_HB_DEFAULT;
}
break;
case SCE_HB_STRINGEOL:
if (!isLineEnd(ch)) {
styler.ColourTo(i - 1, StateToPrint);
state = SCE_HB_DEFAULT;
} else if (!isLineEnd(chNext)) {
styler.ColourTo(i, StateToPrint);
state = SCE_HB_DEFAULT;
}
break;
case SCE_HP_DEFAULT:
case SCE_HP_START:
if (IsAWordStart(ch)) {
styler.ColourTo(i - 1, StateToPrint);
state = SCE_HP_WORD;
} else if ((ch == '<') && (chNext == '!') && (chNext2 == '-') &&
styler.SafeGetCharAt(i + 3) == '-') {
styler.ColourTo(i - 1, StateToPrint);
state = SCE_HP_COMMENTLINE;
} else if (ch == '#') {
styler.ColourTo(i - 1, StateToPrint);
state = SCE_HP_COMMENTLINE;
} else if (ch == '\"') {
styler.ColourTo(i - 1, StateToPrint);
if (chNext == '\"' && chNext2 == '\"') {
i += 2;
state = SCE_HP_TRIPLEDOUBLE;
ch = ' ';
chPrev = ' ';
chNext = static_cast<unsigned char>(styler.SafeGetCharAt(i + 1));
} else {
// state = statePrintForState(SCE_HP_STRING,inScriptType);
state = SCE_HP_STRING;
}
} else if (ch == '\'') {
styler.ColourTo(i - 1, StateToPrint);
if (chNext == '\'' && chNext2 == '\'') {
i += 2;
state = SCE_HP_TRIPLE;
ch = ' ';
chPrev = ' ';
chNext = static_cast<unsigned char>(styler.SafeGetCharAt(i + 1));
} else {
state = SCE_HP_CHARACTER;
}
} else if (IsOperator(ch)) {
styler.ColourTo(i - 1, StateToPrint);
styler.ColourTo(i, statePrintForState(SCE_HP_OPERATOR, inScriptType));
} else if ((ch == ' ') || (ch == '\t')) {
if (state == SCE_HP_START) {
styler.ColourTo(i - 1, StateToPrint);
state = SCE_HP_DEFAULT;
}
}
break;
case SCE_HP_WORD:
if (!IsAWordChar(ch)) {
classifyWordHTPy(styler.GetStartSegment(), i - 1, keywords4, styler, prevWord, inScriptType, isMako);
state = SCE_HP_DEFAULT;
if (ch == '#') {
state = SCE_HP_COMMENTLINE;
} else if (ch == '\"') {
if (chNext == '\"' && chNext2 == '\"') {
i += 2;
state = SCE_HP_TRIPLEDOUBLE;
ch = ' ';
chPrev = ' ';
chNext = static_cast<unsigned char>(styler.SafeGetCharAt(i + 1));
} else {
state = SCE_HP_STRING;
}
} else if (ch == '\'') {
if (chNext == '\'' && chNext2 == '\'') {
i += 2;
state = SCE_HP_TRIPLE;
ch = ' ';
chPrev = ' ';
chNext = static_cast<unsigned char>(styler.SafeGetCharAt(i + 1));
} else {
state = SCE_HP_CHARACTER;
}
} else if (IsOperator(ch)) {
styler.ColourTo(i, statePrintForState(SCE_HP_OPERATOR, inScriptType));
}
}
break;
case SCE_HP_COMMENTLINE:
if (ch == '\r' || ch == '\n') {
styler.ColourTo(i - 1, StateToPrint);
state = SCE_HP_DEFAULT;
}
break;
case SCE_HP_STRING:
if (ch == '\\') {
if (chNext == '\"' || chNext == '\'' || chNext == '\\') {
i++;
ch = chNext;
chNext = static_cast<unsigned char>(styler.SafeGetCharAt(i + 1));
}
} else if (ch == '\"') {
styler.ColourTo(i, StateToPrint);
state = SCE_HP_DEFAULT;
}
break;
case SCE_HP_CHARACTER:
if (ch == '\\') {
if (chNext == '\"' || chNext == '\'' || chNext == '\\') {
i++;
ch = chNext;
chNext = static_cast<unsigned char>(styler.SafeGetCharAt(i + 1));
}
} else if (ch == '\'') {
styler.ColourTo(i, StateToPrint);
state = SCE_HP_DEFAULT;
}
break;
case SCE_HP_TRIPLE:
if (ch == '\'' && chPrev == '\'' && chPrev2 == '\'') {
styler.ColourTo(i, StateToPrint);
state = SCE_HP_DEFAULT;
}
break;
case SCE_HP_TRIPLEDOUBLE:
if (ch == '\"' && chPrev == '\"' && chPrev2 == '\"') {
styler.ColourTo(i, StateToPrint);
state = SCE_HP_DEFAULT;
}
break;
///////////// start - PHP state handling
case SCE_HPHP_WORD:
if (!IsAWordChar(ch)) {
classifyWordHTPHP(styler.GetStartSegment(), i - 1, keywords5, styler);
if (ch == '/' && chNext == '*') {
i++;
state = SCE_HPHP_COMMENT;
} else if (ch == '/' && chNext == '/') {
i++;
state = SCE_HPHP_COMMENTLINE;
} else if (ch == '#') {
state = SCE_HPHP_COMMENTLINE;
} else if (ch == '\"') {
state = SCE_HPHP_HSTRING;
phpStringDelimiter = "\"";
} else if (styler.Match(i, "<<<")) {
bool isSimpleString = false;
i = FindPhpStringDelimiter(phpStringDelimiter, i + 3, lengthDoc, styler, isSimpleString);
if (!phpStringDelimiter.empty()) {
state = (isSimpleString ? SCE_HPHP_SIMPLESTRING : SCE_HPHP_HSTRING);
if (foldHeredoc) levelCurrent++;
}
} else if (ch == '\'') {
state = SCE_HPHP_SIMPLESTRING;
phpStringDelimiter = "\'";
} else if (ch == '$' && IsPhpWordStart(chNext)) {
state = SCE_HPHP_VARIABLE;
} else if (IsOperator(ch)) {
state = SCE_HPHP_OPERATOR;
} else {
state = SCE_HPHP_DEFAULT;
}
}
break;
case SCE_HPHP_NUMBER:
// recognize bases 8,10 or 16 integers OR floating-point numbers
if (!IsADigit(ch)
&& strchr(".xXabcdefABCDEF", ch) == NULL
&& ((ch != '-' && ch != '+') || (chPrev != 'e' && chPrev != 'E'))) {
styler.ColourTo(i - 1, SCE_HPHP_NUMBER);
if (IsOperator(ch))
state = SCE_HPHP_OPERATOR;
else
state = SCE_HPHP_DEFAULT;
}
break;
case SCE_HPHP_VARIABLE:
if (!IsPhpWordChar(chNext)) {
styler.ColourTo(i, SCE_HPHP_VARIABLE);
state = SCE_HPHP_DEFAULT;
}
break;
case SCE_HPHP_COMMENT:
if (ch == '/' && chPrev == '*') {
styler.ColourTo(i, StateToPrint);
state = SCE_HPHP_DEFAULT;
}
break;
case SCE_HPHP_COMMENTLINE:
if (ch == '\r' || ch == '\n') {
styler.ColourTo(i - 1, StateToPrint);
state = SCE_HPHP_DEFAULT;
}
break;
case SCE_HPHP_HSTRING:
if (ch == '\\' && ((phpStringDelimiter == "\"") || chNext == '$' || chNext == '{')) {
// skip the next char
i++;
} else if (((ch == '{' && chNext == '$') || (ch == '$' && chNext == '{'))
&& IsPhpWordStart(chNext2)) {
styler.ColourTo(i - 1, StateToPrint);
state = SCE_HPHP_COMPLEX_VARIABLE;
} else if (ch == '$' && IsPhpWordStart(chNext)) {
styler.ColourTo(i - 1, StateToPrint);
state = SCE_HPHP_HSTRING_VARIABLE;
} else if (styler.Match(i, phpStringDelimiter.c_str())) {
if (phpStringDelimiter == "\"") {
styler.ColourTo(i, StateToPrint);
state = SCE_HPHP_DEFAULT;
} else if (isLineEnd(chPrev)) {
const int psdLength = static_cast<int>(phpStringDelimiter.length());
const char chAfterPsd = styler.SafeGetCharAt(i + psdLength);
const char chAfterPsd2 = styler.SafeGetCharAt(i + psdLength + 1);
if (isLineEnd(chAfterPsd) ||
(chAfterPsd == ';' && isLineEnd(chAfterPsd2))) {
i += (((i + psdLength) < lengthDoc) ? psdLength : lengthDoc) - 1;
styler.ColourTo(i, StateToPrint);
state = SCE_HPHP_DEFAULT;
if (foldHeredoc) levelCurrent--;
}
}
}
break;
case SCE_HPHP_SIMPLESTRING:
if (phpStringDelimiter == "\'") {
if (ch == '\\') {
// skip the next char
i++;
} else if (ch == '\'') {
styler.ColourTo(i, StateToPrint);
state = SCE_HPHP_DEFAULT;
}
} else if (isLineEnd(chPrev) && styler.Match(i, phpStringDelimiter.c_str())) {
const int psdLength = static_cast<int>(phpStringDelimiter.length());
const char chAfterPsd = styler.SafeGetCharAt(i + psdLength);
const char chAfterPsd2 = styler.SafeGetCharAt(i + psdLength + 1);
if (isLineEnd(chAfterPsd) ||
(chAfterPsd == ';' && isLineEnd(chAfterPsd2))) {
i += (((i + psdLength) < lengthDoc) ? psdLength : lengthDoc) - 1;
styler.ColourTo(i, StateToPrint);
state = SCE_HPHP_DEFAULT;
if (foldHeredoc) levelCurrent--;
}
}
break;
case SCE_HPHP_HSTRING_VARIABLE:
if (!IsPhpWordChar(chNext)) {
styler.ColourTo(i, StateToPrint);
state = SCE_HPHP_HSTRING;
}
break;
case SCE_HPHP_COMPLEX_VARIABLE:
if (ch == '}') {
styler.ColourTo(i, StateToPrint);
state = SCE_HPHP_HSTRING;
}
break;
case SCE_HPHP_OPERATOR:
case SCE_HPHP_DEFAULT:
styler.ColourTo(i - 1, StateToPrint);
if (IsADigit(ch) || (ch == '.' && IsADigit(chNext))) {
state = SCE_HPHP_NUMBER;
} else if (IsAWordStart(ch)) {
state = SCE_HPHP_WORD;
} else if (ch == '/' && chNext == '*') {
i++;
state = SCE_HPHP_COMMENT;
} else if (ch == '/' && chNext == '/') {
i++;
state = SCE_HPHP_COMMENTLINE;
} else if (ch == '#') {
state = SCE_HPHP_COMMENTLINE;
} else if (ch == '\"') {
state = SCE_HPHP_HSTRING;
phpStringDelimiter = "\"";
} else if (styler.Match(i, "<<<")) {
bool isSimpleString = false;
i = FindPhpStringDelimiter(phpStringDelimiter, i + 3, lengthDoc, styler, isSimpleString);
if (!phpStringDelimiter.empty()) {
state = (isSimpleString ? SCE_HPHP_SIMPLESTRING : SCE_HPHP_HSTRING);
if (foldHeredoc) levelCurrent++;
}
} else if (ch == '\'') {
state = SCE_HPHP_SIMPLESTRING;
phpStringDelimiter = "\'";
} else if (ch == '$' && IsPhpWordStart(chNext)) {
state = SCE_HPHP_VARIABLE;
} else if (IsOperator(ch)) {
state = SCE_HPHP_OPERATOR;
} else if ((state == SCE_HPHP_OPERATOR) && (IsASpace(ch))) {
state = SCE_HPHP_DEFAULT;
}
break;
///////////// end - PHP state handling
}
// Some of the above terminated their lexeme but since the same character starts
// the same class again, only reenter if non empty segment.
const bool nonEmptySegment = i >= static_cast<Sci_Position>(styler.GetStartSegment());
if (state == SCE_HB_DEFAULT) { // One of the above succeeded
if ((ch == '\"') && (nonEmptySegment)) {
state = SCE_HB_STRING;
} else if (ch == '\'') {
state = SCE_HB_COMMENTLINE;
} else if (IsAWordStart(ch)) {
state = SCE_HB_WORD;
} else if (IsOperator(ch)) {
styler.ColourTo(i, SCE_HB_DEFAULT);
}
} else if (state == SCE_HBA_DEFAULT) { // One of the above succeeded
if ((ch == '\"') && (nonEmptySegment)) {
state = SCE_HBA_STRING;
} else if (ch == '\'') {
state = SCE_HBA_COMMENTLINE;
} else if (IsAWordStart(ch)) {
state = SCE_HBA_WORD;
} else if (IsOperator(ch)) {
styler.ColourTo(i, SCE_HBA_DEFAULT);
}
} else if (state == SCE_HJ_DEFAULT) { // One of the above succeeded
if (ch == '/' && chNext == '*') {
if (styler.SafeGetCharAt(i + 2) == '*')
state = SCE_HJ_COMMENTDOC;
else
state = SCE_HJ_COMMENT;
} else if (ch == '/' && chNext == '/') {
state = SCE_HJ_COMMENTLINE;
} else if ((ch == '\"') && (nonEmptySegment)) {
state = SCE_HJ_DOUBLESTRING;
} else if ((ch == '\'') && (nonEmptySegment)) {
state = SCE_HJ_SINGLESTRING;
} else if (IsAWordStart(ch)) {
state = SCE_HJ_WORD;
} else if (IsOperator(ch)) {
styler.ColourTo(i, statePrintForState(SCE_HJ_SYMBOLS, inScriptType));
}
}
}
switch (state) {
case SCE_HJ_WORD:
classifyWordHTJS(styler.GetStartSegment(), lengthDoc - 1, keywords2, styler, inScriptType);
break;
case SCE_HB_WORD:
classifyWordHTVB(styler.GetStartSegment(), lengthDoc - 1, keywords3, styler, inScriptType);
break;
case SCE_HP_WORD:
classifyWordHTPy(styler.GetStartSegment(), lengthDoc - 1, keywords4, styler, prevWord, inScriptType, isMako);
break;
case SCE_HPHP_WORD:
classifyWordHTPHP(styler.GetStartSegment(), lengthDoc - 1, keywords5, styler);
break;
default:
StateToPrint = statePrintForState(state, inScriptType);
if (static_cast<Sci_Position>(styler.GetStartSegment()) < lengthDoc)
styler.ColourTo(lengthDoc - 1, StateToPrint);
break;
}
// Fill in the real level of the next line, keeping the current flags as they will be filled in later
if (fold) {
const int flagsNext = styler.LevelAt(lineCurrent) & ~SC_FOLDLEVELNUMBERMASK;
styler.SetLevel(lineCurrent, levelPrev | flagsNext);
}
styler.Flush();
}
LexerModule lmHTML(SCLEX_HTML, LexerHTML::LexerFactoryHTML, "hypertext", htmlWordListDesc);
LexerModule lmXML(SCLEX_XML, LexerHTML::LexerFactoryXML, "xml", htmlWordListDesc);
LexerModule lmPHPSCRIPT(SCLEX_PHPSCRIPT, LexerHTML::LexerFactoryPHPScript, "phpscript", phpscriptWordListDesc);
|