]>
git.saurik.com Git - wxWidgets.git/blob - src/stc/scintilla/src/LexScriptol.cxx
fda10e316c61bea044cf1c55e4a9499290f557e2
1 // Scintilla source code edit control
2 /** @file LexScriptol.cxx
17 #include "Scintilla.h"
20 static void ClassifyWordSol(unsigned int start
, unsigned int end
, WordList
&keywords
, Accessor
&styler
, char *prevWord
)
23 bool wordIsNumber
= isdigit(styler
[start
]) != 0;
24 for (unsigned int i
= 0; i
< end
- start
+ 1 && i
< 30; i
++)
26 s
[i
] = styler
[start
+ i
];
29 char chAttr
= SCE_P_IDENTIFIER
;
30 if (0 == strcmp(prevWord
, "class")) chAttr
= SCE_P_CLASSNAME
;
31 else if (wordIsNumber
) chAttr
= SCE_P_NUMBER
;
32 else if (keywords
.InList(s
)) chAttr
= SCE_P_WORD
;
33 else for (unsigned int i
= 0; i
< end
- start
+ 1; i
++) // test dotted idents
35 if (styler
[start
+ i
] == '.')
37 styler
.ColourTo(start
+ i
- 1, chAttr
);
38 styler
.ColourTo(start
+ i
, SCE_P_OPERATOR
);
41 styler
.ColourTo(end
, chAttr
);
45 static bool IsSolComment(Accessor
&styler
, int pos
, int len
)
47 // return len > 0 && styler[pos]=='`';
52 if(c
== '`') return true;
58 if(c
== '/') return true;
59 if(c
== '*') return true;
66 static bool IsSolStringStart(char ch
, char /*chNext*/)
68 if (ch
== '\'' || ch
== '"') return true;
69 //chNext = chNext; // for future use
74 static bool IsSolWordStart(char ch
, char chNext
)
76 return (iswordchar(ch
) && !IsSolStringStart(ch
, chNext
));
79 /* Return the state to use for the string starting at i; *nextIndex will be set to the first index following the quote(s) */
80 static int GetSolStringState(Accessor
&styler
, int i
, int *nextIndex
)
82 char ch
= styler
.SafeGetCharAt(i
);
83 char chNext
= styler
.SafeGetCharAt(i
+ 1);
85 if (ch
!= '"' && ch
!= '\'') {
90 if (ch
== chNext
&& ch
== styler
.SafeGetCharAt(i
+ 2))
93 if (ch
== '"') return SCE_P_TRIPLEDOUBLE
;
94 else return SCE_P_TRIPLE
;
99 if (ch
== '"') return SCE_P_STRING
;
100 else return SCE_P_CHARACTER
;
104 static void ColouriseSolDoc(unsigned int startPos
, int length
, int initStyle
,
105 WordList
*keywordlists
[], Accessor
&styler
)
108 int lengthDoc
= startPos
+ length
;
110 // Backtrack to previous line in case need to fix its tab whinging
113 int lineCurrent
= styler
.GetLine(startPos
);
116 startPos
= styler
.LineStart(lineCurrent
-1);
117 if (startPos
== 0) initStyle
= SCE_P_DEFAULT
;
118 else initStyle
= styler
.StyleAt(startPos
-1);
122 styler
.StartAt(startPos
, 127);
124 WordList
&keywords
= *keywordlists
[0];
126 int whingeLevel
= styler
.GetPropertyInt("tab.timmy.whinge.level");
129 if (length
== 0) return ;
131 int state
= initStyle
& 31;
135 //char chPrev2 = ' ';
136 char chNext
= styler
[startPos
];
137 styler
.StartSegment(startPos
);
138 bool atStartLine
= true;
140 for (int i
= startPos
; i
< lengthDoc
; i
++)
145 char chBad
= static_cast<char>(64);
146 char chGood
= static_cast<char>(0);
147 char chFlags
= chGood
;
149 if (whingeLevel
== 1)
151 chFlags
= (spaceFlags
& wsInconsistent
) ? chBad
: chGood
;
153 else if (whingeLevel
== 2)
155 chFlags
= (spaceFlags
& wsSpaceTab
) ? chBad
: chGood
;
157 else if (whingeLevel
== 3)
159 chFlags
= (spaceFlags
& wsSpace
) ? chBad
: chGood
;
161 else if (whingeLevel
== 4)
163 chFlags
= (spaceFlags
& wsTab
) ? chBad
: chGood
;
165 styler
.SetFlags(chFlags
, static_cast<char>(state
));
170 chNext
= styler
.SafeGetCharAt(i
+ 1);
172 if ((ch
== '\r' && chNext
!= '\n') || (ch
== '\n') || (i
== lengthDoc
))
174 if ((state
== SCE_P_DEFAULT
) || (state
== SCE_P_TRIPLE
) || (state
== SCE_P_TRIPLEDOUBLE
))
176 styler
.ColourTo(i
, state
);
181 if (styler
.IsLeadByte(ch
))
183 chNext
= styler
.SafeGetCharAt(i
+ 2);
190 if (state
== SCE_P_STRINGEOL
)
192 if (ch
!= '\r' && ch
!= '\n')
194 styler
.ColourTo(i
- 1, state
);
195 state
= SCE_P_DEFAULT
;
199 if (state
== SCE_P_DEFAULT
)
201 if (IsSolWordStart(ch
, chNext
))
203 styler
.ColourTo(i
- 1, state
);
208 styler
.ColourTo(i
- 1, state
);
209 state
= SCE_P_COMMENTLINE
;
213 styler
.ColourTo(i
- 1, state
);
214 if(chNext
== '/') state
= SCE_P_COMMENTLINE
;
215 if(chNext
== '*') state
= SCE_P_COMMENTBLOCK
;
218 else if (ch
== '=' && chNext
== 'b')
220 // =begin indicates the start of a comment (doc) block
221 if(styler
.SafeGetCharAt(i
+ 2) == 'e' && styler
.SafeGetCharAt(i
+ 3) == 'g' && styler
.SafeGetCharAt(i
+ 4) == 'i' && styler
.SafeGetCharAt(i
+ 5) == 'n')
223 styler
.ColourTo(i
- 1, state
);
224 state
= SCE_P_TRIPLEDOUBLE
; //SCE_C_COMMENT;
227 else if (IsSolStringStart(ch
, chNext
))
229 styler
.ColourTo(i
- 1, state
);
230 state
= GetSolStringState(styler
, i
, &nextIndex
);
231 if (nextIndex
!= i
+ 1)
236 chNext
= styler
.SafeGetCharAt(i
+ 1);
239 else if (isoperator(ch
))
241 styler
.ColourTo(i
- 1, state
);
242 styler
.ColourTo(i
, SCE_P_OPERATOR
);
245 else if (state
== SCE_P_WORD
)
249 ClassifyWordSol(styler
.GetStartSegment(), i
- 1, keywords
, styler
, prevWord
);
250 state
= SCE_P_DEFAULT
;
253 state
= chNext
== '`' ? SCE_P_COMMENTBLOCK
: SCE_P_COMMENTLINE
;
255 else if (IsSolStringStart(ch
, chNext
))
257 styler
.ColourTo(i
- 1, state
);
258 state
= GetSolStringState(styler
, i
, &nextIndex
);
259 if (nextIndex
!= i
+ 1)
264 chNext
= styler
.SafeGetCharAt(i
+ 1);
267 else if (isoperator(ch
))
269 styler
.ColourTo(i
, SCE_P_OPERATOR
);
275 if (state
== SCE_P_COMMENTLINE
)
277 if (ch
== '\r' || ch
== '\n')
279 styler
.ColourTo(i
- 1, state
);
280 state
= SCE_P_DEFAULT
;
283 else if(state
== SCE_P_COMMENTBLOCK
)
285 if(ch
== '*' && chNext
== '/') state
= SCE_P_DEFAULT
;
287 else if (state
== SCE_P_STRING
)
289 if ((ch
== '\r' || ch
== '\n') && (chPrev
!= '\\'))
291 styler
.ColourTo(i
- 1, state
);
292 state
= SCE_P_STRINGEOL
;
296 if (chNext
== '\"' || chNext
== '\'' || chNext
== '\\')
300 chNext
= styler
.SafeGetCharAt(i
+ 1);
305 styler
.ColourTo(i
, state
);
306 state
= SCE_P_DEFAULT
;
309 else if (state
== SCE_P_CHARACTER
)
311 if ((ch
== '\r' || ch
== '\n') && (chPrev
!= '\\'))
313 styler
.ColourTo(i
- 1, state
);
314 state
= SCE_P_STRINGEOL
;
318 if (chNext
== '\"' || chNext
== '\'' || chNext
== '\\')
322 chNext
= styler
.SafeGetCharAt(i
+ 1);
327 styler
.ColourTo(i
, state
);
328 state
= SCE_P_DEFAULT
;
332 else if (state == SCE_P_TRIPLE)
334 if (ch == '\'' && chPrev == '\'' && chPrev2 == '\'')
336 styler.ColourTo(i, state);
337 state = SCE_P_DEFAULT;
340 else if (state == SCE_P_TRIPLEDOUBLE)
342 // =end terminates the comment block
343 if (ch == 'd' && chPrev == 'n' && chPrev2 == 'e')
345 if (styler.SafeGetCharAt(i - 3) == '=')
347 styler.ColourTo(i, state);
348 state = SCE_P_DEFAULT;
357 if (state
== SCE_P_WORD
)
359 ClassifyWordSol(styler
.GetStartSegment(), lengthDoc
-1, keywords
, styler
, prevWord
);
363 styler
.ColourTo(lengthDoc
-1, state
);
367 static void FoldSolDoc(unsigned int startPos
, int length
, int initStyle
,
368 WordList
*[], Accessor
&styler
)
370 int lengthDoc
= startPos
+ length
;
372 // Backtrack to previous line in case need to fix its fold status
373 int lineCurrent
= styler
.GetLine(startPos
);
378 startPos
= styler
.LineStart(lineCurrent
);
380 initStyle
= SCE_P_DEFAULT
;
382 initStyle
= styler
.StyleAt(startPos
-1);
385 int state
= initStyle
& 31;
387 int indentCurrent
= styler
.IndentAmount(lineCurrent
, &spaceFlags
, IsSolComment
);
388 if ((state
== SCE_P_TRIPLE
) || (state
== SCE_P_TRIPLEDOUBLE
))
389 indentCurrent
|= SC_FOLDLEVELWHITEFLAG
;
390 char chNext
= styler
[startPos
];
391 for (int i
= startPos
; i
< lengthDoc
; i
++)
394 chNext
= styler
.SafeGetCharAt(i
+ 1);
395 int style
= styler
.StyleAt(i
) & 31;
397 if ((ch
== '\r' && chNext
!= '\n') || (ch
== '\n') || (i
== lengthDoc
))
399 int lev
= indentCurrent
;
400 int indentNext
= styler
.IndentAmount(lineCurrent
+ 1, &spaceFlags
, IsSolComment
);
401 if ((style
== SCE_P_TRIPLE
) || (style
== SCE_P_TRIPLEDOUBLE
))
402 indentNext
|= SC_FOLDLEVELWHITEFLAG
;
403 if (!(indentCurrent
& SC_FOLDLEVELWHITEFLAG
))
405 // Only non whitespace lines can be headers
406 if ((indentCurrent
& SC_FOLDLEVELNUMBERMASK
) < (indentNext
& SC_FOLDLEVELNUMBERMASK
))
408 lev
|= SC_FOLDLEVELHEADERFLAG
;
409 } else if (indentNext
& SC_FOLDLEVELWHITEFLAG
)
411 // Line after is blank so check the next - maybe should continue further?
413 int indentNext2
= styler
.IndentAmount(lineCurrent
+ 2, &spaceFlags2
, IsSolComment
);
414 if ((indentCurrent
& SC_FOLDLEVELNUMBERMASK
) < (indentNext2
& SC_FOLDLEVELNUMBERMASK
))
416 lev
|= SC_FOLDLEVELHEADERFLAG
;
420 indentCurrent
= indentNext
;
421 styler
.SetLevel(lineCurrent
, lev
);
427 LexerModule
lmScriptol(SCLEX_SCRIPTOL
, ColouriseSolDoc
, "scriptol", FoldSolDoc
);