PageRenderTime 55ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 1ms

/QScintilla/src/LexOthers.cpp

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