]> git.saurik.com Git - wxWidgets.git/blob - contrib/src/stc/scintilla/src/LexVB.cxx
This commit includes the following changes:
[wxWidgets.git] / contrib / src / stc / scintilla / src / LexVB.cxx
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.
5
6 #include <stdlib.h>
7 #include <string.h>
8 #include <ctype.h>
9 #include <stdio.h>
10 #include <stdarg.h>
11
12 #include "Platform.h"
13
14 #include "PropSet.h"
15 #include "Accessor.h"
16 #include "KeyWords.h"
17 #include "Scintilla.h"
18 #include "SciLexer.h"
19
20 static int classifyWordVB(unsigned int start, unsigned int end, WordList &keywords, StylingContext &styler) {
21
22 char s[100];
23 bool wordIsNumber = isdigit(styler[start]) || (styler[start] == '.');
24 for (unsigned int i = 0; i < end - start + 1 && i < 30; i++) {
25 s[i] = tolower(styler[start + i]);
26 s[i + 1] = '\0';
27 }
28 char chAttr = SCE_C_DEFAULT;
29 if (wordIsNumber)
30 chAttr = SCE_C_NUMBER;
31 else {
32 if (keywords.InList(s)) {
33 chAttr = SCE_C_WORD;
34 if (strcmp(s, "rem") == 0)
35 chAttr = SCE_C_COMMENTLINE;
36 }
37 }
38 styler.ColourTo(end, chAttr);
39 if (chAttr == SCE_C_COMMENTLINE)
40 return SCE_C_COMMENTLINE;
41 else
42 return SCE_C_DEFAULT;
43 }
44
45 static void ColouriseVBDoc(unsigned int startPos, int length, int initStyle,
46 WordList *keywordlists[], StylingContext &styler) {
47
48 WordList &keywords = *keywordlists[0];
49
50 styler.StartAt(startPos);
51
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++) {
57 char ch = chNext;
58 chNext = styler.SafeGetCharAt(i + 1);
59
60 if (styler.IsLeadByte(ch)) {
61 chNext = styler.SafeGetCharAt(i + 2);
62 i += 1;
63 continue;
64 }
65
66 if (state == SCE_C_DEFAULT) {
67 if (iswordstart(ch)) {
68 styler.ColourTo(i - 1, state);
69 state = SCE_C_WORD;
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);
75 state = SCE_C_STRING;
76 }
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) {
81 if (ch == '\'') {
82 state = SCE_C_COMMENTLINE;
83 } else if (ch == '\"') {
84 state = SCE_C_STRING;
85 }
86 }
87 }
88 } else {
89 if (state == SCE_C_COMMENTLINE) {
90 if (ch == '\r' || ch == '\n') {
91 styler.ColourTo(i - 1, state);
92 state = SCE_C_DEFAULT;
93 }
94 } else if (state == SCE_C_STRING) {
95 // VB doubles quotes to preserve them
96 if (ch == '\"') {
97 styler.ColourTo(i, state);
98 state = SCE_C_DEFAULT;
99 i++;
100 ch = chNext;
101 chNext = styler.SafeGetCharAt(i + 1);
102 }
103 }
104 if (state == SCE_C_DEFAULT) { // One of the above succeeded
105 if (ch == '\'') {
106 state = SCE_C_COMMENTLINE;
107 } else if (ch == '\"') {
108 state = SCE_C_STRING;
109 } else if (iswordstart(ch)) {
110 state = SCE_C_WORD;
111 }
112 }
113 }
114 }
115 styler.ColourTo(lengthDoc, state);
116 }
117
118 LexerModule lmVB(SCLEX_VB, ColouriseVBDoc);