LexOScript.cpp 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549
  1. // Scintilla source code edit control
  2. /** @file LexOScript.cxx
  3. ** Lexer for OScript sources; ocx files and/or OSpace dumps.
  4. ** OScript is a programming language used to develop applications for the
  5. ** Livelink server platform.
  6. **/
  7. // Written by Ferdinand Prantl <prantlf@gmail.com>, inspired by the code from
  8. // LexVB.cxx and LexPascal.cxx. The License.txt file describes the conditions
  9. // under which this software may be distributed.
  10. #include <stdlib.h>
  11. #include <string.h>
  12. #include <stdio.h>
  13. #include <stdarg.h>
  14. #include <assert.h>
  15. #include <ctype.h>
  16. #include "ILexer.h"
  17. #include "Scintilla.h"
  18. #include "SciLexer.h"
  19. #include "WordList.h"
  20. #include "LexAccessor.h"
  21. #include "Accessor.h"
  22. #include "StyleContext.h"
  23. #include "CharacterSet.h"
  24. #include "LexerModule.h"
  25. #ifdef SCI_NAMESPACE
  26. using namespace Scintilla;
  27. #endif
  28. // -----------------------------------------
  29. // Functions classifying a single character.
  30. // This function is generic and should be probably moved to CharSet.h where
  31. // IsAlphaNumeric the others reside.
  32. inline bool IsAlpha(int ch) {
  33. return (ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z');
  34. }
  35. static inline bool IsIdentifierChar(int ch) {
  36. // Identifiers cannot contain non-ASCII letters; a word with non-English
  37. // language-specific characters cannot be an identifier.
  38. return IsAlphaNumeric(ch) || ch == '_';
  39. }
  40. static inline bool IsIdentifierStart(int ch) {
  41. // Identifiers cannot contain non-ASCII letters; a word with non-English
  42. // language-specific characters cannot be an identifier.
  43. return IsAlpha(ch) || ch == '_';
  44. }
  45. static inline bool IsNumberChar(int ch, int chNext) {
  46. // Numeric constructs are not checked for lexical correctness. They are
  47. // expected to look like +1.23-E9 but actually any bunch of the following
  48. // characters will be styled as number.
  49. // KNOWN PROBLEM: if you put + or - operators immediately after a number
  50. // and the next operand starts with the letter E, the operator will not be
  51. // recognized and it will be styled together with the preceding number.
  52. // This should not occur; at least not often. The coding style recommends
  53. // putting spaces around operators.
  54. return IsADigit(ch) || toupper(ch) == 'E' || ch == '.' ||
  55. ((ch == '-' || ch == '+') && toupper(chNext) == 'E');
  56. }
  57. // This function checks for the start or a natural number without any symbols
  58. // or operators as a prefix; the IsPrefixedNumberStart should be called
  59. // immediately after this one to cover all possible numeric constructs.
  60. static inline bool IsNaturalNumberStart(int ch) {
  61. return IsADigit(ch) != 0;
  62. }
  63. static inline bool IsPrefixedNumberStart(int ch, int chNext) {
  64. // KNOWN PROBLEM: if you put + or - operators immediately before a number
  65. // the operator will not be recognized and it will be styled together with
  66. // the succeeding number. This should not occur; at least not often. The
  67. // coding style recommends putting spaces around operators.
  68. return (ch == '.' || ch == '-' || ch == '+') && IsADigit(chNext);
  69. }
  70. static inline bool IsOperator(int ch) {
  71. return strchr("%^&*()-+={}[]:;<>,/?!.~|\\", ch) != NULL;
  72. }
  73. // ---------------------------------------------------------------
  74. // Functions classifying a token currently processed in the lexer.
  75. // Checks if the current line starts with the preprocessor directive used
  76. // usually to introduce documentation comments: #ifdef DOC. This method is
  77. // supposed to be called if the line has been recognized as a preprocessor
  78. // directive already.
  79. static bool IsDocCommentStart(StyleContext &sc) {
  80. // Check the line back to its start only if the end looks promising.
  81. if (sc.LengthCurrent() == 10 && !IsAlphaNumeric(sc.ch)) {
  82. char s[11];
  83. sc.GetCurrentLowered(s, sizeof(s));
  84. return strcmp(s, "#ifdef doc") == 0;
  85. }
  86. return false;
  87. }
  88. // Checks if the current line starts with the preprocessor directive that
  89. // is complementary to the #ifdef DOC start: #endif. This method is supposed
  90. // to be called if the current state point to the documentation comment.
  91. // QUESTIONAL ASSUMPTION: The complete #endif directive is not checked; just
  92. // the starting #e. However, there is no other preprocessor directive with
  93. // the same starting letter and thus this optimization should always work.
  94. static bool IsDocCommentEnd(StyleContext &sc) {
  95. return sc.ch == '#' && sc.chNext == 'e';
  96. }
  97. class IdentifierClassifier {
  98. WordList &keywords; // Passed from keywords property.
  99. WordList &constants; // Passed from keywords2 property.
  100. WordList &operators; // Passed from keywords3 property.
  101. WordList &types; // Passed from keywords4 property.
  102. WordList &functions; // Passed from keywords5 property.
  103. WordList &objects; // Passed from keywords6 property.
  104. IdentifierClassifier(IdentifierClassifier const&);
  105. IdentifierClassifier& operator=(IdentifierClassifier const&);
  106. public:
  107. IdentifierClassifier(WordList *keywordlists[]) :
  108. keywords(*keywordlists[0]), constants(*keywordlists[1]),
  109. operators(*keywordlists[2]), types(*keywordlists[3]),
  110. functions(*keywordlists[4]), objects(*keywordlists[5])
  111. {}
  112. void ClassifyIdentifier(StyleContext &sc) {
  113. // Opening parenthesis following an identifier makes it a possible
  114. // function call.
  115. // KNOWN PROBLEM: If some whitespace is inserted between the
  116. // identifier and the parenthesis they will not be able to be
  117. // recognized as a function call. This should not occur; at
  118. // least not often. Such coding style would be weird.
  119. if (sc.Match('(')) {
  120. char s[100];
  121. sc.GetCurrentLowered(s, sizeof(s));
  122. // Before an opening brace can be control statements and
  123. // operators too; function call is the last option.
  124. if (keywords.InList(s)) {
  125. sc.ChangeState(SCE_OSCRIPT_KEYWORD);
  126. } else if (operators.InList(s)) {
  127. sc.ChangeState(SCE_OSCRIPT_OPERATOR);
  128. } else if (functions.InList(s)) {
  129. sc.ChangeState(SCE_OSCRIPT_FUNCTION);
  130. } else {
  131. sc.ChangeState(SCE_OSCRIPT_METHOD);
  132. }
  133. sc.SetState(SCE_OSCRIPT_OPERATOR);
  134. } else {
  135. char s[100];
  136. sc.GetCurrentLowered(s, sizeof(s));
  137. // A dot following an identifier means an access to an object
  138. // member. The related object identifier can be special.
  139. // KNOWN PROBLEM: If there is whitespace between the identifier
  140. // and the following dot, the identifier will not be recognized
  141. // as an object in an object member access. If it is one of the
  142. // listed static objects it will not be styled.
  143. if (sc.Match('.') && objects.InList(s)) {
  144. sc.ChangeState(SCE_OSCRIPT_OBJECT);
  145. sc.SetState(SCE_OSCRIPT_OPERATOR);
  146. } else {
  147. if (keywords.InList(s)) {
  148. sc.ChangeState(SCE_OSCRIPT_KEYWORD);
  149. } else if (constants.InList(s)) {
  150. sc.ChangeState(SCE_OSCRIPT_CONSTANT);
  151. } else if (operators.InList(s)) {
  152. sc.ChangeState(SCE_OSCRIPT_OPERATOR);
  153. } else if (types.InList(s)) {
  154. sc.ChangeState(SCE_OSCRIPT_TYPE);
  155. } else if (functions.InList(s)) {
  156. sc.ChangeState(SCE_OSCRIPT_FUNCTION);
  157. }
  158. sc.SetState(SCE_OSCRIPT_DEFAULT);
  159. }
  160. }
  161. }
  162. };
  163. // ------------------------------------------------
  164. // Function colourising an excerpt of OScript code.
  165. static void ColouriseOScriptDoc(Sci_PositionU startPos, Sci_Position length,
  166. int initStyle, WordList *keywordlists[],
  167. Accessor &styler) {
  168. // I wonder how whole-line styles ended by EOLN can escape the resetting
  169. // code in the loop below and overflow to the next line. Let us make sure
  170. // that a new line does not start with them carried from the previous one.
  171. // NOTE: An overflowing string is intentionally not checked; it reminds
  172. // the developer that the string must be ended on the same line.
  173. if (initStyle == SCE_OSCRIPT_LINE_COMMENT ||
  174. initStyle == SCE_OSCRIPT_PREPROCESSOR) {
  175. initStyle = SCE_OSCRIPT_DEFAULT;
  176. }
  177. styler.StartAt(startPos);
  178. StyleContext sc(startPos, length, initStyle, styler);
  179. IdentifierClassifier identifierClassifier(keywordlists);
  180. // It starts with true at the beginning of a line and changes to false as
  181. // soon as the first non-whitespace character has been processed.
  182. bool isFirstToken = true;
  183. // It starts with true at the beginning of a line and changes to false as
  184. // soon as the first identifier on the line is passed by.
  185. bool isFirstIdentifier = true;
  186. // It becomes false when #ifdef DOC (the preprocessor directive often
  187. // used to start a documentation comment) is encountered and remain false
  188. // until the end of the documentation block is not detected. This is done
  189. // by checking for the complementary #endif preprocessor directive.
  190. bool endDocComment = false;
  191. for (; sc.More(); sc.Forward()) {
  192. if (sc.atLineStart) {
  193. isFirstToken = true;
  194. isFirstIdentifier = true;
  195. // Detect the current state is neither whitespace nor identifier. It
  196. // means that no next identifier can be the first token on the line.
  197. } else if (isFirstIdentifier && sc.state != SCE_OSCRIPT_DEFAULT &&
  198. sc.state != SCE_OSCRIPT_IDENTIFIER) {
  199. isFirstIdentifier = false;
  200. }
  201. // Check if the current state should be changed.
  202. if (sc.state == SCE_OSCRIPT_OPERATOR) {
  203. // Multiple-symbol operators are marked by single characters.
  204. sc.SetState(SCE_OSCRIPT_DEFAULT);
  205. } else if (sc.state == SCE_OSCRIPT_IDENTIFIER) {
  206. if (!IsIdentifierChar(sc.ch)) {
  207. // Colon after an identifier makes it a label if it is the
  208. // first token on the line.
  209. // KNOWN PROBLEM: If some whitespace is inserted between the
  210. // identifier and the colon they will not be recognized as a
  211. // label. This should not occur; at least not often. It would
  212. // make the code structure less legible and examples in the
  213. // Livelink documentation do not show it.
  214. if (sc.Match(':') && isFirstIdentifier) {
  215. sc.ChangeState(SCE_OSCRIPT_LABEL);
  216. sc.ForwardSetState(SCE_OSCRIPT_DEFAULT);
  217. } else {
  218. identifierClassifier.ClassifyIdentifier(sc);
  219. }
  220. // Avoid a sequence of two words be mistaken for a label. A
  221. // switch case would be an example.
  222. isFirstIdentifier = false;
  223. }
  224. } else if (sc.state == SCE_OSCRIPT_GLOBAL) {
  225. if (!IsIdentifierChar(sc.ch)) {
  226. sc.SetState(SCE_OSCRIPT_DEFAULT);
  227. }
  228. } else if (sc.state == SCE_OSCRIPT_PROPERTY) {
  229. if (!IsIdentifierChar(sc.ch)) {
  230. // Any member access introduced by the dot operator is
  231. // initially marked as a property access. If an opening
  232. // parenthesis is detected later it is changed to method call.
  233. // KNOWN PROBLEM: The same as at the function call recognition
  234. // for SCE_OSCRIPT_IDENTIFIER above.
  235. if (sc.Match('(')) {
  236. sc.ChangeState(SCE_OSCRIPT_METHOD);
  237. }
  238. sc.SetState(SCE_OSCRIPT_DEFAULT);
  239. }
  240. } else if (sc.state == SCE_OSCRIPT_NUMBER) {
  241. if (!IsNumberChar(sc.ch, sc.chNext)) {
  242. sc.SetState(SCE_OSCRIPT_DEFAULT);
  243. }
  244. } else if (sc.state == SCE_OSCRIPT_SINGLEQUOTE_STRING) {
  245. if (sc.ch == '\'') {
  246. // Two consequential apostrophes convert to a single one.
  247. if (sc.chNext == '\'') {
  248. sc.Forward();
  249. } else {
  250. sc.ForwardSetState(SCE_OSCRIPT_DEFAULT);
  251. }
  252. } else if (sc.atLineEnd) {
  253. sc.ForwardSetState(SCE_OSCRIPT_DEFAULT);
  254. }
  255. } else if (sc.state == SCE_OSCRIPT_DOUBLEQUOTE_STRING) {
  256. if (sc.ch == '\"') {
  257. // Two consequential quotation marks convert to a single one.
  258. if (sc.chNext == '\"') {
  259. sc.Forward();
  260. } else {
  261. sc.ForwardSetState(SCE_OSCRIPT_DEFAULT);
  262. }
  263. } else if (sc.atLineEnd) {
  264. sc.ForwardSetState(SCE_OSCRIPT_DEFAULT);
  265. }
  266. } else if (sc.state == SCE_OSCRIPT_BLOCK_COMMENT) {
  267. if (sc.Match('*', '/')) {
  268. sc.Forward();
  269. sc.ForwardSetState(SCE_OSCRIPT_DEFAULT);
  270. }
  271. } else if (sc.state == SCE_OSCRIPT_LINE_COMMENT) {
  272. if (sc.atLineEnd) {
  273. sc.ForwardSetState(SCE_OSCRIPT_DEFAULT);
  274. }
  275. } else if (sc.state == SCE_OSCRIPT_PREPROCESSOR) {
  276. if (IsDocCommentStart(sc)) {
  277. sc.ChangeState(SCE_OSCRIPT_DOC_COMMENT);
  278. endDocComment = false;
  279. } else if (sc.atLineEnd) {
  280. sc.ForwardSetState(SCE_OSCRIPT_DEFAULT);
  281. }
  282. } else if (sc.state == SCE_OSCRIPT_DOC_COMMENT) {
  283. // KNOWN PROBLEM: The first line detected that would close a
  284. // conditional preprocessor block (#endif) the documentation
  285. // comment block will end. (Nested #if-#endif blocks are not
  286. // supported. Hopefully it will not occur often that a line
  287. // within the text block would stat with #endif.
  288. if (isFirstToken && IsDocCommentEnd(sc)) {
  289. endDocComment = true;
  290. } else if (sc.atLineEnd && endDocComment) {
  291. sc.ForwardSetState(SCE_OSCRIPT_DEFAULT);
  292. }
  293. }
  294. // Check what state starts with the current character.
  295. if (sc.state == SCE_OSCRIPT_DEFAULT) {
  296. if (sc.Match('\'')) {
  297. sc.SetState(SCE_OSCRIPT_SINGLEQUOTE_STRING);
  298. } else if (sc.Match('\"')) {
  299. sc.SetState(SCE_OSCRIPT_DOUBLEQUOTE_STRING);
  300. } else if (sc.Match('/', '/')) {
  301. sc.SetState(SCE_OSCRIPT_LINE_COMMENT);
  302. sc.Forward();
  303. } else if (sc.Match('/', '*')) {
  304. sc.SetState(SCE_OSCRIPT_BLOCK_COMMENT);
  305. sc.Forward();
  306. } else if (isFirstToken && sc.Match('#')) {
  307. sc.SetState(SCE_OSCRIPT_PREPROCESSOR);
  308. } else if (sc.Match('$')) {
  309. // Both process-global ($xxx) and thread-global ($$xxx)
  310. // variables are handled as one global.
  311. sc.SetState(SCE_OSCRIPT_GLOBAL);
  312. } else if (IsNaturalNumberStart(sc.ch)) {
  313. sc.SetState(SCE_OSCRIPT_NUMBER);
  314. } else if (IsPrefixedNumberStart(sc.ch, sc.chNext)) {
  315. sc.SetState(SCE_OSCRIPT_NUMBER);
  316. sc.Forward();
  317. } else if (sc.Match('.') && IsIdentifierStart(sc.chNext)) {
  318. // Every object member access is marked as a property access
  319. // initially. The decision between property and method is made
  320. // after parsing the identifier and looking what comes then.
  321. // KNOWN PROBLEM: If there is whitespace between the following
  322. // identifier and the dot, the dot will not be recognized
  323. // as a member accessing operator. In turn, the identifier
  324. // will not be recognizable as a property or a method too.
  325. sc.SetState(SCE_OSCRIPT_OPERATOR);
  326. sc.Forward();
  327. sc.SetState(SCE_OSCRIPT_PROPERTY);
  328. } else if (IsIdentifierStart(sc.ch)) {
  329. sc.SetState(SCE_OSCRIPT_IDENTIFIER);
  330. } else if (IsOperator(sc.ch)) {
  331. sc.SetState(SCE_OSCRIPT_OPERATOR);
  332. }
  333. }
  334. if (isFirstToken && !IsASpaceOrTab(sc.ch)) {
  335. isFirstToken = false;
  336. }
  337. }
  338. sc.Complete();
  339. }
  340. // ------------------------------------------
  341. // Functions supporting OScript code folding.
  342. static inline bool IsBlockComment(int style) {
  343. return style == SCE_OSCRIPT_BLOCK_COMMENT;
  344. }
  345. static bool IsLineComment(Sci_Position line, Accessor &styler) {
  346. Sci_Position pos = styler.LineStart(line);
  347. Sci_Position eolPos = styler.LineStart(line + 1) - 1;
  348. for (Sci_Position i = pos; i < eolPos; i++) {
  349. char ch = styler[i];
  350. char chNext = styler.SafeGetCharAt(i + 1);
  351. int style = styler.StyleAt(i);
  352. if (ch == '/' && chNext == '/' && style == SCE_OSCRIPT_LINE_COMMENT) {
  353. return true;
  354. } else if (!IsASpaceOrTab(ch)) {
  355. return false;
  356. }
  357. }
  358. return false;
  359. }
  360. static inline bool IsPreprocessor(int style) {
  361. return style == SCE_OSCRIPT_PREPROCESSOR ||
  362. style == SCE_OSCRIPT_DOC_COMMENT;
  363. }
  364. static void GetRangeLowered(Sci_PositionU start, Sci_PositionU end,
  365. Accessor &styler, char *s, Sci_PositionU len) {
  366. Sci_PositionU i = 0;
  367. while (i < end - start + 1 && i < len - 1) {
  368. s[i] = static_cast<char>(tolower(styler[start + i]));
  369. i++;
  370. }
  371. s[i] = '\0';
  372. }
  373. static void GetForwardWordLowered(Sci_PositionU start, Accessor &styler,
  374. char *s, Sci_PositionU len) {
  375. Sci_PositionU i = 0;
  376. while (i < len - 1 && IsAlpha(styler.SafeGetCharAt(start + i))) {
  377. s[i] = static_cast<char>(tolower(styler.SafeGetCharAt(start + i)));
  378. i++;
  379. }
  380. s[i] = '\0';
  381. }
  382. static void UpdatePreprocessorFoldLevel(int &levelCurrent,
  383. Sci_PositionU startPos, Accessor &styler) {
  384. char s[7]; // Size of the longest possible keyword + null.
  385. GetForwardWordLowered(startPos, styler, s, sizeof(s));
  386. if (strcmp(s, "ifdef") == 0 ||
  387. strcmp(s, "ifndef") == 0) {
  388. levelCurrent++;
  389. } else if (strcmp(s, "endif") == 0) {
  390. levelCurrent--;
  391. if (levelCurrent < SC_FOLDLEVELBASE) {
  392. levelCurrent = SC_FOLDLEVELBASE;
  393. }
  394. }
  395. }
  396. static void UpdateKeywordFoldLevel(int &levelCurrent, Sci_PositionU lastStart,
  397. Sci_PositionU currentPos, Accessor &styler) {
  398. char s[9];
  399. GetRangeLowered(lastStart, currentPos, styler, s, sizeof(s));
  400. if (strcmp(s, "if") == 0 || strcmp(s, "for") == 0 ||
  401. strcmp(s, "switch") == 0 || strcmp(s, "function") == 0 ||
  402. strcmp(s, "while") == 0 || strcmp(s, "repeat") == 0) {
  403. levelCurrent++;
  404. } else if (strcmp(s, "end") == 0 || strcmp(s, "until") == 0) {
  405. levelCurrent--;
  406. if (levelCurrent < SC_FOLDLEVELBASE) {
  407. levelCurrent = SC_FOLDLEVELBASE;
  408. }
  409. }
  410. }
  411. // ------------------------------
  412. // Function folding OScript code.
  413. static void FoldOScriptDoc(Sci_PositionU startPos, Sci_Position length, int initStyle,
  414. WordList *[], Accessor &styler) {
  415. bool foldComment = styler.GetPropertyInt("fold.comment") != 0;
  416. bool foldPreprocessor = styler.GetPropertyInt("fold.preprocessor") != 0;
  417. bool foldCompact = styler.GetPropertyInt("fold.compact", 1) != 0;
  418. Sci_Position endPos = startPos + length;
  419. int visibleChars = 0;
  420. Sci_Position lineCurrent = styler.GetLine(startPos);
  421. int levelPrev = styler.LevelAt(lineCurrent) & SC_FOLDLEVELNUMBERMASK;
  422. int levelCurrent = levelPrev;
  423. char chNext = styler[startPos];
  424. int styleNext = styler.StyleAt(startPos);
  425. int style = initStyle;
  426. int lastStart = 0;
  427. for (Sci_Position i = startPos; i < endPos; i++) {
  428. char ch = chNext;
  429. chNext = styler.SafeGetCharAt(i + 1);
  430. int stylePrev = style;
  431. style = styleNext;
  432. styleNext = styler.StyleAt(i + 1);
  433. bool atLineEnd = (ch == '\r' && chNext != '\n') || (ch == '\n');
  434. if (foldComment && IsBlockComment(style)) {
  435. if (!IsBlockComment(stylePrev)) {
  436. levelCurrent++;
  437. } else if (!IsBlockComment(styleNext) && !atLineEnd) {
  438. // Comments do not end at end of line and the next character
  439. // may not be styled.
  440. levelCurrent--;
  441. }
  442. }
  443. if (foldComment && atLineEnd && IsLineComment(lineCurrent, styler)) {
  444. if (!IsLineComment(lineCurrent - 1, styler) &&
  445. IsLineComment(lineCurrent + 1, styler))
  446. levelCurrent++;
  447. else if (IsLineComment(lineCurrent - 1, styler) &&
  448. !IsLineComment(lineCurrent+1, styler))
  449. levelCurrent--;
  450. }
  451. if (foldPreprocessor) {
  452. if (ch == '#' && IsPreprocessor(style)) {
  453. UpdatePreprocessorFoldLevel(levelCurrent, i + 1, styler);
  454. }
  455. }
  456. if (stylePrev != SCE_OSCRIPT_KEYWORD && style == SCE_OSCRIPT_KEYWORD) {
  457. lastStart = i;
  458. }
  459. if (stylePrev == SCE_OSCRIPT_KEYWORD) {
  460. if(IsIdentifierChar(ch) && !IsIdentifierChar(chNext)) {
  461. UpdateKeywordFoldLevel(levelCurrent, lastStart, i, styler);
  462. }
  463. }
  464. if (!IsASpace(ch))
  465. visibleChars++;
  466. if (atLineEnd) {
  467. int level = levelPrev;
  468. if (visibleChars == 0 && foldCompact)
  469. level |= SC_FOLDLEVELWHITEFLAG;
  470. if ((levelCurrent > levelPrev) && (visibleChars > 0))
  471. level |= SC_FOLDLEVELHEADERFLAG;
  472. if (level != styler.LevelAt(lineCurrent)) {
  473. styler.SetLevel(lineCurrent, level);
  474. }
  475. lineCurrent++;
  476. levelPrev = levelCurrent;
  477. visibleChars = 0;
  478. }
  479. }
  480. // If we did not reach EOLN in the previous loop, store the line level and
  481. // whitespace information. The rest will be filled in later.
  482. int lev = levelPrev;
  483. if (visibleChars == 0 && foldCompact)
  484. lev |= SC_FOLDLEVELWHITEFLAG;
  485. styler.SetLevel(lineCurrent, lev);
  486. }
  487. // --------------------------------------------
  488. // Declaration of the OScript lexer descriptor.
  489. static const char * const oscriptWordListDesc[] = {
  490. "Keywords and reserved words",
  491. "Literal constants",
  492. "Literal operators",
  493. "Built-in value and reference types",
  494. "Built-in global functions",
  495. "Built-in static objects",
  496. 0
  497. };
  498. LexerModule lmOScript(SCLEX_OSCRIPT, ColouriseOScriptDoc, "oscript", FoldOScriptDoc, oscriptWordListDesc);