21
21
#include "KeyWords.h"
22
22
#include "Scintilla.h"
23
23
#include "SciLexer.h"
25
// Extended to accept accented characters
26
static inline bool IsAWordChar(int ch) {
28
(isalnum(ch) || ch == '.' || ch == '_');
31
static inline bool IsAWordStart(int ch) {
33
(isalpha(ch) || ch == '_');
36
static inline bool IsANumberChar(int ch) {
37
// Not exactly following number definition (several dots are seen as OK, etc.)
38
// but probably enough in most cases.
40
(isdigit(ch) || toupper(ch) == 'E' ||
41
ch == '.' || ch == '-' || ch == '+');
44
static inline bool IsLuaOperator(int ch) {
45
if (ch >= 0x80 || isalnum(ch)) {
48
// '.' left out as it is used to make up numbers
49
if (ch == '*' || ch == '/' || ch == '-' || ch == '+' ||
50
ch == '(' || ch == ')' || ch == '=' ||
51
ch == '{' || ch == '}' || ch == '~' ||
52
ch == '[' || ch == ']' || ch == ';' ||
53
ch == '<' || ch == '>' || ch == ',' ||
54
ch == '.' || ch == '^' || ch == '%' || ch == ':') {
24
#include "CharacterSet.h"
27
using namespace Scintilla;
60
30
// Test for [=[ ... ]=] delimiters, returns 0 if it's only a [ or ],
61
31
// return 1 for [[ or ]], returns >=2 for [=[ or ]=] and so on.
85
55
WordList &keywords7 = *keywordlists[6];
86
56
WordList &keywords8 = *keywordlists[7];
58
// Accepts accented characters
59
CharacterSet setWordStart(CharacterSet::setAlpha, "_", 0x80, true);
60
CharacterSet setWord(CharacterSet::setAlphaNum, "._", 0x80, true);
61
// Not exactly following number definition (several dots are seen as OK, etc.)
62
// but probably enough in most cases.
63
CharacterSet setNumber(CharacterSet::setDigits, ".-+abcdefABCDEF");
64
CharacterSet setLuaOperator(CharacterSet::setNone, "*/-+()={}~[];<>,.^%:#");
65
CharacterSet setEscapeSkip(CharacterSet::setNone, "\"'\\");
88
67
int currentLine = styler.GetLine(startPos);
89
68
// Initialize long string [[ ... ]] or block comment --[[ ... ]] nesting level,
90
69
// if we are inside such a string. Block comment was introduced in Lua 5.0,
144
123
if (sc.state == SCE_LUA_OPERATOR) {
145
124
sc.SetState(SCE_LUA_DEFAULT);
146
125
} else if (sc.state == SCE_LUA_NUMBER) {
147
// We stop the number definition on non-numerical non-dot non-eE non-sign char
148
if (!IsANumberChar(sc.ch)) {
126
// We stop the number definition on non-numerical non-dot non-eE non-sign non-hexdigit char
127
if (!setNumber.Contains(sc.ch)) {
149
128
sc.SetState(SCE_LUA_DEFAULT);
129
} else if (sc.ch == '-' || sc.ch == '+') {
130
if (sc.chPrev != 'E' && sc.chPrev != 'e')
131
sc.SetState(SCE_LUA_DEFAULT);
151
133
} else if (sc.state == SCE_LUA_IDENTIFIER) {
152
if (!IsAWordChar(sc.ch) || sc.Match('.', '.')) {
134
if (!setWord.Contains(sc.ch) || sc.Match('.', '.')) {
154
136
sc.GetCurrent(s, sizeof(s));
155
137
if (keywords.InList(s)) {
164
146
sc.ChangeState(SCE_LUA_WORD5);
165
147
} else if (keywords6.InList(s)) {
166
148
sc.ChangeState(SCE_LUA_WORD6);
167
} else if (keywords6.InList(s)) {
168
sc.ChangeState(SCE_LUA_WORD6);
169
149
} else if (keywords7.InList(s)) {
170
150
sc.ChangeState(SCE_LUA_WORD7);
171
151
} else if (keywords8.InList(s)) {
225
205
if (sc.state == SCE_LUA_DEFAULT) {
226
206
if (IsADigit(sc.ch) || (sc.ch == '.' && IsADigit(sc.chNext))) {
227
207
sc.SetState(SCE_LUA_NUMBER);
228
} else if (IsAWordStart(sc.ch)) {
208
if (sc.ch == '0' && toupper(sc.chNext) == 'X') {
211
} else if (setWordStart.Contains(sc.ch)) {
229
212
sc.SetState(SCE_LUA_IDENTIFIER);
230
213
} else if (sc.ch == '\"') {
231
214
sc.SetState(SCE_LUA_STRING);
256
239
} else if (sc.atLineStart && sc.Match('$')) {
257
240
sc.SetState(SCE_LUA_PREPROCESSOR); // Obsolete since Lua 4.0, but still in old code
258
} else if (IsLuaOperator(static_cast<char>(sc.ch))) {
241
} else if (setLuaOperator.Contains(sc.ch)) {
259
242
sc.SetState(SCE_LUA_OPERATOR);
247
if (setWord.Contains(sc.chPrev)) {
249
sc.GetCurrent(s, sizeof(s));
250
if (keywords.InList(s)) {
251
sc.ChangeState(SCE_LUA_WORD);
252
} else if (keywords2.InList(s)) {
253
sc.ChangeState(SCE_LUA_WORD2);
254
} else if (keywords3.InList(s)) {
255
sc.ChangeState(SCE_LUA_WORD3);
256
} else if (keywords4.InList(s)) {
257
sc.ChangeState(SCE_LUA_WORD4);
258
} else if (keywords5.InList(s)) {
259
sc.ChangeState(SCE_LUA_WORD5);
260
} else if (keywords6.InList(s)) {
261
sc.ChangeState(SCE_LUA_WORD6);
262
} else if (keywords7.InList(s)) {
263
sc.ChangeState(SCE_LUA_WORD7);
264
} else if (keywords8.InList(s)) {
265
sc.ChangeState(SCE_LUA_WORD8);