PageRenderTime 65ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 1ms

/scintilla/lexers/LexHTML.cxx

https://github.com/cezary12/notepad2-mod
C++ | 2184 lines | 1952 code | 119 blank | 113 comment | 1444 complexity | 88d00d6c6888a757dc4386a8b09e7a8a MD5 | raw file
Possible License(s): BSD-3-Clause
  1. // Scintilla source code edit control
  2. /** @file LexHTML.cxx
  3. ** Lexer for HTML.
  4. **/
  5. // Copyright 1998-2005 by Neil Hodgson <neilh@scintilla.org>
  6. // The License.txt file describes the conditions under which this software may be distributed.
  7. #include <stdlib.h>
  8. #include <string.h>
  9. #include <stdio.h>
  10. #include <stdarg.h>
  11. #include <assert.h>
  12. #include <ctype.h>
  13. #include "ILexer.h"
  14. #include "Scintilla.h"
  15. #include "SciLexer.h"
  16. #include "StringCopy.h"
  17. #include "WordList.h"
  18. #include "LexAccessor.h"
  19. #include "Accessor.h"
  20. #include "StyleContext.h"
  21. #include "CharacterSet.h"
  22. #include "LexerModule.h"
  23. #ifdef SCI_NAMESPACE
  24. using namespace Scintilla;
  25. #endif
  26. #define SCE_HA_JS (SCE_HJA_START - SCE_HJ_START)
  27. #define SCE_HA_VBS (SCE_HBA_START - SCE_HB_START)
  28. #define SCE_HA_PYTHON (SCE_HPA_START - SCE_HP_START)
  29. enum script_type { eScriptNone = 0, eScriptJS, eScriptVBS, eScriptPython, eScriptPHP, eScriptXML, eScriptSGML, eScriptSGMLblock, eScriptComment };
  30. enum script_mode { eHtml = 0, eNonHtmlScript, eNonHtmlPreProc, eNonHtmlScriptPreProc };
  31. static inline bool IsAWordChar(const int ch) {
  32. return (ch < 0x80) && (isalnum(ch) || ch == '.' || ch == '_');
  33. }
  34. static inline bool IsAWordStart(const int ch) {
  35. return (ch < 0x80) && (isalnum(ch) || ch == '_');
  36. }
  37. inline bool IsOperator(int ch) {
  38. if (IsASCII(ch) && isalnum(ch))
  39. return false;
  40. // '.' left out as it is used to make up numbers
  41. if (ch == '%' || ch == '^' || ch == '&' || ch == '*' ||
  42. ch == '(' || ch == ')' || ch == '-' || ch == '+' ||
  43. ch == '=' || ch == '|' || ch == '{' || ch == '}' ||
  44. ch == '[' || ch == ']' || ch == ':' || ch == ';' ||
  45. ch == '<' || ch == '>' || ch == ',' || ch == '/' ||
  46. ch == '?' || ch == '!' || ch == '.' || ch == '~')
  47. return true;
  48. return false;
  49. }
  50. static void GetTextSegment(Accessor &styler, unsigned int start, unsigned int end, char *s, size_t len) {
  51. unsigned int i = 0;
  52. for (; (i < end - start + 1) && (i < len-1); i++) {
  53. s[i] = static_cast<char>(MakeLowerCase(styler[start + i]));
  54. }
  55. s[i] = '\0';
  56. }
  57. static const char *GetNextWord(Accessor &styler, unsigned int start, char *s, size_t sLen) {
  58. unsigned int i = 0;
  59. for (; i < sLen-1; i++) {
  60. char ch = static_cast<char>(styler.SafeGetCharAt(start + i));
  61. if ((i == 0) && !IsAWordStart(ch))
  62. break;
  63. if ((i > 0) && !IsAWordChar(ch))
  64. break;
  65. s[i] = ch;
  66. }
  67. s[i] = '\0';
  68. return s;
  69. }
  70. static script_type segIsScriptingIndicator(Accessor &styler, unsigned int start, unsigned int end, script_type prevValue) {
  71. char s[100];
  72. GetTextSegment(styler, start, end, s, sizeof(s));
  73. //Platform::DebugPrintf("Scripting indicator [%s]\n", s);
  74. if (strstr(s, "src")) // External script
  75. return eScriptNone;
  76. if (strstr(s, "vbs"))
  77. return eScriptVBS;
  78. if (strstr(s, "pyth"))
  79. return eScriptPython;
  80. if (strstr(s, "javas"))
  81. return eScriptJS;
  82. if (strstr(s, "jscr"))
  83. return eScriptJS;
  84. if (strstr(s, "php"))
  85. return eScriptPHP;
  86. if (strstr(s, "xml")) {
  87. const char *xml = strstr(s, "xml");
  88. for (const char *t=s; t<xml; t++) {
  89. if (!IsASpace(*t)) {
  90. return prevValue;
  91. }
  92. }
  93. return eScriptXML;
  94. }
  95. return prevValue;
  96. }
  97. static int PrintScriptingIndicatorOffset(Accessor &styler, unsigned int start, unsigned int end) {
  98. int iResult = 0;
  99. char s[100];
  100. GetTextSegment(styler, start, end, s, sizeof(s));
  101. if (0 == strncmp(s, "php", 3)) {
  102. iResult = 3;
  103. }
  104. return iResult;
  105. }
  106. static script_type ScriptOfState(int state) {
  107. if ((state >= SCE_HP_START) && (state <= SCE_HP_IDENTIFIER)) {
  108. return eScriptPython;
  109. } else if ((state >= SCE_HB_START) && (state <= SCE_HB_STRINGEOL)) {
  110. return eScriptVBS;
  111. } else if ((state >= SCE_HJ_START) && (state <= SCE_HJ_REGEX)) {
  112. return eScriptJS;
  113. } else if ((state >= SCE_HPHP_DEFAULT) && (state <= SCE_HPHP_COMMENTLINE)) {
  114. return eScriptPHP;
  115. } else if ((state >= SCE_H_SGML_DEFAULT) && (state < SCE_H_SGML_BLOCK_DEFAULT)) {
  116. return eScriptSGML;
  117. } else if (state == SCE_H_SGML_BLOCK_DEFAULT) {
  118. return eScriptSGMLblock;
  119. } else {
  120. return eScriptNone;
  121. }
  122. }
  123. static int statePrintForState(int state, script_mode inScriptType) {
  124. int StateToPrint = state;
  125. if (state >= SCE_HJ_START) {
  126. if ((state >= SCE_HP_START) && (state <= SCE_HP_IDENTIFIER)) {
  127. StateToPrint = state + ((inScriptType == eNonHtmlScript) ? 0 : SCE_HA_PYTHON);
  128. } else if ((state >= SCE_HB_START) && (state <= SCE_HB_STRINGEOL)) {
  129. StateToPrint = state + ((inScriptType == eNonHtmlScript) ? 0 : SCE_HA_VBS);
  130. } else if ((state >= SCE_HJ_START) && (state <= SCE_HJ_REGEX)) {
  131. StateToPrint = state + ((inScriptType == eNonHtmlScript) ? 0 : SCE_HA_JS);
  132. }
  133. }
  134. return StateToPrint;
  135. }
  136. static int stateForPrintState(int StateToPrint) {
  137. int state;
  138. if ((StateToPrint >= SCE_HPA_START) && (StateToPrint <= SCE_HPA_IDENTIFIER)) {
  139. state = StateToPrint - SCE_HA_PYTHON;
  140. } else if ((StateToPrint >= SCE_HBA_START) && (StateToPrint <= SCE_HBA_STRINGEOL)) {
  141. state = StateToPrint - SCE_HA_VBS;
  142. } else if ((StateToPrint >= SCE_HJA_START) && (StateToPrint <= SCE_HJA_REGEX)) {
  143. state = StateToPrint - SCE_HA_JS;
  144. } else {
  145. state = StateToPrint;
  146. }
  147. return state;
  148. }
  149. static inline bool IsNumber(unsigned int start, Accessor &styler) {
  150. return IsADigit(styler[start]) || (styler[start] == '.') ||
  151. (styler[start] == '-') || (styler[start] == '#');
  152. }
  153. static inline bool isStringState(int state) {
  154. bool bResult;
  155. switch (state) {
  156. case SCE_HJ_DOUBLESTRING:
  157. case SCE_HJ_SINGLESTRING:
  158. case SCE_HJA_DOUBLESTRING:
  159. case SCE_HJA_SINGLESTRING:
  160. case SCE_HB_STRING:
  161. case SCE_HBA_STRING:
  162. case SCE_HP_STRING:
  163. case SCE_HP_CHARACTER:
  164. case SCE_HP_TRIPLE:
  165. case SCE_HP_TRIPLEDOUBLE:
  166. case SCE_HPA_STRING:
  167. case SCE_HPA_CHARACTER:
  168. case SCE_HPA_TRIPLE:
  169. case SCE_HPA_TRIPLEDOUBLE:
  170. case SCE_HPHP_HSTRING:
  171. case SCE_HPHP_SIMPLESTRING:
  172. case SCE_HPHP_HSTRING_VARIABLE:
  173. case SCE_HPHP_COMPLEX_VARIABLE:
  174. bResult = true;
  175. break;
  176. default :
  177. bResult = false;
  178. break;
  179. }
  180. return bResult;
  181. }
  182. static inline bool stateAllowsTermination(int state) {
  183. bool allowTermination = !isStringState(state);
  184. if (allowTermination) {
  185. switch (state) {
  186. case SCE_HB_COMMENTLINE:
  187. case SCE_HPHP_COMMENT:
  188. case SCE_HP_COMMENTLINE:
  189. case SCE_HPA_COMMENTLINE:
  190. allowTermination = false;
  191. }
  192. }
  193. return allowTermination;
  194. }
  195. // not really well done, since it's only comments that should lex the %> and <%
  196. static inline bool isCommentASPState(int state) {
  197. bool bResult;
  198. switch (state) {
  199. case SCE_HJ_COMMENT:
  200. case SCE_HJ_COMMENTLINE:
  201. case SCE_HJ_COMMENTDOC:
  202. case SCE_HB_COMMENTLINE:
  203. case SCE_HP_COMMENTLINE:
  204. case SCE_HPHP_COMMENT:
  205. case SCE_HPHP_COMMENTLINE:
  206. bResult = true;
  207. break;
  208. default :
  209. bResult = false;
  210. break;
  211. }
  212. return bResult;
  213. }
  214. static void classifyAttribHTML(unsigned int start, unsigned int end, WordList &keywords, Accessor &styler) {
  215. bool wordIsNumber = IsNumber(start, styler);
  216. char chAttr = SCE_H_ATTRIBUTEUNKNOWN;
  217. if (wordIsNumber) {
  218. chAttr = SCE_H_NUMBER;
  219. } else {
  220. char s[100];
  221. GetTextSegment(styler, start, end, s, sizeof(s));
  222. if (keywords.InList(s))
  223. chAttr = SCE_H_ATTRIBUTE;
  224. }
  225. if ((chAttr == SCE_H_ATTRIBUTEUNKNOWN) && !keywords)
  226. // No keywords -> all are known
  227. chAttr = SCE_H_ATTRIBUTE;
  228. styler.ColourTo(end, chAttr);
  229. }
  230. static int classifyTagHTML(unsigned int start, unsigned int end,
  231. WordList &keywords, Accessor &styler, bool &tagDontFold,
  232. bool caseSensitive, bool isXml, bool allowScripts) {
  233. char withSpace[30 + 2] = " ";
  234. const char *s = withSpace + 1;
  235. // Copy after the '<'
  236. unsigned int i = 1;
  237. for (unsigned int cPos = start; cPos <= end && i < 30; cPos++) {
  238. char ch = styler[cPos];
  239. if ((ch != '<') && (ch != '/')) {
  240. withSpace[i++] = caseSensitive ? ch : static_cast<char>(MakeLowerCase(ch));
  241. }
  242. }
  243. //The following is only a quick hack, to see if this whole thing would work
  244. //we first need the tagname with a trailing space...
  245. withSpace[i] = ' ';
  246. withSpace[i+1] = '\0';
  247. // if the current language is XML, I can fold any tag
  248. // if the current language is HTML, I don't want to fold certain tags (input, meta, etc.)
  249. //...to find it in the list of no-container-tags
  250. tagDontFold = (!isXml) && (NULL != strstr(" area base basefont br col command embed frame hr img input isindex keygen link meta param source track wbr ", withSpace));
  251. //now we can remove the trailing space
  252. withSpace[i] = '\0';
  253. // No keywords -> all are known
  254. char chAttr = SCE_H_TAGUNKNOWN;
  255. if (s[0] == '!') {
  256. chAttr = SCE_H_SGML_DEFAULT;
  257. } else if (!keywords || keywords.InList(s)) {
  258. chAttr = SCE_H_TAG;
  259. }
  260. styler.ColourTo(end, chAttr);
  261. if (chAttr == SCE_H_TAG) {
  262. if (allowScripts && 0 == strcmp(s, "script")) {
  263. // check to see if this is a self-closing tag by sniffing ahead
  264. bool isSelfClose = false;
  265. for (unsigned int cPos = end; cPos <= end + 200; cPos++) {
  266. char ch = styler.SafeGetCharAt(cPos, '\0');
  267. if (ch == '\0' || ch == '>')
  268. break;
  269. else if (ch == '/' && styler.SafeGetCharAt(cPos + 1, '\0') == '>') {
  270. isSelfClose = true;
  271. break;
  272. }
  273. }
  274. // do not enter a script state if the tag self-closed
  275. if (!isSelfClose)
  276. chAttr = SCE_H_SCRIPT;
  277. } else if (!isXml && 0 == strcmp(s, "comment")) {
  278. chAttr = SCE_H_COMMENT;
  279. }
  280. }
  281. return chAttr;
  282. }
  283. static void classifyWordHTJS(unsigned int start, unsigned int end,
  284. WordList &keywords, Accessor &styler, script_mode inScriptType) {
  285. char s[30 + 1];
  286. unsigned int i = 0;
  287. for (; i < end - start + 1 && i < 30; i++) {
  288. s[i] = styler[start + i];
  289. }
  290. s[i] = '\0';
  291. char chAttr = SCE_HJ_WORD;
  292. bool wordIsNumber = IsADigit(s[0]) || ((s[0] == '.') && IsADigit(s[1]));
  293. if (wordIsNumber) {
  294. chAttr = SCE_HJ_NUMBER;
  295. } else if (keywords.InList(s)) {
  296. chAttr = SCE_HJ_KEYWORD;
  297. }
  298. styler.ColourTo(end, statePrintForState(chAttr, inScriptType));
  299. }
  300. static int classifyWordHTVB(unsigned int start, unsigned int end, WordList &keywords, Accessor &styler, script_mode inScriptType) {
  301. char chAttr = SCE_HB_IDENTIFIER;
  302. bool wordIsNumber = IsADigit(styler[start]) || (styler[start] == '.');
  303. if (wordIsNumber) {
  304. chAttr = SCE_HB_NUMBER;
  305. } else {
  306. char s[100];
  307. GetTextSegment(styler, start, end, s, sizeof(s));
  308. if (keywords.InList(s)) {
  309. chAttr = SCE_HB_WORD;
  310. if (strcmp(s, "rem") == 0)
  311. chAttr = SCE_HB_COMMENTLINE;
  312. }
  313. }
  314. styler.ColourTo(end, statePrintForState(chAttr, inScriptType));
  315. if (chAttr == SCE_HB_COMMENTLINE)
  316. return SCE_HB_COMMENTLINE;
  317. else
  318. return SCE_HB_DEFAULT;
  319. }
  320. static void classifyWordHTPy(unsigned int start, unsigned int end, WordList &keywords, Accessor &styler, char *prevWord, script_mode inScriptType, bool isMako) {
  321. bool wordIsNumber = IsADigit(styler[start]);
  322. char s[30 + 1];
  323. unsigned int i = 0;
  324. for (; i < end - start + 1 && i < 30; i++) {
  325. s[i] = styler[start + i];
  326. }
  327. s[i] = '\0';
  328. char chAttr = SCE_HP_IDENTIFIER;
  329. if (0 == strcmp(prevWord, "class"))
  330. chAttr = SCE_HP_CLASSNAME;
  331. else if (0 == strcmp(prevWord, "def"))
  332. chAttr = SCE_HP_DEFNAME;
  333. else if (wordIsNumber)
  334. chAttr = SCE_HP_NUMBER;
  335. else if (keywords.InList(s))
  336. chAttr = SCE_HP_WORD;
  337. else if (isMako && 0 == strcmp(s, "block"))
  338. chAttr = SCE_HP_WORD;
  339. styler.ColourTo(end, statePrintForState(chAttr, inScriptType));
  340. strcpy(prevWord, s);
  341. }
  342. // Update the word colour to default or keyword
  343. // Called when in a PHP word
  344. static void classifyWordHTPHP(unsigned int start, unsigned int end, WordList &keywords, Accessor &styler) {
  345. char chAttr = SCE_HPHP_DEFAULT;
  346. bool wordIsNumber = IsADigit(styler[start]) || (styler[start] == '.' && start+1 <= end && IsADigit(styler[start+1]));
  347. if (wordIsNumber) {
  348. chAttr = SCE_HPHP_NUMBER;
  349. } else {
  350. char s[100];
  351. GetTextSegment(styler, start, end, s, sizeof(s));
  352. if (keywords.InList(s))
  353. chAttr = SCE_HPHP_WORD;
  354. }
  355. styler.ColourTo(end, chAttr);
  356. }
  357. static bool isWordHSGML(unsigned int start, unsigned int end, WordList &keywords, Accessor &styler) {
  358. char s[30 + 1];
  359. unsigned int i = 0;
  360. for (; i < end - start + 1 && i < 30; i++) {
  361. s[i] = styler[start + i];
  362. }
  363. s[i] = '\0';
  364. return keywords.InList(s);
  365. }
  366. static bool isWordCdata(unsigned int start, unsigned int end, Accessor &styler) {
  367. char s[30 + 1];
  368. unsigned int i = 0;
  369. for (; i < end - start + 1 && i < 30; i++) {
  370. s[i] = styler[start + i];
  371. }
  372. s[i] = '\0';
  373. return (0 == strcmp(s, "[CDATA["));
  374. }
  375. // Return the first state to reach when entering a scripting language
  376. static int StateForScript(script_type scriptLanguage) {
  377. int Result;
  378. switch (scriptLanguage) {
  379. case eScriptVBS:
  380. Result = SCE_HB_START;
  381. break;
  382. case eScriptPython:
  383. Result = SCE_HP_START;
  384. break;
  385. case eScriptPHP:
  386. Result = SCE_HPHP_DEFAULT;
  387. break;
  388. case eScriptXML:
  389. Result = SCE_H_TAGUNKNOWN;
  390. break;
  391. case eScriptSGML:
  392. Result = SCE_H_SGML_DEFAULT;
  393. break;
  394. case eScriptComment:
  395. Result = SCE_H_COMMENT;
  396. break;
  397. default :
  398. Result = SCE_HJ_START;
  399. break;
  400. }
  401. return Result;
  402. }
  403. static inline bool issgmlwordchar(int ch) {
  404. return !IsASCII(ch) ||
  405. (isalnum(ch) || ch == '.' || ch == '_' || ch == ':' || ch == '!' || ch == '#' || ch == '[');
  406. }
  407. static inline bool IsPhpWordStart(int ch) {
  408. return (IsASCII(ch) && (isalpha(ch) || (ch == '_'))) || (ch >= 0x7f);
  409. }
  410. static inline bool IsPhpWordChar(int ch) {
  411. return IsADigit(ch) || IsPhpWordStart(ch);
  412. }
  413. static bool InTagState(int state) {
  414. return state == SCE_H_TAG || state == SCE_H_TAGUNKNOWN ||
  415. state == SCE_H_SCRIPT ||
  416. state == SCE_H_ATTRIBUTE || state == SCE_H_ATTRIBUTEUNKNOWN ||
  417. state == SCE_H_NUMBER || state == SCE_H_OTHER ||
  418. state == SCE_H_DOUBLESTRING || state == SCE_H_SINGLESTRING;
  419. }
  420. static bool IsCommentState(const int state) {
  421. return state == SCE_H_COMMENT || state == SCE_H_SGML_COMMENT;
  422. }
  423. static bool IsScriptCommentState(const int state) {
  424. return state == SCE_HJ_COMMENT || state == SCE_HJ_COMMENTLINE || state == SCE_HJA_COMMENT ||
  425. state == SCE_HJA_COMMENTLINE || state == SCE_HB_COMMENTLINE || state == SCE_HBA_COMMENTLINE;
  426. }
  427. static bool isLineEnd(int ch) {
  428. return ch == '\r' || ch == '\n';
  429. }
  430. static bool isMakoBlockEnd(const int ch, const int chNext, const char *blockType) {
  431. if (strlen(blockType) == 0) {
  432. return ((ch == '%') && (chNext == '>'));
  433. } else if ((0 == strcmp(blockType, "inherit")) ||
  434. (0 == strcmp(blockType, "namespace")) ||
  435. (0 == strcmp(blockType, "include")) ||
  436. (0 == strcmp(blockType, "page"))) {
  437. return ((ch == '/') && (chNext == '>'));
  438. } else if (0 == strcmp(blockType, "%")) {
  439. if (ch == '/' && isLineEnd(chNext))
  440. return 1;
  441. else
  442. return isLineEnd(ch);
  443. } else if (0 == strcmp(blockType, "{")) {
  444. return ch == '}';
  445. } else {
  446. return (ch == '>');
  447. }
  448. }
  449. static bool isDjangoBlockEnd(const int ch, const int chNext, const char *blockType) {
  450. if (strlen(blockType) == 0) {
  451. return 0;
  452. } else if (0 == strcmp(blockType, "%")) {
  453. return ((ch == '%') && (chNext == '}'));
  454. } else if (0 == strcmp(blockType, "{")) {
  455. return ((ch == '}') && (chNext == '}'));
  456. } else {
  457. return 0;
  458. }
  459. }
  460. static bool isPHPStringState(int state) {
  461. return
  462. (state == SCE_HPHP_HSTRING) ||
  463. (state == SCE_HPHP_SIMPLESTRING) ||
  464. (state == SCE_HPHP_HSTRING_VARIABLE) ||
  465. (state == SCE_HPHP_COMPLEX_VARIABLE);
  466. }
  467. static int FindPhpStringDelimiter(char *phpStringDelimiter, const int phpStringDelimiterSize, int i, const int lengthDoc, Accessor &styler, bool &isSimpleString) {
  468. int j;
  469. const int beginning = i - 1;
  470. bool isValidSimpleString = false;
  471. while (i < lengthDoc && (styler[i] == ' ' || styler[i] == '\t'))
  472. i++;
  473. char ch = styler.SafeGetCharAt(i);
  474. const char chNext = styler.SafeGetCharAt(i + 1);
  475. if (!IsPhpWordStart(ch)) {
  476. if (ch == '\'' && IsPhpWordStart(chNext)) {
  477. i++;
  478. ch = chNext;
  479. isSimpleString = true;
  480. } else {
  481. phpStringDelimiter[0] = '\0';
  482. return beginning;
  483. }
  484. }
  485. phpStringDelimiter[0] = ch;
  486. i++;
  487. for (j = i; j < lengthDoc && !isLineEnd(styler[j]); j++) {
  488. if (!IsPhpWordChar(styler[j])) {
  489. if (isSimpleString && (styler[j] == '\'') && isLineEnd(styler.SafeGetCharAt(j + 1))) {
  490. isValidSimpleString = true;
  491. j++;
  492. break;
  493. } else {
  494. phpStringDelimiter[0] = '\0';
  495. return beginning;
  496. }
  497. }
  498. if (j - i < phpStringDelimiterSize - 2)
  499. phpStringDelimiter[j-i+1] = styler[j];
  500. else
  501. i++;
  502. }
  503. if (isSimpleString && !isValidSimpleString) {
  504. phpStringDelimiter[0] = '\0';
  505. return beginning;
  506. }
  507. phpStringDelimiter[j-i+1 - (isSimpleString ? 1 : 0)] = '\0';
  508. return j - 1;
  509. }
  510. static void ColouriseHyperTextDoc(unsigned int startPos, int length, int initStyle, WordList *keywordlists[],
  511. Accessor &styler, bool isXml) {
  512. WordList &keywords = *keywordlists[0];
  513. WordList &keywords2 = *keywordlists[1];
  514. WordList &keywords3 = *keywordlists[2];
  515. WordList &keywords4 = *keywordlists[3];
  516. WordList &keywords5 = *keywordlists[4];
  517. WordList &keywords6 = *keywordlists[5]; // SGML (DTD) keywords
  518. styler.StartAt(startPos);
  519. char prevWord[200];
  520. prevWord[0] = '\0';
  521. char phpStringDelimiter[200]; // PHP is not limited in length, we are
  522. phpStringDelimiter[0] = '\0';
  523. int StateToPrint = initStyle;
  524. int state = stateForPrintState(StateToPrint);
  525. char makoBlockType[200];
  526. makoBlockType[0] = '\0';
  527. int makoComment = 0;
  528. char djangoBlockType[2];
  529. djangoBlockType[0] = '\0';
  530. // 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
  531. if (InTagState(state)) {
  532. while ((startPos > 0) && (InTagState(styler.StyleAt(startPos - 1)))) {
  533. int backLineStart = styler.LineStart(styler.GetLine(startPos-1));
  534. length += startPos - backLineStart;
  535. startPos = backLineStart;
  536. }
  537. state = SCE_H_DEFAULT;
  538. }
  539. // String can be heredoc, must find a delimiter first. Reread from beginning of line containing the string, to get the correct lineState
  540. if (isPHPStringState(state)) {
  541. while (startPos > 0 && (isPHPStringState(state) || !isLineEnd(styler[startPos - 1]))) {
  542. startPos--;
  543. length++;
  544. state = styler.StyleAt(startPos);
  545. }
  546. if (startPos == 0)
  547. state = SCE_H_DEFAULT;
  548. }
  549. styler.StartAt(startPos);
  550. int lineCurrent = styler.GetLine(startPos);
  551. int lineState;
  552. if (lineCurrent > 0) {
  553. lineState = styler.GetLineState(lineCurrent-1);
  554. } else {
  555. // Default client and ASP scripting language is JavaScript
  556. lineState = eScriptJS << 8;
  557. // property asp.default.language
  558. // Script in ASP code is initially assumed to be in JavaScript.
  559. // To change this to VBScript set asp.default.language to 2. Python is 3.
  560. lineState |= styler.GetPropertyInt("asp.default.language", eScriptJS) << 4;
  561. }
  562. script_mode inScriptType = script_mode((lineState >> 0) & 0x03); // 2 bits of scripting mode
  563. bool tagOpened = (lineState >> 2) & 0x01; // 1 bit to know if we are in an opened tag
  564. bool tagClosing = (lineState >> 3) & 0x01; // 1 bit to know if we are in a closing tag
  565. bool tagDontFold = false; //some HTML tags should not be folded
  566. script_type aspScript = script_type((lineState >> 4) & 0x0F); // 4 bits of script name
  567. script_type clientScript = script_type((lineState >> 8) & 0x0F); // 4 bits of script name
  568. int beforePreProc = (lineState >> 12) & 0xFF; // 8 bits of state
  569. script_type scriptLanguage = ScriptOfState(state);
  570. // If eNonHtmlScript coincides with SCE_H_COMMENT, assume eScriptComment
  571. if (inScriptType == eNonHtmlScript && state == SCE_H_COMMENT) {
  572. scriptLanguage = eScriptComment;
  573. }
  574. script_type beforeLanguage = ScriptOfState(beforePreProc);
  575. // property fold.html
  576. // Folding is turned on or off for HTML and XML files with this option.
  577. // The fold option must also be on for folding to occur.
  578. const bool foldHTML = styler.GetPropertyInt("fold.html", 0) != 0;
  579. const bool fold = foldHTML && styler.GetPropertyInt("fold", 0);
  580. // property fold.html.preprocessor
  581. // Folding is turned on or off for scripts embedded in HTML files with this option.
  582. // The default is on.
  583. const bool foldHTMLPreprocessor = foldHTML && styler.GetPropertyInt("fold.html.preprocessor", 1);
  584. const bool foldCompact = styler.GetPropertyInt("fold.compact", 1) != 0;
  585. // property fold.hypertext.comment
  586. // Allow folding for comments in scripts embedded in HTML.
  587. // The default is off.
  588. const bool foldComment = fold && styler.GetPropertyInt("fold.hypertext.comment", 0) != 0;
  589. // property fold.hypertext.heredoc
  590. // Allow folding for heredocs in scripts embedded in HTML.
  591. // The default is off.
  592. const bool foldHeredoc = fold && styler.GetPropertyInt("fold.hypertext.heredoc", 0) != 0;
  593. // property html.tags.case.sensitive
  594. // For XML and HTML, setting this property to 1 will make tags match in a case
  595. // sensitive way which is the expected behaviour for XML and XHTML.
  596. const bool caseSensitive = styler.GetPropertyInt("html.tags.case.sensitive", 0) != 0;
  597. // property lexer.xml.allow.scripts
  598. // Set to 0 to disable scripts in XML.
  599. const bool allowScripts = styler.GetPropertyInt("lexer.xml.allow.scripts", 1) != 0;
  600. // property lexer.html.mako
  601. // Set to 1 to enable the mako template language.
  602. const bool isMako = styler.GetPropertyInt("lexer.html.mako", 0) != 0;
  603. // property lexer.html.django
  604. // Set to 1 to enable the django template language.
  605. const bool isDjango = styler.GetPropertyInt("lexer.html.django", 0) != 0;
  606. const CharacterSet setHTMLWord(CharacterSet::setAlphaNum, ".-_:!#", 0x80, true);
  607. const CharacterSet setTagContinue(CharacterSet::setAlphaNum, ".-_:!#[", 0x80, true);
  608. const CharacterSet setAttributeContinue(CharacterSet::setAlphaNum, ".-_:!#/", 0x80, true);
  609. // TODO: also handle + and - (except if they're part of ++ or --) and return keywords
  610. const CharacterSet setOKBeforeJSRE(CharacterSet::setNone, "([{=,:;!%^&*|?~");
  611. int levelPrev = styler.LevelAt(lineCurrent) & SC_FOLDLEVELNUMBERMASK;
  612. int levelCurrent = levelPrev;
  613. int visibleChars = 0;
  614. int lineStartVisibleChars = 0;
  615. int chPrev = ' ';
  616. int ch = ' ';
  617. int chPrevNonWhite = ' ';
  618. // look back to set chPrevNonWhite properly for better regex colouring
  619. if (scriptLanguage == eScriptJS && startPos > 0) {
  620. int back = startPos;
  621. int style = 0;
  622. while (--back) {
  623. style = styler.StyleAt(back);
  624. if (style < SCE_HJ_DEFAULT || style > SCE_HJ_COMMENTDOC)
  625. // includes SCE_HJ_COMMENT & SCE_HJ_COMMENTLINE
  626. break;
  627. }
  628. if (style == SCE_HJ_SYMBOLS) {
  629. chPrevNonWhite = static_cast<unsigned char>(styler.SafeGetCharAt(back));
  630. }
  631. }
  632. styler.StartSegment(startPos);
  633. const int lengthDoc = startPos + length;
  634. for (int i = startPos; i < lengthDoc; i++) {
  635. const int chPrev2 = chPrev;
  636. chPrev = ch;
  637. if (!IsASpace(ch) && state != SCE_HJ_COMMENT &&
  638. state != SCE_HJ_COMMENTLINE && state != SCE_HJ_COMMENTDOC)
  639. chPrevNonWhite = ch;
  640. ch = static_cast<unsigned char>(styler[i]);
  641. int chNext = static_cast<unsigned char>(styler.SafeGetCharAt(i + 1));
  642. const int chNext2 = static_cast<unsigned char>(styler.SafeGetCharAt(i + 2));
  643. // Handle DBCS codepages
  644. if (styler.IsLeadByte(static_cast<char>(ch))) {
  645. chPrev = ' ';
  646. i += 1;
  647. continue;
  648. }
  649. if ((!IsASpace(ch) || !foldCompact) && fold)
  650. visibleChars++;
  651. if (!IsASpace(ch))
  652. lineStartVisibleChars++;
  653. // decide what is the current state to print (depending of the script tag)
  654. StateToPrint = statePrintForState(state, inScriptType);
  655. // handle script folding
  656. if (fold) {
  657. switch (scriptLanguage) {
  658. case eScriptJS:
  659. case eScriptPHP:
  660. //not currently supported case eScriptVBS:
  661. if ((state != SCE_HPHP_COMMENT) && (state != SCE_HPHP_COMMENTLINE) && (state != SCE_HJ_COMMENT) && (state != SCE_HJ_COMMENTLINE) && (state != SCE_HJ_COMMENTDOC) && (!isStringState(state))) {
  662. //Platform::DebugPrintf("state=%d, StateToPrint=%d, initStyle=%d\n", state, StateToPrint, initStyle);
  663. //if ((state == SCE_HPHP_OPERATOR) || (state == SCE_HPHP_DEFAULT) || (state == SCE_HJ_SYMBOLS) || (state == SCE_HJ_START) || (state == SCE_HJ_DEFAULT)) {
  664. if (ch == '#') {
  665. int j = i + 1;
  666. while ((j < lengthDoc) && IsASpaceOrTab(styler.SafeGetCharAt(j))) {
  667. j++;
  668. }
  669. if (styler.Match(j, "region") || styler.Match(j, "if")) {
  670. levelCurrent++;
  671. } else if (styler.Match(j, "end")) {
  672. levelCurrent--;
  673. }
  674. } else if ((ch == '{') || (ch == '}') || (foldComment && (ch == '/') && (chNext == '*'))) {
  675. levelCurrent += (((ch == '{') || (ch == '/')) ? 1 : -1);
  676. }
  677. } else if (((state == SCE_HPHP_COMMENT) || (state == SCE_HJ_COMMENT)) && foldComment && (ch == '*') && (chNext == '/')) {
  678. levelCurrent--;
  679. }
  680. break;
  681. case eScriptPython:
  682. if (state != SCE_HP_COMMENTLINE && !isMako) {
  683. if ((ch == ':') && ((chNext == '\n') || (chNext == '\r' && chNext2 == '\n'))) {
  684. levelCurrent++;
  685. } else if ((ch == '\n') && !((chNext == '\r') && (chNext2 == '\n')) && (chNext != '\n')) {
  686. // check if the number of tabs is lower than the level
  687. int Findlevel = (levelCurrent & ~SC_FOLDLEVELBASE) * 8;
  688. for (int j = 0; Findlevel > 0; j++) {
  689. char chTmp = styler.SafeGetCharAt(i + j + 1);
  690. if (chTmp == '\t') {
  691. Findlevel -= 8;
  692. } else if (chTmp == ' ') {
  693. Findlevel--;
  694. } else {
  695. break;
  696. }
  697. }
  698. if (Findlevel > 0) {
  699. levelCurrent -= Findlevel / 8;
  700. if (Findlevel % 8)
  701. levelCurrent--;
  702. }
  703. }
  704. }
  705. break;
  706. default:
  707. break;
  708. }
  709. }
  710. if ((ch == '\r' && chNext != '\n') || (ch == '\n')) {
  711. // Trigger on CR only (Mac style) or either on LF from CR+LF (Dos/Win) or on LF alone (Unix)
  712. // Avoid triggering two times on Dos/Win
  713. // New line -> record any line state onto /next/ line
  714. if (fold) {
  715. int lev = levelPrev;
  716. if (visibleChars == 0)
  717. lev |= SC_FOLDLEVELWHITEFLAG;
  718. if ((levelCurrent > levelPrev) && (visibleChars > 0))
  719. lev |= SC_FOLDLEVELHEADERFLAG;
  720. styler.SetLevel(lineCurrent, lev);
  721. visibleChars = 0;
  722. levelPrev = levelCurrent;
  723. }
  724. styler.SetLineState(lineCurrent,
  725. ((inScriptType & 0x03) << 0) |
  726. ((tagOpened ? 1 : 0) << 2) |
  727. ((tagClosing ? 1 : 0) << 3) |
  728. ((aspScript & 0x0F) << 4) |
  729. ((clientScript & 0x0F) << 8) |
  730. ((beforePreProc & 0xFF) << 12));
  731. lineCurrent++;
  732. lineStartVisibleChars = 0;
  733. }
  734. // handle start of Mako comment line
  735. if (isMako && ch == '#' && chNext == '#') {
  736. makoComment = 1;
  737. }
  738. // handle end of Mako comment line
  739. else if (isMako && makoComment && (ch == '\r' || ch == '\n')) {
  740. makoComment = 0;
  741. styler.ColourTo(i, SCE_HP_COMMENTLINE);
  742. state = SCE_HP_DEFAULT;
  743. }
  744. // Allow falling through to mako handling code if newline is going to end a block
  745. if (((ch == '\r' && chNext != '\n') || (ch == '\n')) &&
  746. (!isMako || (0 != strcmp(makoBlockType, "%")))) {
  747. }
  748. // generic end of script processing
  749. else if ((inScriptType == eNonHtmlScript) && (ch == '<') && (chNext == '/')) {
  750. // Check if it's the end of the script tag (or any other HTML tag)
  751. switch (state) {
  752. // in these cases, you can embed HTML tags (to confirm !!!!!!!!!!!!!!!!!!!!!!)
  753. case SCE_H_DOUBLESTRING:
  754. case SCE_H_SINGLESTRING:
  755. case SCE_HJ_COMMENT:
  756. case SCE_HJ_COMMENTDOC:
  757. //case SCE_HJ_COMMENTLINE: // removed as this is a common thing done to hide
  758. // the end of script marker from some JS interpreters.
  759. case SCE_HB_COMMENTLINE:
  760. case SCE_HBA_COMMENTLINE:
  761. case SCE_HJ_DOUBLESTRING:
  762. case SCE_HJ_SINGLESTRING:
  763. case SCE_HJ_REGEX:
  764. case SCE_HB_STRING:
  765. case SCE_HBA_STRING:
  766. case SCE_HP_STRING:
  767. case SCE_HP_TRIPLE:
  768. case SCE_HP_TRIPLEDOUBLE:
  769. case SCE_HPHP_HSTRING:
  770. case SCE_HPHP_SIMPLESTRING:
  771. case SCE_HPHP_COMMENT:
  772. case SCE_HPHP_COMMENTLINE:
  773. break;
  774. default :
  775. // check if the closing tag is a script tag
  776. if (const char *tag =
  777. state == SCE_HJ_COMMENTLINE || isXml ? "script" :
  778. state == SCE_H_COMMENT ? "comment" : 0) {
  779. int j = i + 2;
  780. int chr;
  781. do {
  782. chr = static_cast<int>(*tag++);
  783. } while (chr != 0 && chr == MakeLowerCase(styler.SafeGetCharAt(j++)));
  784. if (chr != 0) break;
  785. }
  786. // closing tag of the script (it's a closing HTML tag anyway)
  787. styler.ColourTo(i - 1, StateToPrint);
  788. state = SCE_H_TAGUNKNOWN;
  789. inScriptType = eHtml;
  790. scriptLanguage = eScriptNone;
  791. clientScript = eScriptJS;
  792. i += 2;
  793. visibleChars += 2;
  794. tagClosing = true;
  795. continue;
  796. }
  797. }
  798. /////////////////////////////////////
  799. // handle the start of PHP pre-processor = Non-HTML
  800. else if ((state != SCE_H_ASPAT) &&
  801. !isPHPStringState(state) &&
  802. (state != SCE_HPHP_COMMENT) &&
  803. (state != SCE_HPHP_COMMENTLINE) &&
  804. (ch == '<') &&
  805. (chNext == '?') &&
  806. !IsScriptCommentState(state)) {
  807. beforeLanguage = scriptLanguage;
  808. scriptLanguage = segIsScriptingIndicator(styler, i + 2, i + 6, isXml ? eScriptXML : eScriptPHP);
  809. if ((scriptLanguage != eScriptPHP) && (isStringState(state) || (state==SCE_H_COMMENT))) continue;
  810. styler.ColourTo(i - 1, StateToPrint);
  811. beforePreProc = state;
  812. i++;
  813. visibleChars++;
  814. i += PrintScriptingIndicatorOffset(styler, styler.GetStartSegment() + 2, i + 6);
  815. if (scriptLanguage == eScriptXML)
  816. styler.ColourTo(i, SCE_H_XMLSTART);
  817. else
  818. styler.ColourTo(i, SCE_H_QUESTION);
  819. state = StateForScript(scriptLanguage);
  820. if (inScriptType == eNonHtmlScript)
  821. inScriptType = eNonHtmlScriptPreProc;
  822. else
  823. inScriptType = eNonHtmlPreProc;
  824. // Fold whole script, but not if the XML first tag (all XML-like tags in this case)
  825. if (foldHTMLPreprocessor && (scriptLanguage != eScriptXML)) {
  826. levelCurrent++;
  827. }
  828. // should be better
  829. ch = static_cast<unsigned char>(styler.SafeGetCharAt(i));
  830. continue;
  831. }
  832. // handle the start Mako template Python code
  833. else if (isMako && scriptLanguage == eScriptNone && ((ch == '<' && chNext == '%') ||
  834. (lineStartVisibleChars == 1 && ch == '%') ||
  835. (lineStartVisibleChars == 1 && ch == '/' && chNext == '%') ||
  836. (ch == '$' && chNext == '{') ||
  837. (ch == '<' && chNext == '/' && chNext2 == '%'))) {
  838. if (ch == '%' || ch == '/')
  839. StringCopy(makoBlockType, "%");
  840. else if (ch == '$')
  841. StringCopy(makoBlockType, "{");
  842. else if (chNext == '/')
  843. GetNextWord(styler, i+3, makoBlockType, sizeof(makoBlockType));
  844. else
  845. GetNextWord(styler, i+2, makoBlockType, sizeof(makoBlockType));
  846. styler.ColourTo(i - 1, StateToPrint);
  847. beforePreProc = state;
  848. if (inScriptType == eNonHtmlScript)
  849. inScriptType = eNonHtmlScriptPreProc;
  850. else
  851. inScriptType = eNonHtmlPreProc;
  852. if (chNext == '/') {
  853. i += 2;
  854. visibleChars += 2;
  855. } else if (ch != '%') {
  856. i++;
  857. visibleChars++;
  858. }
  859. state = SCE_HP_START;
  860. scriptLanguage = eScriptPython;
  861. styler.ColourTo(i, SCE_H_ASP);
  862. if (ch != '%' && ch != '$' && ch != '/') {
  863. i += static_cast<int>(strlen(makoBlockType));
  864. visibleChars += static_cast<int>(strlen(makoBlockType));
  865. if (keywords4.InList(makoBlockType))
  866. styler.ColourTo(i, SCE_HP_WORD);
  867. else
  868. styler.ColourTo(i, SCE_H_TAGUNKNOWN);
  869. }
  870. ch = static_cast<unsigned char>(styler.SafeGetCharAt(i));
  871. continue;
  872. }
  873. // handle the start/end of Django comment
  874. else if (isDjango && state != SCE_H_COMMENT && (ch == '{' && chNext == '#')) {
  875. styler.ColourTo(i - 1, StateToPrint);
  876. beforePreProc = state;
  877. beforeLanguage = scriptLanguage;
  878. if (inScriptType == eNonHtmlScript)
  879. inScriptType = eNonHtmlScriptPreProc;
  880. else
  881. inScriptType = eNonHtmlPreProc;
  882. i += 1;
  883. visibleChars += 1;
  884. scriptLanguage = eScriptComment;
  885. state = SCE_H_COMMENT;
  886. styler.ColourTo(i, SCE_H_ASP);
  887. ch = static_cast<unsigned char>(styler.SafeGetCharAt(i));
  888. continue;
  889. } else if (isDjango && state == SCE_H_COMMENT && (ch == '#' && chNext == '}')) {
  890. styler.ColourTo(i - 1, StateToPrint);
  891. i += 1;
  892. visibleChars += 1;
  893. styler.ColourTo(i, SCE_H_ASP);
  894. state = beforePreProc;
  895. if (inScriptType == eNonHtmlScriptPreProc)
  896. inScriptType = eNonHtmlScript;
  897. else
  898. inScriptType = eHtml;
  899. scriptLanguage = beforeLanguage;
  900. continue;
  901. }
  902. // handle the start Django template code
  903. else if (isDjango && scriptLanguage != eScriptPython && (ch == '{' && (chNext == '%' || chNext == '{'))) {
  904. if (chNext == '%')
  905. StringCopy(djangoBlockType, "%");
  906. else
  907. StringCopy(djangoBlockType, "{");
  908. styler.ColourTo(i - 1, StateToPrint);
  909. beforePreProc = state;
  910. if (inScriptType == eNonHtmlScript)
  911. inScriptType = eNonHtmlScriptPreProc;
  912. else
  913. inScriptType = eNonHtmlPreProc;
  914. i += 1;
  915. visibleChars += 1;
  916. state = SCE_HP_START;
  917. beforeLanguage = scriptLanguage;
  918. scriptLanguage = eScriptPython;
  919. styler.ColourTo(i, SCE_H_ASP);
  920. ch = static_cast<unsigned char>(styler.SafeGetCharAt(i));
  921. continue;
  922. }
  923. // handle the start of ASP pre-processor = Non-HTML
  924. else if (!isMako && !isDjango && !isCommentASPState(state) && (ch == '<') && (chNext == '%') && !isPHPStringState(state)) {
  925. styler.ColourTo(i - 1, StateToPrint);
  926. beforePreProc = state;
  927. if (inScriptType == eNonHtmlScript)
  928. inScriptType = eNonHtmlScriptPreProc;
  929. else
  930. inScriptType = eNonHtmlPreProc;
  931. if (chNext2 == '@') {
  932. i += 2; // place as if it was the second next char treated
  933. visibleChars += 2;
  934. state = SCE_H_ASPAT;
  935. } else if ((chNext2 == '-') && (styler.SafeGetCharAt(i + 3) == '-')) {
  936. styler.ColourTo(i + 3, SCE_H_ASP);
  937. state = SCE_H_XCCOMMENT;
  938. scriptLanguage = eScriptVBS;
  939. continue;
  940. } else {
  941. if (chNext2 == '=') {
  942. i += 2; // place as if it was the second next char treated
  943. visibleChars += 2;
  944. } else {
  945. i++; // place as if it was the next char treated
  946. visibleChars++;
  947. }
  948. state = StateForScript(aspScript);
  949. }
  950. scriptLanguage = eScriptVBS;
  951. styler.ColourTo(i, SCE_H_ASP);
  952. // fold whole script
  953. if (foldHTMLPreprocessor)
  954. levelCurrent++;
  955. // should be better
  956. ch = static_cast<unsigned char>(styler.SafeGetCharAt(i));
  957. continue;
  958. }
  959. /////////////////////////////////////
  960. // handle the start of SGML language (DTD)
  961. else if (((scriptLanguage == eScriptNone) || (scriptLanguage == eScriptXML)) &&
  962. (chPrev == '<') &&
  963. (ch == '!') &&
  964. (StateToPrint != SCE_H_CDATA) &&
  965. (!IsCommentState(StateToPrint)) &&
  966. (!IsScriptCommentState(StateToPrint))) {
  967. beforePreProc = state;
  968. styler.ColourTo(i - 2, StateToPrint);
  969. if ((chNext == '-') && (chNext2 == '-')) {
  970. state = SCE_H_COMMENT; // wait for a pending command
  971. styler.ColourTo(i + 2, SCE_H_COMMENT);
  972. i += 2; // follow styling after the --
  973. } else if (isWordCdata(i + 1, i + 7, styler)) {
  974. state = SCE_H_CDATA;
  975. } else {
  976. styler.ColourTo(i, SCE_H_SGML_DEFAULT); // <! is default
  977. scriptLanguage = eScriptSGML;
  978. state = SCE_H_SGML_COMMAND; // wait for a pending command
  979. }
  980. // fold whole tag (-- when closing the tag)
  981. if (foldHTMLPreprocessor || state == SCE_H_COMMENT || state == SCE_H_CDATA)
  982. levelCurrent++;
  983. continue;
  984. }
  985. // handle the end of Mako Python code
  986. else if (isMako &&
  987. ((inScriptType == eNonHtmlPreProc) || (inScriptType == eNonHtmlScriptPreProc)) &&
  988. (scriptLanguage != eScriptNone) && stateAllowsTermination(state) &&
  989. isMakoBlockEnd(ch, chNext, makoBlockType)) {
  990. if (state == SCE_H_ASPAT) {
  991. aspScript = segIsScriptingIndicator(styler,
  992. styler.GetStartSegment(), i - 1, aspScript);
  993. }
  994. if (state == SCE_HP_WORD) {
  995. classifyWordHTPy(styler.GetStartSegment(), i - 1, keywords4, styler, prevWord, inScriptType, isMako);
  996. } else {
  997. styler.ColourTo(i - 1, StateToPrint);
  998. }
  999. if (0 != strcmp(makoBlockType, "%") && (0 != strcmp(makoBlockType, "{")) && ch != '>') {
  1000. i++;
  1001. visibleChars++;
  1002. }
  1003. else if (0 == strcmp(makoBlockType, "%") && ch == '/') {
  1004. i++;
  1005. visibleChars++;
  1006. }
  1007. if (0 != strcmp(makoBlockType, "%") || ch == '/') {
  1008. styler.ColourTo(i, SCE_H_ASP);
  1009. }
  1010. state = beforePreProc;
  1011. if (inScriptType == eNonHtmlScriptPreProc)
  1012. inScriptType = eNonHtmlScript;
  1013. else
  1014. inScriptType = eHtml;
  1015. scriptLanguage = eScriptNone;
  1016. continue;
  1017. }
  1018. // handle the end of Django template code
  1019. else if (isDjango &&
  1020. ((inScriptType == eNonHtmlPreProc) || (inScriptType == eNonHtmlScriptPreProc)) &&
  1021. (scriptLanguage != eScriptNone) && stateAllowsTermination(state) &&
  1022. isDjangoBlockEnd(ch, chNext, djangoBlockType)) {
  1023. if (state == SCE_H_ASPAT) {
  1024. aspScript = segIsScriptingIndicator(styler,
  1025. styler.GetStartSegment(), i - 1, aspScript);
  1026. }
  1027. if (state == SCE_HP_WORD) {
  1028. classifyWordHTPy(styler.GetStartSegment(), i - 1, keywords4, styler, prevWord, inScriptType, isMako);
  1029. } else {
  1030. styler.ColourTo(i - 1, StateToPrint);
  1031. }
  1032. i += 1;
  1033. visibleChars += 1;
  1034. styler.ColourTo(i, SCE_H_ASP);
  1035. state = beforePreProc;
  1036. if (inScriptType == eNonHtmlScriptPreProc)
  1037. inScriptType = eNonHtmlScript;
  1038. else
  1039. inScriptType = eHtml;
  1040. scriptLanguage = beforeLanguage;
  1041. continue;
  1042. }
  1043. // handle the end of a pre-processor = Non-HTML
  1044. else if ((!isMako && !isDjango && ((inScriptType == eNonHtmlPreProc) || (inScriptType == eNonHtmlScriptPreProc)) &&
  1045. (((scriptLanguage != eScriptNone) && stateAllowsTermination(state))) &&
  1046. (((ch == '%') || (ch == '?')) && (chNext == '>'))) ||
  1047. ((scriptLanguage == eScriptSGML) && (ch == '>') && (state != SCE_H_SGML_COMMENT))) {
  1048. if (state == SCE_H_ASPAT) {
  1049. aspScript = segIsScriptingIndicator(styler,
  1050. styler.GetStartSegment(), i - 1, aspScript);
  1051. }
  1052. // Bounce out of any ASP mode
  1053. switch (state) {
  1054. case SCE_HJ_WORD:
  1055. classifyWordHTJS(styler.GetStartSegment(), i - 1, keywords2, styler, inScriptType);
  1056. break;
  1057. case SCE_HB_WORD:
  1058. classifyWordHTVB(styler.GetStartSegment(), i - 1, keywords3, styler, inScriptType);
  1059. break;
  1060. case SCE_HP_WORD:
  1061. classifyWordHTPy(styler.GetStartSegment(), i - 1, keywords4, styler, prevWord, inScriptType, isMako);
  1062. break;
  1063. case SCE_HPHP_WORD:
  1064. classifyWordHTPHP(styler.GetStartSegment(), i - 1, keywords5, styler);
  1065. break;
  1066. case SCE_H_XCCOMMENT:
  1067. styler.ColourTo(i - 1, state);
  1068. break;
  1069. default :
  1070. styler.ColourTo(i - 1, StateToPrint);
  1071. break;
  1072. }
  1073. if (scriptLanguage != eScriptSGML) {
  1074. i++;
  1075. visibleChars++;
  1076. }
  1077. if (ch == '%')
  1078. styler.ColourTo(i, SCE_H_ASP);
  1079. else if (scriptLanguage == eScriptXML)
  1080. styler.ColourTo(i, SCE_H_XMLEND);
  1081. else if (scriptLanguage == eScriptSGML)
  1082. styler.ColourTo(i, SCE_H_SGML_DEFAULT);
  1083. else
  1084. styler.ColourTo(i, SCE_H_QUESTION);
  1085. state = beforePreProc;
  1086. if (inScriptType == eNonHtmlScriptPreProc)
  1087. inScriptType = eNonHtmlScript;
  1088. else
  1089. inScriptType = eHtml;
  1090. // Unfold all scripting languages, except for XML tag
  1091. if (foldHTMLPreprocessor && (scriptLanguage != eScriptXML)) {
  1092. levelCurrent--;
  1093. }
  1094. scriptLanguage = beforeLanguage;
  1095. continue;
  1096. }
  1097. /////////////////////////////////////
  1098. switch (state) {
  1099. case SCE_H_DEFAULT:
  1100. if (ch == '<') {
  1101. // in HTML, fold on tag open and unfold on tag close
  1102. tagOpened = true;
  1103. tagClosing = (chNext == '/');
  1104. styler.ColourTo(i - 1, StateToPrint);
  1105. if (chNext != '!')
  1106. state = SCE_H_TAGUNKNOWN;
  1107. } else if (ch == '&') {
  1108. styler.ColourTo(i - 1, SCE_H_DEFAULT);
  1109. state = SCE_H_ENTITY;
  1110. }
  1111. break;
  1112. case SCE_H_SGML_DEFAULT:
  1113. case SCE_H_SGML_BLOCK_DEFAULT:
  1114. // if (scriptLanguage == eScriptSGMLblock)
  1115. // StateToPrint = SCE_H_SGML_BLOCK_DEFAULT;
  1116. if (ch == '\"') {
  1117. styler.ColourTo(i - 1, StateToPrint);
  1118. state = SCE_H_SGML_DOUBLESTRING;
  1119. } else if (ch == '\'') {
  1120. styler.ColourTo(i - 1, StateToPrint);
  1121. state = SCE_H_SGML_SIMPLESTRING;
  1122. } else if ((ch == '-') && (chPrev == '-')) {
  1123. if (static_cast<int>(styler.GetStartSegment()) <= (i - 2)) {
  1124. styler.ColourTo(i - 2, StateToPrint);
  1125. }
  1126. state = SCE_H_SGML_COMMENT;
  1127. } else if (IsASCII(ch) && isalpha(ch) && (chPrev == '%')) {
  1128. styler.ColourTo(i - 2, StateToPrint);
  1129. state = SCE_H_SGML_ENTITY;
  1130. } else if (ch == '#') {
  1131. styler.ColourTo(i - 1, StateToPrint);
  1132. state = SCE_H_SGML_SPECIAL;
  1133. } else if (ch == '[') {
  1134. styler.ColourTo(i - 1, StateToPrint);
  1135. scriptLanguage = eScriptSGMLblock;
  1136. state = SCE_H_SGML_BLOCK_DEFAULT;
  1137. } else if (ch == ']') {
  1138. if (scriptLanguage == eScriptSGMLblock) {
  1139. styler.ColourTo(i, StateToPrint);
  1140. scriptLanguage = eScriptSGML;
  1141. } else {
  1142. styler.ColourTo(i - 1, StateToPrint);
  1143. styler.ColourTo(i, SCE_H_SGML_ERROR);
  1144. }
  1145. state = SCE_H_SGML_DEFAULT;
  1146. } else if (scriptLanguage == eScriptSGMLblock) {
  1147. if ((ch == '!') && (chPrev == '<')) {
  1148. styler.ColourTo(i - 2, StateToPrint);
  1149. styler.ColourTo(i, SCE_H_SGML_DEFAULT);
  1150. state = SCE_H_SGML_COMMAND;
  1151. } else if (ch == '>') {
  1152. styler.ColourTo(i - 1, StateToPrint);
  1153. styler.ColourTo(i, SCE_H_SGML_DEFAULT);
  1154. }
  1155. }
  1156. break;
  1157. case SCE_H_SGML_COMMAND:
  1158. if ((ch == '-') && (chPrev == '-')) {
  1159. styler.ColourTo(i - 2, StateToPrint);
  1160. state = SCE_H_SGML_COMMENT;
  1161. } else if (!issgmlwordchar(ch)) {
  1162. if (isWordHSGML(styler.GetStartSegment(), i - 1, keywords6, styler)) {
  1163. styler.ColourTo(i - 1, StateToPrint);
  1164. state = SCE_H_SGML_1ST_PARAM;
  1165. } else {
  1166. state = SCE_H_SGML_ERROR;
  1167. }
  1168. }
  1169. break;
  1170. case SCE_H_SGML_1ST_PARAM:
  1171. // wait for the beginning of the word
  1172. if ((ch == '-') && (chPrev == '-')) {
  1173. if (scriptLanguage == eScriptSGMLblock) {
  1174. styler.ColourTo(i - 2, SCE_H_SGML_BLOCK_DEFAULT);
  1175. } else {
  1176. styler.ColourTo(i - 2, SCE_H_SGML_DEFAULT);
  1177. }
  1178. state = SCE_H_SGML_1ST_PARAM_COMMENT;
  1179. } else if (issgmlwordchar(ch)) {
  1180. if (scriptLanguage == eScriptSGMLblock) {
  1181. styler.ColourTo(i - 1, SCE_H_SGML_BLOCK_DEFAULT);
  1182. } else {
  1183. styler.ColourTo(i - 1, SCE_H_SGML_DEFAULT);
  1184. }
  1185. // find the length of the word
  1186. int size = 1;
  1187. while (setHTMLWord.Contains(static_cast<unsigned char>(styler.SafeGetCharAt(i + size))))
  1188. size++;
  1189. styler.ColourTo(i + size - 1, StateToPrint);
  1190. i += size - 1;
  1191. visibleChars += size - 1;
  1192. ch = static_cast<unsigned char>(styler.SafeGetCharAt(i));
  1193. if (scriptLanguage == eScriptSGMLblock) {
  1194. state = SCE_H_SGML_BLOCK_DEFAULT;
  1195. } else {
  1196. state = SCE_H_SGML_DEFAULT;
  1197. }
  1198. continue;
  1199. }
  1200. break;
  1201. case SCE_H_SGML_ERROR:
  1202. if ((ch == '-') && (chPrev == '-')) {
  1203. styler.ColourTo(i - 2, StateToPrint);
  1204. state = SCE_H_SGML_COMMENT;
  1205. }
  1206. break;
  1207. case SCE_H_SGML_DOUBLESTRING:
  1208. if (ch == '\"') {
  1209. styler.ColourTo(i, StateToPrint);
  1210. state = SCE_H_SGML_DEFAULT;
  1211. }
  1212. break;
  1213. case SCE_H_SGML_SIMPLESTRING:
  1214. if (ch == '\'') {
  1215. styler.ColourTo(i, StateToPrint);
  1216. state = SCE_H_SGML_DEFAULT;
  1217. }
  1218. break;
  1219. case SCE_H_SGML_COMMENT:
  1220. if ((ch == '-') && (chPrev == '-')) {
  1221. styler.ColourTo(i, StateToPrint);
  1222. state = SCE_H_SGML_DEFAULT;
  1223. }
  1224. break;
  1225. case SCE_H_CDATA:
  1226. if ((chPrev2 == ']') && (chPrev == ']') && (ch == '>')) {
  1227. styler.ColourTo(i, StateToPrint);
  1228. state = SCE_H_DEFAULT;
  1229. levelCurrent--;
  1230. }
  1231. break;
  1232. case SCE_H_COMMENT:
  1233. if ((scriptLanguage != eScriptComment) && (chPrev2 == '-') && (chPrev == '-') && (ch == '>')) {
  1234. styler.ColourTo(i, StateToPrint);
  1235. state = SCE_H_DEFAULT;
  1236. levelCurrent--;
  1237. }
  1238. break;
  1239. case SCE_H_SGML_1ST_PARAM_COMMENT:
  1240. if ((ch == '-') && (chPrev == '-')) {
  1241. styler.ColourTo(i, SCE_H_SGML_COMMENT);
  1242. state = SCE_H_SGML_1ST_PARAM;
  1243. }
  1244. break;
  1245. case SCE_H_SGML_SPECIAL:
  1246. if (!(IsASCII(ch) && isupper(ch))) {
  1247. styler.ColourTo(i - 1, StateToPrint);
  1248. if (isalnum(ch)) {
  1249. state = SCE_H_SGML_ERROR;
  1250. } else {
  1251. state = SCE_H_SGML_DEFAULT;
  1252. }
  1253. }
  1254. break;
  1255. case SCE_H_SGML_ENTITY:
  1256. if (ch == ';') {
  1257. styler.ColourTo(i, StateToPrint);
  1258. state = SCE_H_SGML_DEFAULT;
  1259. } else if (!(IsASCII(ch) && isalnum(ch)) && ch != '-' && ch != '.') {
  1260. styler.ColourTo(i, SCE_H_SGML_ERROR);
  1261. state = SCE_H_SGML_DEFAULT;
  1262. }
  1263. break;
  1264. case SCE_H_ENTITY:
  1265. if (ch == ';') {
  1266. styler.ColourTo(i, StateToPrint);
  1267. state = SCE_H_DEFAULT;
  1268. }
  1269. if (ch != '#' && !(IsASCII(ch) && isalnum(ch)) // Should check that '#' follows '&', but it is unlikely anyway...
  1270. && ch != '.' && ch != '-' && ch != '_' && ch != ':') { // valid in XML
  1271. if (!IsASCII(ch)) // Possibly start of a multibyte character so don't allow this byte to be in entity style
  1272. styler.ColourTo(i-1, SCE_H_TAGUNKNOWN);
  1273. else
  1274. styler.ColourTo(i, SCE_H_TAGUNKNOWN);
  1275. state = SCE_H_DEFAULT;
  1276. }
  1277. break;
  1278. case SCE_H_TAGUNKNOWN:
  1279. if (!setTagContinue.Contains(ch) && !((ch == '/') && (chPrev == '<'))) {
  1280. int eClass = classifyTagHTML(styler.GetStartSegment(),
  1281. i - 1, keywords, styler, tagDontFold, caseSensitive, isXml, allowScripts);
  1282. if (eClass == SCE_H_SCRIPT || eClass == SCE_H_COMMENT) {
  1283. if (!tagClosing) {
  1284. inScriptType = eNonHtmlScript;
  1285. scriptLanguage = eClass == SCE_H_SCRIPT ? clientScript : eScriptComment;
  1286. } else {
  1287. scriptLanguage = eScriptNone;
  1288. }
  1289. eClass = SCE_H_TAG;
  1290. }
  1291. if (ch == '>') {
  1292. styler.ColourTo(i, eClass);
  1293. if (inScriptType == eNonHtmlScript) {
  1294. state = StateForScript(scriptLanguage);
  1295. } else {
  1296. state = SCE_H_DEFAULT;
  1297. }
  1298. tagOpened = false;
  1299. if (!tagDontFold) {
  1300. if (tagClosing) {
  1301. levelCurrent--;
  1302. } else {
  1303. levelCurrent++;
  1304. }
  1305. }
  1306. tagClosing = false;
  1307. } else if (ch == '/' && chNext == '>') {
  1308. if (eClass == SCE_H_TAGUNKNOWN) {
  1309. styler.ColourTo(i + 1, SCE_H_TAGUNKNOWN);
  1310. } else {
  1311. styler.ColourTo(i - 1, StateToPrint);
  1312. styler.ColourTo(i + 1, SCE_H_TAGEND);
  1313. }
  1314. i++;
  1315. ch = chNext;
  1316. state = SCE_H_DEFAULT;
  1317. tagOpened = false;
  1318. } else {
  1319. if (eClass != SCE_H_TAGUNKNOWN) {
  1320. if (eClass == SCE_H_SGML_DEFAULT) {
  1321. state = SCE_H_SGML_DEFAULT;
  1322. } else {
  1323. state = SCE_H_OTHER;
  1324. }
  1325. }
  1326. }
  1327. }
  1328. break;
  1329. case SCE_H_ATTRIBUTE:
  1330. if (!setAttributeContinue.Contains(ch)) {
  1331. if (inScriptType == eNonHtmlScript) {
  1332. int scriptLanguagePrev = scriptLanguage;
  1333. clientScript = segIsScriptingIndicator(styler, styler.GetStartSegment(), i - 1, scriptLanguage);
  1334. scriptLanguage = clientScript;
  1335. if ((scriptLanguagePrev != scriptLanguage) && (scriptLanguage == eScriptNone))
  1336. inScriptType = eHtml;
  1337. }
  1338. classifyAttribHTML(styler.GetStartSegment(), i - 1, keywords, styler);
  1339. if (ch == '>') {
  1340. styler.ColourTo(i, SCE_H_TAG);
  1341. if (inScriptType == eNonHtmlScript) {
  1342. state = StateForScript(scriptLanguage);
  1343. } else {
  1344. state = SCE_H_DEFAULT;
  1345. }
  1346. tagOpened = false;
  1347. if (!tagDontFold) {
  1348. if (tagClosing) {
  1349. levelCurrent--;
  1350. } else {
  1351. levelCurrent++;
  1352. }
  1353. }
  1354. tagClosing = false;
  1355. } else if (ch == '=') {
  1356. styler.ColourTo(i, SCE_H_OTHER);
  1357. state = SCE_H_VALUE;
  1358. } else {
  1359. state = SCE_H_OTHER;
  1360. }
  1361. }
  1362. break;
  1363. case SCE_H_OTHER:
  1364. if (ch == '>') {
  1365. styler.ColourTo(i - 1, StateToPrint);
  1366. styler.ColourTo(i, SCE_H_TAG);
  1367. if (inScriptType == eNonHtmlScript) {
  1368. state = StateForScript(scriptLanguage);
  1369. } else {
  1370. state = SCE_H_DEFAULT;
  1371. }
  1372. tagOpened = false;
  1373. if (!tagDontFold) {
  1374. if (tagClosing) {
  1375. levelCurrent--;
  1376. } else {
  1377. levelCurrent++;
  1378. }
  1379. }
  1380. tagClosing = false;
  1381. } else if (ch == '\"') {
  1382. styler.ColourTo(i - 1, StateToPrint);
  1383. state = SCE_H_DOUBLESTRING;
  1384. } else if (ch == '\'') {
  1385. styler.ColourTo(i - 1, StateToPrint);
  1386. state = SCE_H_SINGLESTRING;
  1387. } else if (ch == '=') {
  1388. styler.ColourTo(i, StateToPrint);
  1389. state = SCE_H_VALUE;
  1390. } else if (ch == '/' && chNext == '>') {
  1391. styler.ColourTo(i - 1, StateToPrint);
  1392. styler.ColourTo(i + 1, SCE_H_TAGEND);
  1393. i++;
  1394. ch = chNext;
  1395. state = SCE_H_DEFAULT;
  1396. tagOpened = false;
  1397. } else if (ch == '?' && chNext == '>') {
  1398. styler.ColourTo(i - 1, StateToPrint);
  1399. styler.ColourTo(i + 1, SCE_H_XMLEND);
  1400. i++;
  1401. ch = chNext;
  1402. state = SCE_H_DEFAULT;
  1403. } else if (setHTMLWord.Contains(ch)) {
  1404. styler.ColourTo(i - 1, StateToPrint);
  1405. state = SCE_H_ATTRIBUTE;
  1406. }
  1407. break;
  1408. case SCE_H_DOUBLESTRING:
  1409. if (ch == '\"') {
  1410. if (inScriptType == eNonHtmlScript) {
  1411. scriptLanguage = segIsScriptingIndicator(styler, styler.GetStartSegment(), i, scriptLanguage);
  1412. }
  1413. styler.ColourTo(i, SCE_H_DOUBLESTRING);
  1414. state = SCE_H_OTHER;
  1415. }
  1416. break;
  1417. case SCE_H_SINGLESTRING:
  1418. if (ch == '\'') {
  1419. if (inScriptType == eNonHtmlScript) {
  1420. scriptLanguage = segIsScriptingIndicator(styler, styler.GetStartSegment(), i, scriptLanguage);
  1421. }
  1422. styler.ColourTo(i, SCE_H_SINGLESTRING);
  1423. state = SCE_H_OTHER;
  1424. }
  1425. break;
  1426. case SCE_H_VALUE:
  1427. if (!setHTMLWord.Contains(ch)) {
  1428. if (ch == '\"' && chPrev == '=') {
  1429. // Should really test for being first character
  1430. state = SCE_H_DOUBLESTRING;
  1431. } else if (ch == '\'' && chPrev == '=') {
  1432. state = SCE_H_SINGLESTRING;
  1433. } else {
  1434. if (IsNumber(styler.GetStartSegment(), styler)) {
  1435. styler.ColourTo(i - 1, SCE_H_NUMBER);
  1436. } else {
  1437. styler.ColourTo(i - 1, StateToPrint);
  1438. }
  1439. if (ch == '>') {
  1440. styler.ColourTo(i, SCE_H_TAG);
  1441. if (inScriptType == eNonHtmlScript) {
  1442. state = StateForScript(scriptLanguage);
  1443. } else {
  1444. state = SCE_H_DEFAULT;
  1445. }
  1446. tagOpened = false;
  1447. if (!tagDontFold) {
  1448. if (tagClosing) {
  1449. levelCurrent--;
  1450. } else {
  1451. levelCurrent++;
  1452. }
  1453. }
  1454. tagClosing = false;
  1455. } else {
  1456. state = SCE_H_OTHER;
  1457. }
  1458. }
  1459. }
  1460. break;
  1461. case SCE_HJ_DEFAULT:
  1462. case SCE_HJ_START:
  1463. case SCE_HJ_SYMBOLS:
  1464. if (IsAWordStart(ch)) {
  1465. styler.ColourTo(i - 1, StateToPrint);
  1466. state = SCE_HJ_WORD;
  1467. } else if (ch == '/' && chNext == '*') {
  1468. styler.ColourTo(i - 1, StateToPrint);
  1469. if (chNext2 == '*')
  1470. state = SCE_HJ_COMMENTDOC;
  1471. else
  1472. state = SCE_HJ_COMMENT;
  1473. if (chNext2 == '/') {
  1474. // Eat the * so it isn't used for the end of the comment
  1475. i++;
  1476. }
  1477. } else if (ch == '/' && chNext == '/') {
  1478. styler.ColourTo(i - 1, StateToPrint);
  1479. state = SCE_HJ_COMMENTLINE;
  1480. } else if (ch == '/' && setOKBeforeJSRE.Contains(chPrevNonWhite)) {
  1481. styler.ColourTo(i - 1, StateToPrint);
  1482. state = SCE_HJ_REGEX;
  1483. } else if (ch == '\"') {
  1484. styler.ColourTo(i - 1, StateToPrint);
  1485. state = SCE_HJ_DOUBLESTRING;
  1486. } else if (ch == '\'') {
  1487. styler.ColourTo(i - 1, StateToPrint);
  1488. state = SCE_HJ_SINGLESTRING;
  1489. } else if ((ch == '<') && (chNext == '!') && (chNext2 == '-') &&
  1490. styler.SafeGetCharAt(i + 3) == '-') {
  1491. styler.ColourTo(i - 1, StateToPrint);
  1492. state = SCE_HJ_COMMENTLINE;
  1493. } else if ((ch == '-') && (chNext == '-') && (chNext2 == '>')) {
  1494. styler.ColourTo(i - 1, StateToPrint);
  1495. state = SCE_HJ_COMMENTLINE;
  1496. i += 2;
  1497. } else if (IsOperator(ch)) {
  1498. styler.ColourTo(i - 1, StateToPrint);
  1499. styler.ColourTo(i, statePrintForState(SCE_HJ_SYMBOLS, inScriptType));
  1500. state = SCE_HJ_DEFAULT;
  1501. } else if ((ch == ' ') || (ch == '\t')) {
  1502. if (state == SCE_HJ_START) {
  1503. styler.ColourTo(i - 1, StateToPrint);
  1504. state = SCE_HJ_DEFAULT;
  1505. }
  1506. }
  1507. break;
  1508. case SCE_HJ_WORD:
  1509. if (!IsAWordChar(ch)) {
  1510. classifyWordHTJS(styler.GetStartSegment(), i - 1, keywords2, styler, inScriptType);
  1511. //styler.ColourTo(i - 1, eHTJSKeyword);
  1512. state = SCE_HJ_DEFAULT;
  1513. if (ch == '/' && chNext == '*') {
  1514. if (chNext2 == '*')
  1515. state = SCE_HJ_COMMENTDOC;
  1516. else
  1517. state = SCE_HJ_COMMENT;
  1518. } else if (ch == '/' && chNext == '/') {
  1519. state = SCE_HJ_COMMENTLINE;
  1520. } else if (ch == '\"') {
  1521. state = SCE_HJ_DOUBLESTRING;
  1522. } else if (ch == '\'') {
  1523. state = SCE_HJ_SINGLESTRING;
  1524. } else if ((ch == '-') && (chNext == '-') && (chNext2 == '>')) {
  1525. styler.ColourTo(i - 1, StateToPrint);
  1526. state = SCE_HJ_COMMENTLINE;
  1527. i += 2;
  1528. } else if (IsOperator(ch)) {
  1529. styler.ColourTo(i, statePrintForState(SCE_HJ_SYMBOLS, inScriptType));
  1530. state = SCE_HJ_DEFAULT;
  1531. }
  1532. }
  1533. break;
  1534. case SCE_HJ_COMMENT:
  1535. case SCE_HJ_COMMENTDOC:
  1536. if (ch == '/' && chPrev == '*') {
  1537. styler.ColourTo(i, StateToPrint);
  1538. state = SCE_HJ_DEFAULT;
  1539. ch = ' ';
  1540. }
  1541. break;
  1542. case SCE_HJ_COMMENTLINE:
  1543. if (ch == '\r' || ch == '\n') {
  1544. styler.ColourTo(i - 1, statePrintForState(SCE_HJ_COMMENTLINE, inScriptType));
  1545. state = SCE_HJ_DEFAULT;
  1546. ch = ' ';
  1547. }
  1548. break;
  1549. case SCE_HJ_DOUBLESTRING:
  1550. if (ch == '\\') {
  1551. if (chNext == '\"' || chNext == '\'' || chNext == '\\') {
  1552. i++;
  1553. }
  1554. } else if (ch == '\"') {
  1555. styler.ColourTo(i, statePrintForState(SCE_HJ_DOUBLESTRING, inScriptType));
  1556. state = SCE_HJ_DEFAULT;
  1557. } else if ((inScriptType == eNonHtmlScript) && (ch == '-') && (chNext == '-') && (chNext2 == '>')) {
  1558. styler.ColourTo(i - 1, StateToPrint);
  1559. state = SCE_HJ_COMMENTLINE;
  1560. i += 2;
  1561. } else if (isLineEnd(ch)) {
  1562. styler.ColourTo(i - 1, StateToPrint);
  1563. state = SCE_HJ_STRINGEOL;
  1564. }
  1565. break;
  1566. case SCE_HJ_SINGLESTRING:
  1567. if (ch == '\\') {
  1568. if (chNext == '\"' || chNext == '\'' || chNext == '\\') {
  1569. i++;
  1570. }
  1571. } else if (ch == '\'') {
  1572. styler.ColourTo(i, statePrintForState(SCE_HJ_SINGLESTRING, inScriptType));
  1573. state = SCE_HJ_DEFAULT;
  1574. } else if ((inScriptType == eNonHtmlScript) && (ch == '-') && (chNext == '-') && (chNext2 == '>')) {
  1575. styler.ColourTo(i - 1, StateToPrint);
  1576. state = SCE_HJ_COMMENTLINE;
  1577. i += 2;
  1578. } else if (isLineEnd(ch)) {
  1579. styler.ColourTo(i - 1, StateToPrint);
  1580. if (chPrev != '\\' && (chPrev2 != '\\' || chPrev != '\r' || ch != '\n')) {
  1581. state = SCE_HJ_STRINGEOL;
  1582. }
  1583. }
  1584. break;
  1585. case SCE_HJ_STRINGEOL:
  1586. if (!isLineEnd(ch)) {
  1587. styler.ColourTo(i - 1, StateToPrint);
  1588. state = SCE_HJ_DEFAULT;
  1589. } else if (!isLineEnd(chNext)) {
  1590. styler.ColourTo(i, StateToPrint);
  1591. state = SCE_HJ_DEFAULT;
  1592. }
  1593. break;
  1594. case SCE_HJ_REGEX:
  1595. if (ch == '\r' || ch == '\n' || ch == '/') {
  1596. if (ch == '/') {
  1597. while (IsASCII(chNext) && islower(chNext)) { // gobble regex flags
  1598. i++;
  1599. ch = chNext;
  1600. chNext = static_cast<unsigned char>(styler.SafeGetCharAt(i + 1));
  1601. }
  1602. }
  1603. styler.ColourTo(i, StateToPrint);
  1604. state = SCE_HJ_DEFAULT;
  1605. } else if (ch == '\\') {
  1606. // Gobble up the quoted character
  1607. if (chNext == '\\' || chNext == '/') {
  1608. i++;
  1609. ch = chNext;
  1610. chNext = static_cast<unsigned char>(styler.SafeGetCharAt(i + 1));
  1611. }
  1612. }
  1613. break;
  1614. case SCE_HB_DEFAULT:
  1615. case SCE_HB_START:
  1616. if (IsAWordStart(ch)) {
  1617. styler.ColourTo(i - 1, StateToPrint);
  1618. state = SCE_HB_WORD;
  1619. } else if (ch == '\'') {
  1620. styler.ColourTo(i - 1, StateToPrint);
  1621. state = SCE_HB_COMMENTLINE;
  1622. } else if (ch == '\"') {
  1623. styler.ColourTo(i - 1, StateToPrint);
  1624. state = SCE_HB_STRING;
  1625. } else if ((ch == '<') && (chNext == '!') && (chNext2 == '-') &&
  1626. styler.SafeGetCharAt(i + 3) == '-') {
  1627. styler.ColourTo(i - 1, StateToPrint);
  1628. state = SCE_HB_COMMENTLINE;
  1629. } else if (IsOperator(ch)) {
  1630. styler.ColourTo(i - 1, StateToPrint);
  1631. styler.ColourTo(i, statePrintForState(SCE_HB_DEFAULT, inScriptType));
  1632. state = SCE_HB_DEFAULT;
  1633. } else if ((ch == ' ') || (ch == '\t')) {
  1634. if (state == SCE_HB_START) {
  1635. styler.ColourTo(i - 1, StateToPrint);
  1636. state = SCE_HB_DEFAULT;
  1637. }
  1638. }
  1639. break;
  1640. case SCE_HB_WORD:
  1641. if (!IsAWordChar(ch)) {
  1642. state = classifyWordHTVB(styler.GetStartSegment(), i - 1, keywords3, styler, inScriptType);
  1643. if (state == SCE_HB_DEFAULT) {
  1644. if (ch == '\"') {
  1645. state = SCE_HB_STRING;
  1646. } else if (ch == '\'') {
  1647. state = SCE_HB_COMMENTLINE;
  1648. } else if (IsOperator(ch)) {
  1649. styler.ColourTo(i, statePrintForState(SCE_HB_DEFAULT, inScriptType));
  1650. state = SCE_HB_DEFAULT;
  1651. }
  1652. }
  1653. }
  1654. break;
  1655. case SCE_HB_STRING:
  1656. if (ch == '\"') {
  1657. styler.ColourTo(i, StateToPrint);
  1658. state = SCE_HB_DEFAULT;
  1659. } else if (ch == '\r' || ch == '\n') {
  1660. styler.ColourTo(i - 1, StateToPrint);
  1661. state = SCE_HB_STRINGEOL;
  1662. }
  1663. break;
  1664. case SCE_HB_COMMENTLINE:
  1665. if (ch == '\r' || ch == '\n') {
  1666. styler.ColourTo(i - 1, StateToPrint);
  1667. state = SCE_HB_DEFAULT;
  1668. }
  1669. break;
  1670. case SCE_HB_STRINGEOL:
  1671. if (!isLineEnd(ch)) {
  1672. styler.ColourTo(i - 1, StateToPrint);
  1673. state = SCE_HB_DEFAULT;
  1674. } else if (!isLineEnd(chNext)) {
  1675. styler.ColourTo(i, StateToPrint);
  1676. state = SCE_HB_DEFAULT;
  1677. }
  1678. break;
  1679. case SCE_HP_DEFAULT:
  1680. case SCE_HP_START:
  1681. if (IsAWordStart(ch)) {
  1682. styler.ColourTo(i - 1, StateToPrint);
  1683. state = SCE_HP_WORD;
  1684. } else if ((ch == '<') && (chNext == '!') && (chNext2 == '-') &&
  1685. styler.SafeGetCharAt(i + 3) == '-') {
  1686. styler.ColourTo(i - 1, StateToPrint);
  1687. state = SCE_HP_COMMENTLINE;
  1688. } else if (ch == '#') {
  1689. styler.ColourTo(i - 1, StateToPrint);
  1690. state = SCE_HP_COMMENTLINE;
  1691. } else if (ch == '\"') {
  1692. styler.ColourTo(i - 1, StateToPrint);
  1693. if (chNext == '\"' && chNext2 == '\"') {
  1694. i += 2;
  1695. state = SCE_HP_TRIPLEDOUBLE;
  1696. ch = ' ';
  1697. chPrev = ' ';
  1698. chNext = static_cast<unsigned char>(styler.SafeGetCharAt(i + 1));
  1699. } else {
  1700. // state = statePrintForState(SCE_HP_STRING,inScriptType);
  1701. state = SCE_HP_STRING;
  1702. }
  1703. } else if (ch == '\'') {
  1704. styler.ColourTo(i - 1, StateToPrint);
  1705. if (chNext == '\'' && chNext2 == '\'') {
  1706. i += 2;
  1707. state = SCE_HP_TRIPLE;
  1708. ch = ' ';
  1709. chPrev = ' ';
  1710. chNext = static_cast<unsigned char>(styler.SafeGetCharAt(i + 1));
  1711. } else {
  1712. state = SCE_HP_CHARACTER;
  1713. }
  1714. } else if (IsOperator(ch)) {
  1715. styler.ColourTo(i - 1, StateToPrint);
  1716. styler.ColourTo(i, statePrintForState(SCE_HP_OPERATOR, inScriptType));
  1717. } else if ((ch == ' ') || (ch == '\t')) {
  1718. if (state == SCE_HP_START) {
  1719. styler.ColourTo(i - 1, StateToPrint);
  1720. state = SCE_HP_DEFAULT;
  1721. }
  1722. }
  1723. break;
  1724. case SCE_HP_WORD:
  1725. if (!IsAWordChar(ch)) {
  1726. classifyWordHTPy(styler.GetStartSegment(), i - 1, keywords4, styler, prevWord, inScriptType, isMako);
  1727. state = SCE_HP_DEFAULT;
  1728. if (ch == '#') {
  1729. state = SCE_HP_COMMENTLINE;
  1730. } else if (ch == '\"') {
  1731. if (chNext == '\"' && chNext2 == '\"') {
  1732. i += 2;
  1733. state = SCE_HP_TRIPLEDOUBLE;
  1734. ch = ' ';
  1735. chPrev = ' ';
  1736. chNext = static_cast<unsigned char>(styler.SafeGetCharAt(i + 1));
  1737. } else {
  1738. state = SCE_HP_STRING;
  1739. }
  1740. } else if (ch == '\'') {
  1741. if (chNext == '\'' && chNext2 == '\'') {
  1742. i += 2;
  1743. state = SCE_HP_TRIPLE;
  1744. ch = ' ';
  1745. chPrev = ' ';
  1746. chNext = static_cast<unsigned char>(styler.SafeGetCharAt(i + 1));
  1747. } else {
  1748. state = SCE_HP_CHARACTER;
  1749. }
  1750. } else if (IsOperator(ch)) {
  1751. styler.ColourTo(i, statePrintForState(SCE_HP_OPERATOR, inScriptType));
  1752. }
  1753. }
  1754. break;
  1755. case SCE_HP_COMMENTLINE:
  1756. if (ch == '\r' || ch == '\n') {
  1757. styler.ColourTo(i - 1, StateToPrint);
  1758. state = SCE_HP_DEFAULT;
  1759. }
  1760. break;
  1761. case SCE_HP_STRING:
  1762. if (ch == '\\') {
  1763. if (chNext == '\"' || chNext == '\'' || chNext == '\\') {
  1764. i++;
  1765. ch = chNext;
  1766. chNext = static_cast<unsigned char>(styler.SafeGetCharAt(i + 1));
  1767. }
  1768. } else if (ch == '\"') {
  1769. styler.ColourTo(i, StateToPrint);
  1770. state = SCE_HP_DEFAULT;
  1771. }
  1772. break;
  1773. case SCE_HP_CHARACTER:
  1774. if (ch == '\\') {
  1775. if (chNext == '\"' || chNext == '\'' || chNext == '\\') {
  1776. i++;
  1777. ch = chNext;
  1778. chNext = static_cast<unsigned char>(styler.SafeGetCharAt(i + 1));
  1779. }
  1780. } else if (ch == '\'') {
  1781. styler.ColourTo(i, StateToPrint);
  1782. state = SCE_HP_DEFAULT;
  1783. }
  1784. break;
  1785. case SCE_HP_TRIPLE:
  1786. if (ch == '\'' && chPrev == '\'' && chPrev2 == '\'') {
  1787. styler.ColourTo(i, StateToPrint);
  1788. state = SCE_HP_DEFAULT;
  1789. }
  1790. break;
  1791. case SCE_HP_TRIPLEDOUBLE:
  1792. if (ch == '\"' && chPrev == '\"' && chPrev2 == '\"') {
  1793. styler.ColourTo(i, StateToPrint);
  1794. state = SCE_HP_DEFAULT;
  1795. }
  1796. break;
  1797. ///////////// start - PHP state handling
  1798. case SCE_HPHP_WORD:
  1799. if (!IsAWordChar(ch)) {
  1800. classifyWordHTPHP(styler.GetStartSegment(), i - 1, keywords5, styler);
  1801. if (ch == '/' && chNext == '*') {
  1802. i++;
  1803. state = SCE_HPHP_COMMENT;
  1804. } else if (ch == '/' && chNext == '/') {
  1805. i++;
  1806. state = SCE_HPHP_COMMENTLINE;
  1807. } else if (ch == '#') {
  1808. state = SCE_HPHP_COMMENTLINE;
  1809. } else if (ch == '\"') {
  1810. state = SCE_HPHP_HSTRING;
  1811. StringCopy(phpStringDelimiter, "\"");
  1812. } else if (styler.Match(i, "<<<")) {
  1813. bool isSimpleString = false;
  1814. i = FindPhpStringDelimiter(phpStringDelimiter, sizeof(phpStringDelimiter), i + 3, lengthDoc, styler, isSimpleString);
  1815. if (strlen(phpStringDelimiter)) {
  1816. state = (isSimpleString ? SCE_HPHP_SIMPLESTRING : SCE_HPHP_HSTRING);
  1817. if (foldHeredoc) levelCurrent++;
  1818. }
  1819. } else if (ch == '\'') {
  1820. state = SCE_HPHP_SIMPLESTRING;
  1821. StringCopy(phpStringDelimiter, "\'");
  1822. } else if (ch == '$' && IsPhpWordStart(chNext)) {
  1823. state = SCE_HPHP_VARIABLE;
  1824. } else if (IsOperator(ch)) {
  1825. state = SCE_HPHP_OPERATOR;
  1826. } else {
  1827. state = SCE_HPHP_DEFAULT;
  1828. }
  1829. }
  1830. break;
  1831. case SCE_HPHP_NUMBER:
  1832. // recognize bases 8,10 or 16 integers OR floating-point numbers
  1833. if (!IsADigit(ch)
  1834. && strchr(".xXabcdefABCDEF", ch) == NULL
  1835. && ((ch != '-' && ch != '+') || (chPrev != 'e' && chPrev != 'E'))) {
  1836. styler.ColourTo(i - 1, SCE_HPHP_NUMBER);
  1837. if (IsOperator(ch))
  1838. state = SCE_HPHP_OPERATOR;
  1839. else
  1840. state = SCE_HPHP_DEFAULT;
  1841. }
  1842. break;
  1843. case SCE_HPHP_VARIABLE:
  1844. if (!IsPhpWordChar(chNext)) {
  1845. styler.ColourTo(i, SCE_HPHP_VARIABLE);
  1846. state = SCE_HPHP_DEFAULT;
  1847. }
  1848. break;
  1849. case SCE_HPHP_COMMENT:
  1850. if (ch == '/' && chPrev == '*') {
  1851. styler.ColourTo(i, StateToPrint);
  1852. state = SCE_HPHP_DEFAULT;
  1853. }
  1854. break;
  1855. case SCE_HPHP_COMMENTLINE:
  1856. if (ch == '\r' || ch == '\n') {
  1857. styler.ColourTo(i - 1, StateToPrint);
  1858. state = SCE_HPHP_DEFAULT;
  1859. }
  1860. break;
  1861. case SCE_HPHP_HSTRING:
  1862. if (ch == '\\' && (phpStringDelimiter[0] == '\"' || chNext == '$' || chNext == '{')) {
  1863. // skip the next char
  1864. i++;
  1865. } else if (((ch == '{' && chNext == '$') || (ch == '$' && chNext == '{'))
  1866. && IsPhpWordStart(chNext2)) {
  1867. styler.ColourTo(i - 1, StateToPrint);
  1868. state = SCE_HPHP_COMPLEX_VARIABLE;
  1869. } else if (ch == '$' && IsPhpWordStart(chNext)) {
  1870. styler.ColourTo(i - 1, StateToPrint);
  1871. state = SCE_HPHP_HSTRING_VARIABLE;
  1872. } else if (styler.Match(i, phpStringDelimiter)) {
  1873. if (phpStringDelimiter[0] == '\"') {
  1874. styler.ColourTo(i, StateToPrint);
  1875. state = SCE_HPHP_DEFAULT;
  1876. } else if (isLineEnd(chPrev)) {
  1877. const int psdLength = static_cast<int>(strlen(phpStringDelimiter));
  1878. const char chAfterPsd = styler.SafeGetCharAt(i + psdLength);
  1879. const char chAfterPsd2 = styler.SafeGetCharAt(i + psdLength + 1);
  1880. if (isLineEnd(chAfterPsd) ||
  1881. (chAfterPsd == ';' && isLineEnd(chAfterPsd2))) {
  1882. i += (((i + psdLength) < lengthDoc) ? psdLength : lengthDoc) - 1;
  1883. styler.ColourTo(i, StateToPrint);
  1884. state = SCE_HPHP_DEFAULT;
  1885. if (foldHeredoc) levelCurrent--;
  1886. }
  1887. }
  1888. }
  1889. break;
  1890. case SCE_HPHP_SIMPLESTRING:
  1891. if (phpStringDelimiter[0] == '\'') {
  1892. if (ch == '\\') {
  1893. // skip the next char
  1894. i++;
  1895. } else if (ch == '\'') {
  1896. styler.ColourTo(i, StateToPrint);
  1897. state = SCE_HPHP_DEFAULT;
  1898. }
  1899. } else if (isLineEnd(chPrev) && styler.Match(i, phpStringDelimiter)) {
  1900. const int psdLength = static_cast<int>(strlen(phpStringDelimiter));
  1901. const char chAfterPsd = styler.SafeGetCharAt(i + psdLength);
  1902. const char chAfterPsd2 = styler.SafeGetCharAt(i + psdLength + 1);
  1903. if (isLineEnd(chAfterPsd) ||
  1904. (chAfterPsd == ';' && isLineEnd(chAfterPsd2))) {
  1905. i += (((i + psdLength) < lengthDoc) ? psdLength : lengthDoc) - 1;
  1906. styler.ColourTo(i, StateToPrint);
  1907. state = SCE_HPHP_DEFAULT;
  1908. if (foldHeredoc) levelCurrent--;
  1909. }
  1910. }
  1911. break;
  1912. case SCE_HPHP_HSTRING_VARIABLE:
  1913. if (!IsPhpWordChar(chNext)) {
  1914. styler.ColourTo(i, StateToPrint);
  1915. state = SCE_HPHP_HSTRING;
  1916. }
  1917. break;
  1918. case SCE_HPHP_COMPLEX_VARIABLE:
  1919. if (ch == '}') {
  1920. styler.ColourTo(i, StateToPrint);
  1921. state = SCE_HPHP_HSTRING;
  1922. }
  1923. break;
  1924. case SCE_HPHP_OPERATOR:
  1925. case SCE_HPHP_DEFAULT:
  1926. styler.ColourTo(i - 1, StateToPrint);
  1927. if (IsADigit(ch) || (ch == '.' && IsADigit(chNext))) {
  1928. state = SCE_HPHP_NUMBER;
  1929. } else if (IsAWordStart(ch)) {
  1930. state = SCE_HPHP_WORD;
  1931. } else if (ch == '/' && chNext == '*') {
  1932. i++;
  1933. state = SCE_HPHP_COMMENT;
  1934. } else if (ch == '/' && chNext == '/') {
  1935. i++;
  1936. state = SCE_HPHP_COMMENTLINE;
  1937. } else if (ch == '#') {
  1938. state = SCE_HPHP_COMMENTLINE;
  1939. } else if (ch == '\"') {
  1940. state = SCE_HPHP_HSTRING;
  1941. StringCopy(phpStringDelimiter, "\"");
  1942. } else if (styler.Match(i, "<<<")) {
  1943. bool isSimpleString = false;
  1944. i = FindPhpStringDelimiter(phpStringDelimiter, sizeof(phpStringDelimiter), i + 3, lengthDoc, styler, isSimpleString);
  1945. if (strlen(phpStringDelimiter)) {
  1946. state = (isSimpleString ? SCE_HPHP_SIMPLESTRING : SCE_HPHP_HSTRING);
  1947. if (foldHeredoc) levelCurrent++;
  1948. }
  1949. } else if (ch == '\'') {
  1950. state = SCE_HPHP_SIMPLESTRING;
  1951. StringCopy(phpStringDelimiter, "\'");
  1952. } else if (ch == '$' && IsPhpWordStart(chNext)) {
  1953. state = SCE_HPHP_VARIABLE;
  1954. } else if (IsOperator(ch)) {
  1955. state = SCE_HPHP_OPERATOR;
  1956. } else if ((state == SCE_HPHP_OPERATOR) && (IsASpace(ch))) {
  1957. state = SCE_HPHP_DEFAULT;
  1958. }
  1959. break;
  1960. ///////////// end - PHP state handling
  1961. }
  1962. // Some of the above terminated their lexeme but since the same character starts
  1963. // the same class again, only reenter if non empty segment.
  1964. bool nonEmptySegment = i >= static_cast<int>(styler.GetStartSegment());
  1965. if (state == SCE_HB_DEFAULT) { // One of the above succeeded
  1966. if ((ch == '\"') && (nonEmptySegment)) {
  1967. state = SCE_HB_STRING;
  1968. } else if (ch == '\'') {
  1969. state = SCE_HB_COMMENTLINE;
  1970. } else if (IsAWordStart(ch)) {
  1971. state = SCE_HB_WORD;
  1972. } else if (IsOperator(ch)) {
  1973. styler.ColourTo(i, SCE_HB_DEFAULT);
  1974. }
  1975. } else if (state == SCE_HBA_DEFAULT) { // One of the above succeeded
  1976. if ((ch == '\"') && (nonEmptySegment)) {
  1977. state = SCE_HBA_STRING;
  1978. } else if (ch == '\'') {
  1979. state = SCE_HBA_COMMENTLINE;
  1980. } else if (IsAWordStart(ch)) {
  1981. state = SCE_HBA_WORD;
  1982. } else if (IsOperator(ch)) {
  1983. styler.ColourTo(i, SCE_HBA_DEFAULT);
  1984. }
  1985. } else if (state == SCE_HJ_DEFAULT) { // One of the above succeeded
  1986. if (ch == '/' && chNext == '*') {
  1987. if (styler.SafeGetCharAt(i + 2) == '*')
  1988. state = SCE_HJ_COMMENTDOC;
  1989. else
  1990. state = SCE_HJ_COMMENT;
  1991. } else if (ch == '/' && chNext == '/') {
  1992. state = SCE_HJ_COMMENTLINE;
  1993. } else if ((ch == '\"') && (nonEmptySegment)) {
  1994. state = SCE_HJ_DOUBLESTRING;
  1995. } else if ((ch == '\'') && (nonEmptySegment)) {
  1996. state = SCE_HJ_SINGLESTRING;
  1997. } else if (IsAWordStart(ch)) {
  1998. state = SCE_HJ_WORD;
  1999. } else if (IsOperator(ch)) {
  2000. styler.ColourTo(i, statePrintForState(SCE_HJ_SYMBOLS, inScriptType));
  2001. }
  2002. }
  2003. }
  2004. switch (state) {
  2005. case SCE_HJ_WORD:
  2006. classifyWordHTJS(styler.GetStartSegment(), lengthDoc - 1, keywords2, styler, inScriptType);
  2007. break;
  2008. case SCE_HB_WORD:
  2009. classifyWordHTVB(styler.GetStartSegment(), lengthDoc - 1, keywords3, styler, inScriptType);
  2010. break;
  2011. case SCE_HP_WORD:
  2012. classifyWordHTPy(styler.GetStartSegment(), lengthDoc - 1, keywords4, styler, prevWord, inScriptType, isMako);
  2013. break;
  2014. case SCE_HPHP_WORD:
  2015. classifyWordHTPHP(styler.GetStartSegment(), lengthDoc - 1, keywords5, styler);
  2016. break;
  2017. default:
  2018. StateToPrint = statePrintForState(state, inScriptType);
  2019. if (static_cast<int>(styler.GetStartSegment()) < lengthDoc)
  2020. styler.ColourTo(lengthDoc - 1, StateToPrint);
  2021. break;
  2022. }
  2023. // Fill in the real level of the next line, keeping the current flags as they will be filled in later
  2024. if (fold) {
  2025. int flagsNext = styler.LevelAt(lineCurrent) & ~SC_FOLDLEVELNUMBERMASK;
  2026. styler.SetLevel(lineCurrent, levelPrev | flagsNext);
  2027. }
  2028. }
  2029. static void ColouriseXMLDoc(unsigned int startPos, int length, int initStyle, WordList *keywordlists[],
  2030. Accessor &styler) {
  2031. // Passing in true because we're lexing XML
  2032. ColouriseHyperTextDoc(startPos, length, initStyle, keywordlists, styler, true);
  2033. }
  2034. static void ColouriseHTMLDoc(unsigned int startPos, int length, int initStyle, WordList *keywordlists[],
  2035. Accessor &styler) {
  2036. // Passing in false because we're notlexing XML
  2037. ColouriseHyperTextDoc(startPos, length, initStyle, keywordlists, styler, false);
  2038. }
  2039. static void ColourisePHPScriptDoc(unsigned int startPos, int length, int initStyle, WordList *keywordlists[],
  2040. Accessor &styler) {
  2041. if (startPos == 0)
  2042. initStyle = SCE_HPHP_DEFAULT;
  2043. ColouriseHTMLDoc(startPos, length, initStyle, keywordlists, styler);
  2044. }
  2045. static const char * const htmlWordListDesc[] = {
  2046. "HTML elements and attributes",
  2047. "JavaScript keywords",
  2048. "VBScript keywords",
  2049. "Python keywords",
  2050. "PHP keywords",
  2051. "SGML and DTD keywords",
  2052. 0,
  2053. };
  2054. static const char * const phpscriptWordListDesc[] = {
  2055. "", //Unused
  2056. "", //Unused
  2057. "", //Unused
  2058. "", //Unused
  2059. "PHP keywords",
  2060. "", //Unused
  2061. 0,
  2062. };
  2063. LexerModule lmHTML(SCLEX_HTML, ColouriseHTMLDoc, "hypertext", 0, htmlWordListDesc);
  2064. LexerModule lmXML(SCLEX_XML, ColouriseXMLDoc, "xml", 0, htmlWordListDesc);
  2065. LexerModule lmPHPSCRIPT(SCLEX_PHPSCRIPT, ColourisePHPScriptDoc, "phpscript", 0, phpscriptWordListDesc);