PageRenderTime 54ms CodeModel.GetById 23ms RepoModel.GetById 1ms app.codeStats 0ms

/src/gtkscintilla2/scintilla/lexers/LexOthers.cxx

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