]>
git.saurik.com Git - wxWidgets.git/blob - src/stc/scintilla/src/LexPascal.cxx
1 // Scintilla source code edit control
2 /** @file LexPascal.cxx
4 ** Written by Laurent le Tynevez
18 #include "Scintilla.h"
22 static int classifyWordPascal(unsigned int start
, unsigned int end
, WordList
&keywords
, Accessor
&styler
) {
24 for (unsigned int i
= 0; i
< end
- start
+ 1 && i
< 30; i
++) {
25 s
[i
] = static_cast<char>(tolower(styler
[start
+ i
]));
29 char chAttr
= SCE_C_IDENTIFIER
;
30 if (isdigit(s
[0]) || (s
[0] == '.')){
31 chAttr
= SCE_C_NUMBER
;
34 if (keywords
.InList(s
)) {
36 if (strcmp(s
, "begin") == 0 || strcmp(s
, "object") == 0)
38 else if (strcmp(s
, "end") == 0)
42 styler
.ColourTo(end
, chAttr
);
46 static void ColourisePascalDoc(unsigned int startPos
, int length
, int initStyle
, WordList
*keywordlists
[],
48 WordList
&keywords
= *keywordlists
[0];
50 styler
.StartAt(startPos
);
52 bool fold
= styler
.GetPropertyInt("fold");
53 int lineCurrent
= styler
.GetLine(startPos
);
54 int levelPrev
= styler
.LevelAt(lineCurrent
) & SC_FOLDLEVELNUMBERMASK
;
55 int levelCurrent
= levelPrev
;
57 int state
= initStyle
;
58 if (state
== SCE_C_STRINGEOL
) // Does not leak onto next line
59 state
= SCE_C_DEFAULT
;
61 char chNext
= styler
[startPos
];
62 unsigned int lengthDoc
= startPos
+ length
;
64 styler
.StartSegment(startPos
);
65 for (unsigned int i
= startPos
; i
< lengthDoc
; i
++) {
67 chNext
= styler
.SafeGetCharAt(i
+ 1);
69 if ((ch
== '\r' && chNext
!= '\n') || (ch
== '\n')) {
70 // Trigger on CR only (Mac style) or either on LF from CR+LF (Dos/Win) or on LF alone (Unix)
71 // Avoid triggering two times on Dos/Win
73 if (state
== SCE_C_STRINGEOL
) {
74 styler
.ColourTo(i
, state
);
75 state
= SCE_C_DEFAULT
;
79 if (visibleChars
== 0)
80 lev
|= SC_FOLDLEVELWHITEFLAG
;
81 if ((levelCurrent
> levelPrev
) && (visibleChars
> 0))
82 lev
|= SC_FOLDLEVELHEADERFLAG
;
83 styler
.SetLevel(lineCurrent
, lev
);
85 levelPrev
= levelCurrent
;
92 if (styler
.IsLeadByte(ch
)) {
93 chNext
= styler
.SafeGetCharAt(i
+ 2);
99 if (state
== SCE_C_DEFAULT
) {
100 if (iswordstart(ch
) || (ch
== '@')) {
101 styler
.ColourTo(i
-1, state
);
102 state
= SCE_C_IDENTIFIER
;
103 } else if (ch
== '{' && chNext
!= '$' && chNext
!= '&') {
104 styler
.ColourTo(i
-1, state
);
105 state
= SCE_C_COMMENT
;
106 } else if (ch
== '(' && chNext
== '*'
107 && styler
.SafeGetCharAt(i
+ 2) != '$'
108 && styler
.SafeGetCharAt(i
+ 2) != '&') {
109 styler
.ColourTo(i
-1, state
);
110 state
= SCE_C_COMMENTDOC
;
111 } else if (ch
== '/' && chNext
== '/') {
112 styler
.ColourTo(i
-1, state
);
113 state
= SCE_C_COMMENTLINE
;
114 } else if (ch
== '\"') {
115 styler
.ColourTo(i
-1, state
);
116 state
= SCE_C_STRING
;
117 } else if (ch
== '\'') {
118 styler
.ColourTo(i
-1, state
);
119 state
= SCE_C_CHARACTER
;
120 } else if (ch
== '{' && (chNext
== '$' || chNext
=='&') && visibleChars
== 1) {
121 styler
.ColourTo(i
-1, state
);
122 state
= SCE_C_PREPROCESSOR
;
123 } else if (isoperator(ch
)) {
124 styler
.ColourTo(i
-1, state
);
125 styler
.ColourTo(i
, SCE_C_OPERATOR
);
128 } else if (state
== SCE_C_IDENTIFIER
) {
129 if (!iswordchar(ch
)) {
130 int levelChange
= classifyWordPascal(styler
.GetStartSegment(), i
- 1, keywords
, styler
);
131 state
= SCE_C_DEFAULT
;
132 chNext
= styler
.SafeGetCharAt(i
+ 1);
133 if (ch
== '{' && chNext
!= '$' && chNext
!= '&') {
134 state
= SCE_C_COMMENT
;
135 } else if (ch
== '(' && chNext
== '*'
136 && styler
.SafeGetCharAt(i
+ 2) != '$'
137 && styler
.SafeGetCharAt(i
+ 2) != '&') {
138 styler
.ColourTo(i
-1, state
);
139 state
= SCE_C_COMMENTDOC
;
140 } else if (ch
== '/' && chNext
== '/') {
141 state
= SCE_C_COMMENTLINE
;
142 } else if (ch
== '\"') {
143 state
= SCE_C_STRING
;
144 } else if (ch
== '\'') {
145 state
= SCE_C_CHARACTER
;
146 } else if (isoperator(ch
)) {
147 styler
.ColourTo(i
, SCE_C_OPERATOR
);
149 levelCurrent
+=levelChange
;
152 if (state
== SCE_C_PREPROCESSOR
) {
154 styler
.ColourTo(i
, state
);
155 state
= SCE_C_DEFAULT
;
157 if ((ch
== '\r' || ch
== '\n') && !(chPrev
== '\\' || chPrev
== '\r')) {
158 styler
.ColourTo(i
-1, state
);
159 state
= SCE_C_DEFAULT
;
162 } else if (state
== SCE_C_COMMENT
) {
164 styler
.ColourTo(i
, state
);
165 state
= SCE_C_DEFAULT
;
167 } else if (state
== SCE_C_COMMENTDOC
) {
168 if (ch
== ')' && chPrev
== '*') {
169 if (((i
> styler
.GetStartSegment() + 2) || (
170 (initStyle
== SCE_C_COMMENTDOC
) &&
171 (styler
.GetStartSegment() == static_cast<unsigned int>(startPos
))))) {
172 styler
.ColourTo(i
, state
);
173 state
= SCE_C_DEFAULT
;
176 } else if (state
== SCE_C_COMMENTLINE
) {
177 if (ch
== '\r' || ch
== '\n') {
178 styler
.ColourTo(i
-1, state
);
179 state
= SCE_C_DEFAULT
;
181 } else if (state
== SCE_C_STRING
) {
183 if (chNext
== '\"' || chNext
== '\'' || chNext
== '\\') {
186 chNext
= styler
.SafeGetCharAt(i
+ 1);
188 } else if (ch
== '\"') {
189 styler
.ColourTo(i
, state
);
190 state
= SCE_C_DEFAULT
;
191 } else if (chNext
== '\r' || chNext
== '\n') {
192 styler
.ColourTo(i
-1, SCE_C_STRINGEOL
);
193 state
= SCE_C_STRINGEOL
;
195 } else if (state
== SCE_C_CHARACTER
) {
196 if ((ch
== '\r' || ch
== '\n') && (chPrev
!= '\\')) {
197 styler
.ColourTo(i
-1, SCE_C_STRINGEOL
);
198 state
= SCE_C_STRINGEOL
;
199 } else if (ch
== '\\') {
200 if (chNext
== '\"' || chNext
== '\'' || chNext
== '\\') {
203 chNext
= styler
.SafeGetCharAt(i
+ 1);
205 } else if (ch
== '\'') {
206 styler
.ColourTo(i
, state
);
207 state
= SCE_C_DEFAULT
;
213 styler
.ColourTo(lengthDoc
- 1, state
);
215 // Fill in the real level of the next line, keeping the current flags as they will be filled in later
217 int flagsNext
= styler
.LevelAt(lineCurrent
) & ~SC_FOLDLEVELNUMBERMASK
;
218 styler
.SetLevel(lineCurrent
, levelPrev
| flagsNext
);
222 LexerModule
lmPascal(SCLEX_PASCAL
, ColourisePascalDoc
, "pascal");