PageRenderTime 62ms CodeModel.GetById 30ms RepoModel.GetById 0ms app.codeStats 0ms

/src/scintilla/lexers/LexOthers.cxx

http://scite-ru.googlecode.com/
C++ | 1921 lines | 1686 code | 75 blank | 160 comment | 648 complexity | 73abb8b4dbb2122af78df7ad19015dbb MD5 | raw file
Possible License(s): 0BSD

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

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