~ubuntu-branches/ubuntu/raring/geany/raring-proposed

« back to all changes in this revision

Viewing changes to scintilla/LexPython.cxx

  • Committer: Bazaar Package Importer
  • Author(s): Damián Viano
  • Date: 2008-05-02 11:37:45 UTC
  • mfrom: (1.2.1 upstream) (9 hardy)
  • mto: (3.2.1 squeeze)
  • mto: This revision was merged to the branch mainline in revision 12.
  • Revision ID: james.westby@ubuntu.com-20080502113745-xzp4g6dmovrpoj17
Tags: 0.14-1
New upstream release (Closes: #478126)

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
#include "Scintilla.h"
21
21
#include "SciLexer.h"
22
22
 
 
23
#ifdef SCI_NAMESPACE
 
24
using namespace Scintilla;
 
25
#endif
 
26
 
23
27
enum kwType { kwOther, kwClass, kwDef, kwImport };
 
28
static const int indicatorWhitespace = 1;
24
29
 
25
30
static bool IsPyComment(Accessor &styler, int pos, int len) {
26
31
        return len > 0 && styler[pos] == '#';
123
128
        styler.IndentAmount(lineCurrent, &spaceFlags, IsPyComment);
124
129
        bool hexadecimal = false;
125
130
 
126
 
        // Python uses a different mask because bad indentation is marked by oring with 32
127
 
        StyleContext sc(startPos, endPos - startPos, initStyle, styler, 0x7f);
 
131
        StyleContext sc(startPos, endPos - startPos, initStyle, styler);
 
132
 
 
133
        bool indentGood = true;
 
134
        int startIndicator = sc.currentPos;
128
135
 
129
136
        for (; sc.More(); sc.Forward()) {
130
137
 
131
138
                if (sc.atLineStart) {
132
 
                        const char chBad = static_cast<char>(64);
133
 
                        const char chGood = static_cast<char>(0);
134
 
                        char chFlags = chGood;
 
139
                        styler.IndentAmount(lineCurrent, &spaceFlags, IsPyComment);
 
140
                        indentGood = true;
135
141
                        if (whingeLevel == 1) {
136
 
                                chFlags = (spaceFlags & wsInconsistent) ? chBad : chGood;
 
142
                                indentGood = (spaceFlags & wsInconsistent) == 0;
137
143
                        } else if (whingeLevel == 2) {
138
 
                                chFlags = (spaceFlags & wsSpaceTab) ? chBad : chGood;
 
144
                                indentGood = (spaceFlags & wsSpaceTab) == 0;
139
145
                        } else if (whingeLevel == 3) {
140
 
                                chFlags = (spaceFlags & wsSpace) ? chBad : chGood;
 
146
                                indentGood = (spaceFlags & wsSpace) == 0;
141
147
                        } else if (whingeLevel == 4) {
142
 
                                chFlags = (spaceFlags & wsTab) ? chBad : chGood;
143
 
                        }
144
 
                        sc.SetState(sc.state);
145
 
                        styler.SetFlags(chFlags, static_cast<char>(sc.state));
 
148
                                indentGood = (spaceFlags & wsTab) == 0;
 
149
                        }
 
150
                        if (!indentGood) {
 
151
                                styler.IndicatorFill(startIndicator, sc.currentPos, indicatorWhitespace, 0);
 
152
                                startIndicator = sc.currentPos;
 
153
                        }
146
154
                }
147
155
 
148
156
                if (sc.atLineEnd) {
154
162
                                sc.SetState(sc.state);
155
163
                        }
156
164
                        lineCurrent++;
157
 
                        styler.IndentAmount(lineCurrent, &spaceFlags, IsPyComment);
158
165
                        if ((sc.state == SCE_P_STRING) || (sc.state == SCE_P_CHARACTER)) {
159
166
                                sc.ChangeState(SCE_P_STRINGEOL);
160
167
                                sc.ForwardSetState(SCE_P_DEFAULT);
210
217
                                sc.SetState(SCE_P_DEFAULT);
211
218
                        }
212
219
                } else if (sc.state == SCE_P_DECORATOR) {
213
 
                        if (sc.ch == '\r' || sc.ch == '\n') {
 
220
                        if (!IsAWordChar(sc.ch)) {
214
221
                                sc.SetState(SCE_P_DEFAULT);
215
 
                        } else if (sc.ch == '#') {
216
 
                                sc.SetState((sc.chNext == '#') ? SCE_P_COMMENTBLOCK  :  SCE_P_COMMENTLINE);
217
222
                        }
218
223
                } else if ((sc.state == SCE_P_STRING) || (sc.state == SCE_P_CHARACTER)) {
219
224
                        if (sc.ch == '\\') {
248
253
                        }
249
254
                }
250
255
 
 
256
                if (!indentGood && !IsASpaceOrTab(sc.ch)) {
 
257
                        styler.IndicatorFill(startIndicator, sc.currentPos, indicatorWhitespace, 1);
 
258
                        startIndicator = sc.currentPos;
 
259
                        indentGood = true;
 
260
                }
 
261
 
251
262
                // State exit code may have moved on to end of line
252
263
                if (needEOLCheck && sc.atLineEnd) {
253
264
                        lineCurrent++;
282
293
                        }
283
294
                }
284
295
        }
 
296
        styler.IndicatorFill(startIndicator, sc.currentPos, indicatorWhitespace, 0);
285
297
        sc.Complete();
286
298
}
287
299