]>
git.saurik.com Git - wxWidgets.git/blob - src/stc/scintilla/src/LexNsis.cxx
1 // Scintilla source code edit control
5 // Copyright 2003 by Angelo Mandato <angelo@spaceblue.com>
6 // The License.txt file describes the conditions under which this software may be distributed.
19 #include "Scintilla.h"
26 #define SCE_NSIS_DEFAULT 0
27 #define SCE_NSIS_COMMENT 1
28 #define SCE_NSIS_STRINGDQ 2
29 #define SCE_NSIS_STRINGLQ 3
30 #define SCE_NSIS_STRINGRQ 4
31 #define SCE_NSIS_FUNCTION 5
32 #define SCE_NSIS_VARIABLE 6
33 #define SCE_NSIS_LABEL 7
34 #define SCE_NSIS_USERDEFINED 8
35 #define SCE_NSIS_SECTIONDEF 9
36 #define SCE_NSIS_SUBSECTIONDEF 10
37 #define SCE_NSIS_IFDEFINEDEF 11
38 #define SCE_NSIS_MACRODEF 12
39 #define SCE_NSIS_STRINGVAR 13
42 static int classifyWordNsis(unsigned int start
, unsigned int end
, WordList
*keywordLists
[], Accessor
&styler
)
46 WordList
&Functions
= *keywordLists
[0];
47 WordList
&Variables
= *keywordLists
[1];
48 WordList
&Lables
= *keywordLists
[2];
49 WordList
&UserDefined
= *keywordLists
[3];
51 for (unsigned int i
= 0; i
< end
- start
+ 1 && i
< 30; i
++)
53 s
[i
] = static_cast<char>( styler
[ start
+ i
] );
57 // Check for special words...
59 if( strcmp(s
, "!macro") == 0 || strcmp(s
, "!macroend") == 0 ) // Covers !micro and !microend
60 return SCE_NSIS_MACRODEF
;
62 if( strcmp(s
, "!ifdef") == 0 || strcmp(s
, "!ifndef") == 0 || strcmp(s
, "!endif") == 0 )
63 return SCE_NSIS_IFDEFINEDEF
;
65 if( strcmp(s
, "Section") == 0 || strcmp(s
, "SectionEnd") == 0 ) // Covers Section and SectionEnd
66 return SCE_NSIS_SECTIONDEF
;
68 if( strcmp(s
, "SubSection") == 0 || strcmp(s
, "SubSectionEnd") == 0 ) // Covers SubSection and SubSectionEnd
69 return SCE_NSIS_SUBSECTIONDEF
;
71 if( strcmp(s
, "Function") == 0 || strcmp(s
, "FunctionEnd") == 0 ) // Covers SubSection and SubSectionEnd
72 return SCE_NSIS_FUNCTION
;
74 if ( Functions
.InList(s
) )
75 return SCE_NSIS_FUNCTION
;
77 if ( Variables
.InList(s
) )
78 return SCE_NSIS_VARIABLE
;
80 if ( Lables
.InList(s
) )
81 return SCE_NSIS_LABEL
;
83 if( UserDefined
.InList(s
) )
84 return SCE_NSIS_USERDEFINED
;
88 if( s
[1] == '{' && s
[strlen(s
)-1] == '}' )
89 return SCE_NSIS_VARIABLE
;
92 return SCE_NSIS_DEFAULT
;
95 static void ColouriseNsisDoc(unsigned int startPos
, int length
, int, WordList
*keywordLists
[], Accessor
&styler
)
97 int state
= SCE_NSIS_DEFAULT
;
98 styler
.StartAt( startPos
);
99 styler
.GetLine( startPos
);
101 unsigned int nLengthDoc
= startPos
+ length
;
102 styler
.StartSegment( startPos
);
105 bool bVarInString
= true;
108 for( i
= startPos
; i
< nLengthDoc
; i
++ )
110 cCurrChar
= styler
.SafeGetCharAt( i
);
111 char cNextChar
= styler
.SafeGetCharAt( i
+1, EOF
);
117 case SCE_NSIS_DEFAULT
:
118 if( cNextChar
== EOF
)
120 styler
.ColourTo(i
,SCE_NSIS_DEFAULT
);
123 if( cCurrChar
== ';' || cCurrChar
== '#' ) // we have a comment line
125 styler
.ColourTo(i
-1, state
);
126 state
= SCE_NSIS_COMMENT
;
129 if( cCurrChar
== '"' )
131 styler
.ColourTo(i
-1, state
);
132 state
= SCE_NSIS_STRINGDQ
;
133 bVarInString
= false;
136 if( cCurrChar
== '\'' )
138 styler
.ColourTo(i
-1, state
);
139 state
= SCE_NSIS_STRINGRQ
;
140 bVarInString
= false;
143 if( cCurrChar
== '`' )
145 styler
.ColourTo(i
-1, state
);
146 state
= SCE_NSIS_STRINGLQ
;
147 bVarInString
= false;
151 // NSIS KeyWord,Function, Variable, UserDefined:
152 if( cCurrChar
== '$' || iswordchar(cCurrChar
) || cCurrChar
== '!' )
154 styler
.ColourTo(i
-1,state
);
155 state
= SCE_NSIS_FUNCTION
;
159 case SCE_NSIS_COMMENT
:
160 if( cNextChar
== '\n' || cNextChar
== '\r' || cNextChar
== EOF
)
162 styler
.ColourTo(i
,state
);
163 state
= SCE_NSIS_DEFAULT
;
166 case SCE_NSIS_STRINGDQ
:
167 if( cCurrChar
== '"' || cNextChar
== '\r' || cNextChar
== '\n' )
169 styler
.ColourTo(i
,SCE_NSIS_STRINGDQ
);
170 state
= SCE_NSIS_DEFAULT
;
173 case SCE_NSIS_STRINGLQ
:
174 if( cCurrChar
== '`' || cNextChar
== '\r' || cNextChar
== '\n' )
176 styler
.ColourTo(i
,SCE_NSIS_STRINGLQ
);
177 state
= SCE_NSIS_DEFAULT
;
180 case SCE_NSIS_STRINGRQ
:
181 if( cCurrChar
== '\'' || cNextChar
== '\r' || cNextChar
== '\n' )
183 styler
.ColourTo(i
,SCE_NSIS_STRINGRQ
);
184 state
= SCE_NSIS_DEFAULT
;
187 case SCE_NSIS_FUNCTION
:
190 if( (iswordchar(cCurrChar
) && !iswordchar( cNextChar
) && cNextChar
!= '}') || cCurrChar
== '}' )
192 state
= classifyWordNsis( styler
.GetStartSegment(), i
, keywordLists
, styler
);
193 styler
.ColourTo( i
, state
);
194 state
= SCE_NSIS_DEFAULT
; // Everything after goes back to the default state
196 else if( !iswordchar( cCurrChar
) && cCurrChar
!= '{' && cCurrChar
!= '}' )
198 state
= SCE_NSIS_DEFAULT
;
200 if( cCurrChar
== '"' ) // Next
202 state
= SCE_NSIS_STRINGDQ
;
203 bVarInString
= false;
205 if( cCurrChar
== '`' )
207 state
= SCE_NSIS_STRINGLQ
;
208 bVarInString
= false;
210 if( cCurrChar
== '\'' )
212 state
= SCE_NSIS_STRINGRQ
;
213 bVarInString
= false;
215 if( cCurrChar
== '#' || cCurrChar
== ';' )
216 state
= SCE_NSIS_COMMENT
;
218 styler
.ColourTo( i
, state
);
223 if( state
== SCE_NSIS_COMMENT
)
225 styler
.ColourTo(i
,state
);
227 else if( state
== SCE_NSIS_STRINGDQ
|| state
== SCE_NSIS_STRINGLQ
|| state
== SCE_NSIS_STRINGRQ
)
229 // Check for var in String..
230 if( bVarInString
&& (iswordchar(cCurrChar
) || cCurrChar
== '}') ) // || cCurrChar == '{' ) )
232 int nWordState
= classifyWordNsis( styler
.GetStartSegment(), i
, keywordLists
, styler
);
233 if( nWordState
== SCE_NSIS_VARIABLE
)
235 styler
.ColourTo( i
, SCE_NSIS_STRINGVAR
);
236 bVarInString
= false;
239 if( cCurrChar
== '$' )
241 styler
.ColourTo( i
-1, state
);
249 static void FoldNsisDoc(unsigned int startPos
, int length
, int, WordList
*[], Accessor
&styler
)
251 // No folding enabled, no reason to continue...
252 if( styler
.GetPropertyInt("fold") == 0 )
255 unsigned int endPos
= startPos
+ length
;
256 int lineCurrent
= styler
.GetLine(startPos
);
257 int levelCurrent
= SC_FOLDLEVELBASE
;
259 levelCurrent
= styler
.LevelAt(lineCurrent
-1) >> 16;
260 int levelNext
= levelCurrent
;
261 char chNext
= styler
[startPos
];
262 int styleNext
= styler
.StyleAt(startPos
);
265 for (unsigned int i
= startPos
; i
< endPos
; i
++)
268 chNext
= styler
.SafeGetCharAt(i
+ 1);
270 styleNext
= styler
.StyleAt(i
+ 1);
271 bool atEOL
= (ch
== '\r' && chNext
!= '\n') || (ch
== '\n');
272 // Functions Start: Function, Section, SubSection
273 // Functions End: FunctionEnd, SectionEnd, SubSectionEnd
274 // Label Start: !ifdef, !ifndef
277 if( style
== SCE_NSIS_FUNCTION
)
279 if( styler
.Match(i
, "FunctionEnd") )
281 else if( styler
.Match(i
, "Function") )
284 else if( style
== SCE_NSIS_SECTIONDEF
)
286 if( styler
.Match(i
, "SectionEnd") )
288 else if( styler
.Match(i
, "Section") )
291 else if( style
== SCE_NSIS_SUBSECTIONDEF
)
293 if( styler
.Match(i
, "SubSectionEnd") )
295 else if( styler
.Match(i
, "SubSection") )
298 else if( style
== SCE_NSIS_IFDEFINEDEF
)
300 if( styler
.Match(i
, "!endif") )
302 else if( styler
.Match(i
, "!ifdef") || styler
.Match(i
, "!ifndef"))
305 else if( style
== SCE_NSIS_MACRODEF
)
307 if( styler
.Match(i
, "!macroend") )
309 else if( styler
.Match(i
, "!macro") )
315 int levelUse
= levelCurrent
;
316 int lev
= levelUse
| levelNext
<< 16;
317 if (levelUse
< levelNext
)
318 lev
|= SC_FOLDLEVELHEADERFLAG
;
319 if (lev
!= styler
.LevelAt(lineCurrent
))
321 styler
.SetLevel(lineCurrent
, lev
);
324 levelCurrent
= levelNext
;
328 int levelUse
= levelCurrent
;
329 int lev
= levelUse
| levelNext
<< 16;
330 if (levelUse
< levelNext
)
331 lev
|= SC_FOLDLEVELHEADERFLAG
;
332 if (lev
!= styler
.LevelAt(lineCurrent
))
334 styler
.SetLevel(lineCurrent
, lev
);
338 static const char * const nsisWordLists
[] = {
346 LexerModule
lmNsis(SCLEX_NSIS
, ColouriseNsisDoc
, "nsis", FoldNsisDoc
, nsisWordLists
);