]>
git.saurik.com Git - wxWidgets.git/blob - src/stc/scintilla/src/LexInno.cxx
ff99da7e4ecf50e3b3daf9dec3618fc47e3fbaed
1 // Scintilla source code edit control
3 ** Lexer for Inno Setup scripts.
5 // Written by Friedrich Vedder <fvedd@t-online.de>, using code from LexOthers.cxx.
6 // The License.txt file describes the conditions under which this software may be distributed.
18 #include "StyleContext.h"
20 #include "Scintilla.h"
23 static void ColouriseInnoDoc(unsigned int startPos
, int length
, int, WordList
*keywordLists
[], Accessor
&styler
) {
24 int state
= SCE_INNO_DEFAULT
;
27 char chNext
= styler
[startPos
];
28 int lengthDoc
= startPos
+ length
;
29 char *buffer
= new char[length
];
31 bool isBOL
, isEOL
, isWS
, isBOLWS
= 0;
33 WordList
§ionKeywords
= *keywordLists
[0];
34 WordList
&standardKeywords
= *keywordLists
[1];
35 WordList
¶meterKeywords
= *keywordLists
[2];
36 WordList
&preprocessorKeywords
= *keywordLists
[3];
37 WordList
&pascalKeywords
= *keywordLists
[4];
38 WordList
&userKeywords
= *keywordLists
[5];
40 // Go through all provided text segment
41 // using the hand-written state machine shown below
42 styler
.StartAt(startPos
);
43 styler
.StartSegment(startPos
);
44 for (int i
= startPos
; i
< lengthDoc
; i
++) {
47 chNext
= styler
.SafeGetCharAt(i
+ 1);
49 if (styler
.IsLeadByte(ch
)) {
50 chNext
= styler
.SafeGetCharAt(i
+ 2);
55 isBOL
= (chPrev
== 0) || (chPrev
== '\n') || (chPrev
== '\r' && ch
!= '\n');
56 isBOLWS
= (isBOL
) ? 1 : (isBOLWS
&& (chPrev
== ' ' || chPrev
== '\t'));
57 isEOL
= (ch
== '\n' || ch
== '\r');
58 isWS
= (ch
== ' ' || ch
== '\t');
61 case SCE_INNO_DEFAULT
:
62 if (ch
== ';' && isBOLWS
) {
64 state
= SCE_INNO_COMMENT
;
65 } else if (ch
== '[' && isBOLWS
) {
66 // Start of a section name
68 state
= SCE_INNO_SECTION
;
69 } else if (ch
== '#' && isBOLWS
) {
70 // Start of a preprocessor directive
71 state
= SCE_INNO_PREPROC
;
72 } else if (ch
== '{' && chNext
== '#') {
73 // Start of a preprocessor inline directive
74 state
= SCE_INNO_PREPROC_INLINE
;
75 } else if ((ch
== '{' && (chNext
== ' ' || chNext
== '\t'))
76 || (ch
== '(' && chNext
== '*')) {
77 // Start of a Pascal comment
78 state
= SCE_INNO_COMMENT_PASCAL
;
79 } else if (ch
== '"') {
80 // Start of a double-quote string
81 state
= SCE_INNO_STRING_DOUBLE
;
82 } else if (ch
== '\'') {
83 // Start of a single-quote string
84 state
= SCE_INNO_STRING_SINGLE
;
85 } else if (isascii(ch
) && (isalpha(ch
) || (ch
== '_'))) {
86 // Start of an identifier
88 buffer
[bufferCount
++] = static_cast<char>(tolower(ch
));
89 state
= SCE_INNO_IDENTIFIER
;
91 // Style it the default style
92 styler
.ColourTo(i
,SCE_INNO_DEFAULT
);
96 case SCE_INNO_COMMENT
:
98 state
= SCE_INNO_DEFAULT
;
99 styler
.ColourTo(i
,SCE_INNO_COMMENT
);
103 case SCE_INNO_IDENTIFIER
:
104 if (isascii(ch
) && (isalnum(ch
) || (ch
== '_'))) {
105 buffer
[bufferCount
++] = static_cast<char>(tolower(ch
));
107 state
= SCE_INNO_DEFAULT
;
108 buffer
[bufferCount
] = '\0';
110 // Check if the buffer contains a keyword
111 if (standardKeywords
.InList(buffer
)) {
112 styler
.ColourTo(i
-1,SCE_INNO_KEYWORD
);
113 } else if (parameterKeywords
.InList(buffer
)) {
114 styler
.ColourTo(i
-1,SCE_INNO_PARAMETER
);
115 } else if (pascalKeywords
.InList(buffer
)) {
116 styler
.ColourTo(i
-1,SCE_INNO_KEYWORD_PASCAL
);
117 } else if (userKeywords
.InList(buffer
)) {
118 styler
.ColourTo(i
-1,SCE_INNO_KEYWORD_USER
);
120 styler
.ColourTo(i
-1,SCE_INNO_DEFAULT
);
123 // Push back the faulty character
124 chNext
= styler
[i
--];
129 case SCE_INNO_SECTION
:
131 state
= SCE_INNO_DEFAULT
;
132 buffer
[bufferCount
] = '\0';
134 // Check if the buffer contains a section name
135 if (sectionKeywords
.InList(buffer
)) {
136 styler
.ColourTo(i
,SCE_INNO_SECTION
);
138 styler
.ColourTo(i
,SCE_INNO_DEFAULT
);
140 } else if (isascii(ch
) && (isalnum(ch
) || (ch
== '_'))) {
141 buffer
[bufferCount
++] = static_cast<char>(tolower(ch
));
143 state
= SCE_INNO_DEFAULT
;
144 styler
.ColourTo(i
,SCE_INNO_DEFAULT
);
148 case SCE_INNO_PREPROC
:
150 if (isascii(chPrev
) && isalpha(chPrev
)) {
151 state
= SCE_INNO_DEFAULT
;
152 buffer
[bufferCount
] = '\0';
154 // Check if the buffer contains a preprocessor directive
155 if (preprocessorKeywords
.InList(buffer
)) {
156 styler
.ColourTo(i
-1,SCE_INNO_PREPROC
);
158 styler
.ColourTo(i
-1,SCE_INNO_DEFAULT
);
161 // Push back the faulty character
162 chNext
= styler
[i
--];
165 } else if (isascii(ch
) && isalpha(ch
)) {
166 if (chPrev
== '#' || chPrev
== ' ' || chPrev
== '\t')
168 buffer
[bufferCount
++] = static_cast<char>(tolower(ch
));
172 case SCE_INNO_STRING_DOUBLE
:
173 if (ch
== '"' || isEOL
) {
174 state
= SCE_INNO_DEFAULT
;
175 styler
.ColourTo(i
,SCE_INNO_DEFAULT
);
179 case SCE_INNO_STRING_SINGLE
:
180 if (ch
== '\'' || isEOL
) {
181 state
= SCE_INNO_DEFAULT
;
182 styler
.ColourTo(i
,SCE_INNO_DEFAULT
);
186 case SCE_INNO_PREPROC_INLINE
:
188 state
= SCE_INNO_DEFAULT
;
189 styler
.ColourTo(i
,SCE_INNO_PREPROC_INLINE
);
191 state
= SCE_INNO_DEFAULT
;
192 styler
.ColourTo(i
,SCE_INNO_DEFAULT
);
196 case SCE_INNO_COMMENT_PASCAL
:
197 if (ch
== '}' || (ch
== ')' && chPrev
== '*')) {
198 state
= SCE_INNO_DEFAULT
;
199 styler
.ColourTo(i
,SCE_INNO_COMMENT_PASCAL
);
201 state
= SCE_INNO_DEFAULT
;
202 styler
.ColourTo(i
,SCE_INNO_DEFAULT
);
211 static const char * const innoWordListDesc
[] = {
215 "Preprocessor directives",
217 "User defined keywords",
221 static void FoldInnoDoc(unsigned int startPos
, int length
, int, WordList
*[], Accessor
&styler
) {
222 bool foldCompact
= styler
.GetPropertyInt("fold.compact", 1) != 0;
224 unsigned int endPos
= startPos
+ length
;
225 int visibleChars
= 0;
226 int lineCurrent
= styler
.GetLine(startPos
);
228 char chNext
= styler
[startPos
];
229 int styleNext
= styler
.StyleAt(startPos
);
230 bool headerPoint
= false;
233 for (unsigned int i
= startPos
; i
< endPos
; i
++) {
235 chNext
= styler
[i
+1];
237 int style
= styleNext
;
238 styleNext
= styler
.StyleAt(i
+ 1);
239 bool atEOL
= (ch
== '\r' && chNext
!= '\n') || (ch
== '\n');
241 if (style
== SCE_INNO_SECTION
)
245 lev
= SC_FOLDLEVELBASE
;
247 if (lineCurrent
> 0) {
248 int levelPrevious
= styler
.LevelAt(lineCurrent
- 1);
250 if (levelPrevious
& SC_FOLDLEVELHEADERFLAG
)
251 lev
= SC_FOLDLEVELBASE
+ 1;
253 lev
= levelPrevious
& SC_FOLDLEVELNUMBERMASK
;
257 lev
= SC_FOLDLEVELBASE
;
259 if (visibleChars
== 0 && foldCompact
)
260 lev
|= SC_FOLDLEVELWHITEFLAG
;
263 lev
|= SC_FOLDLEVELHEADERFLAG
;
265 if (lev
!= styler
.LevelAt(lineCurrent
))
266 styler
.SetLevel(lineCurrent
, lev
);
272 if (!isspacechar(ch
))
276 if (lineCurrent
> 0) {
277 int levelPrevious
= styler
.LevelAt(lineCurrent
- 1);
279 if (levelPrevious
& SC_FOLDLEVELHEADERFLAG
)
280 lev
= SC_FOLDLEVELBASE
+ 1;
282 lev
= levelPrevious
& SC_FOLDLEVELNUMBERMASK
;
284 lev
= SC_FOLDLEVELBASE
;
286 int flagsNext
= styler
.LevelAt(lineCurrent
);
287 styler
.SetLevel(lineCurrent
, lev
| flagsNext
& ~SC_FOLDLEVELNUMBERMASK
);
290 LexerModule
lmInno(SCLEX_INNOSETUP
, ColouriseInnoDoc
, "inno", FoldInnoDoc
, innoWordListDesc
);