]>
git.saurik.com Git - wxWidgets.git/blob - contrib/src/stc/scintilla/src/LexVB.cxx
acc3b0d548b2e1935b411b0aa23eea91b766c447
1 // SciTE - Scintilla based Text Editor
2 // LexVB.cxx - lexer for Visual Basic and VBScript
3 // Copyright 1998-2000 by Neil Hodgson <neilh@scintilla.org>
4 // The License.txt file describes the conditions under which this software may be distributed.
17 #include "Scintilla.h"
20 static int classifyWordVB(unsigned int start
, unsigned int end
, WordList
&keywords
, Accessor
&styler
) {
23 bool wordIsNumber
= isdigit(styler
[start
]) || (styler
[start
] == '.');
24 for (unsigned int i
= 0; i
< end
- start
+ 1 && i
< 30; i
++) {
25 s
[i
] = static_cast<char>(tolower(styler
[start
+ i
]));
28 char chAttr
= SCE_C_DEFAULT
;
30 chAttr
= SCE_C_NUMBER
;
32 if (keywords
.InList(s
)) {
34 if (strcmp(s
, "rem") == 0)
35 chAttr
= SCE_C_COMMENTLINE
;
38 styler
.ColourTo(end
, chAttr
);
39 if (chAttr
== SCE_C_COMMENTLINE
)
40 return SCE_C_COMMENTLINE
;
45 static void ColouriseVBDoc(unsigned int startPos
, int length
, int initStyle
,
46 WordList
*keywordlists
[], Accessor
&styler
) {
48 WordList
&keywords
= *keywordlists
[0];
50 styler
.StartAt(startPos
);
52 int state
= initStyle
;
53 char chNext
= styler
[startPos
];
54 styler
.StartSegment(startPos
);
55 int lengthDoc
= startPos
+ length
;
56 for (int i
= startPos
; i
< lengthDoc
; i
++) {
58 chNext
= styler
.SafeGetCharAt(i
+ 1);
60 if (styler
.IsLeadByte(ch
)) {
61 chNext
= styler
.SafeGetCharAt(i
+ 2);
66 if (state
== SCE_C_DEFAULT
) {
67 if (iswordstart(ch
)) {
68 styler
.ColourTo(i
- 1, state
);
70 } else if (ch
== '\'') {
71 styler
.ColourTo(i
- 1, state
);
72 state
= SCE_C_COMMENTLINE
;
73 } else if (ch
== '\"') {
74 styler
.ColourTo(i
- 1, state
);
77 } else if (state
== SCE_C_WORD
) {
78 if (!iswordchar(ch
)) {
79 state
= classifyWordVB(styler
.GetStartSegment(), i
- 1, keywords
, styler
);
80 if (state
== SCE_C_DEFAULT
) {
82 state
= SCE_C_COMMENTLINE
;
83 } else if (ch
== '\"') {
89 if (state
== SCE_C_COMMENTLINE
) {
90 if (ch
== '\r' || ch
== '\n') {
91 styler
.ColourTo(i
- 1, state
);
92 state
= SCE_C_DEFAULT
;
94 } else if (state
== SCE_C_STRING
) {
95 // VB doubles quotes to preserve them
97 styler
.ColourTo(i
, state
);
98 state
= SCE_C_DEFAULT
;
101 chNext
= styler
.SafeGetCharAt(i
+ 1);
104 if (state
== SCE_C_DEFAULT
) { // One of the above succeeded
106 state
= SCE_C_COMMENTLINE
;
107 } else if (ch
== '\"') {
108 state
= SCE_C_STRING
;
109 } else if (iswordstart(ch
)) {
115 styler
.ColourTo(lengthDoc
, state
);
118 LexerModule
lmVB(SCLEX_VB
, ColouriseVBDoc
);