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