PageRenderTime 44ms CodeModel.GetById 13ms RepoModel.GetById 1ms app.codeStats 0ms

/cssed-0.4.0/scintilla/src/LexOthers.cxx

#
C++ | 1130 lines | 896 code | 61 blank | 173 comment | 539 complexity | 9b882b494cab315509d4ab08c45afd5a MD5 | raw file
Possible License(s): GPL-2.0
  1. // Scintilla source code edit control
  2. /** @file LexOthers.cxx
  3. ** Lexers for batch files, diff results, properties files, make files and error lists.
  4. ** Also lexer for LaTeX documents.
  5. **/
  6. // Copyright 1998-2001 by Neil Hodgson <neilh@scintilla.org>
  7. // The License.txt file describes the conditions under which this software may be distributed.
  8. #include <stdlib.h>
  9. #include <string.h>
  10. #include <ctype.h>
  11. #include <stdio.h>
  12. #include <stdarg.h>
  13. #include "Platform.h"
  14. #include "PropSet.h"
  15. #include "Accessor.h"
  16. #include "KeyWords.h"
  17. #include "Scintilla.h"
  18. #include "SciLexer.h"
  19. static bool Is0To9(char ch) {
  20. return (ch >= '0') && (ch <= '9');
  21. }
  22. static bool Is1To9(char ch) {
  23. return (ch >= '1') && (ch <= '9');
  24. }
  25. static inline bool AtEOL(Accessor &styler, unsigned int i) {
  26. return (styler[i] == '\n') ||
  27. ((styler[i] == '\r') && (styler.SafeGetCharAt(i + 1) != '\n'));
  28. }
  29. // Tests for BATCH Operators
  30. static bool IsBOperator(char ch) {
  31. return (ch == '=') || (ch == '+') || (ch == '>') || (ch == '<') ||
  32. (ch == '|') || (ch == '?') || (ch == '*');
  33. }
  34. // Tests for BATCH Separators
  35. static bool IsBSeparator(char ch) {
  36. return (ch == ':') || (ch == '\\') || (ch == '.') || (ch == ';') ||
  37. (ch == '\"') || (ch == '\'') || (ch == '/') || (ch == ')');
  38. }
  39. static void ColouriseBatchLine(
  40. char *lineBuffer,
  41. unsigned int lengthLine,
  42. unsigned int startLine,
  43. unsigned int endPos,
  44. WordList &keywords,
  45. Accessor &styler) {
  46. unsigned int offset = 0; // Line Buffer Offset
  47. unsigned int enVarEnd; // Environment Variable End point
  48. unsigned int cmdLoc; // External Command / Program Location
  49. char wordBuffer[81]; // Word Buffer - large to catch long paths
  50. unsigned int wbl; // Word Buffer Length
  51. unsigned int wbo; // Word Buffer Offset - also Special Keyword Buffer Length
  52. bool forFound = false; // No Local Variable without FOR statement
  53. // CHOICE, ECHO, GOTO, PROMPT and SET have Default Text that may contain Regular Keywords
  54. // Toggling Regular Keyword Checking off improves readability
  55. // Other Regular Keywords and External Commands / Programs might also benefit from toggling
  56. // Need a more robust algorithm to properly toggle Regular Keyword Checking
  57. bool continueProcessing = true; // Used to toggle Regular Keyword Checking
  58. // Special Keywords are those that allow certain characters without whitespace after the command
  59. // Examples are: cd. cd\ md. rd. dir| dir> echo: echo. path=
  60. // Special Keyword Buffer used to determine if the first n characters is a Keyword
  61. char sKeywordBuffer[10]; // Special Keyword Buffer
  62. bool sKeywordFound; // Exit Special Keyword for-loop if found
  63. // Skip initial spaces
  64. while ((offset < lengthLine) && (isspacechar(lineBuffer[offset]))) {
  65. offset++;
  66. }
  67. // Colorize Default Text
  68. styler.ColourTo(startLine + offset - 1, SCE_BAT_DEFAULT);
  69. // Set External Command / Program Location
  70. cmdLoc = offset;
  71. // Check for Fake Label (Comment) or Real Label - return if found
  72. if (lineBuffer[offset] == ':') {
  73. if (lineBuffer[offset + 1] == ':') {
  74. // Colorize Fake Label (Comment) - :: is similar to REM, see http://content.techweb.com/winmag/columns/explorer/2000/21.htm
  75. styler.ColourTo(endPos, SCE_BAT_COMMENT);
  76. } else {
  77. // Colorize Real Label
  78. styler.ColourTo(endPos, SCE_BAT_LABEL);
  79. }
  80. return;
  81. // Check for Drive Change (Drive Change is internal command) - return if found
  82. } else if ((isalpha(lineBuffer[offset])) &&
  83. (lineBuffer[offset + 1] == ':') &&
  84. ((isspacechar(lineBuffer[offset + 2])) ||
  85. (((lineBuffer[offset + 2] == '\\')) &&
  86. (isspacechar(lineBuffer[offset + 3]))))) {
  87. // Colorize Regular Keyword
  88. styler.ColourTo(endPos, SCE_BAT_WORD);
  89. return;
  90. }
  91. // Check for Hide Command (@ECHO OFF/ON)
  92. if (lineBuffer[offset] == '@') {
  93. styler.ColourTo(startLine + offset, SCE_BAT_HIDE);
  94. offset++;
  95. // Check for Argument (%n) or Environment Variable (%x...%)
  96. } else if (lineBuffer[offset] == '%') {
  97. enVarEnd = offset + 1;
  98. // Search end of word for second % (can be a long path)
  99. while ((enVarEnd < lengthLine) &&
  100. (!isspacechar(lineBuffer[enVarEnd])) &&
  101. (lineBuffer[enVarEnd] != '%') &&
  102. (!IsBOperator(lineBuffer[enVarEnd])) &&
  103. (!IsBSeparator(lineBuffer[enVarEnd]))) {
  104. enVarEnd++;
  105. }
  106. // Check for Argument (%n)
  107. if ((Is0To9(lineBuffer[offset + 1])) &&
  108. (lineBuffer[enVarEnd] != '%')) {
  109. // Colorize Argument
  110. styler.ColourTo(startLine + offset + 1, SCE_BAT_IDENTIFIER);
  111. offset += 2;
  112. // Check for External Command / Program
  113. if (!isspacechar(lineBuffer[offset])) {
  114. cmdLoc = offset;
  115. }
  116. // Check for Environment Variable (%x...%)
  117. } else if ((lineBuffer[offset + 1] != '%') &&
  118. (lineBuffer[enVarEnd] == '%')) {
  119. offset = enVarEnd;
  120. // Colorize Environment Variable
  121. styler.ColourTo(startLine + offset, SCE_BAT_IDENTIFIER);
  122. offset++;
  123. // Check for External Command / Program
  124. if (!isspacechar(lineBuffer[offset])) {
  125. cmdLoc = offset;
  126. }
  127. }
  128. }
  129. // Skip next spaces
  130. while ((offset < lengthLine) && (isspacechar(lineBuffer[offset]))) {
  131. offset++;
  132. }
  133. // Read remainder of line word-at-a-time or remainder-of-word-at-a-time
  134. while (offset < lengthLine) {
  135. if (offset > startLine) {
  136. // Colorize Default Text
  137. styler.ColourTo(startLine + offset - 1, SCE_BAT_DEFAULT);
  138. }
  139. // Copy word from Line Buffer into Word Buffer
  140. wbl = 0;
  141. for (; offset < lengthLine && wbl < 80 &&
  142. !isspacechar(lineBuffer[offset]); wbl++, offset++) {
  143. wordBuffer[wbl] = static_cast<char>(tolower(lineBuffer[offset]));
  144. }
  145. wordBuffer[wbl] = '\0';
  146. wbo = 0;
  147. // Check for Comment - return if found
  148. if (CompareCaseInsensitive(wordBuffer, "rem") == 0) {
  149. styler.ColourTo(endPos, SCE_BAT_COMMENT);
  150. return;
  151. }
  152. // Check for Separator
  153. if (IsBSeparator(wordBuffer[0])) {
  154. // Check for External Command / Program
  155. if ((cmdLoc == offset - wbl) &&
  156. ((wordBuffer[0] == ':') ||
  157. (wordBuffer[0] == '\\') ||
  158. (wordBuffer[0] == '.'))) {
  159. // Reset Offset to re-process remainder of word
  160. offset -= (wbl - 1);
  161. // Colorize External Command / Program
  162. styler.ColourTo(startLine + offset - 1, SCE_BAT_COMMAND);
  163. // Reset External Command / Program Location
  164. cmdLoc = offset;
  165. } else {
  166. // Reset Offset to re-process remainder of word
  167. offset -= (wbl - 1);
  168. // Colorize Default Text
  169. styler.ColourTo(startLine + offset - 1, SCE_BAT_DEFAULT);
  170. }
  171. // Check for Regular Keyword in list
  172. } else if ((keywords.InList(wordBuffer)) &&
  173. (continueProcessing)) {
  174. // Local Variables do not exist if no FOR statement
  175. if (CompareCaseInsensitive(wordBuffer, "for") == 0) {
  176. forFound = true;
  177. }
  178. // ECHO, GOTO, PROMPT and SET require no further Regular Keyword Checking
  179. if ((CompareCaseInsensitive(wordBuffer, "echo") == 0) ||
  180. (CompareCaseInsensitive(wordBuffer, "goto") == 0) ||
  181. (CompareCaseInsensitive(wordBuffer, "prompt") == 0) ||
  182. (CompareCaseInsensitive(wordBuffer, "set") == 0)) {
  183. continueProcessing = false;
  184. }
  185. // Identify External Command / Program Location for ERRORLEVEL, and EXIST
  186. if ((CompareCaseInsensitive(wordBuffer, "errorlevel") == 0) ||
  187. (CompareCaseInsensitive(wordBuffer, "exist") == 0)) {
  188. // Reset External Command / Program Location
  189. cmdLoc = offset;
  190. // Skip next spaces
  191. while ((cmdLoc < lengthLine) &&
  192. (isspacechar(lineBuffer[cmdLoc]))) {
  193. cmdLoc++;
  194. }
  195. // Skip comparison
  196. while ((cmdLoc < lengthLine) &&
  197. (!isspacechar(lineBuffer[cmdLoc]))) {
  198. cmdLoc++;
  199. }
  200. // Skip next spaces
  201. while ((cmdLoc < lengthLine) &&
  202. (isspacechar(lineBuffer[cmdLoc]))) {
  203. cmdLoc++;
  204. }
  205. // Identify External Command / Program Location for CALL, DO, LOADHIGH and LH
  206. } else if ((CompareCaseInsensitive(wordBuffer, "call") == 0) ||
  207. (CompareCaseInsensitive(wordBuffer, "do") == 0) ||
  208. (CompareCaseInsensitive(wordBuffer, "loadhigh") == 0) ||
  209. (CompareCaseInsensitive(wordBuffer, "lh") == 0)) {
  210. // Reset External Command / Program Location
  211. cmdLoc = offset;
  212. // Skip next spaces
  213. while ((cmdLoc < lengthLine) &&
  214. (isspacechar(lineBuffer[cmdLoc]))) {
  215. cmdLoc++;
  216. }
  217. }
  218. // Colorize Regular keyword
  219. styler.ColourTo(startLine + offset - 1, SCE_BAT_WORD);
  220. // No need to Reset Offset
  221. // Check for Special Keyword in list, External Command / Program, or Default Text
  222. } else if ((wordBuffer[0] != '%') &&
  223. (!IsBOperator(wordBuffer[0])) &&
  224. (continueProcessing)) {
  225. // Check for Special Keyword
  226. // Affected Commands are in Length range 2-6
  227. // Good that ERRORLEVEL, EXIST, CALL, DO, LOADHIGH, and LH are unaffected
  228. sKeywordFound = false;
  229. for (unsigned int keywordLength = 2; keywordLength < wbl && keywordLength < 7 && !sKeywordFound; keywordLength++) {
  230. wbo = 0;
  231. // Copy Keyword Length from Word Buffer into Special Keyword Buffer
  232. for (; wbo < keywordLength; wbo++) {
  233. sKeywordBuffer[wbo] = static_cast<char>(wordBuffer[wbo]);
  234. }
  235. sKeywordBuffer[wbo] = '\0';
  236. // Check for Special Keyword in list
  237. if ((keywords.InList(sKeywordBuffer)) &&
  238. ((IsBOperator(wordBuffer[wbo])) ||
  239. (IsBSeparator(wordBuffer[wbo])))) {
  240. sKeywordFound = true;
  241. // ECHO requires no further Regular Keyword Checking
  242. if (CompareCaseInsensitive(sKeywordBuffer, "echo") == 0) {
  243. continueProcessing = false;
  244. }
  245. // Colorize Special Keyword as Regular Keyword
  246. styler.ColourTo(startLine + offset - 1 - (wbl - wbo), SCE_BAT_WORD);
  247. // Reset Offset to re-process remainder of word
  248. offset -= (wbl - wbo);
  249. }
  250. }
  251. // Check for External Command / Program or Default Text
  252. if (!sKeywordFound) {
  253. wbo = 0;
  254. // Check for External Command / Program
  255. if (cmdLoc == offset - wbl) {
  256. // Read up to %, Operator or Separator
  257. while ((wbo < wbl) &&
  258. (wordBuffer[wbo] != '%') &&
  259. (!IsBOperator(wordBuffer[wbo])) &&
  260. (!IsBSeparator(wordBuffer[wbo]))) {
  261. wbo++;
  262. }
  263. // Reset External Command / Program Location
  264. cmdLoc = offset - (wbl - wbo);
  265. // Reset Offset to re-process remainder of word
  266. offset -= (wbl - wbo);
  267. // CHOICE requires no further Regular Keyword Checking
  268. if (CompareCaseInsensitive(wordBuffer, "choice") == 0) {
  269. continueProcessing = false;
  270. }
  271. // Check for START (and its switches) - What follows is External Command \ Program
  272. if (CompareCaseInsensitive(wordBuffer, "start") == 0) {
  273. // Reset External Command / Program Location
  274. cmdLoc = offset;
  275. // Skip next spaces
  276. while ((cmdLoc < lengthLine) &&
  277. (isspacechar(lineBuffer[cmdLoc]))) {
  278. cmdLoc++;
  279. }
  280. // Reset External Command / Program Location if command switch detected
  281. if (lineBuffer[cmdLoc] == '/') {
  282. // Skip command switch
  283. while ((cmdLoc < lengthLine) &&
  284. (!isspacechar(lineBuffer[cmdLoc]))) {
  285. cmdLoc++;
  286. }
  287. // Skip next spaces
  288. while ((cmdLoc < lengthLine) &&
  289. (isspacechar(lineBuffer[cmdLoc]))) {
  290. cmdLoc++;
  291. }
  292. }
  293. }
  294. // Colorize External command / program
  295. styler.ColourTo(startLine + offset - 1, SCE_BAT_COMMAND);
  296. // No need to Reset Offset
  297. // Check for Default Text
  298. } else {
  299. // Read up to %, Operator or Separator
  300. while ((wbo < wbl) &&
  301. (wordBuffer[wbo] != '%') &&
  302. (!IsBOperator(wordBuffer[wbo])) &&
  303. (!IsBSeparator(wordBuffer[wbo]))) {
  304. wbo++;
  305. }
  306. // Colorize Default Text
  307. styler.ColourTo(startLine + offset - 1 - (wbl - wbo), SCE_BAT_DEFAULT);
  308. // Reset Offset to re-process remainder of word
  309. offset -= (wbl - wbo);
  310. }
  311. }
  312. // Check for Argument (%n), Environment Variable (%x...%) or Local Variable (%%a)
  313. } else if (wordBuffer[0] == '%') {
  314. // Colorize Default Text
  315. styler.ColourTo(startLine + offset - 1 - wbl, SCE_BAT_DEFAULT);
  316. wbo++;
  317. // Search to end of word for second % (can be a long path)
  318. while ((wbo < wbl) &&
  319. (wordBuffer[wbo] != '%') &&
  320. (!IsBOperator(wordBuffer[wbo])) &&
  321. (!IsBSeparator(wordBuffer[wbo]))) {
  322. wbo++;
  323. }
  324. // Check for Argument (%n)
  325. if ((Is0To9(wordBuffer[1])) &&
  326. (wordBuffer[wbo] != '%')) {
  327. // Check for External Command / Program
  328. if (cmdLoc == offset - wbl) {
  329. cmdLoc = offset - (wbl - 2);
  330. }
  331. // Colorize Argument
  332. styler.ColourTo(startLine + offset - 1 - (wbl - 2), SCE_BAT_IDENTIFIER);
  333. // Reset Offset to re-process remainder of word
  334. offset -= (wbl - 2);
  335. // Check for Environment Variable (%x...%)
  336. } else if ((wordBuffer[1] != '%') &&
  337. (wordBuffer[wbo] == '%')) {
  338. wbo++;
  339. // Check for External Command / Program
  340. if (cmdLoc == offset - wbl) {
  341. cmdLoc = offset - (wbl - wbo);
  342. }
  343. // Colorize Environment Variable
  344. styler.ColourTo(startLine + offset - 1 - (wbl - wbo), SCE_BAT_IDENTIFIER);
  345. // Reset Offset to re-process remainder of word
  346. offset -= (wbl - wbo);
  347. // Check for Local Variable (%%a)
  348. } else if ((forFound) &&
  349. (wordBuffer[1] == '%') &&
  350. (wordBuffer[2] != '%') &&
  351. (!IsBOperator(wordBuffer[2])) &&
  352. (!IsBSeparator(wordBuffer[2]))) {
  353. // Check for External Command / Program
  354. if (cmdLoc == offset - wbl) {
  355. cmdLoc = offset - (wbl - 3);
  356. }
  357. // Colorize Local Variable
  358. styler.ColourTo(startLine + offset - 1 - (wbl - 3), SCE_BAT_IDENTIFIER);
  359. // Reset Offset to re-process remainder of word
  360. offset -= (wbl - 3);
  361. }
  362. // Check for Operator
  363. } else if (IsBOperator(wordBuffer[0])) {
  364. // Colorize Default Text
  365. styler.ColourTo(startLine + offset - 1 - wbl, SCE_BAT_DEFAULT);
  366. // Check for Comparison Operator
  367. if ((wordBuffer[0] == '=') && (wordBuffer[1] == '=')) {
  368. // Identify External Command / Program Location for IF
  369. cmdLoc = offset;
  370. // Skip next spaces
  371. while ((cmdLoc < lengthLine) &&
  372. (isspacechar(lineBuffer[cmdLoc]))) {
  373. cmdLoc++;
  374. }
  375. // Colorize Comparison Operator
  376. styler.ColourTo(startLine + offset - 1 - (wbl - 2), SCE_BAT_OPERATOR);
  377. // Reset Offset to re-process remainder of word
  378. offset -= (wbl - 2);
  379. // Check for Pipe Operator
  380. } else if (wordBuffer[0] == '|') {
  381. // Reset External Command / Program Location
  382. cmdLoc = offset - wbl + 1;
  383. // Skip next spaces
  384. while ((cmdLoc < lengthLine) &&
  385. (isspacechar(lineBuffer[cmdLoc]))) {
  386. cmdLoc++;
  387. }
  388. // Colorize Pipe Operator
  389. styler.ColourTo(startLine + offset - 1 - (wbl - 1), SCE_BAT_OPERATOR);
  390. // Reset Offset to re-process remainder of word
  391. offset -= (wbl - 1);
  392. // Check for Other Operator
  393. } else {
  394. // Check for > Operator
  395. if (wordBuffer[0] == '>') {
  396. // Turn Keyword and External Command / Program checking back on
  397. continueProcessing = true;
  398. }
  399. // Colorize Other Operator
  400. styler.ColourTo(startLine + offset - 1 - (wbl - 1), SCE_BAT_OPERATOR);
  401. // Reset Offset to re-process remainder of word
  402. offset -= (wbl - 1);
  403. }
  404. // Check for Default Text
  405. } else {
  406. // Read up to %, Operator or Separator
  407. while ((wbo < wbl) &&
  408. (wordBuffer[wbo] != '%') &&
  409. (!IsBOperator(wordBuffer[wbo])) &&
  410. (!IsBSeparator(wordBuffer[wbo]))) {
  411. wbo++;
  412. }
  413. // Colorize Default Text
  414. styler.ColourTo(startLine + offset - 1 - (wbl - wbo), SCE_BAT_DEFAULT);
  415. // Reset Offset to re-process remainder of word
  416. offset -= (wbl - wbo);
  417. }
  418. // Skip next spaces - nothing happens if Offset was Reset
  419. while ((offset < lengthLine) && (isspacechar(lineBuffer[offset]))) {
  420. offset++;
  421. }
  422. }
  423. // Colorize Default Text for remainder of line - currently not lexed
  424. styler.ColourTo(endPos, SCE_BAT_DEFAULT);
  425. }
  426. static void ColouriseBatchDoc(
  427. unsigned int startPos,
  428. int length,
  429. int /*initStyle*/,
  430. WordList *keywordlists[],
  431. Accessor &styler) {
  432. char lineBuffer[1024];
  433. WordList &keywords = *keywordlists[0];
  434. styler.StartAt(startPos);
  435. styler.StartSegment(startPos);
  436. unsigned int linePos = 0;
  437. unsigned int startLine = startPos;
  438. for (unsigned int i = startPos; i < startPos + length; i++) {
  439. lineBuffer[linePos++] = styler[i];
  440. if (AtEOL(styler, i) || (linePos >= sizeof(lineBuffer) - 1)) {
  441. // End of line (or of line buffer) met, colourise it
  442. lineBuffer[linePos] = '\0';
  443. ColouriseBatchLine(lineBuffer, linePos, startLine, i, keywords, styler);
  444. linePos = 0;
  445. startLine = i + 1;
  446. }
  447. }
  448. if (linePos > 0) { // Last line does not have ending characters
  449. ColouriseBatchLine(lineBuffer, linePos, startLine, startPos + length - 1,
  450. keywords, styler);
  451. }
  452. }
  453. static void ColouriseDiffLine(char *lineBuffer, int endLine, Accessor &styler) {
  454. // It is needed to remember the current state to recognize starting
  455. // comment lines before the first "diff " or "--- ". If a real
  456. // difference starts then each line starting with ' ' is a whitespace
  457. // otherwise it is considered a comment (Only in..., Binary file...)
  458. if (0 == strncmp(lineBuffer, "diff ", 5)) {
  459. styler.ColourTo(endLine, SCE_DIFF_COMMAND);
  460. } else if (0 == strncmp(lineBuffer, "--- ", 4)) {
  461. // In a context diff, --- appears in both the header and the position markers
  462. if (atoi(lineBuffer+4) && !strchr(lineBuffer, '/'))
  463. styler.ColourTo(endLine, SCE_DIFF_POSITION);
  464. else
  465. styler.ColourTo(endLine, SCE_DIFF_HEADER);
  466. } else if (0 == strncmp(lineBuffer, "+++ ", 4)) {
  467. // I don't know of any diff where "+++ " is a position marker, but for
  468. // consistency, do the same as with "--- " and "*** ".
  469. if (atoi(lineBuffer+4) && !strchr(lineBuffer, '/'))
  470. styler.ColourTo(endLine, SCE_DIFF_POSITION);
  471. else
  472. styler.ColourTo(endLine, SCE_DIFF_HEADER);
  473. } else if (0 == strncmp(lineBuffer, "====", 4)) { // For p4's diff
  474. styler.ColourTo(endLine, SCE_DIFF_HEADER);
  475. } else if (0 == strncmp(lineBuffer, "***", 3)) {
  476. // In a context diff, *** appears in both the header and the position markers.
  477. // Also ******** is a chunk header, but here it's treated as part of the
  478. // position marker since there is no separate style for a chunk header.
  479. if (lineBuffer[3] == ' ' && atoi(lineBuffer+4) && !strchr(lineBuffer, '/'))
  480. styler.ColourTo(endLine, SCE_DIFF_POSITION);
  481. else if (lineBuffer[3] == '*')
  482. styler.ColourTo(endLine, SCE_DIFF_POSITION);
  483. else
  484. styler.ColourTo(endLine, SCE_DIFF_HEADER);
  485. } else if (0 == strncmp(lineBuffer, "? ", 2)) { // For difflib
  486. styler.ColourTo(endLine, SCE_DIFF_HEADER);
  487. } else if (lineBuffer[0] == '@') {
  488. styler.ColourTo(endLine, SCE_DIFF_POSITION);
  489. } else if (lineBuffer[0] >= '0' && lineBuffer[0] <= '9') {
  490. styler.ColourTo(endLine, SCE_DIFF_POSITION);
  491. } else if (lineBuffer[0] == '-' || lineBuffer[0] == '<') {
  492. styler.ColourTo(endLine, SCE_DIFF_DELETED);
  493. } else if (lineBuffer[0] == '+' || lineBuffer[0] == '>') {
  494. styler.ColourTo(endLine, SCE_DIFF_ADDED);
  495. } else if (lineBuffer[0] != ' ') {
  496. styler.ColourTo(endLine, SCE_DIFF_COMMENT);
  497. } else {
  498. styler.ColourTo(endLine, SCE_DIFF_DEFAULT);
  499. }
  500. }
  501. static void ColouriseDiffDoc(unsigned int startPos, int length, int, WordList *[], Accessor &styler) {
  502. char lineBuffer[1024];
  503. styler.StartAt(startPos);
  504. styler.StartSegment(startPos);
  505. unsigned int linePos = 0;
  506. for (unsigned int i = startPos; i < startPos + length; i++) {
  507. lineBuffer[linePos++] = styler[i];
  508. if (AtEOL(styler, i) || (linePos >= sizeof(lineBuffer) - 1)) {
  509. // End of line (or of line buffer) met, colourise it
  510. lineBuffer[linePos] = '\0';
  511. ColouriseDiffLine(lineBuffer, i, styler);
  512. linePos = 0;
  513. }
  514. }
  515. if (linePos > 0) { // Last line does not have ending characters
  516. ColouriseDiffLine(lineBuffer, startPos + length - 1, styler);
  517. }
  518. }
  519. static void FoldDiffDoc(unsigned int startPos, int length, int, WordList*[], Accessor &styler) {
  520. int curLine = styler.GetLine(startPos);
  521. int prevLevel = SC_FOLDLEVELBASE;
  522. if (curLine > 0)
  523. prevLevel = styler.LevelAt(curLine-1);
  524. int curLineStart = styler.LineStart(curLine);
  525. do {
  526. int nextLevel = prevLevel;
  527. if (prevLevel & SC_FOLDLEVELHEADERFLAG)
  528. nextLevel = (prevLevel & SC_FOLDLEVELNUMBERMASK) + 1;
  529. int lineType = styler.StyleAt(curLineStart);
  530. if (lineType == SCE_DIFF_COMMAND)
  531. nextLevel = (SC_FOLDLEVELBASE + 1) | SC_FOLDLEVELHEADERFLAG;
  532. else if (lineType == SCE_DIFF_HEADER) {
  533. nextLevel = (SC_FOLDLEVELBASE + 2) | SC_FOLDLEVELHEADERFLAG;
  534. } else if (lineType == SCE_DIFF_POSITION)
  535. nextLevel = (SC_FOLDLEVELBASE + 3) | SC_FOLDLEVELHEADERFLAG;
  536. if ((nextLevel & SC_FOLDLEVELHEADERFLAG) && (nextLevel == prevLevel))
  537. styler.SetLevel(curLine-1, prevLevel & ~SC_FOLDLEVELHEADERFLAG);
  538. styler.SetLevel(curLine, nextLevel);
  539. prevLevel = nextLevel;
  540. curLineStart = styler.LineStart(++curLine);
  541. } while (static_cast<int>(startPos) + length > curLineStart);
  542. }
  543. static void ColourisePropsLine(
  544. char *lineBuffer,
  545. unsigned int lengthLine,
  546. unsigned int startLine,
  547. unsigned int endPos,
  548. Accessor &styler) {
  549. unsigned int i = 0;
  550. while ((i < lengthLine) && isspacechar(lineBuffer[i])) // Skip initial spaces
  551. i++;
  552. if (i < lengthLine) {
  553. if (lineBuffer[i] == '#' || lineBuffer[i] == '!' || lineBuffer[i] == ';') {
  554. styler.ColourTo(endPos, SCE_PROPS_COMMENT);
  555. } else if (lineBuffer[i] == '[') {
  556. styler.ColourTo(endPos, SCE_PROPS_SECTION);
  557. } else if (lineBuffer[i] == '@') {
  558. styler.ColourTo(startLine + i, SCE_PROPS_DEFVAL);
  559. if (lineBuffer[++i] == '=')
  560. styler.ColourTo(startLine + i, SCE_PROPS_ASSIGNMENT);
  561. styler.ColourTo(endPos, SCE_PROPS_DEFAULT);
  562. } else {
  563. // Search for the '=' character
  564. while ((i < lengthLine) && (lineBuffer[i] != '='))
  565. i++;
  566. if ((i < lengthLine) && (lineBuffer[i] == '=')) {
  567. styler.ColourTo(startLine + i - 1, SCE_PROPS_DEFAULT);
  568. styler.ColourTo(startLine + i, 3);
  569. styler.ColourTo(endPos, SCE_PROPS_DEFAULT);
  570. } else {
  571. styler.ColourTo(endPos, SCE_PROPS_DEFAULT);
  572. }
  573. }
  574. } else {
  575. styler.ColourTo(endPos, SCE_PROPS_DEFAULT);
  576. }
  577. }
  578. static void ColourisePropsDoc(unsigned int startPos, int length, int, WordList *[], Accessor &styler) {
  579. char lineBuffer[1024];
  580. styler.StartAt(startPos);
  581. styler.StartSegment(startPos);
  582. unsigned int linePos = 0;
  583. unsigned int startLine = startPos;
  584. for (unsigned int i = startPos; i < startPos + length; i++) {
  585. lineBuffer[linePos++] = styler[i];
  586. if (AtEOL(styler, i) || (linePos >= sizeof(lineBuffer) - 1)) {
  587. // End of line (or of line buffer) met, colourise it
  588. lineBuffer[linePos] = '\0';
  589. ColourisePropsLine(lineBuffer, linePos, startLine, i, styler);
  590. linePos = 0;
  591. startLine = i + 1;
  592. }
  593. }
  594. if (linePos > 0) { // Last line does not have ending characters
  595. ColourisePropsLine(lineBuffer, linePos, startLine, startPos + length - 1, styler);
  596. }
  597. }
  598. // adaption by ksc, using the "} else {" trick of 1.53
  599. // 030721
  600. static void FoldPropsDoc(unsigned int startPos, int length, int, WordList *[], Accessor &styler) {
  601. bool foldCompact = styler.GetPropertyInt("fold.compact", 1) != 0;
  602. unsigned int endPos = startPos + length;
  603. int visibleChars = 0;
  604. int lineCurrent = styler.GetLine(startPos);
  605. char chNext = styler[startPos];
  606. int styleNext = styler.StyleAt(startPos);
  607. bool headerPoint = false;
  608. int lev;
  609. for (unsigned int i = startPos; i < endPos; i++) {
  610. char ch = chNext;
  611. chNext = styler[i+1];
  612. int style = styleNext;
  613. styleNext = styler.StyleAt(i + 1);
  614. bool atEOL = (ch == '\r' && chNext != '\n') || (ch == '\n');
  615. if (style == SCE_PROPS_SECTION) {
  616. headerPoint = true;
  617. }
  618. if (atEOL) {
  619. lev = SC_FOLDLEVELBASE;
  620. if (lineCurrent > 0) {
  621. int levelPrevious = styler.LevelAt(lineCurrent - 1);
  622. if (levelPrevious & SC_FOLDLEVELHEADERFLAG) {
  623. lev = SC_FOLDLEVELBASE + 1;
  624. } else {
  625. lev = levelPrevious & SC_FOLDLEVELNUMBERMASK;
  626. }
  627. }
  628. if (headerPoint) {
  629. lev = SC_FOLDLEVELBASE;
  630. }
  631. if (visibleChars == 0 && foldCompact)
  632. lev |= SC_FOLDLEVELWHITEFLAG;
  633. if (headerPoint) {
  634. lev |= SC_FOLDLEVELHEADERFLAG;
  635. }
  636. if (lev != styler.LevelAt(lineCurrent)) {
  637. styler.SetLevel(lineCurrent, lev);
  638. }
  639. lineCurrent++;
  640. visibleChars = 0;
  641. headerPoint = false;
  642. }
  643. if (!isspacechar(ch))
  644. visibleChars++;
  645. }
  646. if (lineCurrent > 0) {
  647. int levelPrevious = styler.LevelAt(lineCurrent - 1);
  648. if (levelPrevious & SC_FOLDLEVELHEADERFLAG) {
  649. lev = SC_FOLDLEVELBASE + 1;
  650. } else {
  651. lev = levelPrevious & SC_FOLDLEVELNUMBERMASK;
  652. }
  653. } else {
  654. lev = SC_FOLDLEVELBASE;
  655. }
  656. int flagsNext = styler.LevelAt(lineCurrent);
  657. styler.SetLevel(lineCurrent, lev | flagsNext & ~SC_FOLDLEVELNUMBERMASK);
  658. }
  659. static void ColouriseMakeLine(
  660. char *lineBuffer,
  661. unsigned int lengthLine,
  662. unsigned int startLine,
  663. unsigned int endPos,
  664. Accessor &styler) {
  665. unsigned int i = 0;
  666. int lastNonSpace = -1;
  667. unsigned int state = SCE_MAKE_DEFAULT;
  668. bool bSpecial = false;
  669. // Skip initial spaces
  670. while ((i < lengthLine) && isspacechar(lineBuffer[i])) {
  671. i++;
  672. }
  673. if (lineBuffer[i] == '#') { // Comment
  674. styler.ColourTo(endPos, SCE_MAKE_COMMENT);
  675. return;
  676. }
  677. if (lineBuffer[i] == '!') { // Special directive
  678. styler.ColourTo(endPos, SCE_MAKE_PREPROCESSOR);
  679. return;
  680. }
  681. while (i < lengthLine) {
  682. if (lineBuffer[i] == '$' && lineBuffer[i + 1] == '(') {
  683. styler.ColourTo(startLine + i - 1, state);
  684. state = SCE_MAKE_IDENTIFIER;
  685. } else if (state == SCE_MAKE_IDENTIFIER && lineBuffer[i] == ')') {
  686. styler.ColourTo(startLine + i, state);
  687. state = SCE_MAKE_DEFAULT;
  688. }
  689. if (!bSpecial) {
  690. if (lineBuffer[i] == ':') {
  691. // We should check that no colouring was made since the beginning of the line,
  692. // to avoid colouring stuff like /OUT:file
  693. if (lastNonSpace >= 0)
  694. styler.ColourTo(startLine + lastNonSpace, SCE_MAKE_TARGET);
  695. styler.ColourTo(startLine + i - 1, SCE_MAKE_DEFAULT);
  696. styler.ColourTo(startLine + i, SCE_MAKE_OPERATOR);
  697. bSpecial = true; // Only react to the first ':' of the line
  698. state = SCE_MAKE_DEFAULT;
  699. } else if (lineBuffer[i] == '=') {
  700. if (lastNonSpace >= 0)
  701. styler.ColourTo(startLine + lastNonSpace, SCE_MAKE_IDENTIFIER);
  702. styler.ColourTo(startLine + i - 1, SCE_MAKE_DEFAULT);
  703. styler.ColourTo(startLine + i, SCE_MAKE_OPERATOR);
  704. bSpecial = true; // Only react to the first '=' of the line
  705. state = SCE_MAKE_DEFAULT;
  706. }
  707. }
  708. if (!isspacechar(lineBuffer[i])) {
  709. lastNonSpace = i;
  710. }
  711. i++;
  712. }
  713. if (state == SCE_MAKE_IDENTIFIER) {
  714. styler.ColourTo(endPos, SCE_MAKE_IDEOL); // Error, variable reference not ended
  715. } else {
  716. styler.ColourTo(endPos, SCE_MAKE_DEFAULT);
  717. }
  718. }
  719. static void ColouriseMakeDoc(unsigned int startPos, int length, int, WordList *[], Accessor &styler) {
  720. char lineBuffer[1024];
  721. styler.StartAt(startPos);
  722. styler.StartSegment(startPos);
  723. unsigned int linePos = 0;
  724. unsigned int startLine = startPos;
  725. for (unsigned int i = startPos; i < startPos + length; i++) {
  726. lineBuffer[linePos++] = styler[i];
  727. if (AtEOL(styler, i) || (linePos >= sizeof(lineBuffer) - 1)) {
  728. // End of line (or of line buffer) met, colourise it
  729. lineBuffer[linePos] = '\0';
  730. ColouriseMakeLine(lineBuffer, linePos, startLine, i, styler);
  731. linePos = 0;
  732. startLine = i + 1;
  733. }
  734. }
  735. if (linePos > 0) { // Last line does not have ending characters
  736. ColouriseMakeLine(lineBuffer, linePos, startLine, startPos + length - 1, styler);
  737. }
  738. }
  739. static bool strstart(const char *haystack, const char *needle) {
  740. return strncmp(haystack, needle, strlen(needle)) == 0;
  741. }
  742. static int RecogniseErrorListLine(const char *lineBuffer, unsigned int lengthLine) {
  743. if (lineBuffer[0] == '>') {
  744. // Command or return status
  745. return SCE_ERR_CMD;
  746. } else if (lineBuffer[0] == '<') {
  747. // Diff removal, but not interested. Trapped to avoid hitting CTAG cases.
  748. return SCE_ERR_DEFAULT;
  749. } else if (lineBuffer[0] == '!') {
  750. return SCE_ERR_DIFF_CHANGED;
  751. } else if (lineBuffer[0] == '+') {
  752. if (strstart(lineBuffer, "+++ ")) {
  753. return SCE_ERR_DIFF_MESSAGE;
  754. } else {
  755. return SCE_ERR_DIFF_ADDITION;
  756. }
  757. } else if (lineBuffer[0] == '-') {
  758. if (strstart(lineBuffer, "--- ")) {
  759. return SCE_ERR_DIFF_MESSAGE;
  760. } else {
  761. return SCE_ERR_DIFF_DELETION;
  762. }
  763. } else if (strstart(lineBuffer, "cf90-")) {
  764. // Absoft Pro Fortran 90/95 v8.2 error and/or warning message
  765. return SCE_ERR_ABSF;
  766. } else if (strstart(lineBuffer, "fortcom:")) {
  767. // Intel Fortran Compiler v8.0 error/warning message
  768. return SCE_ERR_IFORT;
  769. } else if (strstr(lineBuffer, "File \"") && strstr(lineBuffer, ", line ")) {
  770. return SCE_ERR_PYTHON;
  771. } else if (strstr(lineBuffer, " in ") && strstr(lineBuffer, " on line ")) {
  772. return SCE_ERR_PHP;
  773. } else if ((strstart(lineBuffer, "Error ") ||
  774. strstart(lineBuffer, "Warning ")) &&
  775. strstr(lineBuffer, " at (") &&
  776. strstr(lineBuffer, ") : ") &&
  777. (strstr(lineBuffer, " at (") < strstr(lineBuffer, ") : "))) {
  778. // Intel Fortran Compiler error/warning message
  779. return SCE_ERR_IFC;
  780. } else if (strstart(lineBuffer, "Error ")) {
  781. // Borland error message
  782. return SCE_ERR_BORLAND;
  783. } else if (strstart(lineBuffer, "Warning ")) {
  784. // Borland warning message
  785. return SCE_ERR_BORLAND;
  786. } else if (strstr(lineBuffer, "at line " ) &&
  787. (strstr(lineBuffer, "at line " ) < (lineBuffer + lengthLine)) &&
  788. strstr(lineBuffer, "file ") &&
  789. (strstr(lineBuffer, "file ") < (lineBuffer + lengthLine))) {
  790. // Lua 4 error message
  791. return SCE_ERR_LUA;
  792. } else if (strstr(lineBuffer, " at " ) &&
  793. (strstr(lineBuffer, " at " ) < (lineBuffer + lengthLine)) &&
  794. strstr(lineBuffer, " line ") &&
  795. (strstr(lineBuffer, " line ") < (lineBuffer + lengthLine)) &&
  796. (strstr(lineBuffer, " at " ) < (strstr(lineBuffer, " line ")))) {
  797. // perl error message
  798. return SCE_ERR_PERL;
  799. } else if ((memcmp(lineBuffer, " at ", 6) == 0) &&
  800. strstr(lineBuffer, ":line ")) {
  801. // A .NET traceback
  802. return SCE_ERR_NET;
  803. } else if (strstart(lineBuffer, "Line ") &&
  804. strstr(lineBuffer, ", file ")) {
  805. // Essential Lahey Fortran error message
  806. return SCE_ERR_ELF;
  807. } else if (strstart(lineBuffer, "line ") &&
  808. strstr(lineBuffer, " column ")) {
  809. // HTML tidy style: line 42 column 1
  810. return SCE_ERR_TIDY;
  811. } else if (strstart(lineBuffer, "\tat ") &&
  812. strstr(lineBuffer, "(") &&
  813. strstr(lineBuffer, ".java:")) {
  814. // Java stack back trace
  815. return SCE_ERR_JAVA_STACK;
  816. } else {
  817. // Look for one of the following formats:
  818. // GCC: <filename>:<line>:<message>
  819. // Microsoft: <filename>(<line>) :<message>
  820. // Common: <filename>(<line>): warning|error|note|remark|catastrophic|fatal
  821. // Common: <filename>(<line>) warning|error|note|remark|catastrophic|fatal
  822. // Microsoft: <filename>(<line>,<column>)<message>
  823. // CTags: \t<message>
  824. // Lua 5 traceback: \t<filename>:<line>:<message>
  825. bool initialTab = (lineBuffer[0] == '\t');
  826. enum { stInitial,
  827. stGccStart, stGccDigit, stGcc,
  828. stMsStart, stMsDigit, stMsBracket, stMsVc, stMsDigitComma, stMsDotNet,
  829. stCtagsStart, stCtagsStartString, stCtagsStringDollar, stCtags,
  830. stUnrecognized
  831. } state = stInitial;
  832. for (unsigned int i = 0; i < lengthLine; i++) {
  833. char ch = lineBuffer[i];
  834. char chNext = ' ';
  835. if ((i + 1) < lengthLine)
  836. chNext = lineBuffer[i + 1];
  837. if (state == stInitial) {
  838. if (ch == ':') {
  839. // May be GCC, or might be Lua 5 (Lua traceback same but with tab prefix)
  840. if ((chNext != '\\') && (chNext != '/')) {
  841. // This check is not completely accurate as may be on
  842. // GTK+ with a file name that includes ':'.
  843. state = stGccStart;
  844. }
  845. } else if ((ch == '(') && Is1To9(chNext) && (!initialTab)) {
  846. // May be Microsoft
  847. // Check against '0' often removes phone numbers
  848. state = stMsStart;
  849. } else if ((ch == '\t') && (!initialTab)) {
  850. // May be CTags
  851. state = stCtagsStart;
  852. }
  853. } else if (state == stGccStart) { // <filename>:
  854. state = Is1To9(ch) ? stGccDigit : stUnrecognized;
  855. } else if (state == stGccDigit) { // <filename>:<line>
  856. if (ch == ':') {
  857. state = stGcc; // :9.*: is GCC
  858. break;
  859. } else if (!Is0To9(ch)) {
  860. state = stUnrecognized;
  861. }
  862. } else if (state == stMsStart) { // <filename>(
  863. state = Is0To9(ch) ? stMsDigit : stUnrecognized;
  864. } else if (state == stMsDigit) { // <filename>(<line>
  865. if (ch == ',') {
  866. state = stMsDigitComma;
  867. } else if (ch == ')') {
  868. state = stMsBracket;
  869. } else if ((ch != ' ') && !Is0To9(ch)) {
  870. state = stUnrecognized;
  871. }
  872. } else if (state == stMsBracket) { // <filename>(<line>)
  873. if ((ch == ' ') && (chNext == ':')) {
  874. state = stMsVc;
  875. } else if ((ch == ':' && chNext == ' ') || (ch == ' ')) {
  876. // Possibly Delphi.. don't test against chNext as it's one of the strings below.
  877. char word[512];
  878. unsigned int j, chPos;
  879. unsigned numstep;
  880. chPos = 0;
  881. if (ch == ' ')
  882. numstep = 1; // ch was ' ', handle as if it's a delphi errorline, only add 1 to i.
  883. else
  884. numstep = 2; // otherwise add 2.
  885. for (j = i + numstep; j < lengthLine && isalpha(lineBuffer[j]) && chPos < sizeof(word) - 1; j++)
  886. word[chPos++] = lineBuffer[j];
  887. word[chPos] = 0;
  888. if (!CompareCaseInsensitive(word, "error") || !CompareCaseInsensitive(word, "warning") ||
  889. !CompareCaseInsensitive(word, "fatal") || !CompareCaseInsensitive(word, "catastrophic") ||
  890. !CompareCaseInsensitive(word, "note") || !CompareCaseInsensitive(word, "remark")) {
  891. state = stMsVc;
  892. } else
  893. state = stUnrecognized;
  894. } else {
  895. state = stUnrecognized;
  896. }
  897. } else if (state == stMsDigitComma) { // <filename>(<line>,
  898. if (ch == ')') {
  899. state = stMsDotNet;
  900. break;
  901. } else if ((ch != ' ') && !Is0To9(ch)) {
  902. state = stUnrecognized;
  903. }
  904. } else if (state == stCtagsStart) {
  905. if ((lineBuffer[i - 1] == '\t') &&
  906. ((ch == '/' && lineBuffer[i + 1] == '^') || Is0To9(ch))) {
  907. state = stCtags;
  908. break;
  909. } else if ((ch == '/') && (lineBuffer[i + 1] == '^')) {
  910. state = stCtagsStartString;
  911. }
  912. } else if ((state == stCtagsStartString) && ((lineBuffer[i] == '$') && (lineBuffer[i + 1] == '/'))) {
  913. state = stCtagsStringDollar;
  914. break;
  915. }
  916. }
  917. if (state == stGcc) {
  918. return SCE_ERR_GCC;
  919. } else if ((state == stMsVc) || (state == stMsDotNet)) {
  920. return SCE_ERR_MS;
  921. } else if ((state == stCtagsStringDollar) || (state == stCtags)) {
  922. return SCE_ERR_CTAG;
  923. } else {
  924. return SCE_ERR_DEFAULT;
  925. }
  926. }
  927. }
  928. static void ColouriseErrorListLine(
  929. char *lineBuffer,
  930. unsigned int lengthLine,
  931. unsigned int endPos,
  932. Accessor &styler) {
  933. styler.ColourTo(endPos, RecogniseErrorListLine(lineBuffer, lengthLine));
  934. }
  935. static void ColouriseErrorListDoc(unsigned int startPos, int length, int, WordList *[], Accessor &styler) {
  936. char lineBuffer[10000];
  937. styler.StartAt(startPos);
  938. styler.StartSegment(startPos);
  939. unsigned int linePos = 0;
  940. for (unsigned int i = startPos; i < startPos + length; i++) {
  941. lineBuffer[linePos++] = styler[i];
  942. if (AtEOL(styler, i) || (linePos >= sizeof(lineBuffer) - 1)) {
  943. // End of line (or of line buffer) met, colourise it
  944. lineBuffer[linePos] = '\0';
  945. ColouriseErrorListLine(lineBuffer, linePos, i, styler);
  946. linePos = 0;
  947. }
  948. }
  949. if (linePos > 0) { // Last line does not have ending characters
  950. ColouriseErrorListLine(lineBuffer, linePos, startPos + length - 1, styler);
  951. }
  952. }
  953. static int isSpecial(char s) {
  954. return (s == '\\') || (s == ',') || (s == ';') || (s == '\'') || (s == ' ') ||
  955. (s == '\"') || (s == '`') || (s == '^') || (s == '~');
  956. }
  957. static int isTag(int start, Accessor &styler) {
  958. char s[6];
  959. unsigned int i = 0, e = 1;
  960. while (i < 5 && e) {
  961. s[i] = styler[start + i];
  962. i++;
  963. e = styler[start + i] != '{';
  964. }
  965. s[i] = '\0';
  966. return (strcmp(s, "begin") == 0) || (strcmp(s, "end") == 0);
  967. }
  968. static void ColouriseLatexDoc(unsigned int startPos, int length, int initStyle,
  969. WordList *[], Accessor &styler) {
  970. styler.StartAt(startPos);
  971. int state = initStyle;
  972. char chNext = styler[startPos];
  973. styler.StartSegment(startPos);
  974. int lengthDoc = startPos + length;
  975. for (int i = startPos; i < lengthDoc; i++) {
  976. char ch = chNext;
  977. chNext = styler.SafeGetCharAt(i + 1);
  978. if (styler.IsLeadByte(ch)) {
  979. chNext = styler.SafeGetCharAt(i + 2);
  980. i++;
  981. continue;
  982. }
  983. switch (state) {
  984. case SCE_L_DEFAULT :
  985. switch (ch) {
  986. case '\\' :
  987. styler.ColourTo(i - 1, state);
  988. if (isSpecial(styler[i + 1])) {
  989. styler.ColourTo(i + 1, SCE_L_COMMAND);
  990. i++;
  991. chNext = styler.SafeGetCharAt(i + 1);
  992. } else {
  993. if (isTag(i + 1, styler))
  994. state = SCE_L_TAG;
  995. else
  996. state = SCE_L_COMMAND;
  997. }
  998. break;
  999. case '$' :
  1000. styler.ColourTo(i - 1, state);
  1001. state = SCE_L_MATH;
  1002. if (chNext == '$') {
  1003. i++;
  1004. chNext = styler.SafeGetCharAt(i + 1);
  1005. }
  1006. break;
  1007. case '%' :
  1008. styler.ColourTo(i - 1, state);
  1009. state = SCE_L_COMMENT;
  1010. break;
  1011. }
  1012. break;
  1013. case SCE_L_COMMAND :
  1014. if (chNext == '[' || chNext == '{' || chNext == '}' ||
  1015. chNext == ' ' || chNext == '\r' || chNext == '\n') {
  1016. styler.ColourTo(i, state);
  1017. state = SCE_L_DEFAULT;
  1018. i++;
  1019. chNext = styler.SafeGetCharAt(i + 1);
  1020. }
  1021. break;
  1022. case SCE_L_TAG :
  1023. if (ch == '}') {
  1024. styler.ColourTo(i, state);
  1025. state = SCE_L_DEFAULT;
  1026. }
  1027. break;
  1028. case SCE_L_MATH :
  1029. if (ch == '$') {
  1030. if (chNext == '$') {
  1031. i++;
  1032. chNext = styler.SafeGetCharAt(i + 1);
  1033. }
  1034. styler.ColourTo(i, state);
  1035. state = SCE_L_DEFAULT;
  1036. }
  1037. break;
  1038. case SCE_L_COMMENT :
  1039. if (ch == '\r' || ch == '\n') {
  1040. styler.ColourTo(i - 1, state);
  1041. state = SCE_L_DEFAULT;
  1042. }
  1043. }
  1044. }
  1045. styler.ColourTo(lengthDoc-1, state);
  1046. }
  1047. static const char * const batchWordListDesc[] = {
  1048. "Keywords",
  1049. 0
  1050. };
  1051. static const char * const emptyWordListDesc[] = {
  1052. 0
  1053. };
  1054. static void ColouriseNullDoc(unsigned int startPos, int length, int, WordList *[],
  1055. Accessor &styler) {
  1056. // Null language means all style bytes are 0 so just mark the end - no need to fill in.
  1057. if (length > 0) {
  1058. styler.StartAt(startPos + length - 1);
  1059. styler.StartSegment(startPos + length - 1);
  1060. styler.ColourTo(startPos + length - 1, 0);
  1061. }
  1062. }
  1063. LexerModule lmBatch(SCLEX_BATCH, ColouriseBatchDoc, "batch", 0, batchWordListDesc);
  1064. LexerModule lmDiff(SCLEX_DIFF, ColouriseDiffDoc, "diff", FoldDiffDoc, emptyWordListDesc);
  1065. LexerModule lmProps(SCLEX_PROPERTIES, ColourisePropsDoc, "props", FoldPropsDoc, emptyWordListDesc);
  1066. LexerModule lmMake(SCLEX_MAKEFILE, ColouriseMakeDoc, "makefile", 0, emptyWordListDesc);
  1067. LexerModule lmErrorList(SCLEX_ERRORLIST, ColouriseErrorListDoc, "errorlist", 0, emptyWordListDesc);
  1068. LexerModule lmLatex(SCLEX_LATEX, ColouriseLatexDoc, "latex", 0, emptyWordListDesc);
  1069. LexerModule lmNull(SCLEX_NULL, ColouriseNullDoc, "null");