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