mirror of
https://github.com/NohamR/Reclass.git
synced 2026-05-10 19:59:21 +00:00
Initial commit: ReclassX structured binary editor
This commit is contained in:
73
third_party/qscintilla/scintilla/lexlib/Accessor.cpp
vendored
Normal file
73
third_party/qscintilla/scintilla/lexlib/Accessor.cpp
vendored
Normal file
@@ -0,0 +1,73 @@
|
||||
// Scintilla source code edit control
|
||||
/** @file Accessor.cxx
|
||||
** Interfaces between Scintilla and lexers.
|
||||
**/
|
||||
// Copyright 1998-2002 by Neil Hodgson <neilh@scintilla.org>
|
||||
// The License.txt file describes the conditions under which this software may be distributed.
|
||||
|
||||
#include <cstdlib>
|
||||
#include <cassert>
|
||||
|
||||
#include "ILexer.h"
|
||||
#include "Scintilla.h"
|
||||
#include "SciLexer.h"
|
||||
|
||||
#include "PropSetSimple.h"
|
||||
#include "WordList.h"
|
||||
#include "LexAccessor.h"
|
||||
#include "Accessor.h"
|
||||
|
||||
using namespace Scintilla;
|
||||
|
||||
Accessor::Accessor(IDocument *pAccess_, PropSetSimple *pprops_) : LexAccessor(pAccess_), pprops(pprops_) {
|
||||
}
|
||||
|
||||
int Accessor::GetPropertyInt(const char *key, int defaultValue) const {
|
||||
return pprops->GetInt(key, defaultValue);
|
||||
}
|
||||
|
||||
int Accessor::IndentAmount(Sci_Position line, int *flags, PFNIsCommentLeader pfnIsCommentLeader) {
|
||||
const Sci_Position end = Length();
|
||||
int spaceFlags = 0;
|
||||
|
||||
// Determines the indentation level of the current line and also checks for consistent
|
||||
// indentation compared to the previous line.
|
||||
// Indentation is judged consistent when the indentation whitespace of each line lines
|
||||
// the same or the indentation of one line is a prefix of the other.
|
||||
|
||||
Sci_Position pos = LineStart(line);
|
||||
char ch = (*this)[pos];
|
||||
int indent = 0;
|
||||
bool inPrevPrefix = line > 0;
|
||||
Sci_Position posPrev = inPrevPrefix ? LineStart(line-1) : 0;
|
||||
while ((ch == ' ' || ch == '\t') && (pos < end)) {
|
||||
if (inPrevPrefix) {
|
||||
const char chPrev = (*this)[posPrev++];
|
||||
if (chPrev == ' ' || chPrev == '\t') {
|
||||
if (chPrev != ch)
|
||||
spaceFlags |= wsInconsistent;
|
||||
} else {
|
||||
inPrevPrefix = false;
|
||||
}
|
||||
}
|
||||
if (ch == ' ') {
|
||||
spaceFlags |= wsSpace;
|
||||
indent++;
|
||||
} else { // Tab
|
||||
spaceFlags |= wsTab;
|
||||
if (spaceFlags & wsSpace)
|
||||
spaceFlags |= wsSpaceTab;
|
||||
indent = (indent / 8 + 1) * 8;
|
||||
}
|
||||
ch = (*this)[++pos];
|
||||
}
|
||||
|
||||
*flags = spaceFlags;
|
||||
indent += SC_FOLDLEVELBASE;
|
||||
// if completely empty line or the start of a comment...
|
||||
if ((LineStart(line) == Length()) || (ch == ' ' || ch == '\t' || ch == '\n' || ch == '\r') ||
|
||||
(pfnIsCommentLeader && (*pfnIsCommentLeader)(*this, pos, end-pos)))
|
||||
return indent | SC_FOLDLEVELWHITEFLAG;
|
||||
else
|
||||
return indent;
|
||||
}
|
||||
31
third_party/qscintilla/scintilla/lexlib/Accessor.h
vendored
Normal file
31
third_party/qscintilla/scintilla/lexlib/Accessor.h
vendored
Normal file
@@ -0,0 +1,31 @@
|
||||
// Scintilla source code edit control
|
||||
/** @file Accessor.h
|
||||
** Interfaces between Scintilla and lexers.
|
||||
**/
|
||||
// Copyright 1998-2010 by Neil Hodgson <neilh@scintilla.org>
|
||||
// The License.txt file describes the conditions under which this software may be distributed.
|
||||
|
||||
#ifndef ACCESSOR_H
|
||||
#define ACCESSOR_H
|
||||
|
||||
namespace Scintilla {
|
||||
|
||||
enum { wsSpace=1, wsTab=2, wsSpaceTab=4, wsInconsistent=8 };
|
||||
|
||||
class Accessor;
|
||||
class WordList;
|
||||
class PropSetSimple;
|
||||
|
||||
typedef bool (*PFNIsCommentLeader)(Accessor &styler, Sci_Position pos, Sci_Position len);
|
||||
|
||||
class Accessor : public LexAccessor {
|
||||
public:
|
||||
PropSetSimple *pprops;
|
||||
Accessor(IDocument *pAccess_, PropSetSimple *pprops_);
|
||||
int GetPropertyInt(const char *, int defaultValue=0) const;
|
||||
int IndentAmount(Sci_Position line, int *flags, PFNIsCommentLeader pfnIsCommentLeader = 0);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
3966
third_party/qscintilla/scintilla/lexlib/CharacterCategory.cpp
vendored
Normal file
3966
third_party/qscintilla/scintilla/lexlib/CharacterCategory.cpp
vendored
Normal file
File diff suppressed because it is too large
Load Diff
33
third_party/qscintilla/scintilla/lexlib/CharacterCategory.h
vendored
Normal file
33
third_party/qscintilla/scintilla/lexlib/CharacterCategory.h
vendored
Normal file
@@ -0,0 +1,33 @@
|
||||
// Scintilla source code edit control
|
||||
/** @file CharacterCategory.h
|
||||
** Returns the Unicode general category of a character.
|
||||
**/
|
||||
// Copyright 2013 by Neil Hodgson <neilh@scintilla.org>
|
||||
// The License.txt file describes the conditions under which this software may be distributed.
|
||||
|
||||
#ifndef CHARACTERCATEGORY_H
|
||||
#define CHARACTERCATEGORY_H
|
||||
|
||||
namespace Scintilla {
|
||||
|
||||
enum CharacterCategory {
|
||||
ccLu, ccLl, ccLt, ccLm, ccLo,
|
||||
ccMn, ccMc, ccMe,
|
||||
ccNd, ccNl, ccNo,
|
||||
ccPc, ccPd, ccPs, ccPe, ccPi, ccPf, ccPo,
|
||||
ccSm, ccSc, ccSk, ccSo,
|
||||
ccZs, ccZl, ccZp,
|
||||
ccCc, ccCf, ccCs, ccCo, ccCn
|
||||
};
|
||||
|
||||
CharacterCategory CategoriseCharacter(int character);
|
||||
|
||||
// Common definitions of allowable characters in identifiers from UAX #31.
|
||||
bool IsIdStart(int character);
|
||||
bool IsIdContinue(int character);
|
||||
bool IsXidStart(int character);
|
||||
bool IsXidContinue(int character);
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
52
third_party/qscintilla/scintilla/lexlib/CharacterSet.cpp
vendored
Normal file
52
third_party/qscintilla/scintilla/lexlib/CharacterSet.cpp
vendored
Normal file
@@ -0,0 +1,52 @@
|
||||
// Scintilla source code edit control
|
||||
/** @file CharacterSet.cxx
|
||||
** Simple case functions for ASCII.
|
||||
** Lexer infrastructure.
|
||||
**/
|
||||
// Copyright 1998-2010 by Neil Hodgson <neilh@scintilla.org>
|
||||
// The License.txt file describes the conditions under which this software may be distributed.
|
||||
|
||||
#include <cstdlib>
|
||||
#include <cassert>
|
||||
|
||||
#include "CharacterSet.h"
|
||||
|
||||
using namespace Scintilla;
|
||||
|
||||
namespace Scintilla {
|
||||
|
||||
int CompareCaseInsensitive(const char *a, const char *b) {
|
||||
while (*a && *b) {
|
||||
if (*a != *b) {
|
||||
const char upperA = MakeUpperCase(*a);
|
||||
const char upperB = MakeUpperCase(*b);
|
||||
if (upperA != upperB)
|
||||
return upperA - upperB;
|
||||
}
|
||||
a++;
|
||||
b++;
|
||||
}
|
||||
// Either *a or *b is nul
|
||||
return *a - *b;
|
||||
}
|
||||
|
||||
int CompareNCaseInsensitive(const char *a, const char *b, size_t len) {
|
||||
while (*a && *b && len) {
|
||||
if (*a != *b) {
|
||||
const char upperA = MakeUpperCase(*a);
|
||||
const char upperB = MakeUpperCase(*b);
|
||||
if (upperA != upperB)
|
||||
return upperA - upperB;
|
||||
}
|
||||
a++;
|
||||
b++;
|
||||
len--;
|
||||
}
|
||||
if (len == 0)
|
||||
return 0;
|
||||
else
|
||||
// Either *a or *b is nul
|
||||
return *a - *b;
|
||||
}
|
||||
|
||||
}
|
||||
194
third_party/qscintilla/scintilla/lexlib/CharacterSet.h
vendored
Normal file
194
third_party/qscintilla/scintilla/lexlib/CharacterSet.h
vendored
Normal file
@@ -0,0 +1,194 @@
|
||||
// Scintilla source code edit control
|
||||
/** @file CharacterSet.h
|
||||
** Encapsulates a set of characters. Used to test if a character is within a set.
|
||||
**/
|
||||
// Copyright 2007 by Neil Hodgson <neilh@scintilla.org>
|
||||
// The License.txt file describes the conditions under which this software may be distributed.
|
||||
|
||||
#ifndef CHARACTERSET_H
|
||||
#define CHARACTERSET_H
|
||||
|
||||
namespace Scintilla {
|
||||
|
||||
class CharacterSet {
|
||||
int size;
|
||||
bool valueAfter;
|
||||
bool *bset;
|
||||
public:
|
||||
enum setBase {
|
||||
setNone=0,
|
||||
setLower=1,
|
||||
setUpper=2,
|
||||
setDigits=4,
|
||||
setAlpha=setLower|setUpper,
|
||||
setAlphaNum=setAlpha|setDigits
|
||||
};
|
||||
CharacterSet(setBase base=setNone, const char *initialSet="", int size_=0x80, bool valueAfter_=false) {
|
||||
size = size_;
|
||||
valueAfter = valueAfter_;
|
||||
bset = new bool[size];
|
||||
for (int i=0; i < size; i++) {
|
||||
bset[i] = false;
|
||||
}
|
||||
AddString(initialSet);
|
||||
if (base & setLower)
|
||||
AddString("abcdefghijklmnopqrstuvwxyz");
|
||||
if (base & setUpper)
|
||||
AddString("ABCDEFGHIJKLMNOPQRSTUVWXYZ");
|
||||
if (base & setDigits)
|
||||
AddString("0123456789");
|
||||
}
|
||||
CharacterSet(const CharacterSet &other) {
|
||||
size = other.size;
|
||||
valueAfter = other.valueAfter;
|
||||
bset = new bool[size];
|
||||
for (int i=0; i < size; i++) {
|
||||
bset[i] = other.bset[i];
|
||||
}
|
||||
}
|
||||
CharacterSet &operator=(CharacterSet &&other) {
|
||||
if (this != &other) {
|
||||
delete []bset;
|
||||
size = other.size;
|
||||
valueAfter = other.valueAfter;
|
||||
bset = other.bset;
|
||||
other.size = 0;
|
||||
other.bset = nullptr;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
~CharacterSet() {
|
||||
delete []bset;
|
||||
bset = nullptr;
|
||||
size = 0;
|
||||
}
|
||||
CharacterSet &operator=(const CharacterSet &other) {
|
||||
if (this != &other) {
|
||||
bool *bsetNew = new bool[other.size];
|
||||
for (int i=0; i < other.size; i++) {
|
||||
bsetNew[i] = other.bset[i];
|
||||
}
|
||||
delete []bset;
|
||||
size = other.size;
|
||||
valueAfter = other.valueAfter;
|
||||
bset = bsetNew;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
void Add(int val) {
|
||||
assert(val >= 0);
|
||||
assert(val < size);
|
||||
bset[val] = true;
|
||||
}
|
||||
void AddString(const char *setToAdd) {
|
||||
for (const char *cp=setToAdd; *cp; cp++) {
|
||||
int val = static_cast<unsigned char>(*cp);
|
||||
assert(val >= 0);
|
||||
assert(val < size);
|
||||
bset[val] = true;
|
||||
}
|
||||
}
|
||||
bool Contains(int val) const {
|
||||
// val being -ve is valid (or there is a sign extension bug elsewhere.
|
||||
//assert(val >= 0);
|
||||
if (val < 0) return false;
|
||||
return (val < size) ? bset[val] : valueAfter;
|
||||
}
|
||||
};
|
||||
|
||||
// Functions for classifying characters
|
||||
|
||||
inline bool IsASpace(int ch) {
|
||||
return (ch == ' ') || ((ch >= 0x09) && (ch <= 0x0d));
|
||||
}
|
||||
|
||||
inline bool IsASpaceOrTab(int ch) {
|
||||
return (ch == ' ') || (ch == '\t');
|
||||
}
|
||||
|
||||
inline bool IsADigit(int ch) {
|
||||
return (ch >= '0') && (ch <= '9');
|
||||
}
|
||||
|
||||
inline bool IsADigit(int ch, int base) {
|
||||
if (base <= 10) {
|
||||
return (ch >= '0') && (ch < '0' + base);
|
||||
} else {
|
||||
return ((ch >= '0') && (ch <= '9')) ||
|
||||
((ch >= 'A') && (ch < 'A' + base - 10)) ||
|
||||
((ch >= 'a') && (ch < 'a' + base - 10));
|
||||
}
|
||||
}
|
||||
|
||||
inline bool IsASCII(int ch) {
|
||||
return (ch >= 0) && (ch < 0x80);
|
||||
}
|
||||
|
||||
inline bool IsLowerCase(int ch) {
|
||||
return (ch >= 'a') && (ch <= 'z');
|
||||
}
|
||||
|
||||
inline bool IsUpperCase(int ch) {
|
||||
return (ch >= 'A') && (ch <= 'Z');
|
||||
}
|
||||
|
||||
inline bool IsAlphaNumeric(int ch) {
|
||||
return
|
||||
((ch >= '0') && (ch <= '9')) ||
|
||||
((ch >= 'a') && (ch <= 'z')) ||
|
||||
((ch >= 'A') && (ch <= 'Z'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a character is a space.
|
||||
* This is ASCII specific but is safe with chars >= 0x80.
|
||||
*/
|
||||
inline bool isspacechar(int ch) {
|
||||
return (ch == ' ') || ((ch >= 0x09) && (ch <= 0x0d));
|
||||
}
|
||||
|
||||
inline bool iswordchar(int ch) {
|
||||
return IsAlphaNumeric(ch) || ch == '.' || ch == '_';
|
||||
}
|
||||
|
||||
inline bool iswordstart(int ch) {
|
||||
return IsAlphaNumeric(ch) || ch == '_';
|
||||
}
|
||||
|
||||
inline bool isoperator(int ch) {
|
||||
if (IsAlphaNumeric(ch))
|
||||
return false;
|
||||
if (ch == '%' || ch == '^' || ch == '&' || ch == '*' ||
|
||||
ch == '(' || ch == ')' || ch == '-' || ch == '+' ||
|
||||
ch == '=' || ch == '|' || ch == '{' || ch == '}' ||
|
||||
ch == '[' || ch == ']' || ch == ':' || ch == ';' ||
|
||||
ch == '<' || ch == '>' || ch == ',' || ch == '/' ||
|
||||
ch == '?' || ch == '!' || ch == '.' || ch == '~')
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
// Simple case functions for ASCII supersets.
|
||||
|
||||
template <typename T>
|
||||
inline T MakeUpperCase(T ch) {
|
||||
if (ch < 'a' || ch > 'z')
|
||||
return ch;
|
||||
else
|
||||
return ch - 'a' + 'A';
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline T MakeLowerCase(T ch) {
|
||||
if (ch < 'A' || ch > 'Z')
|
||||
return ch;
|
||||
else
|
||||
return ch - 'A' + 'a';
|
||||
}
|
||||
|
||||
int CompareCaseInsensitive(const char *a, const char *b);
|
||||
int CompareNCaseInsensitive(const char *a, const char *b, size_t len);
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
125
third_party/qscintilla/scintilla/lexlib/DefaultLexer.cpp
vendored
Normal file
125
third_party/qscintilla/scintilla/lexlib/DefaultLexer.cpp
vendored
Normal file
@@ -0,0 +1,125 @@
|
||||
// Scintilla source code edit control
|
||||
/** @file DefaultLexer.cxx
|
||||
** A lexer base class that provides reasonable default behaviour.
|
||||
**/
|
||||
// Copyright 2017 by Neil Hodgson <neilh@scintilla.org>
|
||||
// The License.txt file describes the conditions under which this software may be distributed.
|
||||
|
||||
#include <cstdlib>
|
||||
#include <cassert>
|
||||
#include <cstring>
|
||||
|
||||
#include "ILexer.h"
|
||||
#include "Scintilla.h"
|
||||
#include "SciLexer.h"
|
||||
|
||||
#include "PropSetSimple.h"
|
||||
#include "WordList.h"
|
||||
#include "LexAccessor.h"
|
||||
#include "Accessor.h"
|
||||
#include "LexerModule.h"
|
||||
#include "DefaultLexer.h"
|
||||
|
||||
using namespace Scintilla;
|
||||
|
||||
static const char styleSubable[] = { 0 };
|
||||
|
||||
DefaultLexer::DefaultLexer(const LexicalClass *lexClasses_, size_t nClasses_) :
|
||||
lexClasses(lexClasses_), nClasses(nClasses_) {
|
||||
}
|
||||
|
||||
DefaultLexer::~DefaultLexer() {
|
||||
}
|
||||
|
||||
void SCI_METHOD DefaultLexer::Release() {
|
||||
delete this;
|
||||
}
|
||||
|
||||
int SCI_METHOD DefaultLexer::Version() const {
|
||||
return lvMetaData;
|
||||
}
|
||||
|
||||
const char * SCI_METHOD DefaultLexer::PropertyNames() {
|
||||
return "";
|
||||
}
|
||||
|
||||
int SCI_METHOD DefaultLexer::PropertyType(const char *) {
|
||||
return SC_TYPE_BOOLEAN;
|
||||
}
|
||||
|
||||
const char * SCI_METHOD DefaultLexer::DescribeProperty(const char *) {
|
||||
return "";
|
||||
}
|
||||
|
||||
Sci_Position SCI_METHOD DefaultLexer::PropertySet(const char *, const char *) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
const char * SCI_METHOD DefaultLexer::DescribeWordListSets() {
|
||||
return "";
|
||||
}
|
||||
|
||||
Sci_Position SCI_METHOD DefaultLexer::WordListSet(int, const char *) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
void SCI_METHOD DefaultLexer::Fold(Sci_PositionU, Sci_Position, int, IDocument *) {
|
||||
}
|
||||
|
||||
void * SCI_METHOD DefaultLexer::PrivateCall(int, void *) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
int SCI_METHOD DefaultLexer::LineEndTypesSupported() {
|
||||
return SC_LINE_END_TYPE_DEFAULT;
|
||||
}
|
||||
|
||||
int SCI_METHOD DefaultLexer::AllocateSubStyles(int, int) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
int SCI_METHOD DefaultLexer::SubStylesStart(int) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
int SCI_METHOD DefaultLexer::SubStylesLength(int) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int SCI_METHOD DefaultLexer::StyleFromSubStyle(int subStyle) {
|
||||
return subStyle;
|
||||
}
|
||||
|
||||
int SCI_METHOD DefaultLexer::PrimaryStyleFromStyle(int style) {
|
||||
return style;
|
||||
}
|
||||
|
||||
void SCI_METHOD DefaultLexer::FreeSubStyles() {
|
||||
}
|
||||
|
||||
void SCI_METHOD DefaultLexer::SetIdentifiers(int, const char *) {
|
||||
}
|
||||
|
||||
int SCI_METHOD DefaultLexer::DistanceToSecondaryStyles() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
const char * SCI_METHOD DefaultLexer::GetSubStyleBases() {
|
||||
return styleSubable;
|
||||
}
|
||||
|
||||
int SCI_METHOD DefaultLexer::NamedStyles() {
|
||||
return static_cast<int>(nClasses);
|
||||
}
|
||||
|
||||
const char * SCI_METHOD DefaultLexer::NameOfStyle(int style) {
|
||||
return (style < NamedStyles()) ? lexClasses[style].name : "";
|
||||
}
|
||||
|
||||
const char * SCI_METHOD DefaultLexer::TagsOfStyle(int style) {
|
||||
return (style < NamedStyles()) ? lexClasses[style].tags : "";
|
||||
}
|
||||
|
||||
const char * SCI_METHOD DefaultLexer::DescriptionOfStyle(int style) {
|
||||
return (style < NamedStyles()) ? lexClasses[style].description : "";
|
||||
}
|
||||
51
third_party/qscintilla/scintilla/lexlib/DefaultLexer.h
vendored
Normal file
51
third_party/qscintilla/scintilla/lexlib/DefaultLexer.h
vendored
Normal file
@@ -0,0 +1,51 @@
|
||||
// Scintilla source code edit control
|
||||
/** @file DefaultLexer.h
|
||||
** A lexer base class with default empty implementations of methods.
|
||||
** For lexers that do not support all features so do not need real implementations.
|
||||
** Does have real implementation for style metadata.
|
||||
**/
|
||||
// Copyright 2017 by Neil Hodgson <neilh@scintilla.org>
|
||||
// The License.txt file describes the conditions under which this software may be distributed.
|
||||
|
||||
#ifndef DEFAULTLEXER_H
|
||||
#define DEFAULTLEXER_H
|
||||
|
||||
namespace Scintilla {
|
||||
|
||||
// A simple lexer with no state
|
||||
class DefaultLexer : public ILexerWithMetaData {
|
||||
const LexicalClass *lexClasses;
|
||||
size_t nClasses;
|
||||
public:
|
||||
DefaultLexer(const LexicalClass *lexClasses_ = nullptr, size_t nClasses_ = 0);
|
||||
virtual ~DefaultLexer();
|
||||
void SCI_METHOD Release() override;
|
||||
int SCI_METHOD Version() const override;
|
||||
const char * SCI_METHOD PropertyNames() override;
|
||||
int SCI_METHOD PropertyType(const char *name) override;
|
||||
const char * SCI_METHOD DescribeProperty(const char *name) override;
|
||||
Sci_Position SCI_METHOD PropertySet(const char *key, const char *val) override;
|
||||
const char * SCI_METHOD DescribeWordListSets() override;
|
||||
Sci_Position SCI_METHOD WordListSet(int n, const char *wl) override;
|
||||
void SCI_METHOD Lex(Sci_PositionU startPos, Sci_Position lengthDoc, int initStyle, IDocument *pAccess) override = 0;
|
||||
void SCI_METHOD Fold(Sci_PositionU startPos, Sci_Position lengthDoc, int initStyle, IDocument *pAccess) override;
|
||||
void * SCI_METHOD PrivateCall(int operation, void *pointer) override;
|
||||
int SCI_METHOD LineEndTypesSupported() override;
|
||||
int SCI_METHOD AllocateSubStyles(int styleBase, int numberStyles) override;
|
||||
int SCI_METHOD SubStylesStart(int styleBase) override;
|
||||
int SCI_METHOD SubStylesLength(int styleBase) override;
|
||||
int SCI_METHOD StyleFromSubStyle(int subStyle) override;
|
||||
int SCI_METHOD PrimaryStyleFromStyle(int style) override;
|
||||
void SCI_METHOD FreeSubStyles() override;
|
||||
void SCI_METHOD SetIdentifiers(int style, const char *identifiers) override;
|
||||
int SCI_METHOD DistanceToSecondaryStyles() override;
|
||||
const char * SCI_METHOD GetSubStyleBases() override;
|
||||
int SCI_METHOD NamedStyles() override;
|
||||
const char * SCI_METHOD NameOfStyle(int style) override;
|
||||
const char * SCI_METHOD TagsOfStyle(int style) override;
|
||||
const char * SCI_METHOD DescriptionOfStyle(int style) override;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
208
third_party/qscintilla/scintilla/lexlib/LexAccessor.h
vendored
Normal file
208
third_party/qscintilla/scintilla/lexlib/LexAccessor.h
vendored
Normal file
@@ -0,0 +1,208 @@
|
||||
// Scintilla source code edit control
|
||||
/** @file LexAccessor.h
|
||||
** Interfaces between Scintilla and lexers.
|
||||
**/
|
||||
// Copyright 1998-2010 by Neil Hodgson <neilh@scintilla.org>
|
||||
// The License.txt file describes the conditions under which this software may be distributed.
|
||||
|
||||
#ifndef LEXACCESSOR_H
|
||||
#define LEXACCESSOR_H
|
||||
|
||||
namespace Scintilla {
|
||||
|
||||
enum EncodingType { enc8bit, encUnicode, encDBCS };
|
||||
|
||||
class LexAccessor {
|
||||
private:
|
||||
IDocument *pAccess;
|
||||
enum {extremePosition=0x7FFFFFFF};
|
||||
/** @a bufferSize is a trade off between time taken to copy the characters
|
||||
* and retrieval overhead.
|
||||
* @a slopSize positions the buffer before the desired position
|
||||
* in case there is some backtracking. */
|
||||
enum {bufferSize=4000, slopSize=bufferSize/8};
|
||||
char buf[bufferSize+1];
|
||||
Sci_Position startPos;
|
||||
Sci_Position endPos;
|
||||
int codePage;
|
||||
enum EncodingType encodingType;
|
||||
Sci_Position lenDoc;
|
||||
char styleBuf[bufferSize];
|
||||
Sci_Position validLen;
|
||||
Sci_PositionU startSeg;
|
||||
Sci_Position startPosStyling;
|
||||
int documentVersion;
|
||||
|
||||
void Fill(Sci_Position position) {
|
||||
startPos = position - slopSize;
|
||||
if (startPos + bufferSize > lenDoc)
|
||||
startPos = lenDoc - bufferSize;
|
||||
if (startPos < 0)
|
||||
startPos = 0;
|
||||
endPos = startPos + bufferSize;
|
||||
if (endPos > lenDoc)
|
||||
endPos = lenDoc;
|
||||
|
||||
pAccess->GetCharRange(buf, startPos, endPos-startPos);
|
||||
buf[endPos-startPos] = '\0';
|
||||
}
|
||||
|
||||
public:
|
||||
explicit LexAccessor(IDocument *pAccess_) :
|
||||
pAccess(pAccess_), startPos(extremePosition), endPos(0),
|
||||
codePage(pAccess->CodePage()),
|
||||
encodingType(enc8bit),
|
||||
lenDoc(pAccess->Length()),
|
||||
validLen(0),
|
||||
startSeg(0), startPosStyling(0),
|
||||
documentVersion(pAccess->Version()) {
|
||||
// Prevent warnings by static analyzers about uninitialized buf and styleBuf.
|
||||
buf[0] = 0;
|
||||
styleBuf[0] = 0;
|
||||
switch (codePage) {
|
||||
case 65001:
|
||||
encodingType = encUnicode;
|
||||
break;
|
||||
case 932:
|
||||
case 936:
|
||||
case 949:
|
||||
case 950:
|
||||
case 1361:
|
||||
encodingType = encDBCS;
|
||||
}
|
||||
}
|
||||
char operator[](Sci_Position position) {
|
||||
if (position < startPos || position >= endPos) {
|
||||
Fill(position);
|
||||
}
|
||||
return buf[position - startPos];
|
||||
}
|
||||
IDocumentWithLineEnd *MultiByteAccess() const {
|
||||
if (documentVersion >= dvLineEnd) {
|
||||
return static_cast<IDocumentWithLineEnd *>(pAccess);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
/** Safe version of operator[], returning a defined value for invalid position. */
|
||||
char SafeGetCharAt(Sci_Position position, char chDefault=' ') {
|
||||
if (position < startPos || position >= endPos) {
|
||||
Fill(position);
|
||||
if (position < startPos || position >= endPos) {
|
||||
// Position is outside range of document
|
||||
return chDefault;
|
||||
}
|
||||
}
|
||||
return buf[position - startPos];
|
||||
}
|
||||
bool IsLeadByte(char ch) const {
|
||||
return pAccess->IsDBCSLeadByte(ch);
|
||||
}
|
||||
EncodingType Encoding() const {
|
||||
return encodingType;
|
||||
}
|
||||
bool Match(Sci_Position pos, const char *s) {
|
||||
for (int i=0; *s; i++) {
|
||||
if (*s != SafeGetCharAt(pos+i))
|
||||
return false;
|
||||
s++;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
char StyleAt(Sci_Position position) const {
|
||||
return pAccess->StyleAt(position);
|
||||
}
|
||||
Sci_Position GetLine(Sci_Position position) const {
|
||||
return pAccess->LineFromPosition(position);
|
||||
}
|
||||
Sci_Position LineStart(Sci_Position line) const {
|
||||
return pAccess->LineStart(line);
|
||||
}
|
||||
Sci_Position LineEnd(Sci_Position line) {
|
||||
if (documentVersion >= dvLineEnd) {
|
||||
return (static_cast<IDocumentWithLineEnd *>(pAccess))->LineEnd(line);
|
||||
} else {
|
||||
// Old interface means only '\r', '\n' and '\r\n' line ends.
|
||||
Sci_Position startNext = pAccess->LineStart(line+1);
|
||||
const char chLineEnd = SafeGetCharAt(startNext-1);
|
||||
if (chLineEnd == '\n' && (SafeGetCharAt(startNext-2) == '\r'))
|
||||
return startNext - 2;
|
||||
else
|
||||
return startNext - 1;
|
||||
}
|
||||
}
|
||||
int LevelAt(Sci_Position line) const {
|
||||
return pAccess->GetLevel(line);
|
||||
}
|
||||
Sci_Position Length() const {
|
||||
return lenDoc;
|
||||
}
|
||||
void Flush() {
|
||||
if (validLen > 0) {
|
||||
pAccess->SetStyles(validLen, styleBuf);
|
||||
startPosStyling += validLen;
|
||||
validLen = 0;
|
||||
}
|
||||
}
|
||||
int GetLineState(Sci_Position line) const {
|
||||
return pAccess->GetLineState(line);
|
||||
}
|
||||
int SetLineState(Sci_Position line, int state) {
|
||||
return pAccess->SetLineState(line, state);
|
||||
}
|
||||
// Style setting
|
||||
void StartAt(Sci_PositionU start) {
|
||||
pAccess->StartStyling(start, '\377');
|
||||
startPosStyling = start;
|
||||
}
|
||||
Sci_PositionU GetStartSegment() const {
|
||||
return startSeg;
|
||||
}
|
||||
void StartSegment(Sci_PositionU pos) {
|
||||
startSeg = pos;
|
||||
}
|
||||
void ColourTo(Sci_PositionU pos, int chAttr) {
|
||||
// Only perform styling if non empty range
|
||||
if (pos != startSeg - 1) {
|
||||
//assert(pos >= startSeg);
|
||||
if (pos < startSeg) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (validLen + (pos - startSeg + 1) >= bufferSize)
|
||||
Flush();
|
||||
const char attr = static_cast<char>(chAttr);
|
||||
if (validLen + (pos - startSeg + 1) >= bufferSize) {
|
||||
// Too big for buffer so send directly
|
||||
pAccess->SetStyleFor(pos - startSeg + 1, attr);
|
||||
} else {
|
||||
for (Sci_PositionU i = startSeg; i <= pos; i++) {
|
||||
assert((startPosStyling + validLen) < Length());
|
||||
styleBuf[validLen++] = attr;
|
||||
}
|
||||
}
|
||||
}
|
||||
startSeg = pos+1;
|
||||
}
|
||||
void SetLevel(Sci_Position line, int level) {
|
||||
pAccess->SetLevel(line, level);
|
||||
}
|
||||
void IndicatorFill(Sci_Position start, Sci_Position end, int indicator, int value) {
|
||||
pAccess->DecorationSetCurrentIndicator(indicator);
|
||||
pAccess->DecorationFillRange(start, value, end - start);
|
||||
}
|
||||
|
||||
void ChangeLexerState(Sci_Position start, Sci_Position end) {
|
||||
pAccess->ChangeLexerState(start, end);
|
||||
}
|
||||
};
|
||||
|
||||
struct LexicalClass {
|
||||
int value;
|
||||
const char *name;
|
||||
const char *tags;
|
||||
const char *description;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
144
third_party/qscintilla/scintilla/lexlib/LexerBase.cpp
vendored
Normal file
144
third_party/qscintilla/scintilla/lexlib/LexerBase.cpp
vendored
Normal file
@@ -0,0 +1,144 @@
|
||||
// Scintilla source code edit control
|
||||
/** @file LexerBase.cxx
|
||||
** A simple lexer with no state.
|
||||
**/
|
||||
// Copyright 1998-2010 by Neil Hodgson <neilh@scintilla.org>
|
||||
// The License.txt file describes the conditions under which this software may be distributed.
|
||||
|
||||
#include <cstdlib>
|
||||
#include <cassert>
|
||||
#include <cstring>
|
||||
|
||||
#include "ILexer.h"
|
||||
#include "Scintilla.h"
|
||||
#include "SciLexer.h"
|
||||
|
||||
#include "PropSetSimple.h"
|
||||
#include "WordList.h"
|
||||
#include "LexAccessor.h"
|
||||
#include "Accessor.h"
|
||||
#include "LexerModule.h"
|
||||
#include "LexerBase.h"
|
||||
|
||||
using namespace Scintilla;
|
||||
|
||||
static const char styleSubable[] = { 0 };
|
||||
|
||||
LexerBase::LexerBase(const LexicalClass *lexClasses_, size_t nClasses_) :
|
||||
lexClasses(lexClasses_), nClasses(nClasses_) {
|
||||
for (int wl = 0; wl < numWordLists; wl++)
|
||||
keyWordLists[wl] = new WordList;
|
||||
keyWordLists[numWordLists] = 0;
|
||||
}
|
||||
|
||||
LexerBase::~LexerBase() {
|
||||
for (int wl = 0; wl < numWordLists; wl++) {
|
||||
delete keyWordLists[wl];
|
||||
keyWordLists[wl] = 0;
|
||||
}
|
||||
keyWordLists[numWordLists] = 0;
|
||||
}
|
||||
|
||||
void SCI_METHOD LexerBase::Release() {
|
||||
delete this;
|
||||
}
|
||||
|
||||
int SCI_METHOD LexerBase::Version() const {
|
||||
return lvMetaData;
|
||||
}
|
||||
|
||||
const char * SCI_METHOD LexerBase::PropertyNames() {
|
||||
return "";
|
||||
}
|
||||
|
||||
int SCI_METHOD LexerBase::PropertyType(const char *) {
|
||||
return SC_TYPE_BOOLEAN;
|
||||
}
|
||||
|
||||
const char * SCI_METHOD LexerBase::DescribeProperty(const char *) {
|
||||
return "";
|
||||
}
|
||||
|
||||
Sci_Position SCI_METHOD LexerBase::PropertySet(const char *key, const char *val) {
|
||||
const char *valOld = props.Get(key);
|
||||
if (strcmp(val, valOld) != 0) {
|
||||
props.Set(key, val, strlen(key), strlen(val));
|
||||
return 0;
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
const char * SCI_METHOD LexerBase::DescribeWordListSets() {
|
||||
return "";
|
||||
}
|
||||
|
||||
Sci_Position SCI_METHOD LexerBase::WordListSet(int n, const char *wl) {
|
||||
if (n < numWordLists) {
|
||||
WordList wlNew;
|
||||
wlNew.Set(wl);
|
||||
if (*keyWordLists[n] != wlNew) {
|
||||
keyWordLists[n]->Set(wl);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
void * SCI_METHOD LexerBase::PrivateCall(int, void *) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
int SCI_METHOD LexerBase::LineEndTypesSupported() {
|
||||
return SC_LINE_END_TYPE_DEFAULT;
|
||||
}
|
||||
|
||||
int SCI_METHOD LexerBase::AllocateSubStyles(int, int) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
int SCI_METHOD LexerBase::SubStylesStart(int) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
int SCI_METHOD LexerBase::SubStylesLength(int) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int SCI_METHOD LexerBase::StyleFromSubStyle(int subStyle) {
|
||||
return subStyle;
|
||||
}
|
||||
|
||||
int SCI_METHOD LexerBase::PrimaryStyleFromStyle(int style) {
|
||||
return style;
|
||||
}
|
||||
|
||||
void SCI_METHOD LexerBase::FreeSubStyles() {
|
||||
}
|
||||
|
||||
void SCI_METHOD LexerBase::SetIdentifiers(int, const char *) {
|
||||
}
|
||||
|
||||
int SCI_METHOD LexerBase::DistanceToSecondaryStyles() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
const char * SCI_METHOD LexerBase::GetSubStyleBases() {
|
||||
return styleSubable;
|
||||
}
|
||||
|
||||
int SCI_METHOD LexerBase::NamedStyles() {
|
||||
return static_cast<int>(nClasses);
|
||||
}
|
||||
|
||||
const char * SCI_METHOD LexerBase::NameOfStyle(int style) {
|
||||
return (style < NamedStyles()) ? lexClasses[style].name : "";
|
||||
}
|
||||
|
||||
const char * SCI_METHOD LexerBase::TagsOfStyle(int style) {
|
||||
return (style < NamedStyles()) ? lexClasses[style].tags : "";
|
||||
}
|
||||
|
||||
const char * SCI_METHOD LexerBase::DescriptionOfStyle(int style) {
|
||||
return (style < NamedStyles()) ? lexClasses[style].description : "";
|
||||
}
|
||||
53
third_party/qscintilla/scintilla/lexlib/LexerBase.h
vendored
Normal file
53
third_party/qscintilla/scintilla/lexlib/LexerBase.h
vendored
Normal file
@@ -0,0 +1,53 @@
|
||||
// Scintilla source code edit control
|
||||
/** @file LexerBase.h
|
||||
** A simple lexer with no state.
|
||||
**/
|
||||
// Copyright 1998-2010 by Neil Hodgson <neilh@scintilla.org>
|
||||
// The License.txt file describes the conditions under which this software may be distributed.
|
||||
|
||||
#ifndef LEXERBASE_H
|
||||
#define LEXERBASE_H
|
||||
|
||||
namespace Scintilla {
|
||||
|
||||
// A simple lexer with no state
|
||||
class LexerBase : public ILexerWithMetaData {
|
||||
protected:
|
||||
const LexicalClass *lexClasses;
|
||||
size_t nClasses;
|
||||
PropSetSimple props;
|
||||
enum {numWordLists=KEYWORDSET_MAX+1};
|
||||
WordList *keyWordLists[numWordLists+1];
|
||||
public:
|
||||
LexerBase(const LexicalClass *lexClasses_=nullptr, size_t nClasses_=0);
|
||||
virtual ~LexerBase();
|
||||
void SCI_METHOD Release() override;
|
||||
int SCI_METHOD Version() const override;
|
||||
const char * SCI_METHOD PropertyNames() override;
|
||||
int SCI_METHOD PropertyType(const char *name) override;
|
||||
const char * SCI_METHOD DescribeProperty(const char *name) override;
|
||||
Sci_Position SCI_METHOD PropertySet(const char *key, const char *val) override;
|
||||
const char * SCI_METHOD DescribeWordListSets() override;
|
||||
Sci_Position SCI_METHOD WordListSet(int n, const char *wl) override;
|
||||
void SCI_METHOD Lex(Sci_PositionU startPos, Sci_Position lengthDoc, int initStyle, IDocument *pAccess) override = 0;
|
||||
void SCI_METHOD Fold(Sci_PositionU startPos, Sci_Position lengthDoc, int initStyle, IDocument *pAccess) override = 0;
|
||||
void * SCI_METHOD PrivateCall(int operation, void *pointer) override;
|
||||
int SCI_METHOD LineEndTypesSupported() override;
|
||||
int SCI_METHOD AllocateSubStyles(int styleBase, int numberStyles) override;
|
||||
int SCI_METHOD SubStylesStart(int styleBase) override;
|
||||
int SCI_METHOD SubStylesLength(int styleBase) override;
|
||||
int SCI_METHOD StyleFromSubStyle(int subStyle) override;
|
||||
int SCI_METHOD PrimaryStyleFromStyle(int style) override;
|
||||
void SCI_METHOD FreeSubStyles() override;
|
||||
void SCI_METHOD SetIdentifiers(int style, const char *identifiers) override;
|
||||
int SCI_METHOD DistanceToSecondaryStyles() override;
|
||||
const char * SCI_METHOD GetSubStyleBases() override;
|
||||
int SCI_METHOD NamedStyles() override;
|
||||
const char * SCI_METHOD NameOfStyle(int style) override;
|
||||
const char * SCI_METHOD TagsOfStyle(int style) override;
|
||||
const char * SCI_METHOD DescriptionOfStyle(int style) override;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
126
third_party/qscintilla/scintilla/lexlib/LexerModule.cpp
vendored
Normal file
126
third_party/qscintilla/scintilla/lexlib/LexerModule.cpp
vendored
Normal file
@@ -0,0 +1,126 @@
|
||||
// Scintilla source code edit control
|
||||
/** @file LexerModule.cxx
|
||||
** Colourise for particular languages.
|
||||
**/
|
||||
// Copyright 1998-2010 by Neil Hodgson <neilh@scintilla.org>
|
||||
// The License.txt file describes the conditions under which this software may be distributed.
|
||||
|
||||
#include <cstdlib>
|
||||
#include <cassert>
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "ILexer.h"
|
||||
#include "Scintilla.h"
|
||||
#include "SciLexer.h"
|
||||
|
||||
#include "PropSetSimple.h"
|
||||
#include "WordList.h"
|
||||
#include "LexAccessor.h"
|
||||
#include "Accessor.h"
|
||||
#include "LexerModule.h"
|
||||
#include "LexerBase.h"
|
||||
#include "LexerSimple.h"
|
||||
|
||||
using namespace Scintilla;
|
||||
|
||||
LexerModule::LexerModule(int language_,
|
||||
LexerFunction fnLexer_,
|
||||
const char *languageName_,
|
||||
LexerFunction fnFolder_,
|
||||
const char *const wordListDescriptions_[],
|
||||
const LexicalClass *lexClasses_,
|
||||
size_t nClasses_) :
|
||||
language(language_),
|
||||
fnLexer(fnLexer_),
|
||||
fnFolder(fnFolder_),
|
||||
fnFactory(nullptr),
|
||||
wordListDescriptions(wordListDescriptions_),
|
||||
lexClasses(lexClasses_),
|
||||
nClasses(nClasses_),
|
||||
languageName(languageName_) {
|
||||
}
|
||||
|
||||
LexerModule::LexerModule(int language_,
|
||||
LexerFactoryFunction fnFactory_,
|
||||
const char *languageName_,
|
||||
const char * const wordListDescriptions_[]) :
|
||||
language(language_),
|
||||
fnLexer(nullptr),
|
||||
fnFolder(nullptr),
|
||||
fnFactory(fnFactory_),
|
||||
wordListDescriptions(wordListDescriptions_),
|
||||
lexClasses(nullptr),
|
||||
nClasses(0),
|
||||
languageName(languageName_) {
|
||||
}
|
||||
|
||||
LexerModule::~LexerModule() {
|
||||
}
|
||||
|
||||
int LexerModule::GetLanguage() const {
|
||||
return language;
|
||||
}
|
||||
|
||||
int LexerModule::GetNumWordLists() const {
|
||||
if (!wordListDescriptions) {
|
||||
return -1;
|
||||
} else {
|
||||
int numWordLists = 0;
|
||||
|
||||
while (wordListDescriptions[numWordLists]) {
|
||||
++numWordLists;
|
||||
}
|
||||
|
||||
return numWordLists;
|
||||
}
|
||||
}
|
||||
|
||||
const char *LexerModule::GetWordListDescription(int index) const {
|
||||
assert(index < GetNumWordLists());
|
||||
if (!wordListDescriptions || (index >= GetNumWordLists())) {
|
||||
return "";
|
||||
} else {
|
||||
return wordListDescriptions[index];
|
||||
}
|
||||
}
|
||||
|
||||
const LexicalClass *LexerModule::LexClasses() const {
|
||||
return lexClasses;
|
||||
}
|
||||
|
||||
size_t LexerModule::NamedStyles() const {
|
||||
return nClasses;
|
||||
}
|
||||
|
||||
ILexer *LexerModule::Create() const {
|
||||
if (fnFactory)
|
||||
return fnFactory();
|
||||
else
|
||||
return new LexerSimple(this);
|
||||
}
|
||||
|
||||
void LexerModule::Lex(Sci_PositionU startPos, Sci_Position lengthDoc, int initStyle,
|
||||
WordList *keywordlists[], Accessor &styler) const {
|
||||
if (fnLexer)
|
||||
fnLexer(startPos, lengthDoc, initStyle, keywordlists, styler);
|
||||
}
|
||||
|
||||
void LexerModule::Fold(Sci_PositionU startPos, Sci_Position lengthDoc, int initStyle,
|
||||
WordList *keywordlists[], Accessor &styler) const {
|
||||
if (fnFolder) {
|
||||
Sci_Position lineCurrent = styler.GetLine(startPos);
|
||||
// Move back one line in case deletion wrecked current line fold state
|
||||
if (lineCurrent > 0) {
|
||||
lineCurrent--;
|
||||
const Sci_Position newStartPos = styler.LineStart(lineCurrent);
|
||||
lengthDoc += startPos - newStartPos;
|
||||
startPos = newStartPos;
|
||||
initStyle = 0;
|
||||
if (startPos > 0) {
|
||||
initStyle = styler.StyleAt(startPos - 1);
|
||||
}
|
||||
}
|
||||
fnFolder(startPos, lengthDoc, initStyle, keywordlists, styler);
|
||||
}
|
||||
}
|
||||
87
third_party/qscintilla/scintilla/lexlib/LexerModule.h
vendored
Normal file
87
third_party/qscintilla/scintilla/lexlib/LexerModule.h
vendored
Normal file
@@ -0,0 +1,87 @@
|
||||
// Scintilla source code edit control
|
||||
/** @file LexerModule.h
|
||||
** Colourise for particular languages.
|
||||
**/
|
||||
// Copyright 1998-2001 by Neil Hodgson <neilh@scintilla.org>
|
||||
// The License.txt file describes the conditions under which this software may be distributed.
|
||||
|
||||
#ifndef LEXERMODULE_H
|
||||
#define LEXERMODULE_H
|
||||
|
||||
namespace Scintilla {
|
||||
|
||||
class Accessor;
|
||||
class WordList;
|
||||
struct LexicalClass;
|
||||
|
||||
typedef void (*LexerFunction)(Sci_PositionU startPos, Sci_Position lengthDoc, int initStyle,
|
||||
WordList *keywordlists[], Accessor &styler);
|
||||
typedef ILexer *(*LexerFactoryFunction)();
|
||||
|
||||
/**
|
||||
* A LexerModule is responsible for lexing and folding a particular language.
|
||||
* The Catalogue class maintains a list of LexerModules which can be searched to find a
|
||||
* module appropriate to a particular language.
|
||||
* The ExternalLexerModule subclass holds lexers loaded from DLLs or shared libraries.
|
||||
*/
|
||||
class LexerModule {
|
||||
protected:
|
||||
int language;
|
||||
LexerFunction fnLexer;
|
||||
LexerFunction fnFolder;
|
||||
LexerFactoryFunction fnFactory;
|
||||
const char * const * wordListDescriptions;
|
||||
const LexicalClass *lexClasses;
|
||||
size_t nClasses;
|
||||
|
||||
public:
|
||||
const char *languageName;
|
||||
LexerModule(
|
||||
int language_,
|
||||
LexerFunction fnLexer_,
|
||||
const char *languageName_=nullptr,
|
||||
LexerFunction fnFolder_= nullptr,
|
||||
const char * const wordListDescriptions_[]=nullptr,
|
||||
const LexicalClass *lexClasses_=nullptr,
|
||||
size_t nClasses_=0);
|
||||
LexerModule(
|
||||
int language_,
|
||||
LexerFactoryFunction fnFactory_,
|
||||
const char *languageName_,
|
||||
const char * const wordListDescriptions_[]=nullptr);
|
||||
virtual ~LexerModule();
|
||||
int GetLanguage() const;
|
||||
|
||||
// -1 is returned if no WordList information is available
|
||||
int GetNumWordLists() const;
|
||||
const char *GetWordListDescription(int index) const;
|
||||
const LexicalClass *LexClasses() const;
|
||||
size_t NamedStyles() const;
|
||||
|
||||
ILexer *Create() const;
|
||||
|
||||
virtual void Lex(Sci_PositionU startPos, Sci_Position lengthDoc, int initStyle,
|
||||
WordList *keywordlists[], Accessor &styler) const;
|
||||
virtual void Fold(Sci_PositionU startPos, Sci_Position lengthDoc, int initStyle,
|
||||
WordList *keywordlists[], Accessor &styler) const;
|
||||
|
||||
friend class Catalogue;
|
||||
};
|
||||
|
||||
inline int Maximum(int a, int b) {
|
||||
return (a > b) ? a : b;
|
||||
}
|
||||
|
||||
// Shut up annoying Visual C++ warnings:
|
||||
#ifdef _MSC_VER
|
||||
#pragma warning(disable: 4244 4456 4457)
|
||||
#endif
|
||||
|
||||
// Turn off shadow warnings for lexers as may be maintained by others
|
||||
#if defined(__GNUC__)
|
||||
#pragma GCC diagnostic ignored "-Wshadow"
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
62
third_party/qscintilla/scintilla/lexlib/LexerNoExceptions.cpp
vendored
Normal file
62
third_party/qscintilla/scintilla/lexlib/LexerNoExceptions.cpp
vendored
Normal file
@@ -0,0 +1,62 @@
|
||||
// Scintilla source code edit control
|
||||
/** @file LexerNoExceptions.cxx
|
||||
** A simple lexer with no state which does not throw exceptions so can be used in an external lexer.
|
||||
**/
|
||||
// Copyright 1998-2010 by Neil Hodgson <neilh@scintilla.org>
|
||||
// The License.txt file describes the conditions under which this software may be distributed.
|
||||
|
||||
#include <cstdlib>
|
||||
#include <cassert>
|
||||
|
||||
#include "ILexer.h"
|
||||
#include "Scintilla.h"
|
||||
#include "SciLexer.h"
|
||||
|
||||
#include "PropSetSimple.h"
|
||||
#include "WordList.h"
|
||||
#include "LexAccessor.h"
|
||||
#include "Accessor.h"
|
||||
#include "LexerModule.h"
|
||||
#include "LexerBase.h"
|
||||
#include "LexerNoExceptions.h"
|
||||
|
||||
using namespace Scintilla;
|
||||
|
||||
Sci_Position SCI_METHOD LexerNoExceptions::PropertySet(const char *key, const char *val) {
|
||||
try {
|
||||
return LexerBase::PropertySet(key, val);
|
||||
} catch (...) {
|
||||
// Should not throw into caller as may be compiled with different compiler or options
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
Sci_Position SCI_METHOD LexerNoExceptions::WordListSet(int n, const char *wl) {
|
||||
try {
|
||||
return LexerBase::WordListSet(n, wl);
|
||||
} catch (...) {
|
||||
// Should not throw into caller as may be compiled with different compiler or options
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
void SCI_METHOD LexerNoExceptions::Lex(Sci_PositionU startPos, Sci_Position lengthDoc, int initStyle, IDocument *pAccess) {
|
||||
try {
|
||||
Accessor astyler(pAccess, &props);
|
||||
Lexer(startPos, lengthDoc, initStyle, pAccess, astyler);
|
||||
astyler.Flush();
|
||||
} catch (...) {
|
||||
// Should not throw into caller as may be compiled with different compiler or options
|
||||
pAccess->SetErrorStatus(SC_STATUS_FAILURE);
|
||||
}
|
||||
}
|
||||
void SCI_METHOD LexerNoExceptions::Fold(Sci_PositionU startPos, Sci_Position lengthDoc, int initStyle, IDocument *pAccess) {
|
||||
try {
|
||||
Accessor astyler(pAccess, &props);
|
||||
Folder(startPos, lengthDoc, initStyle, pAccess, astyler);
|
||||
astyler.Flush();
|
||||
} catch (...) {
|
||||
// Should not throw into caller as may be compiled with different compiler or options
|
||||
pAccess->SetErrorStatus(SC_STATUS_FAILURE);
|
||||
}
|
||||
}
|
||||
28
third_party/qscintilla/scintilla/lexlib/LexerNoExceptions.h
vendored
Normal file
28
third_party/qscintilla/scintilla/lexlib/LexerNoExceptions.h
vendored
Normal file
@@ -0,0 +1,28 @@
|
||||
// Scintilla source code edit control
|
||||
/** @file LexerNoExceptions.h
|
||||
** A simple lexer with no state.
|
||||
**/
|
||||
// Copyright 1998-2010 by Neil Hodgson <neilh@scintilla.org>
|
||||
// The License.txt file describes the conditions under which this software may be distributed.
|
||||
|
||||
#ifndef LEXERNOEXCEPTIONS_H
|
||||
#define LEXERNOEXCEPTIONS_H
|
||||
|
||||
namespace Scintilla {
|
||||
|
||||
// A simple lexer with no state
|
||||
class LexerNoExceptions : public LexerBase {
|
||||
public:
|
||||
// TODO Also need to prevent exceptions in constructor and destructor
|
||||
Sci_Position SCI_METHOD PropertySet(const char *key, const char *val) override;
|
||||
Sci_Position SCI_METHOD WordListSet(int n, const char *wl) override;
|
||||
void SCI_METHOD Lex(Sci_PositionU startPos, Sci_Position lengthDoc, int initStyle, IDocument *pAccess) override;
|
||||
void SCI_METHOD Fold(Sci_PositionU startPos, Sci_Position lengthDoc, int initStyle, IDocument *) override;
|
||||
|
||||
virtual void Lexer(Sci_PositionU startPos, Sci_Position length, int initStyle, IDocument *pAccess, Accessor &styler) = 0;
|
||||
virtual void Folder(Sci_PositionU startPos, Sci_Position length, int initStyle, IDocument *pAccess, Accessor &styler) = 0;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
53
third_party/qscintilla/scintilla/lexlib/LexerSimple.cpp
vendored
Normal file
53
third_party/qscintilla/scintilla/lexlib/LexerSimple.cpp
vendored
Normal file
@@ -0,0 +1,53 @@
|
||||
// Scintilla source code edit control
|
||||
/** @file LexerSimple.cxx
|
||||
** A simple lexer with no state.
|
||||
**/
|
||||
// Copyright 1998-2010 by Neil Hodgson <neilh@scintilla.org>
|
||||
// The License.txt file describes the conditions under which this software may be distributed.
|
||||
|
||||
#include <cstdlib>
|
||||
#include <cassert>
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "ILexer.h"
|
||||
#include "Scintilla.h"
|
||||
#include "SciLexer.h"
|
||||
|
||||
#include "PropSetSimple.h"
|
||||
#include "WordList.h"
|
||||
#include "LexAccessor.h"
|
||||
#include "Accessor.h"
|
||||
#include "LexerModule.h"
|
||||
#include "LexerBase.h"
|
||||
#include "LexerSimple.h"
|
||||
|
||||
using namespace Scintilla;
|
||||
|
||||
LexerSimple::LexerSimple(const LexerModule *module_) :
|
||||
LexerBase(module_->LexClasses(), module_->NamedStyles()),
|
||||
module(module_) {
|
||||
for (int wl = 0; wl < module->GetNumWordLists(); wl++) {
|
||||
if (!wordLists.empty())
|
||||
wordLists += "\n";
|
||||
wordLists += module->GetWordListDescription(wl);
|
||||
}
|
||||
}
|
||||
|
||||
const char * SCI_METHOD LexerSimple::DescribeWordListSets() {
|
||||
return wordLists.c_str();
|
||||
}
|
||||
|
||||
void SCI_METHOD LexerSimple::Lex(Sci_PositionU startPos, Sci_Position lengthDoc, int initStyle, IDocument *pAccess) {
|
||||
Accessor astyler(pAccess, &props);
|
||||
module->Lex(startPos, lengthDoc, initStyle, keyWordLists, astyler);
|
||||
astyler.Flush();
|
||||
}
|
||||
|
||||
void SCI_METHOD LexerSimple::Fold(Sci_PositionU startPos, Sci_Position lengthDoc, int initStyle, IDocument *pAccess) {
|
||||
if (props.GetInt("fold")) {
|
||||
Accessor astyler(pAccess, &props);
|
||||
module->Fold(startPos, lengthDoc, initStyle, keyWordLists, astyler);
|
||||
astyler.Flush();
|
||||
}
|
||||
}
|
||||
26
third_party/qscintilla/scintilla/lexlib/LexerSimple.h
vendored
Normal file
26
third_party/qscintilla/scintilla/lexlib/LexerSimple.h
vendored
Normal file
@@ -0,0 +1,26 @@
|
||||
// Scintilla source code edit control
|
||||
/** @file LexerSimple.h
|
||||
** A simple lexer with no state.
|
||||
**/
|
||||
// Copyright 1998-2010 by Neil Hodgson <neilh@scintilla.org>
|
||||
// The License.txt file describes the conditions under which this software may be distributed.
|
||||
|
||||
#ifndef LEXERSIMPLE_H
|
||||
#define LEXERSIMPLE_H
|
||||
|
||||
namespace Scintilla {
|
||||
|
||||
// A simple lexer with no state
|
||||
class LexerSimple : public LexerBase {
|
||||
const LexerModule *module;
|
||||
std::string wordLists;
|
||||
public:
|
||||
explicit LexerSimple(const LexerModule *module_);
|
||||
const char * SCI_METHOD DescribeWordListSets() override;
|
||||
void SCI_METHOD Lex(Sci_PositionU startPos, Sci_Position lengthDoc, int initStyle, IDocument *pAccess) override;
|
||||
void SCI_METHOD Fold(Sci_PositionU startPos, Sci_Position lengthDoc, int initStyle, IDocument *pAccess) override;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
20
third_party/qscintilla/scintilla/lexlib/License.txt
vendored
Normal file
20
third_party/qscintilla/scintilla/lexlib/License.txt
vendored
Normal file
@@ -0,0 +1,20 @@
|
||||
License for Scintilla and SciTE
|
||||
|
||||
Copyright 1998-2003 by Neil Hodgson <neilh@scintilla.org>
|
||||
|
||||
All Rights Reserved
|
||||
|
||||
Permission to use, copy, modify, and distribute this software and its
|
||||
documentation for any purpose and without fee is hereby granted,
|
||||
provided that the above copyright notice appear in all copies and that
|
||||
both that copyright notice and this permission notice appear in
|
||||
supporting documentation.
|
||||
|
||||
NEIL HODGSON DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
|
||||
SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
||||
AND FITNESS, IN NO EVENT SHALL NEIL HODGSON BE LIABLE FOR ANY
|
||||
SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
|
||||
WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
|
||||
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE
|
||||
OR PERFORMANCE OF THIS SOFTWARE.
|
||||
138
third_party/qscintilla/scintilla/lexlib/OptionSet.h
vendored
Normal file
138
third_party/qscintilla/scintilla/lexlib/OptionSet.h
vendored
Normal file
@@ -0,0 +1,138 @@
|
||||
// Scintilla source code edit control
|
||||
/** @file OptionSet.h
|
||||
** Manage descriptive information about an options struct for a lexer.
|
||||
** Hold the names, positions, and descriptions of boolean, integer and string options and
|
||||
** allow setting options and retrieving metadata about the options.
|
||||
**/
|
||||
// Copyright 2010 by Neil Hodgson <neilh@scintilla.org>
|
||||
// The License.txt file describes the conditions under which this software may be distributed.
|
||||
|
||||
#ifndef OPTIONSET_H
|
||||
#define OPTIONSET_H
|
||||
|
||||
namespace Scintilla {
|
||||
|
||||
template <typename T>
|
||||
class OptionSet {
|
||||
typedef T Target;
|
||||
typedef bool T::*plcob;
|
||||
typedef int T::*plcoi;
|
||||
typedef std::string T::*plcos;
|
||||
struct Option {
|
||||
int opType;
|
||||
union {
|
||||
plcob pb;
|
||||
plcoi pi;
|
||||
plcos ps;
|
||||
};
|
||||
std::string description;
|
||||
Option() :
|
||||
opType(SC_TYPE_BOOLEAN), pb(0), description("") {
|
||||
}
|
||||
Option(plcob pb_, std::string description_="") :
|
||||
opType(SC_TYPE_BOOLEAN), pb(pb_), description(description_) {
|
||||
}
|
||||
Option(plcoi pi_, std::string description_) :
|
||||
opType(SC_TYPE_INTEGER), pi(pi_), description(description_) {
|
||||
}
|
||||
Option(plcos ps_, std::string description_) :
|
||||
opType(SC_TYPE_STRING), ps(ps_), description(description_) {
|
||||
}
|
||||
bool Set(T *base, const char *val) const {
|
||||
switch (opType) {
|
||||
case SC_TYPE_BOOLEAN: {
|
||||
bool option = atoi(val) != 0;
|
||||
if ((*base).*pb != option) {
|
||||
(*base).*pb = option;
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case SC_TYPE_INTEGER: {
|
||||
int option = atoi(val);
|
||||
if ((*base).*pi != option) {
|
||||
(*base).*pi = option;
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case SC_TYPE_STRING: {
|
||||
if ((*base).*ps != val) {
|
||||
(*base).*ps = val;
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
};
|
||||
typedef std::map<std::string, Option> OptionMap;
|
||||
OptionMap nameToDef;
|
||||
std::string names;
|
||||
std::string wordLists;
|
||||
|
||||
void AppendName(const char *name) {
|
||||
if (!names.empty())
|
||||
names += "\n";
|
||||
names += name;
|
||||
}
|
||||
public:
|
||||
virtual ~OptionSet() {
|
||||
}
|
||||
void DefineProperty(const char *name, plcob pb, std::string description="") {
|
||||
nameToDef[name] = Option(pb, description);
|
||||
AppendName(name);
|
||||
}
|
||||
void DefineProperty(const char *name, plcoi pi, std::string description="") {
|
||||
nameToDef[name] = Option(pi, description);
|
||||
AppendName(name);
|
||||
}
|
||||
void DefineProperty(const char *name, plcos ps, std::string description="") {
|
||||
nameToDef[name] = Option(ps, description);
|
||||
AppendName(name);
|
||||
}
|
||||
const char *PropertyNames() const {
|
||||
return names.c_str();
|
||||
}
|
||||
int PropertyType(const char *name) {
|
||||
typename OptionMap::iterator it = nameToDef.find(name);
|
||||
if (it != nameToDef.end()) {
|
||||
return it->second.opType;
|
||||
}
|
||||
return SC_TYPE_BOOLEAN;
|
||||
}
|
||||
const char *DescribeProperty(const char *name) {
|
||||
typename OptionMap::iterator it = nameToDef.find(name);
|
||||
if (it != nameToDef.end()) {
|
||||
return it->second.description.c_str();
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
bool PropertySet(T *base, const char *name, const char *val) {
|
||||
typename OptionMap::iterator it = nameToDef.find(name);
|
||||
if (it != nameToDef.end()) {
|
||||
return it->second.Set(base, val);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void DefineWordListSets(const char * const wordListDescriptions[]) {
|
||||
if (wordListDescriptions) {
|
||||
for (size_t wl = 0; wordListDescriptions[wl]; wl++) {
|
||||
if (!wordLists.empty())
|
||||
wordLists += "\n";
|
||||
wordLists += wordListDescriptions[wl];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const char *DescribeWordListSets() const {
|
||||
return wordLists.c_str();
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
157
third_party/qscintilla/scintilla/lexlib/PropSetSimple.cpp
vendored
Normal file
157
third_party/qscintilla/scintilla/lexlib/PropSetSimple.cpp
vendored
Normal file
@@ -0,0 +1,157 @@
|
||||
// Scintilla source code edit control
|
||||
/** @file PropSetSimple.cxx
|
||||
** A basic string to string map.
|
||||
**/
|
||||
// Copyright 1998-2010 by Neil Hodgson <neilh@scintilla.org>
|
||||
// The License.txt file describes the conditions under which this software may be distributed.
|
||||
|
||||
// Maintain a dictionary of properties
|
||||
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
|
||||
#include <string>
|
||||
#include <map>
|
||||
|
||||
#include "PropSetSimple.h"
|
||||
|
||||
using namespace Scintilla;
|
||||
|
||||
namespace {
|
||||
|
||||
typedef std::map<std::string, std::string> mapss;
|
||||
|
||||
mapss *PropsFromPointer(void *impl) {
|
||||
return static_cast<mapss *>(impl);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
PropSetSimple::PropSetSimple() {
|
||||
mapss *props = new mapss;
|
||||
impl = static_cast<void *>(props);
|
||||
}
|
||||
|
||||
PropSetSimple::~PropSetSimple() {
|
||||
mapss *props = PropsFromPointer(impl);
|
||||
delete props;
|
||||
impl = 0;
|
||||
}
|
||||
|
||||
void PropSetSimple::Set(const char *key, const char *val, size_t lenKey, size_t lenVal) {
|
||||
mapss *props = PropsFromPointer(impl);
|
||||
if (!*key) // Empty keys are not supported
|
||||
return;
|
||||
(*props)[std::string(key, lenKey)] = std::string(val, lenVal);
|
||||
}
|
||||
|
||||
static bool IsASpaceCharacter(unsigned int ch) {
|
||||
return (ch == ' ') || ((ch >= 0x09) && (ch <= 0x0d));
|
||||
}
|
||||
|
||||
void PropSetSimple::Set(const char *keyVal) {
|
||||
while (IsASpaceCharacter(*keyVal))
|
||||
keyVal++;
|
||||
const char *endVal = keyVal;
|
||||
while (*endVal && (*endVal != '\n'))
|
||||
endVal++;
|
||||
const char *eqAt = strchr(keyVal, '=');
|
||||
if (eqAt) {
|
||||
Set(keyVal, eqAt + 1, eqAt-keyVal,
|
||||
endVal - eqAt - 1);
|
||||
} else if (*keyVal) { // No '=' so assume '=1'
|
||||
Set(keyVal, "1", endVal-keyVal, 1);
|
||||
}
|
||||
}
|
||||
|
||||
void PropSetSimple::SetMultiple(const char *s) {
|
||||
const char *eol = strchr(s, '\n');
|
||||
while (eol) {
|
||||
Set(s);
|
||||
s = eol + 1;
|
||||
eol = strchr(s, '\n');
|
||||
}
|
||||
Set(s);
|
||||
}
|
||||
|
||||
const char *PropSetSimple::Get(const char *key) const {
|
||||
mapss *props = PropsFromPointer(impl);
|
||||
mapss::const_iterator keyPos = props->find(std::string(key));
|
||||
if (keyPos != props->end()) {
|
||||
return keyPos->second.c_str();
|
||||
} else {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
// There is some inconsistency between GetExpanded("foo") and Expand("$(foo)").
|
||||
// A solution is to keep a stack of variables that have been expanded, so that
|
||||
// recursive expansions can be skipped. For now I'll just use the C++ stack
|
||||
// for that, through a recursive function and a simple chain of pointers.
|
||||
|
||||
struct VarChain {
|
||||
VarChain(const char *var_=nullptr, const VarChain *link_= nullptr): var(var_), link(link_) {}
|
||||
|
||||
bool contains(const char *testVar) const {
|
||||
return (var && (0 == strcmp(var, testVar)))
|
||||
|| (link && link->contains(testVar));
|
||||
}
|
||||
|
||||
const char *var;
|
||||
const VarChain *link;
|
||||
};
|
||||
|
||||
static int ExpandAllInPlace(const PropSetSimple &props, std::string &withVars, int maxExpands, const VarChain &blankVars) {
|
||||
size_t varStart = withVars.find("$(");
|
||||
while ((varStart != std::string::npos) && (maxExpands > 0)) {
|
||||
const size_t varEnd = withVars.find(')', varStart+2);
|
||||
if (varEnd == std::string::npos) {
|
||||
break;
|
||||
}
|
||||
|
||||
// For consistency, when we see '$(ab$(cde))', expand the inner variable first,
|
||||
// regardless whether there is actually a degenerate variable named 'ab$(cde'.
|
||||
size_t innerVarStart = withVars.find("$(", varStart+2);
|
||||
while ((innerVarStart != std::string::npos) && (innerVarStart > varStart) && (innerVarStart < varEnd)) {
|
||||
varStart = innerVarStart;
|
||||
innerVarStart = withVars.find("$(", varStart+2);
|
||||
}
|
||||
|
||||
std::string var(withVars.c_str(), varStart + 2, varEnd - varStart - 2);
|
||||
std::string val = props.Get(var.c_str());
|
||||
|
||||
if (blankVars.contains(var.c_str())) {
|
||||
val = ""; // treat blankVar as an empty string (e.g. to block self-reference)
|
||||
}
|
||||
|
||||
if (--maxExpands >= 0) {
|
||||
maxExpands = ExpandAllInPlace(props, val, maxExpands, VarChain(var.c_str(), &blankVars));
|
||||
}
|
||||
|
||||
withVars.erase(varStart, varEnd-varStart+1);
|
||||
withVars.insert(varStart, val.c_str(), val.length());
|
||||
|
||||
varStart = withVars.find("$(");
|
||||
}
|
||||
|
||||
return maxExpands;
|
||||
}
|
||||
|
||||
int PropSetSimple::GetExpanded(const char *key, char *result) const {
|
||||
std::string val = Get(key);
|
||||
ExpandAllInPlace(*this, val, 100, VarChain(key));
|
||||
const int n = static_cast<int>(val.size());
|
||||
if (result) {
|
||||
memcpy(result, val.c_str(), n+1);
|
||||
}
|
||||
return n; // Not including NUL
|
||||
}
|
||||
|
||||
int PropSetSimple::GetInt(const char *key, int defaultValue) const {
|
||||
std::string val = Get(key);
|
||||
ExpandAllInPlace(*this, val, 100, VarChain(key));
|
||||
if (!val.empty()) {
|
||||
return atoi(val.c_str());
|
||||
}
|
||||
return defaultValue;
|
||||
}
|
||||
28
third_party/qscintilla/scintilla/lexlib/PropSetSimple.h
vendored
Normal file
28
third_party/qscintilla/scintilla/lexlib/PropSetSimple.h
vendored
Normal file
@@ -0,0 +1,28 @@
|
||||
// Scintilla source code edit control
|
||||
/** @file PropSetSimple.h
|
||||
** A basic string to string map.
|
||||
**/
|
||||
// Copyright 1998-2009 by Neil Hodgson <neilh@scintilla.org>
|
||||
// The License.txt file describes the conditions under which this software may be distributed.
|
||||
|
||||
#ifndef PROPSETSIMPLE_H
|
||||
#define PROPSETSIMPLE_H
|
||||
|
||||
namespace Scintilla {
|
||||
|
||||
class PropSetSimple {
|
||||
void *impl;
|
||||
void Set(const char *keyVal);
|
||||
public:
|
||||
PropSetSimple();
|
||||
virtual ~PropSetSimple();
|
||||
void Set(const char *key, const char *val, size_t lenKey, size_t lenVal);
|
||||
void SetMultiple(const char *);
|
||||
const char *Get(const char *key) const;
|
||||
int GetExpanded(const char *key, char *result) const;
|
||||
int GetInt(const char *key, int defaultValue=0) const;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
106
third_party/qscintilla/scintilla/lexlib/SparseState.h
vendored
Normal file
106
third_party/qscintilla/scintilla/lexlib/SparseState.h
vendored
Normal file
@@ -0,0 +1,106 @@
|
||||
// Scintilla source code edit control
|
||||
/** @file SparseState.h
|
||||
** Hold lexer state that may change rarely.
|
||||
** This is often per-line state such as whether a particular type of section has been entered.
|
||||
** A state continues until it is changed.
|
||||
**/
|
||||
// Copyright 2011 by Neil Hodgson <neilh@scintilla.org>
|
||||
// The License.txt file describes the conditions under which this software may be distributed.
|
||||
|
||||
#ifndef SPARSESTATE_H
|
||||
#define SPARSESTATE_H
|
||||
|
||||
namespace Scintilla {
|
||||
|
||||
template <typename T>
|
||||
class SparseState {
|
||||
struct State {
|
||||
Sci_Position position;
|
||||
T value;
|
||||
State(Sci_Position position_, T value_) : position(position_), value(value_) {
|
||||
}
|
||||
inline bool operator<(const State &other) const {
|
||||
return position < other.position;
|
||||
}
|
||||
inline bool operator==(const State &other) const {
|
||||
return (position == other.position) && (value == other.value);
|
||||
}
|
||||
};
|
||||
Sci_Position positionFirst;
|
||||
typedef std::vector<State> stateVector;
|
||||
stateVector states;
|
||||
|
||||
typename stateVector::iterator Find(Sci_Position position) {
|
||||
State searchValue(position, T());
|
||||
return std::lower_bound(states.begin(), states.end(), searchValue);
|
||||
}
|
||||
|
||||
public:
|
||||
explicit SparseState(Sci_Position positionFirst_=-1) {
|
||||
positionFirst = positionFirst_;
|
||||
}
|
||||
void Set(Sci_Position position, T value) {
|
||||
Delete(position);
|
||||
if (states.empty() || (value != states[states.size()-1].value)) {
|
||||
states.push_back(State(position, value));
|
||||
}
|
||||
}
|
||||
T ValueAt(Sci_Position position) {
|
||||
if (states.empty())
|
||||
return T();
|
||||
if (position < states[0].position)
|
||||
return T();
|
||||
typename stateVector::iterator low = Find(position);
|
||||
if (low == states.end()) {
|
||||
return states[states.size()-1].value;
|
||||
} else {
|
||||
if (low->position > position) {
|
||||
--low;
|
||||
}
|
||||
return low->value;
|
||||
}
|
||||
}
|
||||
bool Delete(Sci_Position position) {
|
||||
typename stateVector::iterator low = Find(position);
|
||||
if (low != states.end()) {
|
||||
states.erase(low, states.end());
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
size_t size() const {
|
||||
return states.size();
|
||||
}
|
||||
|
||||
// Returns true if Merge caused a significant change
|
||||
bool Merge(const SparseState<T> &other, Sci_Position ignoreAfter) {
|
||||
// Changes caused beyond ignoreAfter are not significant
|
||||
Delete(ignoreAfter+1);
|
||||
|
||||
bool different = true;
|
||||
bool changed = false;
|
||||
typename stateVector::iterator low = Find(other.positionFirst);
|
||||
if (static_cast<size_t>(states.end() - low) == other.states.size()) {
|
||||
// Same number in other as after positionFirst in this
|
||||
different = !std::equal(low, states.end(), other.states.begin());
|
||||
}
|
||||
if (different) {
|
||||
if (low != states.end()) {
|
||||
states.erase(low, states.end());
|
||||
changed = true;
|
||||
}
|
||||
typename stateVector::const_iterator startOther = other.states.begin();
|
||||
if (!states.empty() && !other.states.empty() && states.back().value == startOther->value)
|
||||
++startOther;
|
||||
if (startOther != other.states.end()) {
|
||||
states.insert(states.end(), startOther, other.states.end());
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
return changed;
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
32
third_party/qscintilla/scintilla/lexlib/StringCopy.h
vendored
Normal file
32
third_party/qscintilla/scintilla/lexlib/StringCopy.h
vendored
Normal file
@@ -0,0 +1,32 @@
|
||||
// Scintilla source code edit control
|
||||
/** @file StringCopy.h
|
||||
** Safe string copy function which always NUL terminates.
|
||||
** ELEMENTS macro for determining array sizes.
|
||||
**/
|
||||
// Copyright 2013 by Neil Hodgson <neilh@scintilla.org>
|
||||
// The License.txt file describes the conditions under which this software may be distributed.
|
||||
|
||||
#ifndef STRINGCOPY_H
|
||||
#define STRINGCOPY_H
|
||||
|
||||
namespace Scintilla {
|
||||
|
||||
// Safer version of string copy functions like strcpy, wcsncpy, etc.
|
||||
// Instantiate over fixed length strings of both char and wchar_t.
|
||||
// May truncate if source doesn't fit into dest with room for NUL.
|
||||
|
||||
template <typename T, size_t count>
|
||||
void StringCopy(T (&dest)[count], const T* source) {
|
||||
for (size_t i=0; i<count; i++) {
|
||||
dest[i] = source[i];
|
||||
if (!source[i])
|
||||
break;
|
||||
}
|
||||
dest[count-1] = 0;
|
||||
}
|
||||
|
||||
#define ELEMENTS(a) (sizeof(a) / sizeof(a[0]))
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
69
third_party/qscintilla/scintilla/lexlib/StyleContext.cpp
vendored
Normal file
69
third_party/qscintilla/scintilla/lexlib/StyleContext.cpp
vendored
Normal file
@@ -0,0 +1,69 @@
|
||||
// Scintilla source code edit control
|
||||
/** @file StyleContext.cxx
|
||||
** Lexer infrastructure.
|
||||
**/
|
||||
// Copyright 1998-2004 by Neil Hodgson <neilh@scintilla.org>
|
||||
// This file is in the public domain.
|
||||
|
||||
#include <cstdlib>
|
||||
#include <cassert>
|
||||
#include <cctype>
|
||||
|
||||
#include "ILexer.h"
|
||||
|
||||
#include "LexAccessor.h"
|
||||
#include "Accessor.h"
|
||||
#include "StyleContext.h"
|
||||
#include "CharacterSet.h"
|
||||
|
||||
using namespace Scintilla;
|
||||
|
||||
bool StyleContext::MatchIgnoreCase(const char *s) {
|
||||
if (MakeLowerCase(ch) != static_cast<unsigned char>(*s))
|
||||
return false;
|
||||
s++;
|
||||
if (MakeLowerCase(chNext) != static_cast<unsigned char>(*s))
|
||||
return false;
|
||||
s++;
|
||||
for (int n = 2; *s; n++) {
|
||||
if (*s !=
|
||||
MakeLowerCase(styler.SafeGetCharAt(currentPos + n, 0)))
|
||||
return false;
|
||||
s++;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
static void getRange(Sci_PositionU start,
|
||||
Sci_PositionU end,
|
||||
LexAccessor &styler,
|
||||
char *s,
|
||||
Sci_PositionU len) {
|
||||
Sci_PositionU i = 0;
|
||||
while ((i < end - start + 1) && (i < len-1)) {
|
||||
s[i] = styler[start + i];
|
||||
i++;
|
||||
}
|
||||
s[i] = '\0';
|
||||
}
|
||||
|
||||
void StyleContext::GetCurrent(char *s, Sci_PositionU len) {
|
||||
getRange(styler.GetStartSegment(), currentPos - 1, styler, s, len);
|
||||
}
|
||||
|
||||
static void getRangeLowered(Sci_PositionU start,
|
||||
Sci_PositionU end,
|
||||
LexAccessor &styler,
|
||||
char *s,
|
||||
Sci_PositionU len) {
|
||||
Sci_PositionU i = 0;
|
||||
while ((i < end - start + 1) && (i < len-1)) {
|
||||
s[i] = MakeLowerCase(styler[start + i]);
|
||||
i++;
|
||||
}
|
||||
s[i] = '\0';
|
||||
}
|
||||
|
||||
void StyleContext::GetCurrentLowered(char *s, Sci_PositionU len) {
|
||||
getRangeLowered(styler.GetStartSegment(), currentPos - 1, styler, s, len);
|
||||
}
|
||||
212
third_party/qscintilla/scintilla/lexlib/StyleContext.h
vendored
Normal file
212
third_party/qscintilla/scintilla/lexlib/StyleContext.h
vendored
Normal file
@@ -0,0 +1,212 @@
|
||||
// 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 Scintilla {
|
||||
|
||||
// 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;
|
||||
IDocumentWithLineEnd *multiByteAccess;
|
||||
Sci_PositionU endPos;
|
||||
Sci_PositionU lengthDocument;
|
||||
|
||||
// Used for optimizing GetRelativeCharacter
|
||||
Sci_PositionU posRelative;
|
||||
Sci_PositionU currentPosLastRelative;
|
||||
Sci_Position offsetRelative;
|
||||
|
||||
void GetNextChar() {
|
||||
if (multiByteAccess) {
|
||||
chNext = multiByteAccess->GetCharacterAndWidth(currentPos+width, &widthNext);
|
||||
} else {
|
||||
chNext = static_cast<unsigned char>(styler.SafeGetCharAt(currentPos+width, 0));
|
||||
widthNext = 1;
|
||||
}
|
||||
// End of line determined from line end position, allowing CR, LF,
|
||||
// CRLF and Unicode line ends as set by document.
|
||||
if (currentLine < lineDocEnd)
|
||||
atLineEnd = static_cast<Sci_Position>(currentPos) >= (lineStartNext-1);
|
||||
else // Last line
|
||||
atLineEnd = static_cast<Sci_Position>(currentPos) >= lineStartNext;
|
||||
}
|
||||
|
||||
public:
|
||||
Sci_PositionU currentPos;
|
||||
Sci_Position currentLine;
|
||||
Sci_Position lineDocEnd;
|
||||
Sci_Position lineStartNext;
|
||||
bool atLineStart;
|
||||
bool atLineEnd;
|
||||
int state;
|
||||
int chPrev;
|
||||
int ch;
|
||||
Sci_Position width;
|
||||
int chNext;
|
||||
Sci_Position widthNext;
|
||||
|
||||
StyleContext(Sci_PositionU startPos, Sci_PositionU length,
|
||||
int initStyle, LexAccessor &styler_, char chMask='\377') :
|
||||
styler(styler_),
|
||||
multiByteAccess(nullptr),
|
||||
endPos(startPos + length),
|
||||
posRelative(0),
|
||||
currentPosLastRelative(0x7FFFFFFF),
|
||||
offsetRelative(0),
|
||||
currentPos(startPos),
|
||||
currentLine(-1),
|
||||
lineStartNext(-1),
|
||||
atLineEnd(false),
|
||||
state(initStyle & chMask), // Mask off all bits which aren't in the chMask.
|
||||
chPrev(0),
|
||||
ch(0),
|
||||
width(0),
|
||||
chNext(0),
|
||||
widthNext(1) {
|
||||
if (styler.Encoding() != enc8bit) {
|
||||
multiByteAccess = styler.MultiByteAccess();
|
||||
}
|
||||
styler.StartAt(startPos /*, chMask*/);
|
||||
styler.StartSegment(startPos);
|
||||
currentLine = styler.GetLine(startPos);
|
||||
lineStartNext = styler.LineStart(currentLine+1);
|
||||
lengthDocument = static_cast<Sci_PositionU>(styler.Length());
|
||||
if (endPos == lengthDocument)
|
||||
endPos++;
|
||||
lineDocEnd = styler.GetLine(lengthDocument);
|
||||
atLineStart = static_cast<Sci_PositionU>(styler.LineStart(currentLine)) == startPos;
|
||||
|
||||
// Variable width is now 0 so GetNextChar gets the char at currentPos into chNext/widthNext
|
||||
width = 0;
|
||||
GetNextChar();
|
||||
ch = chNext;
|
||||
width = widthNext;
|
||||
|
||||
GetNextChar();
|
||||
}
|
||||
// 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 {
|
||||
return currentPos < endPos;
|
||||
}
|
||||
void Forward() {
|
||||
if (currentPos < endPos) {
|
||||
atLineStart = atLineEnd;
|
||||
if (atLineStart) {
|
||||
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_) {
|
||||
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_;
|
||||
}
|
||||
Sci_Position LengthCurrent() const {
|
||||
return currentPos - styler.GetStartSegment();
|
||||
}
|
||||
int GetRelative(Sci_Position n) {
|
||||
return static_cast<unsigned char>(styler.SafeGetCharAt(currentPos+n, 0));
|
||||
}
|
||||
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
|
||||
return static_cast<unsigned char>(styler.SafeGetCharAt(currentPos + n, 0));
|
||||
}
|
||||
}
|
||||
bool Match(char ch0) const {
|
||||
return ch == static_cast<unsigned char>(ch0);
|
||||
}
|
||||
bool Match(char ch0, char ch1) const {
|
||||
return (ch == static_cast<unsigned char>(ch0)) && (chNext == static_cast<unsigned char>(ch1));
|
||||
}
|
||||
bool Match(const char *s) {
|
||||
if (ch != static_cast<unsigned char>(*s))
|
||||
return false;
|
||||
s++;
|
||||
if (!*s)
|
||||
return true;
|
||||
if (chNext != static_cast<unsigned char>(*s))
|
||||
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);
|
||||
void GetCurrent(char *s, Sci_PositionU len);
|
||||
void GetCurrentLowered(char *s, Sci_PositionU len);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
196
third_party/qscintilla/scintilla/lexlib/SubStyles.h
vendored
Normal file
196
third_party/qscintilla/scintilla/lexlib/SubStyles.h
vendored
Normal file
@@ -0,0 +1,196 @@
|
||||
// Scintilla source code edit control
|
||||
/** @file SubStyles.h
|
||||
** Manage substyles for a lexer.
|
||||
**/
|
||||
// Copyright 2012 by Neil Hodgson <neilh@scintilla.org>
|
||||
// The License.txt file describes the conditions under which this software may be distributed.
|
||||
|
||||
#ifndef SUBSTYLES_H
|
||||
#define SUBSTYLES_H
|
||||
|
||||
namespace Scintilla {
|
||||
|
||||
class WordClassifier {
|
||||
int baseStyle;
|
||||
int firstStyle;
|
||||
int lenStyles;
|
||||
std::map<std::string, int> wordToStyle;
|
||||
|
||||
public:
|
||||
|
||||
explicit WordClassifier(int baseStyle_) : baseStyle(baseStyle_), firstStyle(0), lenStyles(0) {
|
||||
}
|
||||
|
||||
void Allocate(int firstStyle_, int lenStyles_) {
|
||||
firstStyle = firstStyle_;
|
||||
lenStyles = lenStyles_;
|
||||
wordToStyle.clear();
|
||||
}
|
||||
|
||||
int Base() const {
|
||||
return baseStyle;
|
||||
}
|
||||
|
||||
int Start() const {
|
||||
return firstStyle;
|
||||
}
|
||||
|
||||
int Last() const {
|
||||
return firstStyle + lenStyles - 1;
|
||||
}
|
||||
|
||||
int Length() const {
|
||||
return lenStyles;
|
||||
}
|
||||
|
||||
void Clear() {
|
||||
firstStyle = 0;
|
||||
lenStyles = 0;
|
||||
wordToStyle.clear();
|
||||
}
|
||||
|
||||
int ValueFor(const std::string &s) const {
|
||||
std::map<std::string, int>::const_iterator it = wordToStyle.find(s);
|
||||
if (it != wordToStyle.end())
|
||||
return it->second;
|
||||
else
|
||||
return -1;
|
||||
}
|
||||
|
||||
bool IncludesStyle(int style) const {
|
||||
return (style >= firstStyle) && (style < (firstStyle + lenStyles));
|
||||
}
|
||||
|
||||
void SetIdentifiers(int style, const char *identifiers) {
|
||||
while (*identifiers) {
|
||||
const char *cpSpace = identifiers;
|
||||
while (*cpSpace && !(*cpSpace == ' ' || *cpSpace == '\t' || *cpSpace == '\r' || *cpSpace == '\n'))
|
||||
cpSpace++;
|
||||
if (cpSpace > identifiers) {
|
||||
std::string word(identifiers, cpSpace - identifiers);
|
||||
wordToStyle[word] = style;
|
||||
}
|
||||
identifiers = cpSpace;
|
||||
if (*identifiers)
|
||||
identifiers++;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
class SubStyles {
|
||||
int classifications;
|
||||
const char *baseStyles;
|
||||
int styleFirst;
|
||||
int stylesAvailable;
|
||||
int secondaryDistance;
|
||||
int allocated;
|
||||
std::vector<WordClassifier> classifiers;
|
||||
|
||||
int BlockFromBaseStyle(int baseStyle) const {
|
||||
for (int b=0; b < classifications; b++) {
|
||||
if (baseStyle == baseStyles[b])
|
||||
return b;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
int BlockFromStyle(int style) const {
|
||||
int b = 0;
|
||||
for (std::vector<WordClassifier>::const_iterator it=classifiers.begin(); it != classifiers.end(); ++it) {
|
||||
if (it->IncludesStyle(style))
|
||||
return b;
|
||||
b++;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
SubStyles(const char *baseStyles_, int styleFirst_, int stylesAvailable_, int secondaryDistance_) :
|
||||
classifications(0),
|
||||
baseStyles(baseStyles_),
|
||||
styleFirst(styleFirst_),
|
||||
stylesAvailable(stylesAvailable_),
|
||||
secondaryDistance(secondaryDistance_),
|
||||
allocated(0) {
|
||||
while (baseStyles[classifications]) {
|
||||
classifiers.push_back(WordClassifier(baseStyles[classifications]));
|
||||
classifications++;
|
||||
}
|
||||
}
|
||||
|
||||
int Allocate(int styleBase, int numberStyles) {
|
||||
const int block = BlockFromBaseStyle(styleBase);
|
||||
if (block >= 0) {
|
||||
if ((allocated + numberStyles) > stylesAvailable)
|
||||
return -1;
|
||||
const int startBlock = styleFirst + allocated;
|
||||
allocated += numberStyles;
|
||||
classifiers[block].Allocate(startBlock, numberStyles);
|
||||
return startBlock;
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
int Start(int styleBase) {
|
||||
const int block = BlockFromBaseStyle(styleBase);
|
||||
return (block >= 0) ? classifiers[block].Start() : -1;
|
||||
}
|
||||
|
||||
int Length(int styleBase) {
|
||||
const int block = BlockFromBaseStyle(styleBase);
|
||||
return (block >= 0) ? classifiers[block].Length() : 0;
|
||||
}
|
||||
|
||||
int BaseStyle(int subStyle) const {
|
||||
const int block = BlockFromStyle(subStyle);
|
||||
if (block >= 0)
|
||||
return classifiers[block].Base();
|
||||
else
|
||||
return subStyle;
|
||||
}
|
||||
|
||||
int DistanceToSecondaryStyles() const {
|
||||
return secondaryDistance;
|
||||
}
|
||||
|
||||
int FirstAllocated() const {
|
||||
int start = 257;
|
||||
for (std::vector<WordClassifier>::const_iterator it = classifiers.begin(); it != classifiers.end(); ++it) {
|
||||
if (start > it->Start())
|
||||
start = it->Start();
|
||||
}
|
||||
return (start < 256) ? start : -1;
|
||||
}
|
||||
|
||||
int LastAllocated() const {
|
||||
int last = -1;
|
||||
for (std::vector<WordClassifier>::const_iterator it = classifiers.begin(); it != classifiers.end(); ++it) {
|
||||
if (last < it->Last())
|
||||
last = it->Last();
|
||||
}
|
||||
return last;
|
||||
}
|
||||
|
||||
void SetIdentifiers(int style, const char *identifiers) {
|
||||
const int block = BlockFromStyle(style);
|
||||
if (block >= 0)
|
||||
classifiers[block].SetIdentifiers(style, identifiers);
|
||||
}
|
||||
|
||||
void Free() {
|
||||
allocated = 0;
|
||||
for (std::vector<WordClassifier>::iterator it=classifiers.begin(); it != classifiers.end(); ++it)
|
||||
it->Clear();
|
||||
}
|
||||
|
||||
const WordClassifier &Classifier(int baseStyle) const {
|
||||
const int block = BlockFromBaseStyle(baseStyle);
|
||||
return classifiers[block >= 0 ? block : 0];
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
295
third_party/qscintilla/scintilla/lexlib/WordList.cpp
vendored
Normal file
295
third_party/qscintilla/scintilla/lexlib/WordList.cpp
vendored
Normal file
@@ -0,0 +1,295 @@
|
||||
// Scintilla source code edit control
|
||||
/** @file WordList.cxx
|
||||
** Hold a list of words.
|
||||
**/
|
||||
// Copyright 1998-2002 by Neil Hodgson <neilh@scintilla.org>
|
||||
// The License.txt file describes the conditions under which this software may be distributed.
|
||||
|
||||
#include <cstdlib>
|
||||
#include <cassert>
|
||||
#include <cstring>
|
||||
|
||||
#include <algorithm>
|
||||
#include <iterator>
|
||||
|
||||
#include "WordList.h"
|
||||
|
||||
using namespace Scintilla;
|
||||
|
||||
/**
|
||||
* Creates an array that points into each word in the string and puts \0 terminators
|
||||
* after each word.
|
||||
*/
|
||||
static char **ArrayFromWordList(char *wordlist, int *len, bool onlyLineEnds = false) {
|
||||
int prev = '\n';
|
||||
int words = 0;
|
||||
// For rapid determination of whether a character is a separator, build
|
||||
// a look up table.
|
||||
bool wordSeparator[256] = {}; // Initialise all to false.
|
||||
wordSeparator[static_cast<unsigned int>('\r')] = true;
|
||||
wordSeparator[static_cast<unsigned int>('\n')] = true;
|
||||
if (!onlyLineEnds) {
|
||||
wordSeparator[static_cast<unsigned int>(' ')] = true;
|
||||
wordSeparator[static_cast<unsigned int>('\t')] = true;
|
||||
}
|
||||
for (int j = 0; wordlist[j]; j++) {
|
||||
const int curr = static_cast<unsigned char>(wordlist[j]);
|
||||
if (!wordSeparator[curr] && wordSeparator[prev])
|
||||
words++;
|
||||
prev = curr;
|
||||
}
|
||||
char **keywords = new char *[words + 1];
|
||||
int wordsStore = 0;
|
||||
const size_t slen = strlen(wordlist);
|
||||
if (words) {
|
||||
prev = '\0';
|
||||
for (size_t k = 0; k < slen; k++) {
|
||||
if (!wordSeparator[static_cast<unsigned char>(wordlist[k])]) {
|
||||
if (!prev) {
|
||||
keywords[wordsStore] = &wordlist[k];
|
||||
wordsStore++;
|
||||
}
|
||||
} else {
|
||||
wordlist[k] = '\0';
|
||||
}
|
||||
prev = wordlist[k];
|
||||
}
|
||||
}
|
||||
assert(wordsStore < (words + 1));
|
||||
keywords[wordsStore] = &wordlist[slen];
|
||||
*len = wordsStore;
|
||||
return keywords;
|
||||
}
|
||||
|
||||
WordList::WordList(bool onlyLineEnds_) :
|
||||
words(0), list(0), len(0), onlyLineEnds(onlyLineEnds_) {
|
||||
// Prevent warnings by static analyzers about uninitialized starts.
|
||||
starts[0] = -1;
|
||||
}
|
||||
|
||||
WordList::~WordList() {
|
||||
Clear();
|
||||
}
|
||||
|
||||
WordList::operator bool() const {
|
||||
return len ? true : false;
|
||||
}
|
||||
|
||||
bool WordList::operator!=(const WordList &other) const {
|
||||
if (len != other.len)
|
||||
return true;
|
||||
for (int i=0; i<len; i++) {
|
||||
if (strcmp(words[i], other.words[i]) != 0)
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
int WordList::Length() const {
|
||||
return len;
|
||||
}
|
||||
|
||||
void WordList::Clear() {
|
||||
if (words) {
|
||||
delete []list;
|
||||
delete []words;
|
||||
}
|
||||
words = 0;
|
||||
list = 0;
|
||||
len = 0;
|
||||
}
|
||||
|
||||
#ifdef _MSC_VER
|
||||
|
||||
static bool cmpWords(const char *a, const char *b) {
|
||||
return strcmp(a, b) < 0;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
static int cmpWords(const void *a, const void *b) {
|
||||
return strcmp(*static_cast<const char * const *>(a), *static_cast<const char * const *>(b));
|
||||
}
|
||||
|
||||
static void SortWordList(char **words, unsigned int len) {
|
||||
qsort(words, len, sizeof(*words), cmpWords);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
void WordList::Set(const char *s) {
|
||||
Clear();
|
||||
const size_t lenS = strlen(s) + 1;
|
||||
list = new char[lenS];
|
||||
memcpy(list, s, lenS);
|
||||
words = ArrayFromWordList(list, &len, onlyLineEnds);
|
||||
#ifdef _MSC_VER
|
||||
std::sort(words, words + len, cmpWords);
|
||||
#else
|
||||
SortWordList(words, len);
|
||||
#endif
|
||||
std::fill(starts, std::end(starts), -1);
|
||||
for (int l = len - 1; l >= 0; l--) {
|
||||
unsigned char indexChar = words[l][0];
|
||||
starts[indexChar] = l;
|
||||
}
|
||||
}
|
||||
|
||||
/** Check whether a string is in the list.
|
||||
* List elements are either exact matches or prefixes.
|
||||
* Prefix elements start with '^' and match all strings that start with the rest of the element
|
||||
* so '^GTK_' matches 'GTK_X', 'GTK_MAJOR_VERSION', and 'GTK_'.
|
||||
*/
|
||||
bool WordList::InList(const char *s) const {
|
||||
if (0 == words)
|
||||
return false;
|
||||
const unsigned char firstChar = s[0];
|
||||
int j = starts[firstChar];
|
||||
if (j >= 0) {
|
||||
while (words[j][0] == firstChar) {
|
||||
if (s[1] == words[j][1]) {
|
||||
const char *a = words[j] + 1;
|
||||
const char *b = s + 1;
|
||||
while (*a && *a == *b) {
|
||||
a++;
|
||||
b++;
|
||||
}
|
||||
if (!*a && !*b)
|
||||
return true;
|
||||
}
|
||||
j++;
|
||||
}
|
||||
}
|
||||
j = starts[static_cast<unsigned int>('^')];
|
||||
if (j >= 0) {
|
||||
while (words[j][0] == '^') {
|
||||
const char *a = words[j] + 1;
|
||||
const char *b = s;
|
||||
while (*a && *a == *b) {
|
||||
a++;
|
||||
b++;
|
||||
}
|
||||
if (!*a)
|
||||
return true;
|
||||
j++;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/** similar to InList, but word s can be a substring of keyword.
|
||||
* eg. the keyword define is defined as def~ine. This means the word must start
|
||||
* with def to be a keyword, but also defi, defin and define are valid.
|
||||
* The marker is ~ in this case.
|
||||
*/
|
||||
bool WordList::InListAbbreviated(const char *s, const char marker) const {
|
||||
if (0 == words)
|
||||
return false;
|
||||
const unsigned char firstChar = s[0];
|
||||
int j = starts[firstChar];
|
||||
if (j >= 0) {
|
||||
while (words[j][0] == firstChar) {
|
||||
bool isSubword = false;
|
||||
int start = 1;
|
||||
if (words[j][1] == marker) {
|
||||
isSubword = true;
|
||||
start++;
|
||||
}
|
||||
if (s[1] == words[j][start]) {
|
||||
const char *a = words[j] + start;
|
||||
const char *b = s + 1;
|
||||
while (*a && *a == *b) {
|
||||
a++;
|
||||
if (*a == marker) {
|
||||
isSubword = true;
|
||||
a++;
|
||||
}
|
||||
b++;
|
||||
}
|
||||
if ((!*a || isSubword) && !*b)
|
||||
return true;
|
||||
}
|
||||
j++;
|
||||
}
|
||||
}
|
||||
j = starts[static_cast<unsigned int>('^')];
|
||||
if (j >= 0) {
|
||||
while (words[j][0] == '^') {
|
||||
const char *a = words[j] + 1;
|
||||
const char *b = s;
|
||||
while (*a && *a == *b) {
|
||||
a++;
|
||||
b++;
|
||||
}
|
||||
if (!*a)
|
||||
return true;
|
||||
j++;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/** similar to InListAbbreviated, but word s can be a abridged version of a keyword.
|
||||
* eg. the keyword is defined as "after.~:". This means the word must have a prefix (begins with) of
|
||||
* "after." and suffix (ends with) of ":" to be a keyword, Hence "after.field:" , "after.form.item:" are valid.
|
||||
* Similarly "~.is.valid" keyword is suffix only... hence "field.is.valid" , "form.is.valid" are valid.
|
||||
* The marker is ~ in this case.
|
||||
* No multiple markers check is done and wont work.
|
||||
*/
|
||||
bool WordList::InListAbridged(const char *s, const char marker) const {
|
||||
if (0 == words)
|
||||
return false;
|
||||
const unsigned char firstChar = s[0];
|
||||
int j = starts[firstChar];
|
||||
if (j >= 0) {
|
||||
while (words[j][0] == firstChar) {
|
||||
const char *a = words[j];
|
||||
const char *b = s;
|
||||
while (*a && *a == *b) {
|
||||
a++;
|
||||
if (*a == marker) {
|
||||
a++;
|
||||
const size_t suffixLengthA = strlen(a);
|
||||
const size_t suffixLengthB = strlen(b);
|
||||
if (suffixLengthA >= suffixLengthB)
|
||||
break;
|
||||
b = b + suffixLengthB - suffixLengthA - 1;
|
||||
}
|
||||
b++;
|
||||
}
|
||||
if (!*a && !*b)
|
||||
return true;
|
||||
j++;
|
||||
}
|
||||
}
|
||||
|
||||
j = starts[static_cast<unsigned int>(marker)];
|
||||
if (j >= 0) {
|
||||
while (words[j][0] == marker) {
|
||||
const char *a = words[j] + 1;
|
||||
const char *b = s;
|
||||
const size_t suffixLengthA = strlen(a);
|
||||
const size_t suffixLengthB = strlen(b);
|
||||
if (suffixLengthA > suffixLengthB) {
|
||||
j++;
|
||||
continue;
|
||||
}
|
||||
b = b + suffixLengthB - suffixLengthA;
|
||||
|
||||
while (*a && *a == *b) {
|
||||
a++;
|
||||
b++;
|
||||
}
|
||||
if (!*a && !*b)
|
||||
return true;
|
||||
j++;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
const char *WordList::WordAt(int n) const {
|
||||
return words[n];
|
||||
}
|
||||
|
||||
38
third_party/qscintilla/scintilla/lexlib/WordList.h
vendored
Normal file
38
third_party/qscintilla/scintilla/lexlib/WordList.h
vendored
Normal file
@@ -0,0 +1,38 @@
|
||||
// Scintilla source code edit control
|
||||
/** @file WordList.h
|
||||
** Hold a list of words.
|
||||
**/
|
||||
// Copyright 1998-2010 by Neil Hodgson <neilh@scintilla.org>
|
||||
// The License.txt file describes the conditions under which this software may be distributed.
|
||||
|
||||
#ifndef WORDLIST_H
|
||||
#define WORDLIST_H
|
||||
|
||||
namespace Scintilla {
|
||||
|
||||
/**
|
||||
*/
|
||||
class WordList {
|
||||
// Each word contains at least one character - a empty word acts as sentinel at the end.
|
||||
char **words;
|
||||
char *list;
|
||||
int len;
|
||||
bool onlyLineEnds; ///< Delimited by any white space or only line ends
|
||||
int starts[256];
|
||||
public:
|
||||
explicit WordList(bool onlyLineEnds_ = false);
|
||||
~WordList();
|
||||
operator bool() const;
|
||||
bool operator!=(const WordList &other) const;
|
||||
int Length() const;
|
||||
void Clear();
|
||||
void Set(const char *s);
|
||||
bool InList(const char *s) const;
|
||||
bool InListAbbreviated(const char *s, const char marker) const;
|
||||
bool InListAbridged(const char *s, const char marker) const;
|
||||
const char *WordAt(int n) const;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user