20
20
#include "Scintilla.h"
21
21
#include "SciLexer.h"
24
using namespace Scintilla;
23
27
enum kwType { kwOther, kwClass, kwDef, kwImport };
28
static const int indicatorWhitespace = 1;
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;
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);
133
bool indentGood = true;
134
int startIndicator = sc.currentPos;
129
136
for (; sc.More(); sc.Forward()) {
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);
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;
144
sc.SetState(sc.state);
145
styler.SetFlags(chFlags, static_cast<char>(sc.state));
148
indentGood = (spaceFlags & wsTab) == 0;
151
styler.IndicatorFill(startIndicator, sc.currentPos, indicatorWhitespace, 0);
152
startIndicator = sc.currentPos;
148
156
if (sc.atLineEnd) {
154
162
sc.SetState(sc.state);
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);
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);
218
223
} else if ((sc.state == SCE_P_STRING) || (sc.state == SCE_P_CHARACTER)) {
219
224
if (sc.ch == '\\') {
256
if (!indentGood && !IsASpaceOrTab(sc.ch)) {
257
styler.IndicatorFill(startIndicator, sc.currentPos, indicatorWhitespace, 1);
258
startIndicator = sc.currentPos;
251
262
// State exit code may have moved on to end of line
252
263
if (needEOLCheck && sc.atLineEnd) {