Add an UI to enable/disable specific overlay handlers.
[TortoiseGit.git] / ext / scintilla / src / LexBaan.cxx
blob97dd1f4b831dc8192890de494b34efb39c2edb04
1 // Scintilla source code edit control
2 /** @file LexBaan.cxx
3 ** Lexer for Baan.
4 ** Based heavily on LexCPP.cxx
5 **/
6 // Copyright 2001- by Vamsi Potluru <vamsi@who.net> & Praveen Ambekar <ambekarpraveen@yahoo.com>
7 // The License.txt file describes the conditions under which this software may be distributed.
9 #include <stdlib.h>
10 #include <string.h>
11 #include <ctype.h>
12 #include <stdio.h>
13 #include <stdarg.h>
15 #include "Platform.h"
17 #include "PropSet.h"
18 #include "Accessor.h"
19 #include "StyleContext.h"
20 #include "KeyWords.h"
21 #include "Scintilla.h"
22 #include "SciLexer.h"
24 #ifdef SCI_NAMESPACE
25 using namespace Scintilla;
26 #endif
28 static inline bool IsAWordChar(const int ch) {
29 return (ch < 0x80) && (isalnum(ch) || ch == '.' || ch == '_' || ch == '$' || ch == ':');
32 static inline bool IsAWordStart(const int ch) {
33 return (ch < 0x80) && (isalnum(ch) || ch == '_');
36 static void ColouriseBaanDoc(unsigned int startPos, int length, int initStyle, WordList *keywordlists[],
37 Accessor &styler) {
39 WordList &keywords = *keywordlists[0];
40 WordList &keywords2 = *keywordlists[1];
41 bool stylingWithinPreprocessor = styler.GetPropertyInt("styling.within.preprocessor") != 0;
43 if (initStyle == SCE_BAAN_STRINGEOL) // Does not leak onto next line
44 initStyle = SCE_BAAN_DEFAULT;
46 int visibleChars = 0;
48 StyleContext sc(startPos, length, initStyle, styler);
50 for (; sc.More(); sc.Forward()) {
52 if (sc.state == SCE_BAAN_OPERATOR) {
53 sc.SetState(SCE_BAAN_DEFAULT);
54 } else if (sc.state == SCE_BAAN_NUMBER) {
55 if (!IsAWordChar(sc.ch)) {
56 sc.SetState(SCE_BAAN_DEFAULT);
58 } else if (sc.state == SCE_BAAN_IDENTIFIER) {
59 if (!IsAWordChar(sc.ch)) {
60 char s[100];
61 sc.GetCurrentLowered(s, sizeof(s));
62 if (keywords.InList(s)) {
63 sc.ChangeState(SCE_BAAN_WORD);
64 } else if (keywords2.InList(s)) {
65 sc.ChangeState(SCE_BAAN_WORD2);
67 sc.SetState(SCE_BAAN_DEFAULT);
69 } else if (sc.state == SCE_BAAN_PREPROCESSOR) {
70 if (stylingWithinPreprocessor) {
71 if (IsASpace(sc.ch)) {
72 sc.SetState(SCE_BAAN_DEFAULT);
74 } else {
75 if (sc.atLineEnd && (sc.chNext != '^')) {
76 sc.SetState(SCE_BAAN_DEFAULT);
79 } else if (sc.state == SCE_BAAN_COMMENT) {
80 if (sc.atLineEnd) {
81 sc.SetState(SCE_BAAN_DEFAULT);
83 } else if (sc.state == SCE_BAAN_COMMENTDOC) {
84 if (sc.MatchIgnoreCase("enddllusage")) {
85 for (unsigned int i = 0; i < 10; i++){
86 sc.Forward();
88 sc.ForwardSetState(SCE_BAAN_DEFAULT);
90 } else if (sc.state == SCE_BAAN_STRING) {
91 if (sc.ch == '\"') {
92 sc.ForwardSetState(SCE_BAAN_DEFAULT);
93 } else if ((sc.atLineEnd) && (sc.chNext != '^')) {
94 sc.ChangeState(SCE_BAAN_STRINGEOL);
95 sc.ForwardSetState(SCE_C_DEFAULT);
96 visibleChars = 0;
100 if (sc.state == SCE_BAAN_DEFAULT) {
101 if (IsADigit(sc.ch) || (sc.ch == '.' && IsADigit(sc.chNext))) {
102 sc.SetState(SCE_BAAN_NUMBER);
103 } else if (sc.MatchIgnoreCase("dllusage")){
104 sc.SetState(SCE_BAAN_COMMENTDOC);
105 do {
106 sc.Forward();
107 } while ((!sc.atLineEnd) && sc.More());
108 } else if (IsAWordStart(sc.ch)) {
109 sc.SetState(SCE_BAAN_IDENTIFIER);
110 } else if (sc.Match('|')){
111 sc.SetState(SCE_BAAN_COMMENT);
112 } else if (sc.ch == '\"') {
113 sc.SetState(SCE_BAAN_STRING);
114 } else if (sc.ch == '#' && visibleChars == 0) {
115 // Preprocessor commands are alone on their line
116 sc.SetState(SCE_BAAN_PREPROCESSOR);
117 // Skip whitespace between # and preprocessor word
118 do {
119 sc.Forward();
120 } while (IsASpace(sc.ch) && sc.More());
121 } else if (isoperator(static_cast<char>(sc.ch))) {
122 sc.SetState(SCE_BAAN_OPERATOR);
125 if (sc.atLineEnd) {
126 // Reset states to begining of colourise so no surprises
127 // if different sets of lines lexed.
128 visibleChars = 0;
130 if (!IsASpace(sc.ch)) {
131 visibleChars++;
134 sc.Complete();
137 static void FoldBaanDoc(unsigned int startPos, int length, int initStyle, WordList *[],
138 Accessor &styler) {
139 bool foldComment = styler.GetPropertyInt("fold.comment") != 0;
140 bool foldCompact = styler.GetPropertyInt("fold.compact", 1) != 0;
141 unsigned int endPos = startPos + length;
142 int visibleChars = 0;
143 int lineCurrent = styler.GetLine(startPos);
144 int levelPrev = styler.LevelAt(lineCurrent) & SC_FOLDLEVELNUMBERMASK;
145 int levelCurrent = levelPrev;
146 char chNext = styler[startPos];
147 int styleNext = styler.StyleAt(startPos);
148 int style = initStyle;
149 for (unsigned int i = startPos; i < endPos; i++) {
150 char ch = chNext;
151 chNext = styler.SafeGetCharAt(i + 1);
152 int stylePrev = style;
153 style = styleNext;
154 styleNext = styler.StyleAt(i + 1);
155 bool atEOL = (ch == '\r' && chNext != '\n') || (ch == '\n');
156 if (foldComment &&
157 (style == SCE_BAAN_COMMENT || style == SCE_BAAN_COMMENTDOC)) {
158 if (style != stylePrev) {
159 levelCurrent++;
160 } else if ((style != styleNext) && !atEOL) {
161 // Comments don't end at end of line and the next character may be unstyled.
162 levelCurrent--;
165 if (style == SCE_BAAN_OPERATOR) {
166 if (ch == '{') {
167 levelCurrent++;
168 } else if (ch == '}') {
169 levelCurrent--;
172 if (atEOL) {
173 int lev = levelPrev;
174 if (visibleChars == 0 && foldCompact)
175 lev |= SC_FOLDLEVELWHITEFLAG;
176 if ((levelCurrent > levelPrev) && (visibleChars > 0))
177 lev |= SC_FOLDLEVELHEADERFLAG;
178 if (lev != styler.LevelAt(lineCurrent)) {
179 styler.SetLevel(lineCurrent, lev);
181 lineCurrent++;
182 levelPrev = levelCurrent;
183 visibleChars = 0;
185 if (!isspacechar(ch))
186 visibleChars++;
188 // Fill in the real level of the next line, keeping the current flags as they will be filled in later
189 int flagsNext = styler.LevelAt(lineCurrent) & ~SC_FOLDLEVELNUMBERMASK;
190 styler.SetLevel(lineCurrent, levelPrev | flagsNext);
193 LexerModule lmBaan(SCLEX_BAAN, ColouriseBaanDoc, "baan", FoldBaanDoc);