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.
19 #include "StyleContext.h"
21 #include "Scintilla.h"
24 static inline bool IsAWordChar(const int ch
) {
25 return (ch
< 0x80) && (isalnum(ch
) || ch
== '.' || ch
== '_' || ch
== '$' || ch
== ':');
28 static inline bool IsAWordStart(const int ch
) {
29 return (ch
< 0x80) && (isalnum(ch
) || ch
== '_');
32 static void ColouriseBaanDoc(unsigned int startPos
, int length
, int initStyle
, WordList
*keywordlists
[],
35 WordList
&keywords
= *keywordlists
[0];
36 WordList
&keywords2
= *keywordlists
[1];
37 bool stylingWithinPreprocessor
= styler
.GetPropertyInt("styling.within.preprocessor") != 0;
39 if (initStyle
== SCE_BAAN_STRINGEOL
) // Does not leak onto next line
40 initStyle
= SCE_BAAN_DEFAULT
;
44 StyleContext
sc(startPos
, length
, initStyle
, styler
);
46 for (; sc
.More(); sc
.Forward()) {
48 if (sc
.state
== SCE_BAAN_OPERATOR
) {
49 sc
.SetState(SCE_BAAN_DEFAULT
);
50 } else if (sc
.state
== SCE_BAAN_NUMBER
) {
51 if (!IsAWordChar(sc
.ch
)) {
52 sc
.SetState(SCE_BAAN_DEFAULT
);
54 } else if (sc
.state
== SCE_BAAN_IDENTIFIER
) {
55 if (!IsAWordChar(sc
.ch
)) {
57 sc
.GetCurrentLowered(s
, sizeof(s
));
58 if (keywords
.InList(s
)) {
59 sc
.ChangeState(SCE_BAAN_WORD
);
60 } else if (keywords2
.InList(s
)) {
61 sc
.ChangeState(SCE_BAAN_WORD2
);
63 sc
.SetState(SCE_BAAN_DEFAULT
);
65 } else if (sc
.state
== SCE_BAAN_PREPROCESSOR
) {
66 if (stylingWithinPreprocessor
) {
67 if (IsASpace(sc
.ch
)) {
68 sc
.SetState(SCE_BAAN_DEFAULT
);
71 if (sc
.atLineEnd
&& (sc
.chNext
!= '^')) {
72 sc
.SetState(SCE_BAAN_DEFAULT
);
75 } else if (sc
.state
== SCE_BAAN_COMMENT
) {
77 sc
.SetState(SCE_BAAN_DEFAULT
);
79 } else if (sc
.state
== SCE_BAAN_COMMENTDOC
) {
80 if (sc
.MatchIgnoreCase("enddllusage")) {
81 for (unsigned int i
= 0; i
< 10; i
++){
84 sc
.ForwardSetState(SCE_BAAN_DEFAULT
);
86 } else if (sc
.state
== SCE_BAAN_STRING
) {
88 sc
.ForwardSetState(SCE_BAAN_DEFAULT
);
89 } else if ((sc
.atLineEnd
) && (sc
.chNext
!= '^')) {
90 sc
.ChangeState(SCE_BAAN_STRINGEOL
);
91 sc
.ForwardSetState(SCE_C_DEFAULT
);
96 if (sc
.state
== SCE_BAAN_DEFAULT
) {
97 if (IsADigit(sc
.ch
) || (sc
.ch
== '.' && IsADigit(sc
.chNext
))) {
98 sc
.SetState(SCE_BAAN_NUMBER
);
99 } else if (sc
.MatchIgnoreCase("dllusage")){
100 sc
.SetState(SCE_BAAN_COMMENTDOC
);
103 } while ((!sc
.atLineEnd
) && sc
.More());
104 } else if (IsAWordStart(sc
.ch
)) {
105 sc
.SetState(SCE_BAAN_IDENTIFIER
);
106 } else if (sc
.Match('|')){
107 sc
.SetState(SCE_BAAN_COMMENT
);
108 } else if (sc
.ch
== '\"') {
109 sc
.SetState(SCE_BAAN_STRING
);
110 } else if (sc
.ch
== '#' && visibleChars
== 0) {
111 // Preprocessor commands are alone on their line
112 sc
.SetState(SCE_BAAN_PREPROCESSOR
);
113 // Skip whitespace between # and preprocessor word
116 } while (IsASpace(sc
.ch
) && sc
.More());
117 } else if (isoperator(static_cast<char>(sc
.ch
))) {
118 sc
.SetState(SCE_BAAN_OPERATOR
);
122 // Reset states to begining of colourise so no surprises
123 // if different sets of lines lexed.
126 if (!IsASpace(sc
.ch
)) {
133 static void FoldBaanDoc(unsigned int startPos
, int length
, int initStyle
, WordList
*[],
135 bool foldComment
= styler
.GetPropertyInt("fold.comment") != 0;
136 bool foldCompact
= styler
.GetPropertyInt("fold.compact", 1) != 0;
137 unsigned int endPos
= startPos
+ length
;
138 int visibleChars
= 0;
139 int lineCurrent
= styler
.GetLine(startPos
);
140 int levelPrev
= styler
.LevelAt(lineCurrent
) & SC_FOLDLEVELNUMBERMASK
;
141 int levelCurrent
= levelPrev
;
142 char chNext
= styler
[startPos
];
143 int styleNext
= styler
.StyleAt(startPos
);
144 int style
= initStyle
;
145 for (unsigned int i
= startPos
; i
< endPos
; i
++) {
147 chNext
= styler
.SafeGetCharAt(i
+ 1);
148 int stylePrev
= style
;
150 styleNext
= styler
.StyleAt(i
+ 1);
151 bool atEOL
= (ch
== '\r' && chNext
!= '\n') || (ch
== '\n');
153 (style
== SCE_BAAN_COMMENT
|| style
== SCE_BAAN_COMMENTDOC
)) {
154 if (style
!= stylePrev
) {
156 } else if ((style
!= styleNext
) && !atEOL
) {
157 // Comments don't end at end of line and the next character may be unstyled.
161 if (style
== SCE_BAAN_OPERATOR
) {
164 } else if (ch
== '}') {
170 if (visibleChars
== 0 && foldCompact
)
171 lev
|= SC_FOLDLEVELWHITEFLAG
;
172 if ((levelCurrent
> levelPrev
) && (visibleChars
> 0))
173 lev
|= SC_FOLDLEVELHEADERFLAG
;
174 if (lev
!= styler
.LevelAt(lineCurrent
)) {
175 styler
.SetLevel(lineCurrent
, lev
);
178 levelPrev
= levelCurrent
;
181 if (!isspacechar(ch
))
184 // Fill in the real level of the next line, keeping the current flags as they will be filled in later
185 int flagsNext
= styler
.LevelAt(lineCurrent
) & ~SC_FOLDLEVELNUMBERMASK
;
186 styler
.SetLevel(lineCurrent
, levelPrev
| flagsNext
);
189 LexerModule
lmBaan(SCLEX_BAAN
, ColouriseBaanDoc
, "baan", FoldBaanDoc
);