PageRenderTime 123ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/ext/scintilla/lexers/LexOthers.cxx

http://tortoisesvn.googlecode.com/
C++ | 1504 lines | 1332 code | 33 blank | 139 comment | 282 complexity | a3f2221aaa7931b26686a8ec51bfbd57 MD5 | raw file
Possible License(s): CC-BY-SA-3.0, GPL-3.0, MPL-2.0-no-copyleft-exception, GPL-2.0, LGPL-2.0, LGPL-2.1, BSD-3-Clause, Apache-2.0, LGPL-3.0

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

Large files files are truncated, but you can click here to view the full file