2022-01-04 23:07:50 +00:00
|
|
|
// Scintilla source code edit control
|
|
|
|
/** @file StyleContext.h
|
|
|
|
** Lexer infrastructure.
|
|
|
|
**/
|
|
|
|
// Copyright 1998-2004 by Neil Hodgson <neilh@scintilla.org>
|
|
|
|
// This file is in the public domain.
|
|
|
|
|
|
|
|
#ifndef STYLECONTEXT_H
|
|
|
|
#define STYLECONTEXT_H
|
|
|
|
|
|
|
|
namespace Lexilla {
|
|
|
|
|
|
|
|
// All languages handled so far can treat all characters >= 0x80 as one class
|
|
|
|
// which just continues the current token or starts an identifier if in default.
|
|
|
|
// DBCS treated specially as the second character can be < 0x80 and hence
|
|
|
|
// syntactically significant. UTF-8 avoids this as all trail bytes are >= 0x80
|
|
|
|
class StyleContext {
|
|
|
|
LexAccessor &styler;
|
2022-04-13 11:10:12 +00:00
|
|
|
Scintilla::IDocument * const multiByteAccess;
|
|
|
|
const Sci_PositionU lengthDocument;
|
|
|
|
const Sci_PositionU endPos;
|
|
|
|
const Sci_Position lineDocEnd;
|
2022-01-04 23:07:50 +00:00
|
|
|
|
|
|
|
// Used for optimizing GetRelativeCharacter
|
2022-04-13 11:10:12 +00:00
|
|
|
Sci_PositionU posRelative = 0;
|
2022-01-04 23:07:50 +00:00
|
|
|
Sci_PositionU currentPosLastRelative;
|
2022-04-13 11:10:12 +00:00
|
|
|
Sci_Position offsetRelative = 0;
|
2022-01-04 23:07:50 +00:00
|
|
|
|
|
|
|
void GetNextChar() {
|
|
|
|
if (multiByteAccess) {
|
|
|
|
chNext = multiByteAccess->GetCharacterAndWidth(currentPos+width, &widthNext);
|
|
|
|
} else {
|
2023-02-09 16:57:24 +00:00
|
|
|
const unsigned char charNext = styler.SafeGetCharAt(currentPos + width, 0);
|
|
|
|
chNext = charNext;
|
2022-01-04 23:07:50 +00:00
|
|
|
}
|
|
|
|
// End of line determined from line end position, allowing CR, LF,
|
|
|
|
// CRLF and Unicode line ends as set by document.
|
2023-02-09 16:57:24 +00:00
|
|
|
const Sci_Position currentPosSigned = currentPos;
|
2022-01-04 23:07:50 +00:00
|
|
|
if (currentLine < lineDocEnd)
|
2023-02-09 16:57:24 +00:00
|
|
|
atLineEnd = currentPosSigned >= (lineStartNext-1);
|
2022-01-04 23:07:50 +00:00
|
|
|
else // Last line
|
2023-02-09 16:57:24 +00:00
|
|
|
atLineEnd = currentPosSigned >= lineStartNext;
|
2022-01-04 23:07:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public:
|
|
|
|
Sci_PositionU currentPos;
|
|
|
|
Sci_Position currentLine;
|
|
|
|
Sci_Position lineEnd;
|
|
|
|
Sci_Position lineStartNext;
|
|
|
|
bool atLineStart;
|
2022-04-13 11:10:12 +00:00
|
|
|
bool atLineEnd = false;
|
2022-01-04 23:07:50 +00:00
|
|
|
int state;
|
2022-04-13 11:10:12 +00:00
|
|
|
int chPrev = 0;
|
|
|
|
int ch = 0;
|
|
|
|
Sci_Position width = 0;
|
|
|
|
int chNext = 0;
|
|
|
|
Sci_Position widthNext = 1;
|
2022-01-04 23:07:50 +00:00
|
|
|
|
|
|
|
StyleContext(Sci_PositionU startPos, Sci_PositionU length,
|
2022-04-13 11:10:12 +00:00
|
|
|
int initStyle, LexAccessor &styler_, char chMask = '\377');
|
2022-01-04 23:07:50 +00:00
|
|
|
// Deleted so StyleContext objects can not be copied.
|
|
|
|
StyleContext(const StyleContext &) = delete;
|
|
|
|
StyleContext &operator=(const StyleContext &) = delete;
|
|
|
|
void Complete() {
|
|
|
|
styler.ColourTo(currentPos - ((currentPos > lengthDocument) ? 2 : 1), state);
|
|
|
|
styler.Flush();
|
|
|
|
}
|
|
|
|
bool More() const noexcept {
|
|
|
|
return currentPos < endPos;
|
|
|
|
}
|
|
|
|
void Forward() {
|
|
|
|
if (currentPos < endPos) {
|
|
|
|
atLineStart = atLineEnd;
|
|
|
|
if (atLineStart) {
|
|
|
|
currentLine++;
|
|
|
|
lineEnd = styler.LineEnd(currentLine);
|
|
|
|
lineStartNext = styler.LineStart(currentLine+1);
|
|
|
|
}
|
|
|
|
chPrev = ch;
|
|
|
|
currentPos += width;
|
|
|
|
ch = chNext;
|
|
|
|
width = widthNext;
|
|
|
|
GetNextChar();
|
|
|
|
} else {
|
|
|
|
atLineStart = false;
|
|
|
|
chPrev = ' ';
|
|
|
|
ch = ' ';
|
|
|
|
chNext = ' ';
|
|
|
|
atLineEnd = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
void Forward(Sci_Position nb) {
|
|
|
|
for (Sci_Position i = 0; i < nb; i++) {
|
|
|
|
Forward();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
void ForwardBytes(Sci_Position nb) {
|
|
|
|
const Sci_PositionU forwardPos = currentPos + nb;
|
|
|
|
while (forwardPos > currentPos) {
|
|
|
|
const Sci_PositionU currentPosStart = currentPos;
|
|
|
|
Forward();
|
|
|
|
if (currentPos == currentPosStart) {
|
|
|
|
// Reached end
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
void ChangeState(int state_) noexcept {
|
|
|
|
state = state_;
|
|
|
|
}
|
|
|
|
void SetState(int state_) {
|
|
|
|
styler.ColourTo(currentPos - ((currentPos > lengthDocument) ? 2 : 1), state);
|
|
|
|
state = state_;
|
|
|
|
}
|
|
|
|
void ForwardSetState(int state_) {
|
|
|
|
Forward();
|
|
|
|
styler.ColourTo(currentPos - ((currentPos > lengthDocument) ? 2 : 1), state);
|
|
|
|
state = state_;
|
|
|
|
}
|
2023-02-09 16:57:24 +00:00
|
|
|
Sci_Position LengthCurrent() const noexcept {
|
2022-01-04 23:07:50 +00:00
|
|
|
return currentPos - styler.GetStartSegment();
|
|
|
|
}
|
|
|
|
int GetRelative(Sci_Position n, char chDefault='\0') {
|
2023-02-09 16:57:24 +00:00
|
|
|
const unsigned char chRelative = styler.SafeGetCharAt(currentPos + n, chDefault);
|
|
|
|
return chRelative;
|
2022-01-04 23:07:50 +00:00
|
|
|
}
|
|
|
|
int GetRelativeCharacter(Sci_Position n) {
|
|
|
|
if (n == 0)
|
|
|
|
return ch;
|
|
|
|
if (multiByteAccess) {
|
|
|
|
if ((currentPosLastRelative != currentPos) ||
|
|
|
|
((n > 0) && ((offsetRelative < 0) || (n < offsetRelative))) ||
|
|
|
|
((n < 0) && ((offsetRelative > 0) || (n > offsetRelative)))) {
|
|
|
|
posRelative = currentPos;
|
|
|
|
offsetRelative = 0;
|
|
|
|
}
|
|
|
|
const Sci_Position diffRelative = n - offsetRelative;
|
|
|
|
const Sci_Position posNew = multiByteAccess->GetRelativePosition(posRelative, diffRelative);
|
|
|
|
const int chReturn = multiByteAccess->GetCharacterAndWidth(posNew, nullptr);
|
|
|
|
posRelative = posNew;
|
|
|
|
currentPosLastRelative = currentPos;
|
|
|
|
offsetRelative = n;
|
|
|
|
return chReturn;
|
|
|
|
} else {
|
|
|
|
// fast version for single byte encodings
|
2023-02-09 16:57:24 +00:00
|
|
|
const unsigned char chRelative = styler.SafeGetCharAt(currentPos + n, 0);
|
|
|
|
return chRelative;
|
2022-01-04 23:07:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
bool MatchLineEnd() const noexcept {
|
2023-02-09 16:57:24 +00:00
|
|
|
const Sci_Position currentPosSigned = currentPos;
|
|
|
|
return currentPosSigned == lineEnd;
|
2022-01-04 23:07:50 +00:00
|
|
|
}
|
2023-02-09 16:57:24 +00:00
|
|
|
bool Match(char ch0) const noexcept {
|
|
|
|
const unsigned char uch0 = ch0;
|
|
|
|
return ch == uch0;
|
2022-01-04 23:07:50 +00:00
|
|
|
}
|
2023-02-09 16:57:24 +00:00
|
|
|
bool Match(char ch0, char ch1) const noexcept {
|
|
|
|
const unsigned char uch0 = ch0;
|
|
|
|
const unsigned char uch1 = ch1;
|
|
|
|
return (ch == uch0) && (chNext == uch1);
|
2022-01-04 23:07:50 +00:00
|
|
|
}
|
|
|
|
bool Match(const char *s) {
|
2023-02-09 16:57:24 +00:00
|
|
|
const unsigned char su = *s;
|
|
|
|
if (ch != su)
|
2022-01-04 23:07:50 +00:00
|
|
|
return false;
|
|
|
|
s++;
|
|
|
|
if (!*s)
|
|
|
|
return true;
|
2023-02-09 16:57:24 +00:00
|
|
|
const unsigned char sNext = *s;
|
|
|
|
if (chNext != sNext)
|
2022-01-04 23:07:50 +00:00
|
|
|
return false;
|
|
|
|
s++;
|
|
|
|
for (int n=2; *s; n++) {
|
|
|
|
if (*s != styler.SafeGetCharAt(currentPos+n, 0))
|
|
|
|
return false;
|
|
|
|
s++;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
// Non-inline
|
|
|
|
bool MatchIgnoreCase(const char *s);
|
|
|
|
bool MatchIgnoreCase2(const char *s);
|
|
|
|
void GetCurrent(char *s, Sci_PositionU len);
|
|
|
|
void GetCurrentLowered(char *s, Sci_PositionU len);
|
Update scintilla 5.3.4 and lexilla 5.2.4 with:
https://www.scintilla.org/scintilla534.zip
Released 8 March 2023.
Add multithreaded wrap to significantly improve performance of wrapping large files.
More typesafe bindings of *Full APIs in ScintillaCall. Feature #1477.
Fix overlapping of text with line end wrap marker. Bug #2378.
Fix clipping of line end wrap symbol for SC_WRAPVISUALFLAGLOC_END_BY_TEXT.
Where a multi-byte character contains multiple styles, display each byte as a representation. This makes it easier to see and fix lexers that change styles mid-character, commonly because they use fixed size buffers.
Fix a potential crash with autocompletion list fill-ups where a SCN_CHARADDED handler retriggered an autocompletion list, but with no items that match the typed character.
lexilla523
Released 8 March 2023.
Add scripts/PromoteNew.bat script to promote .new files after checking.
Makefile: Remove 1024-byte line length limit..
Ruby: Add new lexical classes for % literals SCE_RB_STRING_W (%w non-interpolable string array), SCE_RB_STRING_I (%i non-interpolable symbol array), SCE_RB_STRING_QI (%I interpolable symbol array), and SCE_RB_STRING_QS (%s symbol). Issue #124.
Ruby: Disambiguate %= which may be a quote or modulo assignment. Issue #124, Bug #1255, Bug #2182.
Ruby: Fix additional fold level for single character in SCE_RB_STRING_QW. Issue #132.
Ruby: Set SCE_RB_HERE_QQ for unquoted and double-quoted heredocs and SCE_RB_HERE_QX for backticks-quoted heredocs. Issue #134.
Ruby: Recognise #{} inside SCE_RB_HERE_QQ and SCE_RB_HERE_QX. Issue #134.
Ruby: Improve regex and heredoc recognition. Issue #136.
Ruby: Highlight #@, #@@ and #$ style interpolation. Issue #140.
Ruby: Fix folding for multiple heredocs started on one line. Fix folding when there is a space after heredoc opening delimiter. Issue #135.
YAML: Remove 1024-byte line length limit.
https://www.scintilla.org/lexilla524.zip
Released 13 March 2023.
C++: Fix failure to recognize keywords containing upper case. Issue #149.
GDScript: Support % and $ node paths. Issue #145, Pull request #146.
Close #13338
2023-03-10 02:37:21 +00:00
|
|
|
enum class Transform { none, lower };
|
|
|
|
void GetCurrentString(std::string &string, Transform transform);
|
2022-01-04 23:07:50 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|