PageRenderTime 50ms CodeModel.GetById 16ms RepoModel.GetById 1ms app.codeStats 0ms

/ExtLibs/wxWidgets/src/stc/scintilla/src/LexPascal.cxx

https://bitbucket.org/lennonchan/cafu
C++ | 592 lines | 429 code | 43 blank | 120 comment | 294 complexity | 2356b64b4ea1647442a2e875704c182f MD5 | raw file
  1. // Scintilla source code edit control
  2. /** @file LexPascal.cxx
  3. ** Lexer for Pascal.
  4. ** Written by Laurent le Tynevez
  5. ** Updated by Simon Steele <s.steele@pnotepad.org> September 2002
  6. ** Updated by Mathias Rauen <scite@madshi.net> May 2003 (Delphi adjustments)
  7. ** Completely rewritten by Marko Njezic <sf@maxempire.com> October 2008
  8. **/
  9. /*
  10. A few words about features of the new completely rewritten LexPascal...
  11. Generally speaking LexPascal tries to support all available Delphi features (up
  12. to Delphi 2009 at this time), including .NET specific features.
  13. ~ HIGHLIGHTING:
  14. If you enable "lexer.pascal.smart.highlighting" property, some keywords will
  15. only be highlighted in appropriate context. As implemented those are keywords
  16. related to property and DLL exports declarations (similar to how Delphi IDE
  17. works).
  18. For example, keywords "read" and "write" will only be highlighted if they are in
  19. property declaration:
  20. property MyProperty: boolean read FMyProperty write FMyProperty;
  21. ~ FOLDING:
  22. Folding is supported in the following cases:
  23. - Folding of stream-like comments
  24. - Folding of groups of consecutive line comments
  25. - Folding of preprocessor blocks (the following preprocessor blocks are
  26. supported: IF / IFEND; IFDEF, IFNDEF, IFOPT / ENDIF and REGION / ENDREGION
  27. blocks), including nesting of preprocessor blocks up to 255 levels
  28. - Folding of code blocks on appropriate keywords (the following code blocks are
  29. supported: "begin, asm, record, try, case / end" blocks, class & object
  30. declarations and interface declarations)
  31. Remarks:
  32. - Folding of code blocks tries to handle all special cases in which folding
  33. should not occur. As implemented those are:
  34. 1. Structure "record case / end" (there's only one "end" statement and "case" is
  35. ignored as fold point)
  36. 2. Forward class declarations ("type TMyClass = class;") and object method
  37. declarations ("TNotifyEvent = procedure(Sender: TObject) of object;") are
  38. ignored as fold points
  39. 3. Simplified complete class declarations ("type TMyClass = class(TObject);")
  40. are ignored as fold points
  41. 4. Every other situation when class keyword doesn't actually start class
  42. declaration ("class procedure", "class function", "class of", "class var",
  43. "class property" and "class operator")
  44. - Folding of code blocks inside preprocessor blocks is disabled (any comments
  45. inside them will be folded fine) because there is no guarantee that complete
  46. code block will be contained inside folded preprocessor block in which case
  47. folded code block could end prematurely at the end of preprocessor block if
  48. there is no closing statement inside. This was done in order to properly process
  49. document that may contain something like this:
  50. type
  51. {$IFDEF UNICODE}
  52. TMyClass = class(UnicodeAncestor)
  53. {$ELSE}
  54. TMyClass = class(AnsiAncestor)
  55. {$ENDIF}
  56. private
  57. ...
  58. public
  59. ...
  60. published
  61. ...
  62. end;
  63. If class declarations were folded, then the second class declaration would end
  64. at "$ENDIF" statement, first class statement would end at "end;" statement and
  65. preprocessor "$IFDEF" block would go all the way to the end of document.
  66. However, having in mind all this, if you want to enable folding of code blocks
  67. inside preprocessor blocks, you can disable folding of preprocessor blocks by
  68. changing "fold.preprocessor" property, in which case everything inside them
  69. would be folded.
  70. ~ KEYWORDS:
  71. The list of keywords that can be used in pascal.properties file (up to Delphi
  72. 2009):
  73. - Keywords: absolute abstract and array as asm assembler automated begin case
  74. cdecl class const constructor deprecated destructor dispid dispinterface div do
  75. downto dynamic else end except export exports external far file final
  76. finalization finally for forward function goto if implementation in inherited
  77. initialization inline interface is label library message mod near nil not object
  78. of on or out overload override packed pascal platform private procedure program
  79. property protected public published raise record register reintroduce repeat
  80. resourcestring safecall sealed set shl shr static stdcall strict string then
  81. threadvar to try type unit unsafe until uses var varargs virtual while with xor
  82. - Keywords related to the "smart highlithing" feature: add default implements
  83. index name nodefault read readonly remove stored write writeonly
  84. - Keywords related to Delphi packages (in addition to all above): package
  85. contains requires
  86. */
  87. #include <stdlib.h>
  88. #include <string.h>
  89. #include <ctype.h>
  90. #include <stdio.h>
  91. #include <stdarg.h>
  92. #include "Platform.h"
  93. #include "PropSet.h"
  94. #include "Accessor.h"
  95. #include "KeyWords.h"
  96. #include "Scintilla.h"
  97. #include "SciLexer.h"
  98. #include "StyleContext.h"
  99. #include "CharacterSet.h"
  100. #ifdef SCI_NAMESPACE
  101. using namespace Scintilla;
  102. #endif
  103. static void GetRangeLowered(unsigned int start,
  104. unsigned int end,
  105. Accessor &styler,
  106. char *s,
  107. unsigned int len) {
  108. unsigned int i = 0;
  109. while ((i < end - start + 1) && (i < len-1)) {
  110. s[i] = static_cast<char>(tolower(styler[start + i]));
  111. i++;
  112. }
  113. s[i] = '\0';
  114. }
  115. static void GetForwardRangeLowered(unsigned int start,
  116. CharacterSet &charSet,
  117. Accessor &styler,
  118. char *s,
  119. unsigned int len) {
  120. unsigned int i = 0;
  121. while ((i < len-1) && charSet.Contains(styler.SafeGetCharAt(start + i))) {
  122. s[i] = static_cast<char>(tolower(styler.SafeGetCharAt(start + i)));
  123. i++;
  124. }
  125. s[i] = '\0';
  126. }
  127. enum {
  128. stateInAsm = 0x1000,
  129. stateInProperty = 0x2000,
  130. stateInExport = 0x4000,
  131. stateFoldInPreprocessor = 0x0100,
  132. stateFoldInRecord = 0x0200,
  133. stateFoldInPreprocessorLevelMask = 0x00FF,
  134. stateFoldMaskAll = 0x0FFF
  135. };
  136. static void ClassifyPascalWord(WordList *keywordlists[], StyleContext &sc, int &curLineState, bool bSmartHighlighting) {
  137. WordList& keywords = *keywordlists[0];
  138. char s[100];
  139. sc.GetCurrentLowered(s, sizeof(s));
  140. if (keywords.InList(s)) {
  141. if (curLineState & stateInAsm) {
  142. if (strcmp(s, "end") == 0 && sc.GetRelative(-4) != '@') {
  143. curLineState &= ~stateInAsm;
  144. sc.ChangeState(SCE_PAS_WORD);
  145. } else {
  146. sc.ChangeState(SCE_PAS_ASM);
  147. }
  148. } else {
  149. bool ignoreKeyword = false;
  150. if (strcmp(s, "asm") == 0) {
  151. curLineState |= stateInAsm;
  152. } else if (bSmartHighlighting) {
  153. if (strcmp(s, "property") == 0) {
  154. curLineState |= stateInProperty;
  155. } else if (strcmp(s, "exports") == 0) {
  156. curLineState |= stateInExport;
  157. } else if (!(curLineState & (stateInProperty | stateInExport)) && strcmp(s, "index") == 0) {
  158. ignoreKeyword = true;
  159. } else if (!(curLineState & stateInExport) && strcmp(s, "name") == 0) {
  160. ignoreKeyword = true;
  161. } else if (!(curLineState & stateInProperty) &&
  162. (strcmp(s, "read") == 0 || strcmp(s, "write") == 0 ||
  163. strcmp(s, "default") == 0 || strcmp(s, "nodefault") == 0 ||
  164. strcmp(s, "stored") == 0 || strcmp(s, "implements") == 0 ||
  165. strcmp(s, "readonly") == 0 || strcmp(s, "writeonly") == 0 ||
  166. strcmp(s, "add") == 0 || strcmp(s, "remove") == 0)) {
  167. ignoreKeyword = true;
  168. }
  169. }
  170. if (!ignoreKeyword) {
  171. sc.ChangeState(SCE_PAS_WORD);
  172. }
  173. }
  174. } else if (curLineState & stateInAsm) {
  175. sc.ChangeState(SCE_PAS_ASM);
  176. }
  177. sc.SetState(SCE_PAS_DEFAULT);
  178. }
  179. static void ColourisePascalDoc(unsigned int startPos, int length, int initStyle, WordList *keywordlists[],
  180. Accessor &styler) {
  181. bool bSmartHighlighting = styler.GetPropertyInt("lexer.pascal.smart.highlighting", 1) != 0;
  182. CharacterSet setWordStart(CharacterSet::setAlpha, "_", 0x80, true);
  183. CharacterSet setWord(CharacterSet::setAlphaNum, "_", 0x80, true);
  184. CharacterSet setNumber(CharacterSet::setDigits, ".-+eE");
  185. CharacterSet setHexNumber(CharacterSet::setDigits, "abcdefABCDEF");
  186. CharacterSet setOperator(CharacterSet::setNone, "#$&'()*+,-./:;<=>@[]^{}");
  187. int curLine = styler.GetLine(startPos);
  188. int curLineState = curLine > 0 ? styler.GetLineState(curLine - 1) : 0;
  189. StyleContext sc(startPos, length, initStyle, styler);
  190. for (; sc.More(); sc.Forward()) {
  191. if (sc.atLineEnd) {
  192. // Update the line state, so it can be seen by next line
  193. curLine = styler.GetLine(sc.currentPos);
  194. styler.SetLineState(curLine, curLineState);
  195. }
  196. // Determine if the current state should terminate.
  197. switch (sc.state) {
  198. case SCE_PAS_NUMBER:
  199. if (!setNumber.Contains(sc.ch) || (sc.ch == '.' && sc.chNext == '.')) {
  200. sc.SetState(SCE_PAS_DEFAULT);
  201. } else if (sc.ch == '-' || sc.ch == '+') {
  202. if (sc.chPrev != 'E' && sc.chPrev != 'e') {
  203. sc.SetState(SCE_PAS_DEFAULT);
  204. }
  205. }
  206. break;
  207. case SCE_PAS_IDENTIFIER:
  208. if (!setWord.Contains(sc.ch)) {
  209. ClassifyPascalWord(keywordlists, sc, curLineState, bSmartHighlighting);
  210. }
  211. break;
  212. case SCE_PAS_HEXNUMBER:
  213. if (!setHexNumber.Contains(sc.ch)) {
  214. sc.SetState(SCE_PAS_DEFAULT);
  215. }
  216. break;
  217. case SCE_PAS_COMMENT:
  218. case SCE_PAS_PREPROCESSOR:
  219. if (sc.ch == '}') {
  220. sc.ForwardSetState(SCE_PAS_DEFAULT);
  221. }
  222. break;
  223. case SCE_PAS_COMMENT2:
  224. case SCE_PAS_PREPROCESSOR2:
  225. if (sc.Match('*', ')')) {
  226. sc.Forward();
  227. sc.ForwardSetState(SCE_PAS_DEFAULT);
  228. }
  229. break;
  230. case SCE_PAS_COMMENTLINE:
  231. if (sc.atLineStart) {
  232. sc.SetState(SCE_PAS_DEFAULT);
  233. }
  234. break;
  235. case SCE_PAS_STRING:
  236. if (sc.atLineEnd) {
  237. sc.ChangeState(SCE_PAS_STRINGEOL);
  238. } else if (sc.ch == '\'' && sc.chNext == '\'') {
  239. sc.Forward();
  240. } else if (sc.ch == '\'') {
  241. sc.ForwardSetState(SCE_PAS_DEFAULT);
  242. }
  243. break;
  244. case SCE_PAS_STRINGEOL:
  245. if (sc.atLineStart) {
  246. sc.SetState(SCE_PAS_DEFAULT);
  247. }
  248. break;
  249. case SCE_PAS_CHARACTER:
  250. if (!setHexNumber.Contains(sc.ch) && sc.ch != '$') {
  251. sc.SetState(SCE_PAS_DEFAULT);
  252. }
  253. break;
  254. case SCE_PAS_OPERATOR:
  255. if (bSmartHighlighting && sc.chPrev == ';') {
  256. curLineState &= ~(stateInProperty | stateInExport);
  257. }
  258. sc.SetState(SCE_PAS_DEFAULT);
  259. break;
  260. case SCE_PAS_ASM:
  261. sc.SetState(SCE_PAS_DEFAULT);
  262. break;
  263. }
  264. // Determine if a new state should be entered.
  265. if (sc.state == SCE_PAS_DEFAULT) {
  266. if (IsADigit(sc.ch) && !(curLineState & stateInAsm)) {
  267. sc.SetState(SCE_PAS_NUMBER);
  268. } else if (setWordStart.Contains(sc.ch)) {
  269. sc.SetState(SCE_PAS_IDENTIFIER);
  270. } else if (sc.ch == '$' && !(curLineState & stateInAsm)) {
  271. sc.SetState(SCE_PAS_HEXNUMBER);
  272. } else if (sc.Match('{', '$')) {
  273. sc.SetState(SCE_PAS_PREPROCESSOR);
  274. } else if (sc.ch == '{') {
  275. sc.SetState(SCE_PAS_COMMENT);
  276. } else if (sc.Match("(*$")) {
  277. sc.SetState(SCE_PAS_PREPROCESSOR2);
  278. } else if (sc.Match('(', '*')) {
  279. sc.SetState(SCE_PAS_COMMENT2);
  280. sc.Forward(); // Eat the * so it isn't used for the end of the comment
  281. } else if (sc.Match('/', '/')) {
  282. sc.SetState(SCE_PAS_COMMENTLINE);
  283. } else if (sc.ch == '\'') {
  284. sc.SetState(SCE_PAS_STRING);
  285. } else if (sc.ch == '#') {
  286. sc.SetState(SCE_PAS_CHARACTER);
  287. } else if (setOperator.Contains(sc.ch) && !(curLineState & stateInAsm)) {
  288. sc.SetState(SCE_PAS_OPERATOR);
  289. } else if (curLineState & stateInAsm) {
  290. sc.SetState(SCE_PAS_ASM);
  291. }
  292. }
  293. }
  294. if (sc.state == SCE_PAS_IDENTIFIER && setWord.Contains(sc.chPrev)) {
  295. ClassifyPascalWord(keywordlists, sc, curLineState, bSmartHighlighting);
  296. }
  297. sc.Complete();
  298. }
  299. static bool IsStreamCommentStyle(int style) {
  300. return style == SCE_PAS_COMMENT || style == SCE_PAS_COMMENT2;
  301. }
  302. static bool IsCommentLine(int line, Accessor &styler) {
  303. int pos = styler.LineStart(line);
  304. int eolPos = styler.LineStart(line + 1) - 1;
  305. for (int i = pos; i < eolPos; i++) {
  306. char ch = styler[i];
  307. char chNext = styler.SafeGetCharAt(i + 1);
  308. int style = styler.StyleAt(i);
  309. if (ch == '/' && chNext == '/' && style == SCE_PAS_COMMENTLINE) {
  310. return true;
  311. } else if (!IsASpaceOrTab(ch)) {
  312. return false;
  313. }
  314. }
  315. return false;
  316. }
  317. static unsigned int GetFoldInPreprocessorLevelFlag(int lineFoldStateCurrent) {
  318. return lineFoldStateCurrent & stateFoldInPreprocessorLevelMask;
  319. }
  320. static void SetFoldInPreprocessorLevelFlag(int &lineFoldStateCurrent, unsigned int nestLevel) {
  321. lineFoldStateCurrent &= ~stateFoldInPreprocessorLevelMask;
  322. lineFoldStateCurrent |= nestLevel & stateFoldInPreprocessorLevelMask;
  323. }
  324. static void ClassifyPascalPreprocessorFoldPoint(int &levelCurrent, int &lineFoldStateCurrent,
  325. unsigned int startPos, Accessor &styler) {
  326. CharacterSet setWord(CharacterSet::setAlpha);
  327. char s[11]; // Size of the longest possible keyword + one additional character + null
  328. GetForwardRangeLowered(startPos, setWord, styler, s, sizeof(s));
  329. unsigned int nestLevel = GetFoldInPreprocessorLevelFlag(lineFoldStateCurrent);
  330. if (strcmp(s, "if") == 0 ||
  331. strcmp(s, "ifdef") == 0 ||
  332. strcmp(s, "ifndef") == 0 ||
  333. strcmp(s, "ifopt") == 0 ||
  334. strcmp(s, "region") == 0) {
  335. nestLevel++;
  336. SetFoldInPreprocessorLevelFlag(lineFoldStateCurrent, nestLevel);
  337. lineFoldStateCurrent |= stateFoldInPreprocessor;
  338. levelCurrent++;
  339. } else if (strcmp(s, "endif") == 0 ||
  340. strcmp(s, "ifend") == 0 ||
  341. strcmp(s, "endregion") == 0) {
  342. nestLevel--;
  343. SetFoldInPreprocessorLevelFlag(lineFoldStateCurrent, nestLevel);
  344. if (nestLevel == 0) {
  345. lineFoldStateCurrent &= ~stateFoldInPreprocessor;
  346. }
  347. levelCurrent--;
  348. if (levelCurrent < SC_FOLDLEVELBASE) {
  349. levelCurrent = SC_FOLDLEVELBASE;
  350. }
  351. }
  352. }
  353. static unsigned int SkipWhiteSpace(unsigned int currentPos, unsigned int endPos,
  354. Accessor &styler, bool includeChars = false) {
  355. CharacterSet setWord(CharacterSet::setAlphaNum, "_");
  356. unsigned int j = currentPos + 1;
  357. char ch = styler.SafeGetCharAt(j);
  358. while ((j < endPos) && (IsASpaceOrTab(ch) || ch == '\r' || ch == '\n' ||
  359. IsStreamCommentStyle(styler.StyleAt(j)) || (includeChars && setWord.Contains(ch)))) {
  360. j++;
  361. ch = styler.SafeGetCharAt(j);
  362. }
  363. return j;
  364. }
  365. static void ClassifyPascalWordFoldPoint(int &levelCurrent, int &lineFoldStateCurrent,
  366. int startPos, unsigned int endPos,
  367. unsigned int lastStart, unsigned int currentPos, Accessor &styler) {
  368. char s[100];
  369. GetRangeLowered(lastStart, currentPos, styler, s, sizeof(s));
  370. if (strcmp(s, "record") == 0) {
  371. lineFoldStateCurrent |= stateFoldInRecord;
  372. levelCurrent++;
  373. } else if (strcmp(s, "begin") == 0 ||
  374. strcmp(s, "asm") == 0 ||
  375. strcmp(s, "try") == 0 ||
  376. (strcmp(s, "case") == 0 && !(lineFoldStateCurrent & stateFoldInRecord))) {
  377. levelCurrent++;
  378. } else if (strcmp(s, "class") == 0 || strcmp(s, "object") == 0) {
  379. // "class" & "object" keywords require special handling...
  380. bool ignoreKeyword = false;
  381. unsigned int j = SkipWhiteSpace(currentPos, endPos, styler);
  382. if (j < endPos) {
  383. CharacterSet setWordStart(CharacterSet::setAlpha, "_");
  384. CharacterSet setWord(CharacterSet::setAlphaNum, "_");
  385. if (styler.SafeGetCharAt(j) == ';') {
  386. // Handle forward class declarations ("type TMyClass = class;")
  387. // and object method declarations ("TNotifyEvent = procedure(Sender: TObject) of object;")
  388. ignoreKeyword = true;
  389. } else if (strcmp(s, "class") == 0) {
  390. // "class" keyword has a few more special cases...
  391. if (styler.SafeGetCharAt(j) == '(') {
  392. // Handle simplified complete class declarations ("type TMyClass = class(TObject);")
  393. j = SkipWhiteSpace(j, endPos, styler, true);
  394. if (j < endPos && styler.SafeGetCharAt(j) == ')') {
  395. j = SkipWhiteSpace(j, endPos, styler);
  396. if (j < endPos && styler.SafeGetCharAt(j) == ';') {
  397. ignoreKeyword = true;
  398. }
  399. }
  400. } else if (setWordStart.Contains(styler.SafeGetCharAt(j))) {
  401. char s2[11]; // Size of the longest possible keyword + one additional character + null
  402. GetForwardRangeLowered(j, setWord, styler, s2, sizeof(s2));
  403. if (strcmp(s2, "procedure") == 0 ||
  404. strcmp(s2, "function") == 0 ||
  405. strcmp(s2, "of") == 0 ||
  406. strcmp(s2, "var") == 0 ||
  407. strcmp(s2, "property") == 0 ||
  408. strcmp(s2, "operator") == 0) {
  409. ignoreKeyword = true;
  410. }
  411. }
  412. }
  413. }
  414. if (!ignoreKeyword) {
  415. levelCurrent++;
  416. }
  417. } else if (strcmp(s, "interface") == 0) {
  418. // "interface" keyword requires special handling...
  419. bool ignoreKeyword = true;
  420. int j = lastStart - 1;
  421. char ch = styler.SafeGetCharAt(j);
  422. while ((j >= startPos) && (IsASpaceOrTab(ch) || ch == '\r' || ch == '\n' ||
  423. IsStreamCommentStyle(styler.StyleAt(j)))) {
  424. j--;
  425. ch = styler.SafeGetCharAt(j);
  426. }
  427. if (j >= startPos && styler.SafeGetCharAt(j) == '=') {
  428. ignoreKeyword = false;
  429. }
  430. if (!ignoreKeyword) {
  431. levelCurrent++;
  432. }
  433. } else if (strcmp(s, "end") == 0) {
  434. lineFoldStateCurrent &= ~stateFoldInRecord;
  435. levelCurrent--;
  436. if (levelCurrent < SC_FOLDLEVELBASE) {
  437. levelCurrent = SC_FOLDLEVELBASE;
  438. }
  439. }
  440. }
  441. static void FoldPascalDoc(unsigned int startPos, int length, int initStyle, WordList *[],
  442. Accessor &styler) {
  443. bool foldComment = styler.GetPropertyInt("fold.comment") != 0;
  444. bool foldPreprocessor = styler.GetPropertyInt("fold.preprocessor") != 0;
  445. bool foldCompact = styler.GetPropertyInt("fold.compact", 1) != 0;
  446. unsigned int endPos = startPos + length;
  447. int visibleChars = 0;
  448. int lineCurrent = styler.GetLine(startPos);
  449. int levelPrev = styler.LevelAt(lineCurrent) & SC_FOLDLEVELNUMBERMASK;
  450. int levelCurrent = levelPrev;
  451. int lineFoldStateCurrent = lineCurrent > 0 ? styler.GetLineState(lineCurrent - 1) & stateFoldMaskAll : 0;
  452. char chNext = styler[startPos];
  453. int styleNext = styler.StyleAt(startPos);
  454. int style = initStyle;
  455. int lastStart = 0;
  456. CharacterSet setWord(CharacterSet::setAlphaNum, "_", 0x80, true);
  457. for (unsigned int i = startPos; i < endPos; i++) {
  458. char ch = chNext;
  459. chNext = styler.SafeGetCharAt(i + 1);
  460. int stylePrev = style;
  461. style = styleNext;
  462. styleNext = styler.StyleAt(i + 1);
  463. bool atEOL = (ch == '\r' && chNext != '\n') || (ch == '\n');
  464. if (foldComment && IsStreamCommentStyle(style)) {
  465. if (!IsStreamCommentStyle(stylePrev)) {
  466. levelCurrent++;
  467. } else if (!IsStreamCommentStyle(styleNext) && !atEOL) {
  468. // Comments don't end at end of line and the next character may be unstyled.
  469. levelCurrent--;
  470. }
  471. }
  472. if (foldComment && atEOL && IsCommentLine(lineCurrent, styler))
  473. {
  474. if (!IsCommentLine(lineCurrent - 1, styler)
  475. && IsCommentLine(lineCurrent + 1, styler))
  476. levelCurrent++;
  477. else if (IsCommentLine(lineCurrent - 1, styler)
  478. && !IsCommentLine(lineCurrent+1, styler))
  479. levelCurrent--;
  480. }
  481. if (foldPreprocessor) {
  482. if (style == SCE_PAS_PREPROCESSOR && ch == '{' && chNext == '$') {
  483. ClassifyPascalPreprocessorFoldPoint(levelCurrent, lineFoldStateCurrent, i + 2, styler);
  484. } else if (style == SCE_PAS_PREPROCESSOR2 && ch == '(' && chNext == '*'
  485. && styler.SafeGetCharAt(i + 2) == '$') {
  486. ClassifyPascalPreprocessorFoldPoint(levelCurrent, lineFoldStateCurrent, i + 3, styler);
  487. }
  488. }
  489. if (stylePrev != SCE_PAS_WORD && style == SCE_PAS_WORD)
  490. {
  491. // Store last word start point.
  492. lastStart = i;
  493. }
  494. if (stylePrev == SCE_PAS_WORD && !(lineFoldStateCurrent & stateFoldInPreprocessor)) {
  495. if(setWord.Contains(ch) && !setWord.Contains(chNext)) {
  496. ClassifyPascalWordFoldPoint(levelCurrent, lineFoldStateCurrent, startPos, endPos, lastStart, i, styler);
  497. }
  498. }
  499. if (!IsASpace(ch))
  500. visibleChars++;
  501. if (atEOL) {
  502. int lev = levelPrev;
  503. if (visibleChars == 0 && foldCompact)
  504. lev |= SC_FOLDLEVELWHITEFLAG;
  505. if ((levelCurrent > levelPrev) && (visibleChars > 0))
  506. lev |= SC_FOLDLEVELHEADERFLAG;
  507. if (lev != styler.LevelAt(lineCurrent)) {
  508. styler.SetLevel(lineCurrent, lev);
  509. }
  510. int newLineState = (styler.GetLineState(lineCurrent) & ~stateFoldMaskAll) | lineFoldStateCurrent;
  511. styler.SetLineState(lineCurrent, newLineState);
  512. lineCurrent++;
  513. levelPrev = levelCurrent;
  514. visibleChars = 0;
  515. }
  516. }
  517. // If we didn't reach the EOL in previous loop, store line level and whitespace information.
  518. // The rest will be filled in later...
  519. int lev = levelPrev;
  520. if (visibleChars == 0 && foldCompact)
  521. lev |= SC_FOLDLEVELWHITEFLAG;
  522. styler.SetLevel(lineCurrent, lev);
  523. }
  524. static const char * const pascalWordListDesc[] = {
  525. "Keywords",
  526. 0
  527. };
  528. LexerModule lmPascal(SCLEX_PASCAL, ColourisePascalDoc, "pascal", FoldPascalDoc, pascalWordListDesc);