1 // Scintilla source code edit control
4 ** Based heavily on LexCPP.cxx
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.
17 #include "Scintilla.h"
21 #include "LexAccessor.h"
23 #include "StyleContext.h"
24 #include "CharacterSet.h"
25 #include "LexerModule.h"
28 using namespace Scintilla
;
31 static inline bool IsAWordChar(const int ch
) {
32 return (ch
< 0x80) && (isalnum(ch
) || ch
== '.' || ch
== '_' || ch
== '$' || ch
== ':');
35 static inline bool IsAWordStart(const int ch
) {
36 return (ch
< 0x80) && (isalnum(ch
) || ch
== '_');
39 static void ColouriseBaanDoc(unsigned int startPos
, int length
, int initStyle
, WordList
*keywordlists
[],
42 WordList
&keywords
= *keywordlists
[0];
43 WordList
&keywords2
= *keywordlists
[1];
44 bool stylingWithinPreprocessor
= styler
.GetPropertyInt("styling.within.preprocessor") != 0;
46 if (initStyle
== SCE_BAAN_STRINGEOL
) // Does not leak onto next line
47 initStyle
= SCE_BAAN_DEFAULT
;
51 StyleContext
sc(startPos
, length
, initStyle
, styler
);
53 for (; sc
.More(); sc
.Forward()) {
55 if (sc
.state
== SCE_BAAN_OPERATOR
) {
56 sc
.SetState(SCE_BAAN_DEFAULT
);
57 } else if (sc
.state
== SCE_BAAN_NUMBER
) {
58 if (!IsAWordChar(sc
.ch
)) {
59 sc
.SetState(SCE_BAAN_DEFAULT
);
61 } else if (sc
.state
== SCE_BAAN_IDENTIFIER
) {
62 if (!IsAWordChar(sc
.ch
)) {
64 sc
.GetCurrentLowered(s
, sizeof(s
));
65 if (keywords
.InList(s
)) {
66 sc
.ChangeState(SCE_BAAN_WORD
);
67 } else if (keywords2
.InList(s
)) {
68 sc
.ChangeState(SCE_BAAN_WORD2
);
70 sc
.SetState(SCE_BAAN_DEFAULT
);
72 } else if (sc
.state
== SCE_BAAN_PREPROCESSOR
) {
73 if (stylingWithinPreprocessor
) {
74 if (IsASpace(sc
.ch
)) {
75 sc
.SetState(SCE_BAAN_DEFAULT
);
78 if (sc
.atLineEnd
&& (sc
.chNext
!= '^')) {
79 sc
.SetState(SCE_BAAN_DEFAULT
);
82 } else if (sc
.state
== SCE_BAAN_COMMENT
) {
84 sc
.SetState(SCE_BAAN_DEFAULT
);
86 } else if (sc
.state
== SCE_BAAN_COMMENTDOC
) {
87 if (sc
.MatchIgnoreCase("enddllusage")) {
88 for (unsigned int i
= 0; i
< 10; i
++){
91 sc
.ForwardSetState(SCE_BAAN_DEFAULT
);
93 } else if (sc
.state
== SCE_BAAN_STRING
) {
95 sc
.ForwardSetState(SCE_BAAN_DEFAULT
);
96 } else if ((sc
.atLineEnd
) && (sc
.chNext
!= '^')) {
97 sc
.ChangeState(SCE_BAAN_STRINGEOL
);
98 sc
.ForwardSetState(SCE_C_DEFAULT
);
103 if (sc
.state
== SCE_BAAN_DEFAULT
) {
104 if (IsADigit(sc
.ch
) || (sc
.ch
== '.' && IsADigit(sc
.chNext
))) {
105 sc
.SetState(SCE_BAAN_NUMBER
);
106 } else if (sc
.MatchIgnoreCase("dllusage")){
107 sc
.SetState(SCE_BAAN_COMMENTDOC
);
110 } while ((!sc
.atLineEnd
) && sc
.More());
111 } else if (IsAWordStart(sc
.ch
)) {
112 sc
.SetState(SCE_BAAN_IDENTIFIER
);
113 } else if (sc
.Match('|')){
114 sc
.SetState(SCE_BAAN_COMMENT
);
115 } else if (sc
.ch
== '\"') {
116 sc
.SetState(SCE_BAAN_STRING
);
117 } else if (sc
.ch
== '#' && visibleChars
== 0) {
118 // Preprocessor commands are alone on their line
119 sc
.SetState(SCE_BAAN_PREPROCESSOR
);
120 // Skip whitespace between # and preprocessor word
123 } while (IsASpace(sc
.ch
) && sc
.More());
124 } else if (isoperator(static_cast<char>(sc
.ch
))) {
125 sc
.SetState(SCE_BAAN_OPERATOR
);
129 // Reset states to begining of colourise so no surprises
130 // if different sets of lines lexed.
133 if (!IsASpace(sc
.ch
)) {
140 static void FoldBaanDoc(unsigned int startPos
, int length
, int initStyle
, WordList
*[],
142 bool foldComment
= styler
.GetPropertyInt("fold.comment") != 0;
143 bool foldCompact
= styler
.GetPropertyInt("fold.compact", 1) != 0;
144 unsigned int endPos
= startPos
+ length
;
145 int visibleChars
= 0;
146 int lineCurrent
= styler
.GetLine(startPos
);
147 int levelPrev
= styler
.LevelAt(lineCurrent
) & SC_FOLDLEVELNUMBERMASK
;
148 int levelCurrent
= levelPrev
;
149 char chNext
= styler
[startPos
];
150 int styleNext
= styler
.StyleAt(startPos
);
151 int style
= initStyle
;
152 for (unsigned int i
= startPos
; i
< endPos
; i
++) {
154 chNext
= styler
.SafeGetCharAt(i
+ 1);
155 int stylePrev
= style
;
157 styleNext
= styler
.StyleAt(i
+ 1);
158 bool atEOL
= (ch
== '\r' && chNext
!= '\n') || (ch
== '\n');
160 (style
== SCE_BAAN_COMMENT
|| style
== SCE_BAAN_COMMENTDOC
)) {
161 if (style
!= stylePrev
) {
163 } else if ((style
!= styleNext
) && !atEOL
) {
164 // Comments don't end at end of line and the next character may be unstyled.
168 if (style
== SCE_BAAN_OPERATOR
) {
171 } else if (ch
== '}') {
177 if (visibleChars
== 0 && foldCompact
)
178 lev
|= SC_FOLDLEVELWHITEFLAG
;
179 if ((levelCurrent
> levelPrev
) && (visibleChars
> 0))
180 lev
|= SC_FOLDLEVELHEADERFLAG
;
181 if (lev
!= styler
.LevelAt(lineCurrent
)) {
182 styler
.SetLevel(lineCurrent
, lev
);
185 levelPrev
= levelCurrent
;
188 if (!isspacechar(ch
))
191 // Fill in the real level of the next line, keeping the current flags as they will be filled in later
192 int flagsNext
= styler
.LevelAt(lineCurrent
) & ~SC_FOLDLEVELNUMBERMASK
;
193 styler
.SetLevel(lineCurrent
, levelPrev
| flagsNext
);
196 LexerModule
lmBaan(SCLEX_BAAN
, ColouriseBaanDoc
, "baan", FoldBaanDoc
);