PageRenderTime 51ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/Tools/MaterialEditor/wxscintilla_1.69.2/src/scintilla/src/LexOthers.cxx

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