PageRenderTime 42ms CodeModel.GetById 11ms RepoModel.GetById 0ms app.codeStats 0ms

/wxWidgets-2.9.1/src/stc/scintilla/src/LexOthers.cxx

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