PageRenderTime 65ms CodeModel.GetById 27ms RepoModel.GetById 0ms app.codeStats 0ms

/Pythonwin/Scintilla/src/LexOthers.cxx

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