PageRenderTime 56ms CodeModel.GetById 17ms RepoModel.GetById 1ms app.codeStats 0ms

/Branches/4.0/Scintilla/src/Lexers/LexOthers.cxx

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