]>
git.saurik.com Git - wxWidgets.git/blob - src/stc/scintilla/src/LexPascal.cxx
491d968ac99743bfa9404ab64056d5ceeaf5d7ce
1 // Scintilla source code edit control
2 /** @file LexPascal.cxx
4 ** Written by Laurent le Tynevez
18 #include "Scintilla.h"
21 static int classifyWordPascal(unsigned int start
, unsigned int end
, WordList
&keywords
, Accessor
&styler
) {
23 for (unsigned int i
= 0; i
< end
- start
+ 1 && i
< 30; i
++) {
24 s
[i
] = static_cast<char>(tolower(styler
[start
+ i
]));
28 char chAttr
= SCE_C_IDENTIFIER
;
29 if (isdigit(s
[0]) || (s
[0] == '.')){
30 chAttr
= SCE_C_NUMBER
;
33 if (keywords
.InList(s
)) {
35 if (strcmp(s
, "begin") == 0 || strcmp(s
, "object") == 0)
37 else if (strcmp(s
, "end") == 0)
41 styler
.ColourTo(end
, chAttr
);
45 static void ColourisePascalDoc(unsigned int startPos
, int length
, int initStyle
, WordList
*keywordlists
[],
47 WordList
&keywords
= *keywordlists
[0];
49 styler
.StartAt(startPos
);
51 bool fold
= styler
.GetPropertyInt("fold") != 0;
52 int lineCurrent
= styler
.GetLine(startPos
);
53 int levelPrev
= styler
.LevelAt(lineCurrent
) & SC_FOLDLEVELNUMBERMASK
;
54 int levelCurrent
= levelPrev
;
56 int state
= initStyle
;
57 if (state
== SCE_C_STRINGEOL
) // Does not leak onto next line
58 state
= SCE_C_DEFAULT
;
60 char chNext
= styler
[startPos
];
61 unsigned int lengthDoc
= startPos
+ length
;
63 styler
.StartSegment(startPos
);
64 for (unsigned int i
= startPos
; i
< lengthDoc
; i
++) {
66 chNext
= styler
.SafeGetCharAt(i
+ 1);
68 if ((ch
== '\r' && chNext
!= '\n') || (ch
== '\n')) {
69 // Trigger on CR only (Mac style) or either on LF from CR+LF (Dos/Win) or on LF alone (Unix)
70 // Avoid triggering two times on Dos/Win
72 if (state
== SCE_C_STRINGEOL
) {
73 styler
.ColourTo(i
, state
);
74 state
= SCE_C_DEFAULT
;
78 if (visibleChars
== 0)
79 lev
|= SC_FOLDLEVELWHITEFLAG
;
80 if ((levelCurrent
> levelPrev
) && (visibleChars
> 0))
81 lev
|= SC_FOLDLEVELHEADERFLAG
;
82 styler
.SetLevel(lineCurrent
, lev
);
84 levelPrev
= levelCurrent
;
91 if (styler
.IsLeadByte(ch
)) {
92 chNext
= styler
.SafeGetCharAt(i
+ 2);
98 if (state
== SCE_C_DEFAULT
) {
99 if (iswordstart(ch
) || (ch
== '@')) {
100 styler
.ColourTo(i
-1, state
);
101 state
= SCE_C_IDENTIFIER
;
102 } else if (ch
== '{' && chNext
!= '$' && chNext
!= '&') {
103 styler
.ColourTo(i
-1, state
);
104 state
= SCE_C_COMMENT
;
105 } else if (ch
== '(' && chNext
== '*'
106 && styler
.SafeGetCharAt(i
+ 2) != '$'
107 && styler
.SafeGetCharAt(i
+ 2) != '&') {
108 styler
.ColourTo(i
-1, state
);
109 state
= SCE_C_COMMENTDOC
;
110 } else if (ch
== '/' && chNext
== '/') {
111 styler
.ColourTo(i
-1, state
);
112 state
= SCE_C_COMMENTLINE
;
113 } else if (ch
== '\"') {
114 styler
.ColourTo(i
-1, state
);
115 state
= SCE_C_STRING
;
116 } else if (ch
== '\'') {
117 styler
.ColourTo(i
-1, state
);
118 state
= SCE_C_CHARACTER
;
119 } else if (ch
== '{' && (chNext
== '$' || chNext
=='&') && visibleChars
== 1) {
120 styler
.ColourTo(i
-1, state
);
121 state
= SCE_C_PREPROCESSOR
;
122 } else if (isoperator(ch
)) {
123 styler
.ColourTo(i
-1, state
);
124 styler
.ColourTo(i
, SCE_C_OPERATOR
);
127 } else if (state
== SCE_C_IDENTIFIER
) {
128 if (!iswordchar(ch
)) {
129 int levelChange
= classifyWordPascal(styler
.GetStartSegment(), i
- 1, keywords
, styler
);
130 state
= SCE_C_DEFAULT
;
131 chNext
= styler
.SafeGetCharAt(i
+ 1);
132 if (ch
== '{' && chNext
!= '$' && chNext
!= '&') {
133 state
= SCE_C_COMMENT
;
134 } else if (ch
== '(' && chNext
== '*'
135 && styler
.SafeGetCharAt(i
+ 2) != '$'
136 && styler
.SafeGetCharAt(i
+ 2) != '&') {
137 styler
.ColourTo(i
-1, state
);
138 state
= SCE_C_COMMENTDOC
;
139 } else if (ch
== '/' && chNext
== '/') {
140 state
= SCE_C_COMMENTLINE
;
141 } else if (ch
== '\"') {
142 state
= SCE_C_STRING
;
143 } else if (ch
== '\'') {
144 state
= SCE_C_CHARACTER
;
145 } else if (isoperator(ch
)) {
146 styler
.ColourTo(i
, SCE_C_OPERATOR
);
148 levelCurrent
+=levelChange
;
151 if (state
== SCE_C_PREPROCESSOR
) {
153 styler
.ColourTo(i
, state
);
154 state
= SCE_C_DEFAULT
;
156 if ((ch
== '\r' || ch
== '\n') && !(chPrev
== '\\' || chPrev
== '\r')) {
157 styler
.ColourTo(i
-1, state
);
158 state
= SCE_C_DEFAULT
;
161 } else if (state
== SCE_C_COMMENT
) {
163 styler
.ColourTo(i
, state
);
164 state
= SCE_C_DEFAULT
;
166 } else if (state
== SCE_C_COMMENTDOC
) {
167 if (ch
== ')' && chPrev
== '*') {
168 if (((i
> styler
.GetStartSegment() + 2) || (
169 (initStyle
== SCE_C_COMMENTDOC
) &&
170 (styler
.GetStartSegment() == static_cast<unsigned int>(startPos
))))) {
171 styler
.ColourTo(i
, state
);
172 state
= SCE_C_DEFAULT
;
175 } else if (state
== SCE_C_COMMENTLINE
) {
176 if (ch
== '\r' || ch
== '\n') {
177 styler
.ColourTo(i
-1, state
);
178 state
= SCE_C_DEFAULT
;
180 } else if (state
== SCE_C_STRING
) {
182 if (chNext
== '\"' || chNext
== '\'' || chNext
== '\\') {
185 chNext
= styler
.SafeGetCharAt(i
+ 1);
187 } else if (ch
== '\"') {
188 styler
.ColourTo(i
, state
);
189 state
= SCE_C_DEFAULT
;
190 } else if (chNext
== '\r' || chNext
== '\n') {
191 styler
.ColourTo(i
-1, SCE_C_STRINGEOL
);
192 state
= SCE_C_STRINGEOL
;
194 } else if (state
== SCE_C_CHARACTER
) {
195 if ((ch
== '\r' || ch
== '\n') && (chPrev
!= '\\')) {
196 styler
.ColourTo(i
-1, SCE_C_STRINGEOL
);
197 state
= SCE_C_STRINGEOL
;
198 } else if (ch
== '\\') {
199 if (chNext
== '\"' || chNext
== '\'' || chNext
== '\\') {
202 chNext
= styler
.SafeGetCharAt(i
+ 1);
204 } else if (ch
== '\'') {
205 styler
.ColourTo(i
, state
);
206 state
= SCE_C_DEFAULT
;
212 styler
.ColourTo(lengthDoc
- 1, state
);
214 // Fill in the real level of the next line, keeping the current flags as they will be filled in later
216 int flagsNext
= styler
.LevelAt(lineCurrent
) & ~SC_FOLDLEVELNUMBERMASK
;
217 styler
.SetLevel(lineCurrent
, levelPrev
| flagsNext
);
221 LexerModule
lmPascal(SCLEX_PASCAL
, ColourisePascalDoc
, "pascal");