25#include "LexAccessor.h"
27#include "StyleContext.h"
28#include "CharacterSet.h"
29#include "LexerModule.h"
32using namespace Scintilla;
40 return (c ==
'%' || c ==
'#') ;
52 return (ch < 0x80) && (isalnum(ch) || ch ==
'_');
56 return (ch < 0x80) && (isalnum(ch) || ch ==
'_');
65 for (
size_t i = 0; i < startPos; i++)
67 char currentChar = styler.SafeGetCharAt(i);
70 if (currentChar ==
'(' || currentChar ==
'[' || currentChar ==
'{')
72 else if (currentChar ==
')' || currentChar ==
']' || currentChar ==
'}')
80 unsigned int startPos,
int length,
int initStyle,
81 WordList *keywordlists[], Accessor &styler,
82 bool (*IsCommentChar)(
int)) {
84 WordList &keywords = *keywordlists[0];
85 WordList &keywords2 = *keywordlists[1];
87 styler.StartAt(startPos);
89 bool transpose =
false;
91 StyleContext sc(startPos, length, initStyle, styler);
96 for (; sc.More(); sc.Forward()) {
99 if (sc.chPrev ==
'.') {
100 if (sc.ch ==
'*' || sc.ch ==
'/' || sc.ch ==
'\\' || sc.ch ==
'^') {
103 }
else if (sc.ch ==
'\'') {
113 if (!isalnum(sc.ch) && sc.ch !=
'_') {
115 sc.GetCurrentLowered(s,
sizeof(s));
116 if (!strcmp(s,
"end") && nParens)
122 else if (keywords.InList(s)) {
125 }
else if (keywords2.InList(s)) {
136 if (!isdigit(sc.ch) && sc.ch !=
'.'
137 && !(sc.ch ==
'e' || sc.ch ==
'E')
138 && !((sc.ch ==
'+' || sc.ch ==
'-') && (sc.chPrev ==
'e' || sc.chPrev ==
'E'))) {
144 if (sc.chNext ==
'\'') {
152 if (sc.chNext ==
'\"' || sc.chNext ==
'\'' || sc.chNext ==
'\\') {
155 }
else if (sc.ch ==
'\"') {
166 if (IsCommentChar(sc.ch)) {
168 }
else if (sc.ch ==
'!' && sc.chNext !=
'=' ) {
170 }
else if (sc.ch ==
'\'') {
176 }
else if (sc.ch ==
'"') {
178 }
else if (isdigit(sc.ch) || (sc.ch ==
'.' && isdigit(sc.chNext))) {
180 }
else if (isalpha(sc.ch)) {
182 }
else if (isoperator(
static_cast<char>(sc.ch)) || sc.ch ==
'@' || sc.ch ==
'\\') {
183 if (sc.ch ==
')' || sc.ch ==
']' || sc.ch ==
'}') {
188 if (sc.ch ==
'(' || sc.ch ==
'[' || sc.ch ==
'{')
190 if (sc.ch ==
')' || sc.ch ==
']' || sc.ch ==
'}')
202 WordList *keywordlists[], Accessor &styler) {
207 WordList *keywordlists[], Accessor &styler) {
212 WordList *[], Accessor &styler,
213 bool (*IsComment)(Accessor&,
int,
int)) {
215 unsigned int endPos = startPos + length;
216 int visibleChars = 0;
217 int lineCurrent = styler.GetLine(startPos);
218 int levelCurrent = SC_FOLDLEVELBASE;
220 levelCurrent = styler.LevelAt(lineCurrent-1) >> 16;
221 int levelMinCurrent = levelCurrent;
222 int levelNext = levelCurrent;
223 char chNext = styler[startPos];
224 int styleNext = styler.StyleAt(startPos);
225 int style = initStyle;
226 for (
unsigned int i = startPos; i < endPos; i++)
229 chNext = styler.SafeGetCharAt(i + 1);
230 int stylePrev = style;
232 styleNext = styler.StyleAt(i + 1);
233 bool atEOL = (ch ==
'\r' && chNext !=
'\n') || (ch ==
'\n');
236 (styler.SafeGetCharAt(i) ==
'('
237 || styler.SafeGetCharAt(i) ==
'{'
238 || styler.SafeGetCharAt(i) ==
'[')
242 for (
int j = i; j < endPos; j++)
244 atEOL = (styler.SafeGetCharAt(j) ==
'\r' && styler.SafeGetCharAt(j+1) !=
'\n')
245 || (styler.SafeGetCharAt(j) ==
'\n');
247 (styler.SafeGetCharAt(j) ==
'('
248 || styler.SafeGetCharAt(j) ==
'{'
249 || styler.SafeGetCharAt(j) ==
'['))
252 (styler.SafeGetCharAt(j) ==
')'
253 || styler.SafeGetCharAt(j) ==
'}'
254 || styler.SafeGetCharAt(j) ==
']'))
258 int levelUse = levelCurrent;
259 levelUse = levelMinCurrent;
260 int lev = levelUse | levelNext << 16;
263 if (levelUse < levelNext)
264 lev |= SC_FOLDLEVELHEADERFLAG;
265 if (lev != styler.LevelAt(lineCurrent))
267 styler.SetLevel(lineCurrent, lev);
270 levelCurrent = levelNext;
271 levelMinCurrent = levelCurrent;
284 if (styler.Match(i,
"end"))
288 else if (styler.SafeGetCharAt(i-1) !=
'e'
289 && (styler.Match(i,
"if")
290 || styler.Match(i,
"for")
291 || styler.Match(i,
"while")
292 || styler.Match(i,
"do")
293 || styler.Match(i,
"switch")
294 || styler.Match(i,
"try")
295 || styler.Match(i,
"classdef")
296 || styler.Match(i,
"methods")
297 || styler.Match(i,
"properties")
298 || styler.Match(i,
"function"))
304 if (atEOL || (i == endPos-1))
306 int levelUse = levelCurrent;
307 levelUse = levelMinCurrent;
308 int lev = levelUse | levelNext << 16;
311 if (levelUse < levelNext)
312 lev |= SC_FOLDLEVELHEADERFLAG;
313 if (lev != styler.LevelAt(lineCurrent))
315 styler.SetLevel(lineCurrent, lev);
318 levelCurrent = levelNext;
319 levelMinCurrent = levelCurrent;
368 WordList *keywordlists[], Accessor &styler) {
373 WordList *keywordlists[], Accessor &styler) {
static bool IsAWordChar(const int ch)
static const char *const octaveWordListDesc[]
static bool IsMatlabComment(Accessor &styler, int pos, int len)
static void FoldOctaveDoc(unsigned int startPos, int length, int initStyle, WordList *keywordlists[], Accessor &styler)
static const char *const matlabWordListDesc[]
static void ColouriseOctaveDoc(unsigned int startPos, int length, int initStyle, WordList *keywordlists[], Accessor &styler)
static bool IsOctaveCommentChar(int c)
static void ColouriseMatlabDoc(unsigned int startPos, int length, int initStyle, WordList *keywordlists[], Accessor &styler)
static bool IsMatlabCommentChar(int c)
LexerModule lmMatlab(SCLEX_MATLAB, ColouriseMatlabDoc, "matlab", FoldMatlabDoc, matlabWordListDesc)
static void FoldMatlabOctaveDoc(unsigned int startPos, int length, int initStyle, WordList *[], Accessor &styler, bool(*IsComment)(Accessor &, int, int))
static int GetParenthesesCount(unsigned int startPos, Accessor &styler)
static void FoldMatlabDoc(unsigned int startPos, int length, int initStyle, WordList *keywordlists[], Accessor &styler)
static bool IsOctaveComment(Accessor &styler, int pos, int len)
static bool IsAWordStart(const int ch)
static void ColouriseMatlabOctaveDoc(unsigned int startPos, int length, int initStyle, WordList *keywordlists[], Accessor &styler, bool(*IsCommentChar)(int))
LexerModule lmOctave(SCLEX_OCTAVE, ColouriseOctaveDoc, "octave", FoldOctaveDoc, octaveWordListDesc)
#define SCE_MATLAB_IDENTIFIER
#define SCE_MATLAB_NUMBER
#define SCE_MATLAB_COMMAND
#define SCE_MATLAB_DEFAULT
#define SCE_MATLAB_FUNCTIONS
#define SCE_MATLAB_OPERATOR
#define SCE_MATLAB_KEYWORD
#define SCE_MATLAB_STRING
#define SCE_MATLAB_DOUBLEQUOTESTRING
#define SCE_MATLAB_COMMENT