diff options
author | Neil <nyamatongwe@gmail.com> | 2017-06-22 17:43:56 +1000 |
---|---|---|
committer | Neil <nyamatongwe@gmail.com> | 2017-06-22 17:43:56 +1000 |
commit | 3a993f0a5e97435874e06d5496085c4cb7a0d4cb (patch) | |
tree | f1bfbd0aa566e23e67d9340f5fde763ba3621278 | |
parent | 6c72bb1aba1b8b0cea4bd5360f94847316166a92 (diff) | |
download | scintilla-mirror-3a993f0a5e97435874e06d5496085c4cb7a0d4cb.tar.gz |
Backport: Add style metadata methods with null implementations.
Backport based on changesets 6345:faecbd0078e5 and 6346:72bd27f81477.
-rw-r--r-- | include/ILexer.h | 10 | ||||
-rw-r--r-- | include/Scintilla.h | 4 | ||||
-rw-r--r-- | include/Scintilla.iface | 15 | ||||
-rw-r--r-- | lexers/LexCPP.cxx | 20 | ||||
-rw-r--r-- | lexlib/DefaultLexer.cxx | 18 | ||||
-rw-r--r-- | lexlib/DefaultLexer.h | 8 | ||||
-rw-r--r-- | lexlib/LexerBase.cxx | 58 | ||||
-rw-r--r-- | lexlib/LexerBase.h | 16 | ||||
-rw-r--r-- | src/ScintillaBase.cxx | 49 |
9 files changed, 188 insertions, 10 deletions
diff --git a/include/ILexer.h b/include/ILexer.h index 882b52976..03e257c8b 100644 --- a/include/ILexer.h +++ b/include/ILexer.h @@ -54,7 +54,7 @@ public: virtual int SCI_METHOD GetCharacterAndWidth(Sci_Position position, Sci_Position *pWidth) const = 0; }; -enum { lvOriginal=0, lvSubStyles=1 }; +enum { lvOriginal=0, lvSubStyles=1, lvMetaData=2 }; class ILexer { public: @@ -85,6 +85,14 @@ public: virtual const char * SCI_METHOD GetSubStyleBases() = 0; }; +class ILexerWithMetaData : public ILexerWithSubStyles { +public: + virtual int SCI_METHOD NamedStyles() = 0; + virtual const char * SCI_METHOD NameOfStyle(int style) = 0; + virtual const char * SCI_METHOD TagsOfStyle(int style) = 0; + virtual const char * SCI_METHOD DescriptionOfStyle(int style) = 0; +}; + class ILoader { public: virtual int SCI_METHOD Release() = 0; diff --git a/include/Scintilla.h b/include/Scintilla.h index 6f18af9a9..52c810a82 100644 --- a/include/Scintilla.h +++ b/include/Scintilla.h @@ -1010,6 +1010,10 @@ typedef sptr_t (*SciFnDirect)(sptr_t ptr, unsigned int iMessage, uptr_t wParam, #define SCI_SETIDENTIFIERS 4024 #define SCI_DISTANCETOSECONDARYSTYLES 4025 #define SCI_GETSUBSTYLEBASES 4026 +#define SCI_GETNAMEDSTYLES 4029 +#define SCI_NAMEOFSTYLE 4030 +#define SCI_TAGSOFSTYLE 4031 +#define SCI_DESCRIPTIONOFSTYLE 4032 #define SC_MOD_INSERTTEXT 0x1 #define SC_MOD_DELETETEXT 0x2 #define SC_MOD_CHANGESTYLE 0x4 diff --git a/include/Scintilla.iface b/include/Scintilla.iface index 4a2d566a6..1c3b83f3b 100644 --- a/include/Scintilla.iface +++ b/include/Scintilla.iface @@ -2709,6 +2709,21 @@ get int DistanceToSecondaryStyles=4025(,) # Result is NUL-terminated. get int GetSubStyleBases=4026(, stringresult styles) +# Retrieve the number of named styles for the lexer. +get int GetNamedStyles=4029(,) + +# Retrieve the name of a style. +# Result is NUL-terminated. +fun int NameOfStyle=4030(int style, stringresult names) + +# Retrieve a ' ' separated list of style tags like "literal quoted string". +# Result is NUL-terminated. +fun int TagsOfStyle=4031(int style, stringresult names) + +# Retrieve a description of a style. +# Result is NUL-terminated. +fun int DescriptionOfStyle=4032(int style, stringresult names) + # Notifications # Type of modification and the action which caused the modification. # These are defined as a bit mask to make it easy to specify which notifications are wanted. diff --git a/lexers/LexCPP.cxx b/lexers/LexCPP.cxx index 238856b1c..fc42bce54 100644 --- a/lexers/LexCPP.cxx +++ b/lexers/LexCPP.cxx @@ -413,7 +413,7 @@ struct OptionSetCPP : public OptionSet<OptionsCPP> { DefineProperty("fold.cpp.explicit.anywhere", &OptionsCPP::foldExplicitAnywhere, "Set this property to 1 to enable explicit fold points anywhere, not just in line comments."); - + DefineProperty("fold.cpp.preprocessor.at.else", &OptionsCPP::foldPreprocessorAtElse, "This option enables folding on a preprocessor #else or #endif line of an #if statement."); @@ -434,7 +434,7 @@ const char styleSubable[] = {SCE_C_IDENTIFIER, SCE_C_COMMENTDOCKEYWORD, 0}; } -class LexerCPP : public ILexerWithSubStyles { +class LexerCPP : public ILexerWithMetaData { bool caseSensitive; CharacterSet setWord; CharacterSet setNegationOp; @@ -489,7 +489,7 @@ public: delete this; } int SCI_METHOD Version() const override { - return lvSubStyles; + return lvMetaData; } const char * SCI_METHOD PropertyNames() override { return osCPP.PropertyNames(); @@ -545,6 +545,18 @@ public: const char * SCI_METHOD GetSubStyleBases() override { return styleSubable; } + int SCI_METHOD NamedStyles() { + return 0; + } + const char * SCI_METHOD NameOfStyle(int) { + return ""; + } + const char * SCI_METHOD TagsOfStyle(int) { + return ""; + } + const char * SCI_METHOD DescriptionOfStyle(int) { + return ""; + } static ILexer *LexerFactoryCPP() { return new LexerCPP(true); @@ -1354,7 +1366,7 @@ void SCI_METHOD LexerCPP::Fold(Sci_PositionU startPos, Sci_Position length, int } else if (styler.Match(j, "end")) { levelNext--; } - + if (options.foldPreprocessorAtElse && (styler.Match(j, "else") || styler.Match(j, "elif"))) { levelMinCurrent--; } diff --git a/lexlib/DefaultLexer.cxx b/lexlib/DefaultLexer.cxx index 9babbf7a4..4089273f7 100644 --- a/lexlib/DefaultLexer.cxx +++ b/lexlib/DefaultLexer.cxx @@ -37,7 +37,7 @@ void SCI_METHOD DefaultLexer::Release() { } int SCI_METHOD DefaultLexer::Version() const { - return lvOriginal; + return lvMetaData; } const char * SCI_METHOD DefaultLexer::PropertyNames() { @@ -108,3 +108,19 @@ int SCI_METHOD DefaultLexer::DistanceToSecondaryStyles() { const char * SCI_METHOD DefaultLexer::GetSubStyleBases() { return styleSubable; } + +int SCI_METHOD DefaultLexer::NamedStyles() { + return 0; +} + +const char * SCI_METHOD DefaultLexer::NameOfStyle(int) { + return ""; +} + +const char * SCI_METHOD DefaultLexer::TagsOfStyle(int) { + return ""; +} + +const char * SCI_METHOD DefaultLexer::DescriptionOfStyle(int) { + return ""; +} diff --git a/lexlib/DefaultLexer.h b/lexlib/DefaultLexer.h index 7b1490138..0e62a6320 100644 --- a/lexlib/DefaultLexer.h +++ b/lexlib/DefaultLexer.h @@ -1,6 +1,6 @@ // Scintilla source code edit control /** @file DefaultLexer.h - ** A lexer base class with default empty implementations of methods. + ** 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. **/ @@ -15,7 +15,7 @@ namespace Scintilla { #endif // A simple lexer with no state -class DefaultLexer : public ILexerWithSubStyles { +class DefaultLexer : public ILexerWithMetaData { public: DefaultLexer(); virtual ~DefaultLexer(); @@ -40,6 +40,10 @@ public: 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; }; #ifdef SCI_NAMESPACE diff --git a/lexlib/LexerBase.cxx b/lexlib/LexerBase.cxx index 71e2601dc..5ebbe0958 100644 --- a/lexlib/LexerBase.cxx +++ b/lexlib/LexerBase.cxx @@ -24,6 +24,8 @@ using namespace Scintilla; #endif +static const char styleSubable[] = { 0 }; + LexerBase::LexerBase() { for (int wl = 0; wl < numWordLists; wl++) keyWordLists[wl] = new WordList; @@ -43,7 +45,7 @@ void SCI_METHOD LexerBase::Release() { } int SCI_METHOD LexerBase::Version() const { - return lvOriginal; + return lvMetaData; } const char * SCI_METHOD LexerBase::PropertyNames() { @@ -85,5 +87,59 @@ Sci_Position SCI_METHOD LexerBase::WordListSet(int n, const char *wl) { } 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 0; } + +const char * SCI_METHOD LexerBase::NameOfStyle(int) { + return ""; +} + +const char * SCI_METHOD LexerBase::TagsOfStyle(int) { + return ""; +} + +const char * SCI_METHOD LexerBase::DescriptionOfStyle(int) { + return ""; +} diff --git a/lexlib/LexerBase.h b/lexlib/LexerBase.h index ddc561c5c..f320633ef 100644 --- a/lexlib/LexerBase.h +++ b/lexlib/LexerBase.h @@ -13,7 +13,7 @@ namespace Scintilla { #endif // A simple lexer with no state -class LexerBase : public ILexer { +class LexerBase : public ILexerWithMetaData { protected: PropSetSimple props; enum {numWordLists=KEYWORDSET_MAX+1}; @@ -32,6 +32,20 @@ public: 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; }; #ifdef SCI_NAMESPACE diff --git a/src/ScintillaBase.cxx b/src/ScintillaBase.cxx index 0c7df04cb..23dce2fbf 100644 --- a/src/ScintillaBase.cxx +++ b/src/ScintillaBase.cxx @@ -582,6 +582,10 @@ public: void SetIdentifiers(int style, const char *identifiers); int DistanceToSecondaryStyles(); const char *GetSubStyleBases(); + int NamedStyles(); + const char *NameOfStyle(int style); + const char *TagsOfStyle(int style); + const char *DescriptionOfStyle(int style); }; #ifdef SCI_NAMESPACE @@ -790,6 +794,38 @@ const char *LexState::GetSubStyleBases() { return ""; } +int LexState::NamedStyles() { + if (instance && (interfaceVersion >= lvMetaData)) { + return static_cast<ILexerWithMetaData *>(instance)->NamedStyles(); + } else { + return -1; + } +} + +const char *LexState::NameOfStyle(int style) { + if (instance && (interfaceVersion >= lvMetaData)) { + return static_cast<ILexerWithMetaData *>(instance)->NameOfStyle(style); + } else { + return 0; + } +} + +const char *LexState::TagsOfStyle(int style) { + if (instance && (interfaceVersion >= lvMetaData)) { + return static_cast<ILexerWithMetaData *>(instance)->TagsOfStyle(style); + } else { + return 0; + } +} + +const char *LexState::DescriptionOfStyle(int style) { + if (instance && (interfaceVersion >= lvMetaData)) { + return static_cast<ILexerWithMetaData *>(instance)->DescriptionOfStyle(style); + } else { + return 0; + } +} + #endif void ScintillaBase::NotifyStyleToNeeded(Sci::Position endStyleNeeded) { @@ -1101,6 +1137,19 @@ sptr_t ScintillaBase::WndProc(unsigned int iMessage, uptr_t wParam, sptr_t lPara case SCI_GETSUBSTYLEBASES: return StringResult(lParam, DocumentLexState()->GetSubStyleBases()); + + case SCI_GETNAMEDSTYLES: + return DocumentLexState()->NamedStyles(); + + case SCI_NAMEOFSTYLE: + return StringResult(lParam, DocumentLexState()->NameOfStyle(wParam)); + + case SCI_TAGSOFSTYLE: + return StringResult(lParam, DocumentLexState()->TagsOfStyle(wParam)); + + case SCI_DESCRIPTIONOFSTYLE: + return StringResult(lParam, DocumentLexState()->DescriptionOfStyle(wParam)); + #endif default: |