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"
25 using namespace Scintilla
;
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
[],
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
;
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
)) {
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
);
75 if (sc
.atLineEnd
&& (sc
.chNext
!= '^')) {
76 sc
.SetState(SCE_BAAN_DEFAULT
);
79 } else if (sc
.state
== SCE_BAAN_COMMENT
) {
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
++){
88 sc
.ForwardSetState(SCE_BAAN_DEFAULT
);
90 } else if (sc
.state
== SCE_BAAN_STRING
) {
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
);
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
);
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
120 } while (IsASpace(sc
.ch
) && sc
.More());
121 } else if (isoperator(static_cast<char>(sc
.ch
))) {
122 sc
.SetState(SCE_BAAN_OPERATOR
);
126 // Reset states to begining of colourise so no surprises
127 // if different sets of lines lexed.
130 if (!IsASpace(sc
.ch
)) {
137 static void FoldBaanDoc(unsigned int startPos
, int length
, int initStyle
, WordList
*[],
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
++) {
151 chNext
= styler
.SafeGetCharAt(i
+ 1);
152 int stylePrev
= style
;
154 styleNext
= styler
.StyleAt(i
+ 1);
155 bool atEOL
= (ch
== '\r' && chNext
!= '\n') || (ch
== '\n');
157 (style
== SCE_BAAN_COMMENT
|| style
== SCE_BAAN_COMMENTDOC
)) {
158 if (style
!= stylePrev
) {
160 } else if ((style
!= styleNext
) && !atEOL
) {
161 // Comments don't end at end of line and the next character may be unstyled.
165 if (style
== SCE_BAAN_OPERATOR
) {
168 } else if (ch
== '}') {
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
);
182 levelPrev
= levelCurrent
;
185 if (!isspacechar(ch
))
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
);