From 6c3b0f66f31a78f4b070ca75bedb3ccd7f105f21 Mon Sep 17 00:00:00 2001 From: Maarten Bent Date: Tue, 28 Jul 2020 22:57:04 +0200 Subject: [PATCH] Update scintilla to 3.21.1 --- src/stc/scintilla/License.txt | 28 +- src/stc/scintilla/include/Compat.h | 70 + src/stc/scintilla/include/ILexer.h | 29 +- src/stc/scintilla/include/ILoader.h | 21 + src/stc/scintilla/include/Platform.h | 320 +- src/stc/scintilla/include/SciLexer.h | 152 + src/stc/scintilla/include/Sci_Position.h | 12 +- src/stc/scintilla/include/Scintilla.h | 134 +- src/stc/scintilla/include/Scintilla.iface | 1133 +++++-- src/stc/scintilla/lexers/LexA68k.cxx | 2 - src/stc/scintilla/lexers/LexAPDL.cxx | 2 - src/stc/scintilla/lexers/LexASY.cxx | 3 +- src/stc/scintilla/lexers/LexAU3.cxx | 4 +- src/stc/scintilla/lexers/LexAVE.cxx | 2 - src/stc/scintilla/lexers/LexAVS.cxx | 2 - src/stc/scintilla/lexers/LexAbaqus.cxx | 4 +- src/stc/scintilla/lexers/LexAda.cxx | 2 - src/stc/scintilla/lexers/LexAsm.cxx | 48 +- src/stc/scintilla/lexers/LexAsn1.cxx | 2 - src/stc/scintilla/lexers/LexBaan.cxx | 76 +- src/stc/scintilla/lexers/LexBash.cxx | 301 +- src/stc/scintilla/lexers/LexBasic.cxx | 42 +- src/stc/scintilla/lexers/LexBatch.cxx | 904 +++--- src/stc/scintilla/lexers/LexBibTeX.cxx | 2 - src/stc/scintilla/lexers/LexBullant.cxx | 2 - src/stc/scintilla/lexers/LexCIL.cxx | 407 +++ src/stc/scintilla/lexers/LexCLW.cxx | 4 +- src/stc/scintilla/lexers/LexCOBOL.cxx | 2 - src/stc/scintilla/lexers/LexCPP.cxx | 517 ++-- src/stc/scintilla/lexers/LexCSS.cxx | 6 +- src/stc/scintilla/lexers/LexCaml.cxx | 7 +- src/stc/scintilla/lexers/LexCmake.cxx | 7 +- src/stc/scintilla/lexers/LexCoffeeScript.cxx | 7 +- src/stc/scintilla/lexers/LexConf.cxx | 2 - src/stc/scintilla/lexers/LexCrontab.cxx | 2 - src/stc/scintilla/lexers/LexCsound.cxx | 2 - src/stc/scintilla/lexers/LexD.cxx | 33 +- src/stc/scintilla/lexers/LexDMAP.cxx | 2 - src/stc/scintilla/lexers/LexDMIS.cxx | 35 +- src/stc/scintilla/lexers/LexDataflex.cxx | 614 ++++ src/stc/scintilla/lexers/LexDiff.cxx | 16 +- src/stc/scintilla/lexers/LexECL.cxx | 2 - src/stc/scintilla/lexers/LexEDIFACT.cxx | 192 +- src/stc/scintilla/lexers/LexEScript.cxx | 4 +- src/stc/scintilla/lexers/LexEiffel.cxx | 2 - src/stc/scintilla/lexers/LexErlang.cxx | 7 +- src/stc/scintilla/lexers/LexErrorList.cxx | 105 +- src/stc/scintilla/lexers/LexFlagship.cxx | 4 +- src/stc/scintilla/lexers/LexForth.cxx | 2 - src/stc/scintilla/lexers/LexFortran.cxx | 248 +- src/stc/scintilla/lexers/LexGAP.cxx | 2 - src/stc/scintilla/lexers/LexGui4Cli.cxx | 5 +- src/stc/scintilla/lexers/LexHTML.cxx | 886 ++++-- src/stc/scintilla/lexers/LexHaskell.cxx | 37 +- src/stc/scintilla/lexers/LexHex.cxx | 6 +- src/stc/scintilla/lexers/LexHollywood.cxx | 516 ++++ src/stc/scintilla/lexers/LexIndent.cxx | 71 + src/stc/scintilla/lexers/LexInno.cxx | 2 - src/stc/scintilla/lexers/LexJSON.cxx | 37 +- src/stc/scintilla/lexers/LexKVIrc.cxx | 2 - src/stc/scintilla/lexers/LexKix.cxx | 2 - src/stc/scintilla/lexers/LexLPeg.cxx | 968 ++++++ src/stc/scintilla/lexers/LexLaTeX.cxx | 29 +- src/stc/scintilla/lexers/LexLisp.cxx | 2 - src/stc/scintilla/lexers/LexLout.cxx | 2 - src/stc/scintilla/lexers/LexLua.cxx | 218 +- src/stc/scintilla/lexers/LexMMIXAL.cxx | 22 +- src/stc/scintilla/lexers/LexMPT.cxx | 2 - src/stc/scintilla/lexers/LexMSSQL.cxx | 2 - src/stc/scintilla/lexers/LexMagik.cxx | 6 +- src/stc/scintilla/lexers/LexMake.cxx | 2 - src/stc/scintilla/lexers/LexMarkdown.cxx | 62 +- src/stc/scintilla/lexers/LexMatlab.cxx | 60 +- src/stc/scintilla/lexers/LexMaxima.cxx | 222 ++ src/stc/scintilla/lexers/LexMetapost.cxx | 7 +- src/stc/scintilla/lexers/LexModula.cxx | 4 +- src/stc/scintilla/lexers/LexMySQL.cxx | 4 +- src/stc/scintilla/lexers/LexNim.cxx | 811 +++++ src/stc/scintilla/lexers/LexNimrod.cxx | 2 - src/stc/scintilla/lexers/LexNsis.cxx | 2 - src/stc/scintilla/lexers/LexNull.cxx | 2 - src/stc/scintilla/lexers/LexOScript.cxx | 4 +- src/stc/scintilla/lexers/LexOpal.cxx | 2 - src/stc/scintilla/lexers/LexPB.cxx | 2 - src/stc/scintilla/lexers/LexPLM.cxx | 3 +- src/stc/scintilla/lexers/LexPO.cxx | 2 - src/stc/scintilla/lexers/LexPOV.cxx | 2 - src/stc/scintilla/lexers/LexPS.cxx | 2 - src/stc/scintilla/lexers/LexPascal.cxx | 2 - src/stc/scintilla/lexers/LexPerl.cxx | 81 +- src/stc/scintilla/lexers/LexPowerPro.cxx | 2 - src/stc/scintilla/lexers/LexPowerShell.cxx | 18 +- src/stc/scintilla/lexers/LexProgress.cxx | 42 +- src/stc/scintilla/lexers/LexProps.cxx | 38 +- src/stc/scintilla/lexers/LexPython.cxx | 512 +++- src/stc/scintilla/lexers/LexR.cxx | 4 +- src/stc/scintilla/lexers/LexRaku.cxx | 1605 ++++++++++ src/stc/scintilla/lexers/LexRebol.cxx | 2 - src/stc/scintilla/lexers/LexRegistry.cxx | 39 +- src/stc/scintilla/lexers/LexRuby.cxx | 10 +- src/stc/scintilla/lexers/LexRust.cxx | 40 +- src/stc/scintilla/lexers/LexSAS.cxx | 220 ++ src/stc/scintilla/lexers/LexSML.cxx | 6 +- src/stc/scintilla/lexers/LexSQL.cxx | 42 +- src/stc/scintilla/lexers/LexSTTXT.cxx | 2 - src/stc/scintilla/lexers/LexScriptol.cxx | 2 - src/stc/scintilla/lexers/LexSmalltalk.cxx | 2 - src/stc/scintilla/lexers/LexSorcus.cxx | 2 - src/stc/scintilla/lexers/LexSpecman.cxx | 2 - src/stc/scintilla/lexers/LexSpice.cxx | 2 - src/stc/scintilla/lexers/LexStata.cxx | 203 ++ src/stc/scintilla/lexers/LexTACL.cxx | 6 +- src/stc/scintilla/lexers/LexTADS3.cxx | 2 - src/stc/scintilla/lexers/LexTAL.cxx | 2 - src/stc/scintilla/lexers/LexTCL.cxx | 12 +- src/stc/scintilla/lexers/LexTCMD.cxx | 2 - src/stc/scintilla/lexers/LexTeX.cxx | 6 +- src/stc/scintilla/lexers/LexTxt2tags.cxx | 2 - src/stc/scintilla/lexers/LexVB.cxx | 8 +- src/stc/scintilla/lexers/LexVHDL.cxx | 113 +- src/stc/scintilla/lexers/LexVerilog.cxx | 59 +- src/stc/scintilla/lexers/LexVisualProlog.cxx | 36 +- src/stc/scintilla/lexers/LexX12.cxx | 345 +++ src/stc/scintilla/lexers/LexYAML.cxx | 8 +- src/stc/scintilla/lexers/descrip.mms | 241 -- src/stc/scintilla/lexlib/Accessor.cxx | 14 +- src/stc/scintilla/lexlib/Accessor.h | 4 - src/stc/scintilla/lexlib/CatalogueModules.h | 70 + .../scintilla/lexlib/CharacterCategory.cxx | 1080 +++++-- src/stc/scintilla/lexlib/CharacterCategory.h | 27 +- src/stc/scintilla/lexlib/CharacterSet.cxx | 25 +- src/stc/scintilla/lexlib/CharacterSet.h | 90 +- src/stc/scintilla/lexlib/DefaultLexer.cxx | 139 + src/stc/scintilla/lexlib/DefaultLexer.h | 57 + src/stc/scintilla/lexlib/LexAccessor.h | 32 +- src/stc/scintilla/lexlib/LexerBase.cxx | 93 +- src/stc/scintilla/lexlib/LexerBase.h | 50 +- src/stc/scintilla/lexlib/LexerModule.cxx | 46 +- src/stc/scintilla/lexlib/LexerModule.h | 50 +- .../scintilla/lexlib/LexerNoExceptions.cxx | 18 +- src/stc/scintilla/lexlib/LexerNoExceptions.h | 12 +- src/stc/scintilla/lexlib/LexerSimple.cxx | 22 +- src/stc/scintilla/lexlib/LexerSimple.h | 13 +- src/stc/scintilla/lexlib/OptionSet.h | 25 +- src/stc/scintilla/lexlib/PropSetSimple.cxx | 57 +- src/stc/scintilla/lexlib/PropSetSimple.h | 8 +- src/stc/scintilla/lexlib/SparseState.h | 28 +- src/stc/scintilla/lexlib/StringCopy.h | 4 - src/stc/scintilla/lexlib/StyleContext.cxx | 15 +- src/stc/scintilla/lexlib/StyleContext.h | 34 +- src/stc/scintilla/lexlib/SubStyles.h | 70 +- src/stc/scintilla/lexlib/WordList.cxx | 95 +- src/stc/scintilla/lexlib/WordList.h | 22 +- src/stc/scintilla/lexlib/descrip.mms | 94 - src/stc/scintilla/src/AutoComplete.cxx | 43 +- src/stc/scintilla/src/AutoComplete.h | 28 +- src/stc/scintilla/src/CallTip.cxx | 320 +- src/stc/scintilla/src/CallTip.h | 53 +- src/stc/scintilla/src/CaseConvert.cxx | 656 ++-- src/stc/scintilla/src/CaseConvert.h | 6 +- src/stc/scintilla/src/CaseFolder.cxx | 9 +- src/stc/scintilla/src/CaseFolder.h | 16 +- src/stc/scintilla/src/Catalogue.cxx | 70 +- src/stc/scintilla/src/Catalogue.h | 8 +- src/stc/scintilla/src/CellBuffer.cxx | 864 ++++-- src/stc/scintilla/src/CellBuffer.h | 166 +- src/stc/scintilla/src/CharClassify.cxx | 15 +- src/stc/scintilla/src/CharClassify.h | 10 +- src/stc/scintilla/src/ContractionState.cxx | 332 +- src/stc/scintilla/src/ContractionState.h | 74 +- src/stc/scintilla/src/DBCS.cxx | 42 + src/stc/scintilla/src/DBCS.h | 25 + src/stc/scintilla/src/Decoration.cxx | 334 ++- src/stc/scintilla/src/Decoration.h | 71 +- src/stc/scintilla/src/Document.cxx | 1517 ++++++---- src/stc/scintilla/src/Document.h | 469 +-- src/stc/scintilla/src/EditModel.cxx | 55 +- src/stc/scintilla/src/EditModel.h | 32 +- src/stc/scintilla/src/EditView.cxx | 1127 ++++--- src/stc/scintilla/src/EditView.h | 102 +- src/stc/scintilla/src/Editor.cxx | 2671 +++++++++-------- src/stc/scintilla/src/Editor.h | 433 +-- src/stc/scintilla/src/ElapsedPeriod.h | 35 + src/stc/scintilla/src/ExternalLexer.cxx | 207 +- src/stc/scintilla/src/ExternalLexer.h | 79 +- src/stc/scintilla/src/FontQuality.h | 4 - src/stc/scintilla/src/Indicator.cxx | 365 ++- src/stc/scintilla/src/Indicator.h | 26 +- src/stc/scintilla/src/IntegerRectangle.h | 29 + src/stc/scintilla/src/KeyMap.cxx | 11 +- src/stc/scintilla/src/KeyMap.h | 11 +- src/stc/scintilla/src/LineMarker.cxx | 703 +++-- src/stc/scintilla/src/LineMarker.h | 76 +- src/stc/scintilla/src/MarginView.cxx | 159 +- src/stc/scintilla/src/MarginView.h | 14 +- src/stc/scintilla/src/Partitioning.h | 154 +- src/stc/scintilla/src/PerLine.cxx | 411 ++- src/stc/scintilla/src/PerLine.h | 150 +- src/stc/scintilla/src/Position.h | 9 +- src/stc/scintilla/src/PositionCache.cxx | 293 +- src/stc/scintilla/src/PositionCache.h | 140 +- src/stc/scintilla/src/RESearch.cxx | 100 +- src/stc/scintilla/src/RESearch.h | 54 +- src/stc/scintilla/src/RunStyles.cxx | 165 +- src/stc/scintilla/src/RunStyles.h | 64 +- src/stc/scintilla/src/ScintillaBase.cxx | 319 +- src/stc/scintilla/src/ScintillaBase.h | 52 +- src/stc/scintilla/src/Selection.cxx | 156 +- src/stc/scintilla/src/Selection.h | 145 +- src/stc/scintilla/src/SparseVector.h | 231 +- src/stc/scintilla/src/SplitVector.h | 206 +- src/stc/scintilla/src/Style.cxx | 47 +- src/stc/scintilla/src/Style.h | 48 +- src/stc/scintilla/src/UniConversion.cxx | 428 +-- src/stc/scintilla/src/UniConversion.h | 72 +- src/stc/scintilla/src/UnicodeFromUTF8.h | 32 - src/stc/scintilla/src/UniqueString.cxx | 55 + src/stc/scintilla/src/UniqueString.h | 48 + src/stc/scintilla/src/ViewStyle.cxx | 324 +- src/stc/scintilla/src/ViewStyle.h | 106 +- src/stc/scintilla/src/XPM.cxx | 134 +- src/stc/scintilla/src/XPM.h | 62 +- src/stc/scintilla/src/descrip.mms | 126 - 223 files changed, 21171 insertions(+), 9779 deletions(-) create mode 100644 src/stc/scintilla/include/Compat.h create mode 100644 src/stc/scintilla/include/ILoader.h create mode 100644 src/stc/scintilla/lexers/LexCIL.cxx create mode 100644 src/stc/scintilla/lexers/LexDataflex.cxx create mode 100644 src/stc/scintilla/lexers/LexHollywood.cxx create mode 100644 src/stc/scintilla/lexers/LexIndent.cxx create mode 100644 src/stc/scintilla/lexers/LexLPeg.cxx create mode 100644 src/stc/scintilla/lexers/LexMaxima.cxx create mode 100644 src/stc/scintilla/lexers/LexNim.cxx create mode 100644 src/stc/scintilla/lexers/LexRaku.cxx create mode 100644 src/stc/scintilla/lexers/LexSAS.cxx create mode 100644 src/stc/scintilla/lexers/LexStata.cxx create mode 100644 src/stc/scintilla/lexers/LexX12.cxx delete mode 100644 src/stc/scintilla/lexers/descrip.mms create mode 100644 src/stc/scintilla/lexlib/CatalogueModules.h create mode 100644 src/stc/scintilla/lexlib/DefaultLexer.cxx create mode 100644 src/stc/scintilla/lexlib/DefaultLexer.h delete mode 100644 src/stc/scintilla/lexlib/descrip.mms create mode 100644 src/stc/scintilla/src/DBCS.cxx create mode 100644 src/stc/scintilla/src/DBCS.h create mode 100644 src/stc/scintilla/src/ElapsedPeriod.h create mode 100644 src/stc/scintilla/src/IntegerRectangle.h delete mode 100644 src/stc/scintilla/src/UnicodeFromUTF8.h create mode 100644 src/stc/scintilla/src/UniqueString.cxx create mode 100644 src/stc/scintilla/src/UniqueString.h delete mode 100644 src/stc/scintilla/src/descrip.mms diff --git a/src/stc/scintilla/License.txt b/src/stc/scintilla/License.txt index cbe25b2fc2..47c7926558 100644 --- a/src/stc/scintilla/License.txt +++ b/src/stc/scintilla/License.txt @@ -2,19 +2,19 @@ License for Scintilla and SciTE Copyright 1998-2003 by Neil Hodgson -All Rights Reserved +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. +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. \ No newline at end of file +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. \ No newline at end of file diff --git a/src/stc/scintilla/include/Compat.h b/src/stc/scintilla/include/Compat.h new file mode 100644 index 0000000000..b6d41e5918 --- /dev/null +++ b/src/stc/scintilla/include/Compat.h @@ -0,0 +1,70 @@ +// c++11 compatibility with some c++14 features and higher. +// This helps minimize changes from the default branch. + +#ifndef COMPAT_H +#define COMPAT_H + +#ifdef __cplusplus + +#include +#include +#include +#include +#include + +namespace Sci { + +// std::clamp +template +inline constexpr T clamp(T val, T minVal, T maxVal) { + return (val > maxVal) ? maxVal : ((val < minVal) ? minVal : val); +} + +// std::round (not present on older MacOSX SDKs) +template +T round(T arg) { + return ::round(arg); +} + +// std::lround (not present on older MacOSX SDKs) +template +long lround(T arg) { + return ::lround(arg); +} + +// std::make_unique +template struct _Unique_if { + typedef std::unique_ptr _Single_object; +}; +template struct _Unique_if { + typedef std::unique_ptr _Unknown_bound; +}; +template struct _Unique_if { + typedef void _Known_bound; +}; +template + typename _Unique_if::_Single_object + make_unique(Args&&... args) { + return std::unique_ptr(new T(std::forward(args)...)); + } +template + typename _Unique_if::_Unknown_bound + make_unique(size_t n) { + typedef typename std::remove_extent::type U; + return std::unique_ptr(new U[n]()); + } +template + typename _Unique_if::_Known_bound + make_unique(Args&&...) = delete; + +// std::size +template +constexpr size_t size(const T (&)[N]) noexcept { + return N; +} + +} + +#endif + +#endif diff --git a/src/stc/scintilla/include/ILexer.h b/src/stc/scintilla/include/ILexer.h index f01029178d..f7f188972f 100644 --- a/src/stc/scintilla/include/ILexer.h +++ b/src/stc/scintilla/include/ILexer.h @@ -10,15 +10,7 @@ #include "Sci_Position.h" -#ifdef SCI_NAMESPACE namespace Scintilla { -#endif - -#ifdef _WIN32 - #define SCI_METHOD __stdcall -#else - #define SCI_METHOD -#endif enum { dvOriginal=0, dvLineEnd=1 }; @@ -54,7 +46,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, lvIdentity=3 }; class ILexer { public: @@ -85,16 +77,21 @@ public: virtual const char * SCI_METHOD GetSubStyleBases() = 0; }; -class ILoader { +class ILexerWithMetaData : public ILexerWithSubStyles { public: - virtual int SCI_METHOD Release() = 0; - // Returns a status code from SC_STATUS_* - virtual int SCI_METHOD AddData(char *data, Sci_Position length) = 0; - virtual void * SCI_METHOD ConvertToDocument() = 0; + 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 ILexerWithIdentity : public ILexerWithMetaData { +public: + virtual const char * SCI_METHOD GetName() = 0; + virtual int SCI_METHOD GetIdentifier() = 0; + virtual const char * SCI_METHOD PropertyGet(const char *key) = 0; }; -#ifdef SCI_NAMESPACE } -#endif #endif diff --git a/src/stc/scintilla/include/ILoader.h b/src/stc/scintilla/include/ILoader.h new file mode 100644 index 0000000000..e989de8736 --- /dev/null +++ b/src/stc/scintilla/include/ILoader.h @@ -0,0 +1,21 @@ +// Scintilla source code edit control +/** @file ILoader.h + ** Interface for loading into a Scintilla document from a background thread. + **/ +// Copyright 1998-2017 by Neil Hodgson +// The License.txt file describes the conditions under which this software may be distributed. + +#ifndef ILOADER_H +#define ILOADER_H + +#include "Sci_Position.h" + +class ILoader { +public: + virtual int SCI_METHOD Release() = 0; + // Returns a status code from SC_STATUS_* + virtual int SCI_METHOD AddData(const char *data, Sci_Position length) = 0; + virtual void * SCI_METHOD ConvertToDocument() = 0; +}; + +#endif diff --git a/src/stc/scintilla/include/Platform.h b/src/stc/scintilla/include/Platform.h index 1ff48ecb14..b5e2109b4d 100644 --- a/src/stc/scintilla/include/Platform.h +++ b/src/stc/scintilla/include/Platform.h @@ -25,6 +25,7 @@ #define PLAT_FOX 0 #define PLAT_CURSES 0 #define PLAT_TK 0 +#define PLAT_HAIKU 0 #if defined(FOX) #undef PLAT_FOX @@ -38,6 +39,10 @@ #undef PLAT_CURSES #define PLAT_CURSES 1 +#elif defined(__HAIKU__) +#undef PLAT_HAIKU +#define PLAT_HAIKU 1 + #elif defined(SCINTILLA_QT) #undef PLAT_QT #define PLAT_QT 1 @@ -71,15 +76,10 @@ #endif -#ifdef SCI_NAMESPACE namespace Scintilla { -#endif typedef float XYPOSITION; typedef double XYACCUMULATOR; -inline int RoundXYPosition(XYPOSITION xyPos) { - return int(xyPos + 0.5); -} // Underlying the implementation of the platform classes are platform specific types. // Sometimes these need to be passed around by client code so they are defined here @@ -101,21 +101,31 @@ public: XYPOSITION x; XYPOSITION y; - explicit Point(XYPOSITION x_=0, XYPOSITION y_=0) : x(x_), y(y_) { + constexpr explicit Point(XYPOSITION x_=0, XYPOSITION y_=0) noexcept : x(x_), y(y_) { } - static Point FromInts(int x_, int y_) { + static constexpr Point FromInts(int x_, int y_) noexcept { return Point(static_cast(x_), static_cast(y_)); } - // Other automatically defined methods (assignment, copy constructor, destructor) are fine + constexpr bool operator!=(Point other) const noexcept { + return (x != other.x) || (y != other.y); + } - static Point FromLong(long lpoint); + constexpr Point operator+(Point other) const noexcept { + return Point(x + other.x, y + other.y); + } + + constexpr Point operator-(Point other) const noexcept { + return Point(x - other.x, y - other.y); + } + + // Other automatically defined methods (assignment, copy constructor, destructor) are fine }; /** * A geometric rectangle class. - * PRectangle is similar to the Win32 RECT. + * PRectangle is similar to Win32 RECT. * PRectangles contain their top and left sides, but not their right and bottom sides. */ class PRectangle { @@ -125,113 +135,147 @@ public: XYPOSITION right; XYPOSITION bottom; - explicit PRectangle(XYPOSITION left_=0, XYPOSITION top_=0, XYPOSITION right_=0, XYPOSITION bottom_ = 0) : + constexpr explicit PRectangle(XYPOSITION left_=0, XYPOSITION top_=0, XYPOSITION right_=0, XYPOSITION bottom_ = 0) noexcept : left(left_), top(top_), right(right_), bottom(bottom_) { } - static PRectangle FromInts(int left_, int top_, int right_, int bottom_) { + static constexpr PRectangle FromInts(int left_, int top_, int right_, int bottom_) noexcept { return PRectangle(static_cast(left_), static_cast(top_), static_cast(right_), static_cast(bottom_)); } // Other automatically defined methods (assignment, copy constructor, destructor) are fine - bool operator==(PRectangle &rc) const { + constexpr bool operator==(const PRectangle &rc) const noexcept { return (rc.left == left) && (rc.right == right) && (rc.top == top) && (rc.bottom == bottom); } - bool Contains(Point pt) const { + constexpr bool Contains(Point pt) const noexcept { return (pt.x >= left) && (pt.x <= right) && (pt.y >= top) && (pt.y <= bottom); } - bool ContainsWholePixel(Point pt) const { + constexpr bool ContainsWholePixel(Point pt) const noexcept { // Does the rectangle contain all of the pixel to left/below the point return (pt.x >= left) && ((pt.x+1) <= right) && (pt.y >= top) && ((pt.y+1) <= bottom); } - bool Contains(PRectangle rc) const { + constexpr bool Contains(PRectangle rc) const noexcept { return (rc.left >= left) && (rc.right <= right) && (rc.top >= top) && (rc.bottom <= bottom); } - bool Intersects(PRectangle other) const { + constexpr bool Intersects(PRectangle other) const noexcept { return (right > other.left) && (left < other.right) && (bottom > other.top) && (top < other.bottom); } - void Move(XYPOSITION xDelta, XYPOSITION yDelta) { + void Move(XYPOSITION xDelta, XYPOSITION yDelta) noexcept { left += xDelta; top += yDelta; right += xDelta; bottom += yDelta; } - XYPOSITION Width() const { return right - left; } - XYPOSITION Height() const { return bottom - top; } - bool Empty() const { + constexpr XYPOSITION Width() const noexcept { return right - left; } + constexpr XYPOSITION Height() const noexcept { return bottom - top; } + constexpr bool Empty() const noexcept { return (Height() <= 0) || (Width() <= 0); } }; /** - * Holds a desired RGB colour. + * Holds an RGB colour with 8 bits for each component. */ +constexpr const float componentMaximum = 255.0f; class ColourDesired { - long co; + int co; public: - ColourDesired(long lcol=0) { - co = lcol; + constexpr explicit ColourDesired(int co_=0) noexcept : co(co_) { } - ColourDesired(unsigned int red, unsigned int green, unsigned int blue) { - Set(red, green, blue); + constexpr ColourDesired(unsigned int red, unsigned int green, unsigned int blue) noexcept : + co(red | (green << 8) | (blue << 16)) { } - bool operator==(const ColourDesired &other) const { + constexpr bool operator==(const ColourDesired &other) const noexcept { return co == other.co; } - void Set(long lcol) { - co = lcol; - } - - void Set(unsigned int red, unsigned int green, unsigned int blue) { - co = red | (green << 8) | (blue << 16); - } - - static inline unsigned int ValueOfHex(const char ch) { - if (ch >= '0' && ch <= '9') - return ch - '0'; - else if (ch >= 'A' && ch <= 'F') - return ch - 'A' + 10; - else if (ch >= 'a' && ch <= 'f') - return ch - 'a' + 10; - else - return 0; - } - - void Set(const char *val) { - if (*val == '#') { - val++; - } - unsigned int r = ValueOfHex(val[0]) * 16 + ValueOfHex(val[1]); - unsigned int g = ValueOfHex(val[2]) * 16 + ValueOfHex(val[3]); - unsigned int b = ValueOfHex(val[4]) * 16 + ValueOfHex(val[5]); - Set(r, g, b); - } - - long AsLong() const { + constexpr int AsInteger() const noexcept { return co; } - unsigned int GetRed() const { + // Red, green and blue values as bytes 0..255 + constexpr unsigned char GetRed() const noexcept { return co & 0xff; } - - unsigned int GetGreen() const { + constexpr unsigned char GetGreen() const noexcept { return (co >> 8) & 0xff; } - - unsigned int GetBlue() const { + constexpr unsigned char GetBlue() const noexcept { return (co >> 16) & 0xff; } + + // Red, green and blue values as float 0..1.0 + constexpr float GetRedComponent() const noexcept { + return GetRed() / componentMaximum; + } + constexpr float GetGreenComponent() const noexcept { + return GetGreen() / componentMaximum; + } + constexpr float GetBlueComponent() const noexcept { + return GetBlue() / componentMaximum; + } +}; + +/** +* Holds an RGBA colour. +*/ +class ColourAlpha : public ColourDesired { +public: + constexpr explicit ColourAlpha(int co_ = 0) noexcept : ColourDesired(co_) { + } + + constexpr ColourAlpha(unsigned int red, unsigned int green, unsigned int blue) noexcept : + ColourDesired(red | (green << 8) | (blue << 16)) { + } + + constexpr ColourAlpha(unsigned int red, unsigned int green, unsigned int blue, unsigned int alpha) noexcept : + ColourDesired(red | (green << 8) | (blue << 16) | (alpha << 24)) { + } + + constexpr ColourAlpha(ColourDesired cd, unsigned int alpha) noexcept : + ColourDesired(cd.AsInteger() | (alpha << 24)) { + } + + constexpr ColourDesired GetColour() const noexcept { + return ColourDesired(AsInteger() & 0xffffff); + } + + constexpr unsigned char GetAlpha() const noexcept { + return (AsInteger() >> 24) & 0xff; + } + + constexpr float GetAlphaComponent() const noexcept { + return GetAlpha() / componentMaximum; + } + + ColourAlpha MixedWith(ColourAlpha other) const noexcept { + const unsigned int red = (GetRed() + other.GetRed()) / 2; + const unsigned int green = (GetGreen() + other.GetGreen()) / 2; + const unsigned int blue = (GetBlue() + other.GetBlue()) / 2; + const unsigned int alpha = (GetAlpha() + other.GetAlpha()) / 2; + return ColourAlpha(red, green, blue, alpha); + } +}; + +/** +* Holds an element of a gradient with an RGBA colour and a relative position. +*/ +class ColourStop { +public: + float position; + ColourAlpha colour; + ColourStop(float position_, ColourAlpha colour_) noexcept : + position(position_), colour(colour_) { + } }; /** @@ -254,7 +298,7 @@ struct FontParameters { bool italic_=false, int extraFontFlag_=0, int technology_=0, - int characterSet_=0) : + int characterSet_=0) noexcept : faceName(faceName_), size(size_), @@ -271,19 +315,21 @@ struct FontParameters { class Font { protected: FontID fid; - // Private so Font objects can not be copied - Font(const Font &); - Font &operator=(const Font &); public: - Font(); + Font() noexcept; + // Deleted so Font objects can not be copied + Font(const Font &) = delete; + Font(Font &&) = delete; + Font &operator=(const Font &) = delete; + Font &operator=(Font &&) = delete; virtual ~Font(); virtual void Create(const FontParameters &fp); virtual void Release(); - FontID GetID() { return fid; } + FontID GetID() const noexcept { return fid; } // Alias another font - caller guarantees not to Release - void SetID(FontID fid_) { fid = fid_; } + void SetID(FontID fid_) noexcept { fid = fid_; } friend class Surface; friend class SurfaceImpl; }; @@ -292,12 +338,12 @@ public: * A surface abstracts a place to draw. */ class Surface { -private: - // Private so Surface objects can not be copied - Surface(const Surface &) {} - Surface &operator=(const Surface &) { return *this; } public: - Surface() {} + Surface() noexcept = default; + Surface(const Surface &) = delete; + Surface(Surface &&) = delete; + Surface &operator=(const Surface &) = delete; + Surface &operator=(Surface &&) = delete; virtual ~Surface() {} static Surface *Allocate(int technology); @@ -312,27 +358,27 @@ public: virtual int DeviceHeightFont(int points)=0; virtual void MoveTo(int x_, int y_)=0; virtual void LineTo(int x_, int y_)=0; - virtual void Polygon(Point *pts, int npts, ColourDesired fore, ColourDesired back)=0; + virtual void Polygon(Point *pts, size_t npts, ColourDesired fore, ColourDesired back)=0; virtual void RectangleDraw(PRectangle rc, ColourDesired fore, ColourDesired back)=0; virtual void FillRectangle(PRectangle rc, ColourDesired back)=0; virtual void FillRectangle(PRectangle rc, Surface &surfacePattern)=0; virtual void RoundedRectangle(PRectangle rc, ColourDesired fore, ColourDesired back)=0; virtual void AlphaRectangle(PRectangle rc, int cornerSize, ColourDesired fill, int alphaFill, ColourDesired outline, int alphaOutline, int flags)=0; + enum class GradientOptions { leftToRight, topToBottom }; + virtual void GradientRectangle(PRectangle rc, const std::vector &stops, GradientOptions options)=0; virtual void DrawRGBAImage(PRectangle rc, int width, int height, const unsigned char *pixelsImage) = 0; virtual void Ellipse(PRectangle rc, ColourDesired fore, ColourDesired back)=0; virtual void Copy(PRectangle rc, Point from, Surface &surfaceSource)=0; - virtual void DrawTextNoClip(PRectangle rc, Font &font_, XYPOSITION ybase, const char *s, int len, ColourDesired fore, ColourDesired back)=0; - virtual void DrawTextClipped(PRectangle rc, Font &font_, XYPOSITION ybase, const char *s, int len, ColourDesired fore, ColourDesired back)=0; - virtual void DrawTextTransparent(PRectangle rc, Font &font_, XYPOSITION ybase, const char *s, int len, ColourDesired fore)=0; - virtual void MeasureWidths(Font &font_, const char *s, int len, XYPOSITION *positions)=0; - virtual XYPOSITION WidthText(Font &font_, const char *s, int len)=0; - virtual XYPOSITION WidthChar(Font &font_, char ch)=0; + virtual void DrawTextNoClip(PRectangle rc, Font &font_, XYPOSITION ybase, const char *s, int len, ColourDesired fore, ColourDesired back) = 0; + virtual void DrawTextClipped(PRectangle rc, Font &font_, XYPOSITION ybase, const char *s, int len, ColourDesired fore, ColourDesired back) = 0; + virtual void DrawTextTransparent(PRectangle rc, Font &font_, XYPOSITION ybase, const char *s, int len, ColourDesired fore) = 0; + virtual void MeasureWidths(Font &font_, const char *s, int len, XYPOSITION *positions) = 0; + virtual XYPOSITION WidthText(Font &font_, const char *s, int len) = 0; virtual XYPOSITION Ascent(Font &font_)=0; virtual XYPOSITION Descent(Font &font_)=0; virtual XYPOSITION InternalLeading(Font &font_)=0; - virtual XYPOSITION ExternalLeading(Font &font_)=0; virtual XYPOSITION Height(Font &font_)=0; virtual XYPOSITION AverageCharWidth(Font &font_)=0; @@ -343,11 +389,6 @@ public: virtual void SetDBCSMode(int codePage)=0; }; -/** - * A simple callback action passing one piece of untyped user data. - */ -typedef void (*CallBackAction)(void*); - /** * Class to hide the details of window manipulation. * Does not own the window which will normally have a longer life than this object. @@ -356,30 +397,31 @@ class Window { protected: WindowID wid; public: - Window() : wid(0), cursorLast(cursorInvalid) { + Window() noexcept : wid(nullptr), cursorLast(cursorInvalid) { } - Window(const Window &source) : wid(source.wid), cursorLast(cursorInvalid) { - } - virtual ~Window(); - Window &operator=(WindowID wid_) { + Window(const Window &source) = delete; + Window(Window &&) = delete; + Window &operator=(WindowID wid_) noexcept { wid = wid_; + cursorLast = cursorInvalid; return *this; } - WindowID GetID() const { return wid; } - bool Created() const { return wid != 0; } + Window &operator=(const Window &) = delete; + Window &operator=(Window &&) = delete; + virtual ~Window(); + WindowID GetID() const noexcept { return wid; } + bool Created() const noexcept { return wid != nullptr; } void Destroy(); - bool HasFocus(); - PRectangle GetPosition(); + PRectangle GetPosition() const; void SetPosition(PRectangle rc); - void SetPositionRelative(PRectangle rc, Window relativeTo); - PRectangle GetClientPosition(); + void SetPositionRelative(PRectangle rc, const Window *relativeTo); + PRectangle GetClientPosition() const; void Show(bool show=true); void InvalidateAll(); void InvalidateRectangle(PRectangle rc); virtual void SetFont(Font &font); enum Cursor { cursorInvalid, cursorText, cursorArrow, cursorUp, cursorWait, cursorHoriz, cursorVert, cursorReverseArrow, cursorHand }; void SetCursor(Cursor curs); - void SetTitle(const char *s); PRectangle GetMonitorRect(Point pt); private: Cursor cursorLast; @@ -389,13 +431,26 @@ private: * Listbox management. */ +// ScintillaBase implements IListBoxDelegate to receive ListBoxEvents from a ListBox + +struct ListBoxEvent { + enum class EventType { selectionChange, doubleClick } event; + ListBoxEvent(EventType event_) noexcept : event(event_) { + } +}; + +class IListBoxDelegate { +public: + virtual void ListNotify(ListBoxEvent *plbe)=0; +}; + class ListBox : public Window { public: - ListBox(); - virtual ~ListBox(); + ListBox() noexcept; + ~ListBox() override; static ListBox *Allocate(); - virtual void SetFont(Font &font)=0; + void SetFont(Font &font) override =0; virtual void Create(Window &parent, int ctrlID, Point location, int lineHeight_, bool unicodeMode_, int technology_)=0; virtual void SetAverageCharWidth(int width)=0; virtual void SetVisibleRows(int rows)=0; @@ -412,7 +467,7 @@ public: virtual void RegisterImage(int type, const char *xpm_data)=0; virtual void RegisterRGBAImage(int type, int width, int height, const unsigned char *pixelsImage) = 0; virtual void ClearRegisteredImages()=0; - virtual void SetDoubleClickAction(CallBackAction, void *)=0; + virtual void SetDelegate(IListBoxDelegate *lbDelegate)=0; virtual void SetList(const char* list, char separator, char typesep)=0; }; @@ -422,27 +477,19 @@ public: class Menu { MenuID mid; public: - Menu(); - MenuID GetID() { return mid; } + Menu() noexcept; + MenuID GetID() const noexcept { return mid; } void CreatePopUp(); void Destroy(); void Show(Point pt, Window &w); }; -class ElapsedTime { - long bigBit; - long littleBit; -public: - ElapsedTime(); - double Duration(bool reset=false); -}; - /** * Dynamic Library (DLL/SO/...) loading */ class DynamicLibrary { public: - virtual ~DynamicLibrary() {} + virtual ~DynamicLibrary() = default; /// @return Pointer to function "name", or NULL on failure. virtual Function FindFunction(const char *name) = 0; @@ -469,61 +516,34 @@ public: * and chrome colour. Not a creatable object, more of a module with several functions. */ class Platform { - // Private so Platform objects can not be copied - Platform(const Platform &) {} - Platform &operator=(const Platform &) { return *this; } public: - // Should be private because no new Platforms are ever created - // but gcc warns about this - Platform() {} - ~Platform() {} + Platform() = default; + Platform(const Platform &) = delete; + Platform(Platform &&) = delete; + Platform &operator=(const Platform &) = delete; + Platform &operator=(Platform &&) = delete; + ~Platform() = default; static ColourDesired Chrome(); static ColourDesired ChromeHighlight(); static const char *DefaultFont(); static int DefaultFontSize(); static unsigned int DoubleClickTime(); - static bool MouseButtonBounce(); static void DebugDisplay(const char *s); - static bool IsKeyDown(int key); - static long SendScintilla( - WindowID w, unsigned int msg, unsigned long wParam=0, long lParam=0); - static long SendScintillaPointer( - WindowID w, unsigned int msg, unsigned long wParam=0, void *lParam=0); - static bool IsDBCSLeadByte(int codePage, char ch); - static int DBCSCharLength(int codePage, const char *s); - static int DBCSCharMaxLength(); - - // These are utility functions not really tied to a platform - static int Minimum(int a, int b); - static int Maximum(int a, int b); - // Next three assume 16 bit shorts and 32 bit longs - static long LongFromTwoShorts(short a,short b) { + static constexpr long LongFromTwoShorts(short a,short b) noexcept { return (a) | ((b) << 16); } - static short HighShortFromLong(long x) { - return static_cast(x >> 16); - } - static short LowShortFromLong(long x) { - return static_cast(x & 0xffff); - } + static void DebugPrintf(const char *format, ...); static bool ShowAssertionPopUps(bool assertionPopUps_); static void Assert(const char *c, const char *file, int line) CLANG_ANALYZER_NORETURN; - static int Clamp(int val, int minVal, int maxVal); }; #ifdef NDEBUG #define PLATFORM_ASSERT(c) ((void)0) #else -#ifdef SCI_NAMESPACE #define PLATFORM_ASSERT(c) ((c) ? (void)(0) : Scintilla::Platform::Assert(#c, __FILE__, __LINE__)) -#else -#define PLATFORM_ASSERT(c) ((c) ? (void)(0) : Platform::Assert(#c, __FILE__, __LINE__)) -#endif #endif -#ifdef SCI_NAMESPACE } -#endif #endif diff --git a/src/stc/scintilla/include/SciLexer.h b/src/stc/scintilla/include/SciLexer.h index 44c02a84ae..e58f6184cf 100644 --- a/src/stc/scintilla/include/SciLexer.h +++ b/src/stc/scintilla/include/SciLexer.h @@ -134,6 +134,17 @@ #define SCLEX_TEHEX 119 #define SCLEX_JSON 120 #define SCLEX_EDIFACT 121 +#define SCLEX_INDENT 122 +#define SCLEX_MAXIMA 123 +#define SCLEX_STATA 124 +#define SCLEX_SAS 125 +#define SCLEX_NIM 126 +#define SCLEX_CIL 127 +#define SCLEX_X12 128 +#define SCLEX_DATAFLEX 129 +#define SCLEX_HOLLYWOOD 130 +#define SCLEX_RAKU 131 +#define SCLEX_LPEG 999 #define SCLEX_AUTOMATIC 1000 #define SCE_P_DEFAULT 0 #define SCE_P_COMMENTLINE 1 @@ -151,6 +162,10 @@ #define SCE_P_STRINGEOL 13 #define SCE_P_WORD2 14 #define SCE_P_DECORATOR 15 +#define SCE_P_FSTRING 16 +#define SCE_P_FCHARACTER 17 +#define SCE_P_FTRIPLE 18 +#define SCE_P_FTRIPLEDOUBLE 19 #define SCE_C_DEFAULT 0 #define SCE_C_COMMENT 1 #define SCE_C_COMMENTLINE 2 @@ -502,6 +517,7 @@ #define SCE_ERR_GCC_INCLUDED_FROM 22 #define SCE_ERR_ESCSEQ 23 #define SCE_ERR_ESCSEQ_UNKNOWN 24 +#define SCE_ERR_GCC_EXCERPT 25 #define SCE_ERR_ES_BLACK 40 #define SCE_ERR_ES_RED 41 #define SCE_ERR_ES_GREEN 42 @@ -552,6 +568,10 @@ #define SCE_DIFF_DELETED 5 #define SCE_DIFF_ADDED 6 #define SCE_DIFF_CHANGED 7 +#define SCE_DIFF_PATCH_ADD 8 +#define SCE_DIFF_PATCH_DELETE 9 +#define SCE_DIFF_REMOVED_PATCH_ADD 10 +#define SCE_DIFF_REMOVED_PATCH_DELETE 11 #define SCE_CONF_DEFAULT 0 #define SCE_CONF_COMMENT 1 #define SCE_CONF_NUMBER 2 @@ -667,6 +687,14 @@ #define SCE_MATLAB_OPERATOR 6 #define SCE_MATLAB_IDENTIFIER 7 #define SCE_MATLAB_DOUBLEQUOTESTRING 8 +#define SCE_MAXIMA_OPERATOR 0 +#define SCE_MAXIMA_COMMANDENDING 1 +#define SCE_MAXIMA_COMMENT 2 +#define SCE_MAXIMA_NUMBER 3 +#define SCE_MAXIMA_STRING 4 +#define SCE_MAXIMA_COMMAND 5 +#define SCE_MAXIMA_VARIABLE 6 +#define SCE_MAXIMA_UNKNOWN 7 #define SCE_SCRIPTOL_DEFAULT 0 #define SCE_SCRIPTOL_WHITE 1 #define SCE_SCRIPTOL_COMMENTLINE 2 @@ -1807,6 +1835,130 @@ #define SCE_EDI_UNA 6 #define SCE_EDI_UNH 7 #define SCE_EDI_BADSEGMENT 8 +#define SCE_STATA_DEFAULT 0 +#define SCE_STATA_COMMENT 1 +#define SCE_STATA_COMMENTLINE 2 +#define SCE_STATA_COMMENTBLOCK 3 +#define SCE_STATA_NUMBER 4 +#define SCE_STATA_OPERATOR 5 +#define SCE_STATA_IDENTIFIER 6 +#define SCE_STATA_STRING 7 +#define SCE_STATA_TYPE 8 +#define SCE_STATA_WORD 9 +#define SCE_STATA_GLOBAL_MACRO 10 +#define SCE_STATA_MACRO 11 +#define SCE_SAS_DEFAULT 0 +#define SCE_SAS_COMMENT 1 +#define SCE_SAS_COMMENTLINE 2 +#define SCE_SAS_COMMENTBLOCK 3 +#define SCE_SAS_NUMBER 4 +#define SCE_SAS_OPERATOR 5 +#define SCE_SAS_IDENTIFIER 6 +#define SCE_SAS_STRING 7 +#define SCE_SAS_TYPE 8 +#define SCE_SAS_WORD 9 +#define SCE_SAS_GLOBAL_MACRO 10 +#define SCE_SAS_MACRO 11 +#define SCE_SAS_MACRO_KEYWORD 12 +#define SCE_SAS_BLOCK_KEYWORD 13 +#define SCE_SAS_MACRO_FUNCTION 14 +#define SCE_SAS_STATEMENT 15 +#define SCE_NIM_DEFAULT 0 +#define SCE_NIM_COMMENT 1 +#define SCE_NIM_COMMENTDOC 2 +#define SCE_NIM_COMMENTLINE 3 +#define SCE_NIM_COMMENTLINEDOC 4 +#define SCE_NIM_NUMBER 5 +#define SCE_NIM_STRING 6 +#define SCE_NIM_CHARACTER 7 +#define SCE_NIM_WORD 8 +#define SCE_NIM_TRIPLE 9 +#define SCE_NIM_TRIPLEDOUBLE 10 +#define SCE_NIM_BACKTICKS 11 +#define SCE_NIM_FUNCNAME 12 +#define SCE_NIM_STRINGEOL 13 +#define SCE_NIM_NUMERROR 14 +#define SCE_NIM_OPERATOR 15 +#define SCE_NIM_IDENTIFIER 16 +#define SCE_CIL_DEFAULT 0 +#define SCE_CIL_COMMENT 1 +#define SCE_CIL_COMMENTLINE 2 +#define SCE_CIL_WORD 3 +#define SCE_CIL_WORD2 4 +#define SCE_CIL_WORD3 5 +#define SCE_CIL_STRING 6 +#define SCE_CIL_LABEL 7 +#define SCE_CIL_OPERATOR 8 +#define SCE_CIL_IDENTIFIER 9 +#define SCE_CIL_STRINGEOL 10 +#define SCE_X12_DEFAULT 0 +#define SCE_X12_BAD 1 +#define SCE_X12_ENVELOPE 2 +#define SCE_X12_FUNCTIONGROUP 3 +#define SCE_X12_TRANSACTIONSET 4 +#define SCE_X12_SEGMENTHEADER 5 +#define SCE_X12_SEGMENTEND 6 +#define SCE_X12_SEP_ELEMENT 7 +#define SCE_X12_SEP_SUBELEMENT 8 +#define SCE_DF_DEFAULT 0 +#define SCE_DF_IDENTIFIER 1 +#define SCE_DF_METATAG 2 +#define SCE_DF_IMAGE 3 +#define SCE_DF_COMMENTLINE 4 +#define SCE_DF_PREPROCESSOR 5 +#define SCE_DF_PREPROCESSOR2 6 +#define SCE_DF_NUMBER 7 +#define SCE_DF_HEXNUMBER 8 +#define SCE_DF_WORD 9 +#define SCE_DF_STRING 10 +#define SCE_DF_STRINGEOL 11 +#define SCE_DF_SCOPEWORD 12 +#define SCE_DF_OPERATOR 13 +#define SCE_DF_ICODE 14 +#define SCE_HOLLYWOOD_DEFAULT 0 +#define SCE_HOLLYWOOD_COMMENT 1 +#define SCE_HOLLYWOOD_COMMENTBLOCK 2 +#define SCE_HOLLYWOOD_NUMBER 3 +#define SCE_HOLLYWOOD_KEYWORD 4 +#define SCE_HOLLYWOOD_STDAPI 5 +#define SCE_HOLLYWOOD_PLUGINAPI 6 +#define SCE_HOLLYWOOD_PLUGINMETHOD 7 +#define SCE_HOLLYWOOD_STRING 8 +#define SCE_HOLLYWOOD_STRINGBLOCK 9 +#define SCE_HOLLYWOOD_PREPROCESSOR 10 +#define SCE_HOLLYWOOD_OPERATOR 11 +#define SCE_HOLLYWOOD_IDENTIFIER 12 +#define SCE_HOLLYWOOD_CONSTANT 13 +#define SCE_HOLLYWOOD_HEXNUMBER 14 +#define SCE_RAKU_DEFAULT 0 +#define SCE_RAKU_ERROR 1 +#define SCE_RAKU_COMMENTLINE 2 +#define SCE_RAKU_COMMENTEMBED 3 +#define SCE_RAKU_POD 4 +#define SCE_RAKU_CHARACTER 5 +#define SCE_RAKU_HEREDOC_Q 6 +#define SCE_RAKU_HEREDOC_QQ 7 +#define SCE_RAKU_STRING 8 +#define SCE_RAKU_STRING_Q 9 +#define SCE_RAKU_STRING_QQ 10 +#define SCE_RAKU_STRING_Q_LANG 11 +#define SCE_RAKU_STRING_VAR 12 +#define SCE_RAKU_REGEX 13 +#define SCE_RAKU_REGEX_VAR 14 +#define SCE_RAKU_ADVERB 15 +#define SCE_RAKU_NUMBER 16 +#define SCE_RAKU_PREPROCESSOR 17 +#define SCE_RAKU_OPERATOR 18 +#define SCE_RAKU_WORD 19 +#define SCE_RAKU_FUNCTION 20 +#define SCE_RAKU_IDENTIFIER 21 +#define SCE_RAKU_TYPEDEF 22 +#define SCE_RAKU_MU 23 +#define SCE_RAKU_POSITIONAL 24 +#define SCE_RAKU_ASSOCIATIVE 25 +#define SCE_RAKU_CALLABLE 26 +#define SCE_RAKU_GRAMMAR 27 +#define SCE_RAKU_CLASS 28 /* --Autogenerated -- end of section automatically generated from Scintilla.iface */ #endif diff --git a/src/stc/scintilla/include/Sci_Position.h b/src/stc/scintilla/include/Sci_Position.h index a83e2864f6..abd0f34081 100644 --- a/src/stc/scintilla/include/Sci_Position.h +++ b/src/stc/scintilla/include/Sci_Position.h @@ -9,13 +9,21 @@ #ifndef SCI_POSITION_H #define SCI_POSITION_H +#include + // Basic signed type used throughout interface -typedef int Sci_Position; +typedef ptrdiff_t Sci_Position; // Unsigned variant used for ILexer::Lex and ILexer::Fold -typedef unsigned int Sci_PositionU; +typedef size_t Sci_PositionU; // For Sci_CharacterRange which is defined as long to be compatible with Win32 CHARRANGE typedef long Sci_PositionCR; +#ifdef _WIN32 + #define SCI_METHOD __stdcall +#else + #define SCI_METHOD +#endif + #endif diff --git a/src/stc/scintilla/include/Scintilla.h b/src/stc/scintilla/include/Scintilla.h index 8c57520e18..6f59d4e278 100644 --- a/src/stc/scintilla/include/Scintilla.h +++ b/src/stc/scintilla/include/Scintilla.h @@ -27,14 +27,7 @@ int Scintilla_LinkLexers(void); #endif // Include header that defines basic numeric types. -#if defined(_MSC_VER) -// Older releases of MSVC did not have stdint.h. -#include -#elif defined( __VMS ) -#include -#else #include -#endif // Define uptr_t, an unsigned integer type large enough to hold a pointer. typedef uintptr_t uptr_t; @@ -45,6 +38,8 @@ typedef intptr_t sptr_t; typedef sptr_t (*SciFnDirect)(sptr_t ptr, unsigned int iMessage, uptr_t wParam, sptr_t lParam); +#ifndef SCI_DISABLE_AUTOGENERATED + /* ++Autogenerated -- start of section automatically generated from Scintilla.iface */ #define INVALID_POSITION -1 #define SCI_START 2000 @@ -70,6 +65,8 @@ typedef sptr_t (*SciFnDirect)(sptr_t ptr, unsigned int iMessage, uptr_t wParam, #define SCI_CANREDO 2016 #define SCI_MARKERLINEFROMHANDLE 2017 #define SCI_MARKERDELETEHANDLE 2018 +#define SCI_MARKERHANDLEFROMLINE 2732 +#define SCI_MARKERNUMBERFROMLINE 2733 #define SCI_GETUNDOCOLLECTION 2019 #define SCWS_INVISIBLE 0 #define SCWS_VISIBLEALWAYS 1 @@ -100,6 +97,8 @@ typedef sptr_t (*SciFnDirect)(sptr_t ptr, unsigned int iMessage, uptr_t wParam, #define SCI_SETBUFFEREDDRAW 2035 #define SCI_SETTABWIDTH 2036 #define SCI_GETTABWIDTH 2121 +#define SCI_SETTABMINIMUMWIDTH 2724 +#define SCI_GETTABMINIMUMWIDTH 2725 #define SCI_CLEARTABSTOPS 2675 #define SCI_ADDTABSTOP 2676 #define SCI_GETNEXTTABSTOP 2677 @@ -109,6 +108,13 @@ typedef sptr_t (*SciFnDirect)(sptr_t ptr, unsigned int iMessage, uptr_t wParam, #define SC_IME_INLINE 1 #define SCI_GETIMEINTERACTION 2678 #define SCI_SETIMEINTERACTION 2679 +#define SC_ALPHA_TRANSPARENT 0 +#define SC_ALPHA_OPAQUE 255 +#define SC_ALPHA_NOALPHA 256 +#define SC_CURSORNORMAL -1 +#define SC_CURSORARROW 2 +#define SC_CURSORWAIT 4 +#define SC_CURSORREVERSEARROW 7 #define MARKER_MAX 31 #define SC_MARK_CIRCLE 0 #define SC_MARK_ROUNDRECT 1 @@ -142,6 +148,7 @@ typedef sptr_t (*SciFnDirect)(sptr_t ptr, unsigned int iMessage, uptr_t wParam, #define SC_MARK_UNDERLINE 29 #define SC_MARK_RGBAIMAGE 30 #define SC_MARK_BOOKMARK 31 +#define SC_MARK_VERTICALBOOKMARK 32 #define SC_MARK_CHARACTER 10000 #define SC_MARKNUM_FOLDEREND 25 #define SC_MARKNUM_FOLDEROPENMID 26 @@ -273,6 +280,8 @@ typedef sptr_t (*SciFnDirect)(sptr_t ptr, unsigned int iMessage, uptr_t wParam, #define SCI_SETCARETPERIOD 2076 #define SCI_SETWORDCHARS 2077 #define SCI_GETWORDCHARS 2646 +#define SCI_SETCHARACTERCATEGORYOPTIMIZATION 2720 +#define SCI_GETCHARACTERCATEGORYOPTIMIZATION 2721 #define SCI_BEGINUNDOACTION 2078 #define SCI_ENDUNDOACTION 2079 #define INDIC_PLAIN 0 @@ -295,14 +304,16 @@ typedef sptr_t (*SciFnDirect)(sptr_t ptr, unsigned int iMessage, uptr_t wParam, #define INDIC_TEXTFORE 17 #define INDIC_POINT 18 #define INDIC_POINTCHARACTER 19 +#define INDIC_GRADIENT 20 +#define INDIC_GRADIENTCENTRE 21 +#define INDIC_CONTAINER 8 #define INDIC_IME 32 #define INDIC_IME_MAX 35 #define INDIC_MAX 35 -#define INDIC_CONTAINER 8 -#define INDIC0_MASK 0x20 -#define INDIC1_MASK 0x40 -#define INDIC2_MASK 0x80 -#define INDICS_MASK 0xE0 +#define INDICATOR_CONTAINER 8 +#define INDICATOR_IME 32 +#define INDICATOR_IME_MAX 35 +#define INDICATOR_MAX 35 #define SCI_INDICSETSTYLE 2080 #define SCI_INDICGETSTYLE 2081 #define SCI_INDICSETFORE 2082 @@ -322,8 +333,6 @@ typedef sptr_t (*SciFnDirect)(sptr_t ptr, unsigned int iMessage, uptr_t wParam, #define SCI_SETWHITESPACEBACK 2085 #define SCI_SETWHITESPACESIZE 2086 #define SCI_GETWHITESPACESIZE 2087 -#define SCI_SETSTYLEBITS 2090 -#define SCI_GETSTYLEBITS 2091 #define SCI_SETLINESTATE 2092 #define SCI_GETLINESTATE 2093 #define SCI_GETMAXLINESTATE 2094 @@ -331,6 +340,8 @@ typedef sptr_t (*SciFnDirect)(sptr_t ptr, unsigned int iMessage, uptr_t wParam, #define SCI_SETCARETLINEVISIBLE 2096 #define SCI_GETCARETLINEBACK 2097 #define SCI_SETCARETLINEBACK 2098 +#define SCI_GETCARETLINEFRAME 2704 +#define SCI_SETCARETLINEFRAME 2705 #define SCI_STYLESETCHANGEABLE 2099 #define SCI_AUTOCSHOW 2100 #define SCI_AUTOCCANCEL 2101 @@ -370,6 +381,7 @@ typedef sptr_t (*SciFnDirect)(sptr_t ptr, unsigned int iMessage, uptr_t wParam, #define SCI_GETLINEINDENTPOSITION 2128 #define SCI_GETCOLUMN 2129 #define SCI_COUNTCHARACTERS 2633 +#define SCI_COUNTCODEUNITS 2715 #define SCI_SETHSCROLLBAR 2130 #define SCI_GETHSCROLLBAR 2131 #define SC_IV_NONE 0 @@ -397,8 +409,10 @@ typedef sptr_t (*SciFnDirect)(sptr_t ptr, unsigned int iMessage, uptr_t wParam, #define SC_PRINT_BLACKONWHITE 2 #define SC_PRINT_COLOURONWHITE 3 #define SC_PRINT_COLOURONWHITEDEFAULTBG 4 +#define SC_PRINT_SCREENCOLOURS 5 #define SCI_SETPRINTCOLOURMODE 2148 #define SCI_GETPRINTCOLOURMODE 2149 +#define SCFIND_NONE 0x0 #define SCFIND_WHOLEWORD 0x2 #define SCFIND_MATCHCASE 0x4 #define SCFIND_WORDSTART 0x00100000 @@ -448,8 +462,12 @@ typedef sptr_t (*SciFnDirect)(sptr_t ptr, unsigned int iMessage, uptr_t wParam, #define SCI_GETCARETWIDTH 2189 #define SCI_SETTARGETSTART 2190 #define SCI_GETTARGETSTART 2191 +#define SCI_SETTARGETSTARTVIRTUALSPACE 2728 +#define SCI_GETTARGETSTARTVIRTUALSPACE 2729 #define SCI_SETTARGETEND 2192 #define SCI_GETTARGETEND 2193 +#define SCI_SETTARGETENDVIRTUALSPACE 2730 +#define SCI_GETTARGETENDVIRTUALSPACE 2731 #define SCI_SETTARGETRANGE 2686 #define SCI_GETTARGETTEXT 2687 #define SCI_TARGETFROMSELECTION 2287 @@ -493,6 +511,9 @@ typedef sptr_t (*SciFnDirect)(sptr_t ptr, unsigned int iMessage, uptr_t wParam, #define SC_FOLDDISPLAYTEXT_STANDARD 1 #define SC_FOLDDISPLAYTEXT_BOXED 2 #define SCI_FOLDDISPLAYTEXTSETSTYLE 2701 +#define SCI_FOLDDISPLAYTEXTGETSTYLE 2707 +#define SCI_SETDEFAULTFOLDDISPLAYTEXT 2722 +#define SCI_GETDEFAULTFOLDDISPLAYTEXT 2723 #define SC_FOLDACTION_CONTRACT 0 #define SC_FOLDACTION_EXPAND 1 #define SC_FOLDACTION_TOGGLE 2 @@ -552,6 +573,7 @@ typedef sptr_t (*SciFnDirect)(sptr_t ptr, unsigned int iMessage, uptr_t wParam, #define SC_WRAPINDENT_FIXED 0 #define SC_WRAPINDENT_SAME 1 #define SC_WRAPINDENT_INDENT 2 +#define SC_WRAPINDENT_DEEPINDENT 3 #define SCI_SETWRAPINDENTMODE 2472 #define SCI_GETWRAPINDENTMODE 2473 #define SC_CACHE_NONE 0 @@ -595,6 +617,10 @@ typedef sptr_t (*SciFnDirect)(sptr_t ptr, unsigned int iMessage, uptr_t wParam, #define SCI_LINESSPLIT 2289 #define SCI_SETFOLDMARGINCOLOUR 2290 #define SCI_SETFOLDMARGINHICOLOUR 2291 +#define SC_ACCESSIBILITY_DISABLED 0 +#define SC_ACCESSIBILITY_ENABLED 1 +#define SCI_SETACCESSIBILITY 2702 +#define SCI_GETACCESSIBILITY 2703 #define SCI_LINEDOWN 2300 #define SCI_LINEDOWNEXTEND 2301 #define SCI_LINEUP 2302 @@ -636,6 +662,7 @@ typedef sptr_t (*SciFnDirect)(sptr_t ptr, unsigned int iMessage, uptr_t wParam, #define SCI_LINECUT 2337 #define SCI_LINEDELETE 2338 #define SCI_LINETRANSPOSE 2339 +#define SCI_LINEREVERSE 2354 #define SCI_LINEDUPLICATE 2404 #define SCI_LOWERCASE 2340 #define SCI_UPPERCASE 2341 @@ -660,6 +687,7 @@ typedef sptr_t (*SciFnDirect)(sptr_t ptr, unsigned int iMessage, uptr_t wParam, #define SCI_BRACEBADLIGHT 2352 #define SCI_BRACEBADLIGHTINDICATOR 2499 #define SCI_BRACEMATCH 2353 +#define SCI_BRACEMATCHNEXT 2369 #define SCI_GETVIEWEOL 2355 #define SCI_SETVIEWEOL 2356 #define SCI_GETDOCPOINTER 2357 @@ -677,6 +705,7 @@ typedef sptr_t (*SciFnDirect)(sptr_t ptr, unsigned int iMessage, uptr_t wParam, #define SCI_SETEDGECOLOUR 2365 #define SCI_MULTIEDGEADDLINE 2694 #define SCI_MULTIEDGECLEARALL 2695 +#define SCI_GETMULTIEDGECOLUMN 2749 #define SCI_SEARCHANCHOR 2366 #define SCI_SEARCHNEXT 2367 #define SCI_SEARCHPREV 2368 @@ -688,10 +717,16 @@ typedef sptr_t (*SciFnDirect)(sptr_t ptr, unsigned int iMessage, uptr_t wParam, #define SCI_SELECTIONISRECTANGLE 2372 #define SCI_SETZOOM 2373 #define SCI_GETZOOM 2374 +#define SC_DOCUMENTOPTION_DEFAULT 0 +#define SC_DOCUMENTOPTION_STYLES_NONE 0x1 +#define SC_DOCUMENTOPTION_TEXT_LARGE 0x100 #define SCI_CREATEDOCUMENT 2375 #define SCI_ADDREFDOCUMENT 2376 #define SCI_RELEASEDOCUMENT 2377 +#define SCI_GETDOCUMENTOPTIONS 2379 #define SCI_GETMODEVENTMASK 2378 +#define SCI_SETCOMMANDEVENTS 2717 +#define SCI_GETCOMMANDEVENTS 2718 #define SCI_SETFOCUS 2380 #define SCI_GETFOCUS 2381 #define SC_STATUS_OK 0 @@ -705,10 +740,6 @@ typedef sptr_t (*SciFnDirect)(sptr_t ptr, unsigned int iMessage, uptr_t wParam, #define SCI_GETMOUSEDOWNCAPTURES 2385 #define SCI_SETMOUSEWHEELCAPTURES 2696 #define SCI_GETMOUSEWHEELCAPTURES 2697 -#define SC_CURSORNORMAL -1 -#define SC_CURSORARROW 2 -#define SC_CURSORWAIT 4 -#define SC_CURSORREVERSEARROW 7 #define SCI_SETCURSOR 2386 #define SCI_GETCURSOR 2387 #define SCI_SETCONTROLCHARSYMBOL 2388 @@ -749,6 +780,7 @@ typedef sptr_t (*SciFnDirect)(sptr_t ptr, unsigned int iMessage, uptr_t wParam, #define SCI_POSITIONBEFORE 2417 #define SCI_POSITIONAFTER 2418 #define SCI_POSITIONRELATIVE 2670 +#define SCI_POSITIONRELATIVECODEUNITS 2716 #define SCI_COPYRANGE 2419 #define SCI_COPYTEXT 2420 #define SC_SEL_STREAM 0 @@ -757,6 +789,7 @@ typedef sptr_t (*SciFnDirect)(sptr_t ptr, unsigned int iMessage, uptr_t wParam, #define SC_SEL_THIN 3 #define SCI_SETSELECTIONMODE 2422 #define SCI_GETSELECTIONMODE 2423 +#define SCI_GETMOVEEXTENDSSELECTION 2706 #define SCI_GETLINESELSTARTPOSITION 2424 #define SCI_GETLINESELENDPOSITION 2425 #define SCI_LINEDOWNRECTEXTEND 2426 @@ -801,23 +834,24 @@ typedef sptr_t (*SciFnDirect)(sptr_t ptr, unsigned int iMessage, uptr_t wParam, #define SCI_SETLENGTHFORENCODE 2448 #define SCI_ENCODEDFROMUTF8 2449 #define SCI_FINDCOLUMN 2456 -#define SCI_GETCARETSTICKY 2457 -#define SCI_SETCARETSTICKY 2458 #define SC_CARETSTICKY_OFF 0 #define SC_CARETSTICKY_ON 1 #define SC_CARETSTICKY_WHITESPACE 2 +#define SCI_GETCARETSTICKY 2457 +#define SCI_SETCARETSTICKY 2458 #define SCI_TOGGLECARETSTICKY 2459 #define SCI_SETPASTECONVERTENDINGS 2467 #define SCI_GETPASTECONVERTENDINGS 2468 #define SCI_SELECTIONDUPLICATE 2469 -#define SC_ALPHA_TRANSPARENT 0 -#define SC_ALPHA_OPAQUE 255 -#define SC_ALPHA_NOALPHA 256 #define SCI_SETCARETLINEBACKALPHA 2470 #define SCI_GETCARETLINEBACKALPHA 2471 #define CARETSTYLE_INVISIBLE 0 #define CARETSTYLE_LINE 1 #define CARETSTYLE_BLOCK 2 +#define CARETSTYLE_OVERSTRIKE_BAR 0 +#define CARETSTYLE_OVERSTRIKE_BLOCK 0x10 +#define CARETSTYLE_INS_MASK 0xF +#define CARETSTYLE_BLOCK_AFTER 0x100 #define SCI_SETCARETSTYLE 2512 #define SCI_GETCARETSTYLE 2513 #define SCI_SETINDICATORCURRENT 2500 @@ -876,6 +910,7 @@ typedef sptr_t (*SciFnDirect)(sptr_t ptr, unsigned int iMessage, uptr_t wParam, #define SCI_ANNOTATIONGETSTYLEOFFSET 2551 #define SCI_RELEASEALLEXTENDEDSTYLES 2552 #define SCI_ALLOCATEEXTENDEDSTYLES 2553 +#define UNDO_NONE 0 #define UNDO_MAY_COALESCE 1 #define SCI_ADDUNDOACTION 2560 #define SCI_CHARPOSITIONFROMPOINT 2561 @@ -908,7 +943,9 @@ typedef sptr_t (*SciFnDirect)(sptr_t ptr, unsigned int iMessage, uptr_t wParam, #define SCI_GETSELECTIONNANCHORVIRTUALSPACE 2583 #define SCI_SETSELECTIONNSTART 2584 #define SCI_GETSELECTIONNSTART 2585 +#define SCI_GETSELECTIONNSTARTVIRTUALSPACE 2726 #define SCI_SETSELECTIONNEND 2586 +#define SCI_GETSELECTIONNENDVIRTUALSPACE 2727 #define SCI_GETSELECTIONNEND 2587 #define SCI_SETRECTANGULARSELECTIONCARET 2588 #define SCI_GETRECTANGULARSELECTIONCARET 2589 @@ -972,6 +1009,18 @@ typedef sptr_t (*SciFnDirect)(sptr_t ptr, unsigned int iMessage, uptr_t wParam, #define SCI_SETREPRESENTATION 2665 #define SCI_GETREPRESENTATION 2666 #define SCI_CLEARREPRESENTATION 2667 +#define SCI_EOLANNOTATIONSETTEXT 2740 +#define SCI_EOLANNOTATIONGETTEXT 2741 +#define SCI_EOLANNOTATIONSETSTYLE 2742 +#define SCI_EOLANNOTATIONGETSTYLE 2743 +#define SCI_EOLANNOTATIONCLEARALL 2744 +#define EOLANNOTATION_HIDDEN 0 +#define EOLANNOTATION_STANDARD 1 +#define EOLANNOTATION_BOXED 2 +#define SCI_EOLANNOTATIONSETVISIBLE 2745 +#define SCI_EOLANNOTATIONGETVISIBLE 2746 +#define SCI_EOLANNOTATIONSETSTYLEOFFSET 2747 +#define SCI_EOLANNOTATIONGETSTYLEOFFSET 2748 #define SCI_STARTRECORD 3001 #define SCI_STOPRECORD 3002 #define SCI_SETLEXER 4001 @@ -985,7 +1034,6 @@ typedef sptr_t (*SciFnDirect)(sptr_t ptr, unsigned int iMessage, uptr_t wParam, #define SCI_GETPROPERTY 4008 #define SCI_GETPROPERTYEXPANDED 4009 #define SCI_GETPROPERTYINT 4010 -#define SCI_GETSTYLEBITSNEEDED 4011 #define SCI_GETLEXERLANGUAGE 4012 #define SCI_PRIVATELEXERCALL 4013 #define SCI_PROPERTYNAMES 4014 @@ -1005,6 +1053,11 @@ 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_NONE 0x0 #define SC_MOD_INSERTTEXT 0x1 #define SC_MOD_DELETETEXT 0x2 #define SC_MOD_CHANGESTYLE 0x4 @@ -1027,7 +1080,8 @@ typedef sptr_t (*SciFnDirect)(sptr_t ptr, unsigned int iMessage, uptr_t wParam, #define SC_MOD_LEXERSTATE 0x80000 #define SC_MOD_INSERTCHECK 0x100000 #define SC_MOD_CHANGETABSTOPS 0x200000 -#define SC_MODEVENTMASKALL 0x3FFFFF +#define SC_MOD_CHANGEEOLANNOTATION 0x400000 +#define SC_MODEVENTMASKALL 0x7FFFFF #define SC_UPDATE_CONTENT 0x1 #define SC_UPDATE_SELECTION 0x2 #define SC_UPDATE_V_SCROLL 0x4 @@ -1066,6 +1120,9 @@ typedef sptr_t (*SciFnDirect)(sptr_t ptr, unsigned int iMessage, uptr_t wParam, #define SC_AC_TAB 3 #define SC_AC_NEWLINE 4 #define SC_AC_COMMAND 5 +#define SC_CHARACTERSOURCE_DIRECT_INPUT 0 +#define SC_CHARACTERSOURCE_TENTATIVE_INPUT 1 +#define SC_CHARACTERSOURCE_IME_RESULT 2 #define SCN_STYLENEEDED 2000 #define SCN_CHARADDED 2001 #define SCN_SAVEPOINTREACHED 2002 @@ -1097,8 +1154,21 @@ typedef sptr_t (*SciFnDirect)(sptr_t ptr, unsigned int iMessage, uptr_t wParam, #define SCN_FOCUSOUT 2029 #define SCN_AUTOCCOMPLETED 2030 #define SCN_MARGINRIGHTCLICK 2031 +#define SCN_AUTOCSELECTIONCHANGE 2032 +#ifndef SCI_DISABLE_PROVISIONAL +#define SC_LINECHARACTERINDEX_NONE 0 +#define SC_LINECHARACTERINDEX_UTF32 1 +#define SC_LINECHARACTERINDEX_UTF16 2 +#define SCI_GETLINECHARACTERINDEX 2710 +#define SCI_ALLOCATELINECHARACTERINDEX 2711 +#define SCI_RELEASELINECHARACTERINDEX 2712 +#define SCI_LINEFROMINDEXPOSITION 2713 +#define SCI_INDEXPOSITIONFROMLINE 2714 +#endif /* --Autogenerated -- end of section automatically generated from Scintilla.iface */ +#endif + /* These structures are defined to be exactly the same shape as the Win32 * CHARRANGE, TEXTRANGE, FINDTEXTEX, FORMATRANGE, and NMHDR structs. * So older code that treats Scintilla as a RichEdit will work. */ @@ -1192,6 +1262,7 @@ struct SCNotification { int updated; /* SCN_UPDATEUI */ int listCompletionMethod; /* SCN_AUTOCSELECTION, SCN_AUTOCCOMPLETED, SCN_USERLISTSELECTION, */ + int characterSource; /* SCN_CHARADDED */ }; #ifdef INCLUDE_DEPRECATED_FEATURES @@ -1205,6 +1276,17 @@ struct SCNotification { #define RangeToFormat Sci_RangeToFormat #define NotifyHeader Sci_NotifyHeader -#endif +#define SCI_SETSTYLEBITS 2090 +#define SCI_GETSTYLEBITS 2091 +#define SCI_GETSTYLEBITSNEEDED 4011 + +#define INDIC0_MASK 0x20 +#define INDIC1_MASK 0x40 +#define INDIC2_MASK 0x80 +#define INDICS_MASK 0xE0 + +#endif + +#include "Compat.h" #endif diff --git a/src/stc/scintilla/include/Scintilla.iface b/src/stc/scintilla/include/Scintilla.iface index d5be8c58c0..7d32ed46df 100644 --- a/src/stc/scintilla/include/Scintilla.iface +++ b/src/stc/scintilla/include/Scintilla.iface @@ -10,7 +10,7 @@ ## A line starting with # followed by a space is a documentation comment and refers ## to the next feature definition. -## Each feature is defined by a line starting with fun, get, set, val or evt. +## Each feature is defined by a line starting with fun, get, set, val, evt, enu, lex, or ali. ## cat -> start a category ## fun -> a function ## get -> a property get function @@ -19,6 +19,7 @@ ## evt -> an event ## enu -> associate an enumeration with a set of vals with a prefix ## lex -> associate a lexer with the lexical classes it produces +## ali -> add an alias for a val, commonly adding '_' to separate words ## ## All other feature names should be ignored. They may be defined in the future. ## A property may have a set function, a get function or both. Each will have @@ -46,19 +47,22 @@ ## to enu. The name may not be the same as that used within the lexer so the lexerVal ## should be used to tie these entities together. -## Types: +## Types: Never start with a capital letter ## void ## int ## bool -> integer, 1=true, 0=false -## position -> integer position in a document +## position -> intptr_t position in a document +## line -> intptr_t line in a document ## colour -> colour integer containing red, green and blue bytes. ## string -> pointer to const character ## stringresult -> pointer to character, NULL-> return size of result ## cells -> pointer to array of cells, each cell containing a style byte and character byte +## pointer -> void* pointer that may point to a document, loader, internal text storage or similar ## textrange -> range of a min and a max position with an output string ## findtext -> searchrange, text -> foundposition ## keymod -> integer containing key in low half and modifiers in high half ## formatrange +## Enumeration types always start with a capital letter ## Types no longer used: ## findtextex -> searchrange ## charrange -> range of a min and a max position @@ -90,28 +94,28 @@ val SCI_OPTIONAL_START=3000 val SCI_LEXER_START=4000 # Add text to the document at current position. -fun void AddText=2001(int length, string text) +fun void AddText=2001(position length, string text) # Add array of cells to document. -fun void AddStyledText=2002(int length, cells c) +fun void AddStyledText=2002(position length, cells c) # Insert string at a position. fun void InsertText=2003(position pos, string text) # Change the text that is being inserted in response to SC_MOD_INSERTCHECK -fun void ChangeInsertion=2672(int length, string text) +fun void ChangeInsertion=2672(position length, string text) # Delete all text in the document. fun void ClearAll=2004(,) # Delete a range of text in the document. -fun void DeleteRange=2645(position start, int lengthDelete) +fun void DeleteRange=2645(position start, position lengthDelete) # Set all style bytes to 0, remove all folding information. fun void ClearDocumentStyle=2005(,) # Returns the number of bytes in the document. -get int GetLength=2006(,) +get position GetLength=2006(,) # Returns the character byte at the position. get int GetCharAt=2007(position pos,) @@ -141,17 +145,23 @@ fun void SetSavePoint=2014(,) # Retrieve a buffer of cells. # Returns the number of bytes in the buffer not including terminating NULs. -fun int GetStyledText=2015(, textrange tr) +fun position GetStyledText=2015(, textrange tr) # Are there any redoable actions in the undo history? fun bool CanRedo=2016(,) # Retrieve the line number at which a particular marker is located. -fun int MarkerLineFromHandle=2017(int markerHandle,) +fun line MarkerLineFromHandle=2017(int markerHandle,) # Delete a marker. fun void MarkerDeleteHandle=2018(int markerHandle,) +# Retrieve marker handles of a line +fun int MarkerHandleFromLine=2732(line line, int which) + +# Retrieve marker number of a marker handle +fun int MarkerNumberFromLine=2733(line line, int which) + # Is undo history being collected? get bool GetUndoCollection=2019(,) @@ -161,23 +171,30 @@ val SCWS_VISIBLEALWAYS=1 val SCWS_VISIBLEAFTERINDENT=2 val SCWS_VISIBLEONLYININDENT=3 +ali SCWS_VISIBLEALWAYS=VISIBLE_ALWAYS +ali SCWS_VISIBLEAFTERINDENT=VISIBLE_AFTER_INDENT +ali SCWS_VISIBLEONLYININDENT=VISIBLE_ONLY_IN_INDENT + # Are white space characters currently visible? # Returns one of SCWS_* constants. -get int GetViewWS=2020(,) +get WhiteSpace GetViewWS=2020(,) # Make white space characters invisible, always visible or visible outside indentation. -set void SetViewWS=2021(int viewWS,) +set void SetViewWS=2021(WhiteSpace viewWS,) enu TabDrawMode=SCTD_ val SCTD_LONGARROW=0 val SCTD_STRIKEOUT=1 +ali SCTD_LONGARROW=LONG_ARROW +ali SCTD_STRIKEOUT=STRIKE_OUT + # Retrieve the current tab draw mode. # Returns one of SCTD_* constants. -get int GetTabDrawMode=2698(,) +get TabDrawMode GetTabDrawMode=2698(,) # Set how tabs are drawn when visible. -set void SetTabDrawMode=2699(int tabDrawMode,) +set void SetTabDrawMode=2699(TabDrawMode tabDrawMode,) # Find the position from a point within the window. fun position PositionFromPoint=2022(int x, int y) @@ -187,7 +204,7 @@ fun position PositionFromPoint=2022(int x, int y) fun position PositionFromPointClose=2023(int x, int y) # Set caret to start of a line and ensure it is visible. -fun void GotoLine=2024(int line,) +fun void GotoLine=2024(line line,) # Set caret to a position and ensure it is visible. fun void GotoPos=2025(position caret,) @@ -199,7 +216,7 @@ set void SetAnchor=2026(position anchor,) # Retrieve the text of the line containing the caret. # Returns the index of the caret on the line. # Result is NUL-terminated. -fun int GetCurLine=2027(int length, stringresult text) +fun position GetCurLine=2027(position length, stringresult text) # Retrieve the position of the last correctly styled character. get position GetEndStyled=2028(,) @@ -209,14 +226,16 @@ val SC_EOL_CRLF=0 val SC_EOL_CR=1 val SC_EOL_LF=2 +ali SC_EOL_CRLF=CR_LF + # Convert all line endings in the document to one mode. -fun void ConvertEOLs=2029(int eolMode,) +fun void ConvertEOLs=2029(EndOfLine eolMode,) # Retrieve the current end of line mode - one of CRLF, CR, or LF. -get int GetEOLMode=2030(,) +get EndOfLine GetEOLMode=2030(,) # Set the current end of line mode. -set void SetEOLMode=2031(int eolMode,) +set void SetEOLMode=2031(EndOfLine eolMode,) # Set the current styling position to start. # The unused parameter is no longer used and should be set to 0. @@ -224,7 +243,7 @@ fun void StartStyling=2032(position start, int unused) # Change style from current styling position for length characters to a style # and move the current styling position to after this newly styled segment. -fun void SetStyling=2033(int length, int style) +fun void SetStyling=2033(position length, int style) # Is drawing done first into a buffer or direct to the screen? get bool GetBufferedDraw=2034(,) @@ -239,14 +258,20 @@ set void SetTabWidth=2036(int tabWidth,) # Retrieve the visible size of a tab. get int GetTabWidth=2121(,) +# Set the minimum visual width of a tab. +set void SetTabMinimumWidth=2724(int pixels,) + +# Get the minimum visual width of a tab. +get int GetTabMinimumWidth=2725(,) + # Clear explicit tabstops on a line. -fun void ClearTabStops=2675(int line,) +fun void ClearTabStops=2675(line line,) # Add an explicit tab stop for a line. -fun void AddTabStop=2676(int line, int x) +fun void AddTabStop=2676(line line, int x) # Find the next explicit tab stop position on a line after a position. -fun int GetNextTabStop=2677(int line, int x) +fun int GetNextTabStop=2677(line line, int x) # The SC_CP_UTF8 value can be used to enter Unicode mode. # This is the same value as CP_UTF8 in Windows @@ -261,10 +286,25 @@ val SC_IME_WINDOWED=0 val SC_IME_INLINE=1 # Is the IME displayed in a window or inline? -get int GetIMEInteraction=2678(,) +get IMEInteraction GetIMEInteraction=2678(,) -# Choose to display the IME in a winow or inline. -set void SetIMEInteraction=2679(int imeInteraction,) +# Choose to display the IME in a window or inline. +set void SetIMEInteraction=2679(IMEInteraction imeInteraction,) + +enu Alpha=SC_ALPHA_ +val SC_ALPHA_TRANSPARENT=0 +val SC_ALPHA_OPAQUE=255 +val SC_ALPHA_NOALPHA=256 + +ali SC_ALPHA_NOALPHA=NO_ALPHA + +enu CursorShape=SC_CURSOR +val SC_CURSORNORMAL=-1 +val SC_CURSORARROW=2 +val SC_CURSORWAIT=4 +val SC_CURSORREVERSEARROW=7 + +ali SC_CURSORREVERSEARROW=REVERSE_ARROW enu MarkerSymbol=SC_MARK_ val MARKER_MAX=31 @@ -304,9 +344,33 @@ val SC_MARK_AVAILABLE=28 val SC_MARK_UNDERLINE=29 val SC_MARK_RGBAIMAGE=30 val SC_MARK_BOOKMARK=31 +val SC_MARK_VERTICALBOOKMARK=32 val SC_MARK_CHARACTER=10000 +ali SC_MARK_ROUNDRECT=ROUND_RECT +ali SC_MARK_SMALLRECT=SMALL_RECT +ali SC_MARK_SHORTARROW=SHORT_ARROW +ali SC_MARK_ARROWDOWN=ARROW_DOWN +ali SC_MARK_VLINE=V_LINE +ali SC_MARK_LCORNER=L_CORNER +ali SC_MARK_TCORNER=T_CORNER +ali SC_MARK_BOXPLUS=BOX_PLUS +ali SC_MARK_BOXPLUSCONNECTED=BOX_PLUS_CONNECTED +ali SC_MARK_BOXMINUS=BOX_MINUS +ali SC_MARK_BOXMINUSCONNECTED=BOX_MINUS_CONNECTED +ali SC_MARK_LCORNERCURVE=L_CORNER_CURVE +ali SC_MARK_TCORNERCURVE=T_CORNER_CURVE +ali SC_MARK_CIRCLEPLUS=CIRCLE_PLUS +ali SC_MARK_CIRCLEPLUSCONNECTED=CIRCLE_PLUS_CONNECTED +ali SC_MARK_CIRCLEMINUS=CIRCLE_MINUS +ali SC_MARK_CIRCLEMINUSCONNECTED=CIRCLE_MINUS_CONNECTED +ali SC_MARK_DOTDOTDOT=DOT_DOT_DOT +ali SC_MARK_FULLRECT=FULL_RECT +ali SC_MARK_LEFTRECT=LEFT_RECT +ali SC_MARK_RGBAIMAGE=RGBA_IMAGE +ali SC_MARK_VERTICALBOOKMARK=VERTICAL_BOOKMARK + enu MarkerOutline=SC_MARKNUM_ # Markers used for outlining column. val SC_MARKNUM_FOLDEREND=25 @@ -317,10 +381,18 @@ val SC_MARKNUM_FOLDERSUB=29 val SC_MARKNUM_FOLDER=30 val SC_MARKNUM_FOLDEROPEN=31 +ali SC_MARKNUM_FOLDEREND=FOLDER_END +ali SC_MARKNUM_FOLDEROPENMID=FOLDER_OPEN_MID +ali SC_MARKNUM_FOLDERMIDTAIL=FOLDER_MID_TAIL +ali SC_MARKNUM_FOLDERTAIL=FOLDER_TAIL +ali SC_MARKNUM_FOLDERSUB=FOLDER_SUB +ali SC_MARKNUM_FOLDEROPEN=FOLDER_OPEN + +# SC_MASK_FOLDERS doesn't go in an enumeration as larger than max 32-bit positive integer val SC_MASK_FOLDERS=0xFE000000 # Set the symbol used for a particular marker number. -fun void MarkerDefine=2040(int markerNumber, int markerSymbol) +fun void MarkerDefine=2040(int markerNumber, MarkerSymbol markerSymbol) # Set the foreground colour used for a particular marker number. set void MarkerSetFore=2041(int markerNumber, colour fore) @@ -335,32 +407,32 @@ set void MarkerSetBackSelected=2292(int markerNumber, colour back) fun void MarkerEnableHighlight=2293(bool enabled,) # Add a marker to a line, returning an ID which can be used to find or delete the marker. -fun int MarkerAdd=2043(int line, int markerNumber) +fun int MarkerAdd=2043(line line, int markerNumber) # Delete a marker from a line. -fun void MarkerDelete=2044(int line, int markerNumber) +fun void MarkerDelete=2044(line line, int markerNumber) # Delete all markers with a particular number from all lines. fun void MarkerDeleteAll=2045(int markerNumber,) # Get a bit mask of all the markers set on a line. -fun int MarkerGet=2046(int line,) +fun int MarkerGet=2046(line line,) # Find the next line at or after lineStart that includes a marker in mask. # Return -1 when no more lines. -fun int MarkerNext=2047(int lineStart, int markerMask) +fun line MarkerNext=2047(line lineStart, int markerMask) # Find the previous line before lineStart that includes a marker in mask. -fun int MarkerPrevious=2048(int lineStart, int markerMask) +fun line MarkerPrevious=2048(line lineStart, int markerMask) # Define a marker from a pixmap. fun void MarkerDefinePixmap=2049(int markerNumber, string pixmap) # Add a set of markers to a line. -fun void MarkerAddSet=2466(int line, int markerSet) +fun void MarkerAddSet=2466(line line, int markerSet) # Set the alpha used for a marker that is drawn in the text area, not the margin. -set void MarkerSetAlpha=2476(int markerNumber, int alpha) +set void MarkerSetAlpha=2476(int markerNumber, Alpha alpha) val SC_MAX_MARGIN=4 @@ -373,11 +445,13 @@ val SC_MARGIN_TEXT=4 val SC_MARGIN_RTEXT=5 val SC_MARGIN_COLOUR=6 +ali SC_MARGIN_RTEXT=R_TEXT + # Set a margin to be either numeric or symbolic. -set void SetMarginTypeN=2240(int margin, int marginType) +set void SetMarginTypeN=2240(int margin, MarginType marginType) # Retrieve the type of a margin. -get int GetMarginTypeN=2241(int margin,) +get MarginType GetMarginTypeN=2241(int margin,) # Set the width of a margin to a width expressed in pixels. set void SetMarginWidthN=2242(int margin, int pixelWidth) @@ -398,10 +472,10 @@ set void SetMarginSensitiveN=2246(int margin, bool sensitive) get bool GetMarginSensitiveN=2247(int margin,) # Set the cursor shown when the mouse is inside a margin. -set void SetMarginCursorN=2248(int margin, int cursor) +set void SetMarginCursorN=2248(int margin, CursorShape cursor) # Retrieve the cursor shown in a margin. -get int GetMarginCursorN=2249(int margin,) +get CursorShape GetMarginCursorN=2249(int margin,) # Set the background colour of a margin. Only visible for SC_MARGIN_COLOUR. set void SetMarginBackN=2250(int margin, colour back) @@ -415,8 +489,7 @@ set void SetMargins=2252(int margins,) # How many margins are there?. get int GetMargins=2253(,) -# Styles in range 32..38 are predefined for parts of the UI and are not used as normal styles. -# Style 39 is for future use. +# Styles in range 32..39 are predefined for parts of the UI and are not used as normal styles. enu StylesCommon=STYLE_ val STYLE_DEFAULT=32 val STYLE_LINENUMBER=33 @@ -429,6 +502,15 @@ val STYLE_FOLDDISPLAYTEXT=39 val STYLE_LASTPREDEFINED=39 val STYLE_MAX=255 +ali STYLE_LINENUMBER=LINE_NUMBER +ali STYLE_BRACELIGHT=BRACE_LIGHT +ali STYLE_BRACEBAD=BRACE_BAD +ali STYLE_CONTROLCHAR=CONTROL_CHAR +ali STYLE_INDENTGUIDE=INDENT_GUIDE +ali STYLE_CALLTIP=CALL_TIP +ali STYLE_FOLDDISPLAYTEXT=FOLD_DISPLAY_TEXT +ali STYLE_LASTPREDEFINED=LAST_PREDEFINED + # Character set identifiers are used in StyleSetCharacterSet. # The values are the same as the Windows *_CHARSET values. enu CharacterSet=SC_CHARSET_ @@ -455,6 +537,13 @@ val SC_CHARSET_VIETNAMESE=163 val SC_CHARSET_THAI=222 val SC_CHARSET_8859_15=1000 +ali SC_CHARSET_CHINESEBIG5=CHINESE_BIG5 +ali SC_CHARSET_EASTEUROPE=EAST_EUROPE +ali SC_CHARSET_GB2312=G_B_2312 +ali SC_CHARSET_OEM866=OEM_866 +ali SC_CHARSET_SHIFTJIS=SHIFT_JIS +ali SC_CHARSET_8859_15=ISO_8859_15 + # Clear all the styles and make equivalent to the global default style. fun void StyleClearAll=2050(,) @@ -518,10 +607,10 @@ get bool StyleGetEOLFilled=2487(int style,) get bool StyleGetUnderline=2488(int style,) # Get is a style mixed case, or to force upper or lower case. -get int StyleGetCase=2489(int style,) +get CaseVisible StyleGetCase=2489(int style,) # Get the character get of the font in a style. -get int StyleGetCharacterSet=2490(int style,) +get CharacterSet StyleGetCharacterSet=2490(int style,) # Get is a style visible or not. get bool StyleGetVisible=2491(int style,) @@ -534,7 +623,7 @@ get bool StyleGetChangeable=2492(int style,) get bool StyleGetHotSpot=2493(int style,) # Set a style to be mixed case, or to force upper or lower case. -set void StyleSetCase=2060(int style, int caseVisible) +set void StyleSetCase=2060(int style, CaseVisible caseVisible) val SC_FONT_SIZE_MULTIPLIER=100 @@ -549,14 +638,16 @@ val SC_WEIGHT_NORMAL=400 val SC_WEIGHT_SEMIBOLD=600 val SC_WEIGHT_BOLD=700 +ali SC_WEIGHT_SEMIBOLD=SEMI_BOLD + # Set the weight of characters of a style. -set void StyleSetWeight=2063(int style, int weight) +set void StyleSetWeight=2063(int style, FontWeight weight) # Get the weight of characters of a style. -get int StyleGetWeight=2064(int style,) +get FontWeight StyleGetWeight=2064(int style,) # Set the character set of the font in a style. -set void StyleSetCharacterSet=2066(int style, int characterSet) +set void StyleSetCharacterSet=2066(int style, CharacterSet characterSet) # Set a style to be a hotspot or not. set void StyleSetHotSpot=2409(int style, bool hotspot) @@ -568,10 +659,10 @@ fun void SetSelFore=2067(bool useSetting, colour fore) fun void SetSelBack=2068(bool useSetting, colour back) # Get the alpha of the selection. -get int GetSelAlpha=2477(,) +get Alpha GetSelAlpha=2477(,) # Set the alpha of the selection. -set void SetSelAlpha=2478(int alpha,) +set void SetSelAlpha=2478(Alpha alpha,) # Is the selection end of line filled? get bool GetSelEOLFilled=2479(,) @@ -592,7 +683,7 @@ fun void ClearCmdKey=2071(keymod keyDefinition,) fun void ClearAllCmdKeys=2072(,) # Set the styles for a segment of the document. -fun void SetStylingEx=2073(int length, string styles) +fun void SetStylingEx=2073(position length, string styles) # Set a style to be visible or not. set void StyleSetVisible=2074(int style, bool visible) @@ -611,6 +702,12 @@ set void SetWordChars=2077(, string characters) # Returns the number of characters get int GetWordChars=2646(, stringresult characters) +# Set the number of characters to have directly indexed categories +set void SetCharacterCategoryOptimization=2720(int countCharacters,) + +# Get the number of characters to have directly indexed categories +get int GetCharacterCategoryOptimization=2721(,) + # Start a sequence of actions that is undone and redone as a unit. # May be nested. fun void BeginUndoAction=2078(,) @@ -640,20 +737,41 @@ val INDIC_FULLBOX=16 val INDIC_TEXTFORE=17 val INDIC_POINT=18 val INDIC_POINTCHARACTER=19 +val INDIC_GRADIENT=20 +val INDIC_GRADIENTCENTRE=21 + +# INDIC_CONTAINER, INDIC_IME, INDIC_IME_MAX, and INDIC_MAX are indicator numbers, +# not IndicatorStyles so should not really be in the INDIC_ enumeration. +# They are redeclared in IndicatorNumbers INDICATOR_. +val INDIC_CONTAINER=8 val INDIC_IME=32 val INDIC_IME_MAX=35 val INDIC_MAX=35 -val INDIC_CONTAINER=8 -val INDIC0_MASK=0x20 -val INDIC1_MASK=0x40 -val INDIC2_MASK=0x80 -val INDICS_MASK=0xE0 + +enu IndicatorNumbers=INDICATOR_ +val INDICATOR_CONTAINER=8 +val INDICATOR_IME=32 +val INDICATOR_IME_MAX=35 +val INDICATOR_MAX=35 + +ali INDIC_TT=T_T +ali INDIC_ROUNDBOX=ROUND_BOX +ali INDIC_STRAIGHTBOX=STRAIGHT_BOX +ali INDIC_SQUIGGLELOW=SQUIGGLE_LOW +ali INDIC_DOTBOX=DOT_BOX +ali INDIC_SQUIGGLEPIXMAP=SQUIGGLE_PIXMAP +ali INDIC_COMPOSITIONTHICK=COMPOSITION_THICK +ali INDIC_COMPOSITIONTHIN=COMPOSITION_THIN +ali INDIC_FULLBOX=FULL_BOX +ali INDIC_TEXTFORE=TEXT_FORE +ali INDIC_POINTCHARACTER=POINT_CHARACTER +ali INDIC_GRADIENTCENTRE=GRADIENT_CENTRE # Set an indicator to plain, squiggle or TT. -set void IndicSetStyle=2080(int indicator, int indicatorStyle) +set void IndicSetStyle=2080(int indicator, IndicatorStyle indicatorStyle) # Retrieve the style of an indicator. -get int IndicGetStyle=2081(int indicator,) +get IndicatorStyle IndicGetStyle=2081(int indicator,) # Set the foreground colour of an indicator. set void IndicSetFore=2082(int indicator, colour fore) @@ -668,10 +786,10 @@ set void IndicSetUnder=2510(int indicator, bool under) get bool IndicGetUnder=2511(int indicator,) # Set a hover indicator to plain, squiggle or TT. -set void IndicSetHoverStyle=2680(int indicator, int indicatorStyle) +set void IndicSetHoverStyle=2680(int indicator, IndicatorStyle indicatorStyle) # Retrieve the hover style of an indicator. -get int IndicGetHoverStyle=2681(int indicator,) +get IndicatorStyle IndicGetHoverStyle=2681(int indicator,) # Set the foreground hover colour of an indicator. set void IndicSetHoverFore=2682(int indicator, colour fore) @@ -679,17 +797,20 @@ set void IndicSetHoverFore=2682(int indicator, colour fore) # Retrieve the foreground hover colour of an indicator. get colour IndicGetHoverFore=2683(int indicator,) +enu IndicValue=SC_INDICVALUE val SC_INDICVALUEBIT=0x1000000 val SC_INDICVALUEMASK=0xFFFFFF enu IndicFlag=SC_INDICFLAG_ val SC_INDICFLAG_VALUEFORE=1 +ali SC_INDICFLAG_VALUEFORE=VALUE_FORE + # Set the attributes of an indicator. -set void IndicSetFlags=2684(int indicator, int flags) +set void IndicSetFlags=2684(int indicator, IndicFlag flags) # Retrieve the attributes of an indicator. -get int IndicGetFlags=2685(int indicator,) +get IndicFlag IndicGetFlags=2685(int indicator,) # Set the foreground colour of all whitespace and whether to use this setting. fun void SetWhitespaceFore=2084(bool useSetting, colour fore) @@ -703,19 +824,11 @@ set void SetWhitespaceSize=2086(int size,) # Get the size of the dots used to mark space characters. get int GetWhitespaceSize=2087(,) -# Divide each styling byte into lexical class bits (default: 5) and indicator -# bits (default: 3). If a lexer requires more than 32 lexical states, then this -# is used to expand the possible states. -set void SetStyleBits=2090(int bits,) - -# Retrieve number of bits in style bytes used to hold the lexical state. -get int GetStyleBits=2091(,) - # Used to hold extra styling information for each line. -set void SetLineState=2092(int line, int state) +set void SetLineState=2092(line line, int state) # Retrieve the extra styling information for a line. -get int GetLineState=2093(int line,) +get int GetLineState=2093(line line,) # Retrieve the last line number that has line state. get int GetMaxLineState=2094(,) @@ -732,14 +845,22 @@ get colour GetCaretLineBack=2097(,) # Set the colour of the background of the line containing the caret. set void SetCaretLineBack=2098(colour back,) +# Retrieve the caret line frame width. +# Width = 0 means this option is disabled. +get int GetCaretLineFrame=2704(,) + +# Display the caret line framed. +# Set width != 0 to enable this option and width = 0 to disable it. +set void SetCaretLineFrame=2705(int width,) + # Set a style to be changeable or not (read only). # Experimental feature, currently buggy. set void StyleSetChangeable=2099(int style, bool changeable) -# Display an auto-completion list. +# Display a auto-completion list. # The lengthEntered parameter indicates how many characters before # the caret should be used to provide context. -fun void AutoCShow=2100(int lengthEntered, string itemList) +fun void AutoCShow=2100(position lengthEntered, string itemList) # Remove the auto-completion list from the screen. fun void AutoCCancel=2101(,) @@ -847,19 +968,22 @@ set void SetUseTabs=2124(bool useTabs,) get bool GetUseTabs=2125(,) # Change the indentation of a line to a number of columns. -set void SetLineIndentation=2126(int line, int indentation) +set void SetLineIndentation=2126(line line, int indentation) # Retrieve the number of columns that a line is indented. -get int GetLineIndentation=2127(int line,) +get int GetLineIndentation=2127(line line,) # Retrieve the position before the first non indentation character on a line. -get position GetLineIndentPosition=2128(int line,) +get position GetLineIndentPosition=2128(line line,) # Retrieve the column number of a position, taking tab width into account. -get int GetColumn=2129(position pos,) +get position GetColumn=2129(position pos,) # Count characters between two positions. -fun int CountCharacters=2633(position start, position end) +fun position CountCharacters=2633(position start, position end) + +# Count code units between two positions. +fun position CountCodeUnits=2715(position start, position end) # Show or hide the horizontal scroll bar. set void SetHScrollBar=2130(bool visible,) @@ -872,21 +996,24 @@ val SC_IV_REAL=1 val SC_IV_LOOKFORWARD=2 val SC_IV_LOOKBOTH=3 +ali SC_IV_LOOKFORWARD=LOOK_FORWARD +ali SC_IV_LOOKBOTH=LOOK_BOTH + # Show or hide indentation guides. -set void SetIndentationGuides=2132(int indentView,) +set void SetIndentationGuides=2132(IndentView indentView,) # Are the indentation guides visible? -get int GetIndentationGuides=2133(,) +get IndentView GetIndentationGuides=2133(,) # Set the highlighted indentation guide column. # 0 = no highlighted guide. -set void SetHighlightGuide=2134(int column,) +set void SetHighlightGuide=2134(position column,) # Get the highlighted indentation guide column. -get int GetHighlightGuide=2135(,) +get position GetHighlightGuide=2135(,) # Get the position after the last visible characters on a line. -get position GetLineEndPosition=2136(int line,) +get position GetLineEndPosition=2136(line line,) # Get the code page used to interpret the bytes of the document as characters. get int GetCodePage=2137(,) @@ -923,6 +1050,7 @@ get int GetPrintMagnification=2147(,) enu PrintOption=SC_PRINT_ # PrintColourMode - use same colours as screen. +# with the exception of line number margins, which use a white background val SC_PRINT_NORMAL=0 # PrintColourMode - invert the light value of each style for printing. val SC_PRINT_INVERTLIGHT=1 @@ -932,14 +1060,23 @@ val SC_PRINT_BLACKONWHITE=2 val SC_PRINT_COLOURONWHITE=3 # PrintColourMode - only the default-background is forced to be white for printing. val SC_PRINT_COLOURONWHITEDEFAULTBG=4 +# PrintColourMode - use same colours as screen, including line number margins. +val SC_PRINT_SCREENCOLOURS=5 + +ali SC_PRINT_INVERTLIGHT=INVERT_LIGHT +ali SC_PRINT_BLACKONWHITE=BLACK_ON_WHITE +ali SC_PRINT_COLOURONWHITE=COLOUR_ON_WHITE +ali SC_PRINT_COLOURONWHITEDEFAULTBG=COLOUR_ON_WHITE_DEFAULT_B_G +ali SC_PRINT_SCREENCOLOURS=SCREEN_COLOURS # Modify colours when printing for clearer printed text. -set void SetPrintColourMode=2148(int mode,) +set void SetPrintColourMode=2148(PrintOption mode,) # Returns the print colour mode. -get int GetPrintColourMode=2149(,) +get PrintOption GetPrintColourMode=2149(,) enu FindOption=SCFIND_ +val SCFIND_NONE=0x0 val SCFIND_WHOLEWORD=0x2 val SCFIND_MATCHCASE=0x4 val SCFIND_WORDSTART=0x00100000 @@ -947,21 +1084,27 @@ val SCFIND_REGEXP=0x00200000 val SCFIND_POSIX=0x00400000 val SCFIND_CXX11REGEX=0x00800000 +ali SCFIND_WHOLEWORD=WHOLE_WORD +ali SCFIND_MATCHCASE=MATCH_CASE +ali SCFIND_WORDSTART=WORD_START +ali SCFIND_REGEXP=REG_EXP +ali SCFIND_CXX11REGEX=CXX11_REG_EX + # Find some text in the document. -fun position FindText=2150(int searchFlags, findtext ft) +fun position FindText=2150(FindOption searchFlags, findtext ft) # On Windows, will draw the document into a display context such as a printer. fun position FormatRange=2151(bool draw, formatrange fr) # Retrieve the display line at the top of the display. -get int GetFirstVisibleLine=2152(,) +get line GetFirstVisibleLine=2152(,) # Retrieve the contents of a line. # Returns the length of the line. -fun int GetLine=2153(int line, stringresult text) +fun position GetLine=2153(line line, stringresult text) # Returns the number of lines in the document. There is always at least one. -get int GetLineCount=2154(,) +get line GetLineCount=2154(,) # Sets the size in pixels of the left margin. set void SetMarginLeft=2155(, int pixelWidth) @@ -984,13 +1127,13 @@ fun void SetSel=2160(position anchor, position caret) # Retrieve the selected text. # Return the length of the text. # Result is NUL-terminated. -fun int GetSelText=2161(, stringresult text) +fun position GetSelText=2161(, stringresult text) # Retrieve a range of text. # Return the length of the text. -fun int GetTextRange=2162(, textrange tr) +fun position GetTextRange=2162(, textrange tr) -# Draw the selection in normal style or with selection highlighted. +# Draw the selection either highlighted or in normal (non-highlighted) style. fun void HideSelection=2163(bool hide,) # Retrieve the x value of the point in the window where a position is displayed. @@ -1000,13 +1143,13 @@ fun int PointXFromPosition=2164(, position pos) fun int PointYFromPosition=2165(, position pos) # Retrieve the line containing a position. -fun int LineFromPosition=2166(position pos,) +fun line LineFromPosition=2166(position pos,) # Retrieve the position at the start of a line. -fun position PositionFromLine=2167(int line,) +fun position PositionFromLine=2167(line line,) # Scroll horizontally and vertically. -fun void LineScroll=2168(int columns, int lines) +fun void LineScroll=2168(position columns, line lines) # Ensure the caret is visible. fun void ScrollCaret=2169(,) @@ -1055,17 +1198,17 @@ fun void SetText=2181(, string text) # Retrieve all the text in the document. # Returns number of characters retrieved. # Result is NUL-terminated. -fun int GetText=2182(int length, stringresult text) +fun position GetText=2182(position length, stringresult text) # Retrieve the number of characters in the document. -get int GetTextLength=2183(,) +get position GetTextLength=2183(,) # Retrieve a pointer to a function that processes messages for this Scintilla. -get int GetDirectFunction=2184(,) +get pointer GetDirectFunction=2184(,) # Retrieve a pointer value to use as the first argument when calling # the function returned by GetDirectFunction. -get int GetDirectPointer=2185(,) +get pointer GetDirectPointer=2185(,) # Set to overtype (true) or insert mode. set void SetOvertype=2186(bool overType,) @@ -1086,6 +1229,12 @@ set void SetTargetStart=2190(position start,) # Get the position that starts the target. get position GetTargetStart=2191(,) +# Sets the virtual space of the target start +set void SetTargetStartVirtualSpace=2728(position space,) + +# Get the virtual space of the target start +get position GetTargetStartVirtualSpace=2729(,) + # Sets the position that ends the target which is used for updating the # document without affecting the scroll position. set void SetTargetEnd=2192(position end,) @@ -1093,11 +1242,17 @@ set void SetTargetEnd=2192(position end,) # Get the position that ends the target. get position GetTargetEnd=2193(,) +# Sets the virtual space of the target end +set void SetTargetEndVirtualSpace=2730(position space,) + +# Get the virtual space of the target end +get position GetTargetEndVirtualSpace=2731(,) + # Sets both the start and end of the target in one call. fun void SetTargetRange=2686(position start, position end) # Retrieve the text in the target. -get int GetTargetText=2687(, stringresult text) +get position GetTargetText=2687(, stringresult text) # Make the target range start and end be the same as the selection range start and end. fun void TargetFromSelection=2287(,) @@ -1108,7 +1263,7 @@ fun void TargetWholeDocument=2690(,) # Replace the target text with the argument text. # Text is counted so it can contain NULs. # Returns the length of the replacement text. -fun int ReplaceTarget=2194(int length, string text) +fun position ReplaceTarget=2194(position length, string text) # Replace the target text with the argument text after \d processing. # Text is counted so it can contain NULs. @@ -1116,18 +1271,18 @@ fun int ReplaceTarget=2194(int length, string text) # matched in the last search operation which were surrounded by \( and \). # Returns the length of the replacement text including any change # caused by processing the \d patterns. -fun int ReplaceTargetRE=2195(int length, string text) +fun position ReplaceTargetRE=2195(position length, string text) # Search for a counted string in the target and set the target to the found # range. Text is counted so it can contain NULs. -# Returns length of range or -1 for failure in which case target is not moved. -fun int SearchInTarget=2197(int length, string text) +# Returns start of found range or -1 for failure in which case target is not moved. +fun position SearchInTarget=2197(position length, string text) # Set the search flags used by SearchInTarget. -set void SetSearchFlags=2198(int searchFlags,) +set void SetSearchFlags=2198(FindOption searchFlags,) # Get the search flags used by SearchInTarget. -get int GetSearchFlags=2199(,) +get FindOption GetSearchFlags=2199(,) # Show a call tip containing a definition near position pos. fun void CallTipShow=2200(position pos, string definition) @@ -1142,10 +1297,10 @@ fun bool CallTipActive=2202(,) fun position CallTipPosStart=2203(,) # Set the start position in order to change when backspacing removes the calltip. -set void CallTipSetPosStart=2214(int posStart,) +set void CallTipSetPosStart=2214(position posStart,) # Highlight a segment of the definition. -fun void CallTipSetHlt=2204(int highlightStart, int highlightEnd) +fun void CallTipSetHlt=2204(position highlightStart, position highlightEnd) # Set the background colour for the call tip. set void CallTipSetBack=2205(colour back,) @@ -1163,13 +1318,13 @@ set void CallTipUseStyle=2212(int tabSize,) set void CallTipSetPosition=2213(bool above,) # Find the display line of a document line taking hidden lines into account. -fun int VisibleFromDocLine=2220(int docLine,) +fun line VisibleFromDocLine=2220(line docLine,) # Find the document line of a display line taking hidden lines into account. -fun int DocLineFromVisible=2221(int displayLine,) +fun line DocLineFromVisible=2221(line displayLine,) # The number of display lines needed to wrap a document line -fun int WrapCount=2235(int docLine,) +fun line WrapCount=2235(line docLine,) enu FoldLevel=SC_FOLDLEVEL val SC_FOLDLEVELBASE=0x400 @@ -1177,51 +1332,64 @@ val SC_FOLDLEVELWHITEFLAG=0x1000 val SC_FOLDLEVELHEADERFLAG=0x2000 val SC_FOLDLEVELNUMBERMASK=0x0FFF +ali SC_FOLDLEVELWHITEFLAG=WHITE_FLAG +ali SC_FOLDLEVELHEADERFLAG=HEADER_FLAG +ali SC_FOLDLEVELNUMBERMASK=NUMBER_MASK + # Set the fold level of a line. # This encodes an integer level along with flags indicating whether the # line is a header and whether it is effectively white space. -set void SetFoldLevel=2222(int line, int level) +set void SetFoldLevel=2222(line line, FoldLevel level) # Retrieve the fold level of a line. -get int GetFoldLevel=2223(int line,) +get FoldLevel GetFoldLevel=2223(line line,) # Find the last child line of a header line. -get int GetLastChild=2224(int line, int level) +get line GetLastChild=2224(line line, FoldLevel level) # Find the parent line of a child line. -get int GetFoldParent=2225(int line,) +get line GetFoldParent=2225(line line,) # Make a range of lines visible. -fun void ShowLines=2226(int lineStart, int lineEnd) +fun void ShowLines=2226(line lineStart, line lineEnd) # Make a range of lines invisible. -fun void HideLines=2227(int lineStart, int lineEnd) +fun void HideLines=2227(line lineStart, line lineEnd) # Is a line visible? -get bool GetLineVisible=2228(int line,) +get bool GetLineVisible=2228(line line,) # Are all lines visible? get bool GetAllLinesVisible=2236(,) # Show the children of a header line. -set void SetFoldExpanded=2229(int line, bool expanded) +set void SetFoldExpanded=2229(line line, bool expanded) # Is a header line expanded? -get bool GetFoldExpanded=2230(int line,) +get bool GetFoldExpanded=2230(line line,) # Switch a header line between expanded and contracted. -fun void ToggleFold=2231(int line,) +fun void ToggleFold=2231(line line,) # Switch a header line between expanded and contracted and show some text after the line. -fun void ToggleFoldShowText=2700(int line, string text) +fun void ToggleFoldShowText=2700(line line, string text) -enu foldDisplayTextStyle=SC_FOLDDISPLAYTEXTSTYLE_ +enu FoldDisplayTextStyle=SC_FOLDDISPLAYTEXT_ val SC_FOLDDISPLAYTEXT_HIDDEN=0 val SC_FOLDDISPLAYTEXT_STANDARD=1 val SC_FOLDDISPLAYTEXT_BOXED=2 -# Set the style of fold display text -set void FoldDisplayTextSetStyle=2701(int style,) +# Set the style of fold display text. +set void FoldDisplayTextSetStyle=2701(FoldDisplayTextStyle style,) + +# Get the style of fold display text. +get FoldDisplayTextStyle FoldDisplayTextGetStyle=2707(,) + +# Set the default fold display text. +fun void SetDefaultFoldDisplayText=2722(, string text) + +# Get the default fold display text. +fun int GetDefaultFoldDisplayText=2723(, stringresult text) enu FoldAction=SC_FOLDACTION_ val SC_FOLDACTION_CONTRACT=0 @@ -1229,19 +1397,19 @@ val SC_FOLDACTION_EXPAND=1 val SC_FOLDACTION_TOGGLE=2 # Expand or contract a fold header. -fun void FoldLine=2237(int line, int action) +fun void FoldLine=2237(line line, FoldAction action) # Expand or contract a fold header and its children. -fun void FoldChildren=2238(int line, int action) +fun void FoldChildren=2238(line line, FoldAction action) # Expand a fold header and all children. Use the level argument instead of the line's current level. -fun void ExpandChildren=2239(int line, int level) +fun void ExpandChildren=2239(line line, FoldLevel level) # Expand or contract all fold headers. -fun void FoldAll=2662(int action,) +fun void FoldAll=2662(FoldAction action,) # Ensure a particular line is visible by expanding any header line hiding it. -fun void EnsureVisible=2232(int line,) +fun void EnsureVisible=2232(line line,) enu AutomaticFold=SC_AUTOMATICFOLD_ val SC_AUTOMATICFOLD_SHOW=0x0001 @@ -1249,10 +1417,10 @@ val SC_AUTOMATICFOLD_CLICK=0x0002 val SC_AUTOMATICFOLD_CHANGE=0x0004 # Set automatic folding behaviours. -set void SetAutomaticFold=2663(int automaticFold,) +set void SetAutomaticFold=2663(AutomaticFold automaticFold,) # Get automatic folding behaviours. -get int GetAutomaticFold=2664(,) +get AutomaticFold GetAutomaticFold=2664(,) enu FoldFlag=SC_FOLDFLAG_ val SC_FOLDFLAG_LINEBEFORE_EXPANDED=0x0002 @@ -1262,12 +1430,19 @@ val SC_FOLDFLAG_LINEAFTER_CONTRACTED=0x0010 val SC_FOLDFLAG_LEVELNUMBERS=0x0040 val SC_FOLDFLAG_LINESTATE=0x0080 +ali SC_FOLDFLAG_LINEBEFORE_EXPANDED=LINE_BEFORE_EXPANDED +ali SC_FOLDFLAG_LINEBEFORE_CONTRACTED=LINE_BEFORE_CONTRACTED +ali SC_FOLDFLAG_LINEAFTER_EXPANDED=LINE_AFTER_EXPANDED +ali SC_FOLDFLAG_LINEAFTER_CONTRACTED=LINE_AFTER_CONTRACTED +ali SC_FOLDFLAG_LEVELNUMBERS=LEVEL_NUMBERS +ali SC_FOLDFLAG_LINESTATE=LINE_STATE + # Set some style options for folding. -set void SetFoldFlags=2233(int flags,) +set void SetFoldFlags=2233(FoldFlag flags,) # Ensure a particular line is visible by expanding any header line hiding it. # Use the currently set visibility policy to determine which range to display. -fun void EnsureVisibleEnforcePolicy=2234(int line,) +fun void EnsureVisibleEnforcePolicy=2234(line line,) # Sets whether a tab pressed when caret is within indentation indents. set void SetTabIndents=2260(bool tabIndents,) @@ -1290,10 +1465,10 @@ set void SetMouseDwellTime=2264(int periodMilliseconds,) get int GetMouseDwellTime=2265(,) # Get position of start of word. -fun int WordStartPosition=2266(position pos, bool onlyWordCharacters) +fun position WordStartPosition=2266(position pos, bool onlyWordCharacters) # Get position of end of word. -fun int WordEndPosition=2267(position pos, bool onlyWordCharacters) +fun position WordEndPosition=2267(position pos, bool onlyWordCharacters) # Is the range start..end considered a word? fun bool IsRangeWord=2691(position start, position end) @@ -1304,11 +1479,14 @@ val SC_IDLESTYLING_TOVISIBLE=1 val SC_IDLESTYLING_AFTERVISIBLE=2 val SC_IDLESTYLING_ALL=3 +ali SC_IDLESTYLING_TOVISIBLE=TO_VISIBLE +ali SC_IDLESTYLING_AFTERVISIBLE=AFTER_VISIBLE + # Sets limits to idle styling. -set void SetIdleStyling=2692(int idleStyling,) +set void SetIdleStyling=2692(IdleStyling idleStyling,) # Retrieve the limits to idle styling. -get int GetIdleStyling=2693(,) +get IdleStyling GetIdleStyling=2693(,) enu Wrap=SC_WRAP_ val SC_WRAP_NONE=0 @@ -1316,11 +1494,13 @@ val SC_WRAP_WORD=1 val SC_WRAP_CHAR=2 val SC_WRAP_WHITESPACE=3 +ali SC_WRAP_WHITESPACE=WHITE_SPACE + # Sets whether text is word wrapped. -set void SetWrapMode=2268(int wrapMode,) +set void SetWrapMode=2268(Wrap wrapMode,) # Retrieve whether text is word wrapped. -get int GetWrapMode=2269(,) +get Wrap GetWrapMode=2269(,) enu WrapVisualFlag=SC_WRAPVISUALFLAG_ val SC_WRAPVISUALFLAG_NONE=0x0000 @@ -1329,10 +1509,10 @@ val SC_WRAPVISUALFLAG_START=0x0002 val SC_WRAPVISUALFLAG_MARGIN=0x0004 # Set the display mode of visual flags for wrapped lines. -set void SetWrapVisualFlags=2460(int wrapVisualFlags,) +set void SetWrapVisualFlags=2460(WrapVisualFlag wrapVisualFlags,) # Retrive the display mode of visual flags for wrapped lines. -get int GetWrapVisualFlags=2461(,) +get WrapVisualFlag GetWrapVisualFlags=2461(,) enu WrapVisualLocation=SC_WRAPVISUALFLAGLOC_ val SC_WRAPVISUALFLAGLOC_DEFAULT=0x0000 @@ -1340,10 +1520,10 @@ val SC_WRAPVISUALFLAGLOC_END_BY_TEXT=0x0001 val SC_WRAPVISUALFLAGLOC_START_BY_TEXT=0x0002 # Set the location of visual flags for wrapped lines. -set void SetWrapVisualFlagsLocation=2462(int wrapVisualFlagsLocation,) +set void SetWrapVisualFlagsLocation=2462(WrapVisualLocation wrapVisualFlagsLocation,) # Retrive the location of visual flags for wrapped lines. -get int GetWrapVisualFlagsLocation=2463(,) +get WrapVisualLocation GetWrapVisualFlagsLocation=2463(,) # Set the start indent for wrapped lines. set void SetWrapStartIndent=2464(int indent,) @@ -1355,12 +1535,15 @@ enu WrapIndentMode=SC_WRAPINDENT_ val SC_WRAPINDENT_FIXED=0 val SC_WRAPINDENT_SAME=1 val SC_WRAPINDENT_INDENT=2 +val SC_WRAPINDENT_DEEPINDENT=3 + +ali SC_WRAPINDENT_DEEPINDENT=DEEP_INDENT # Sets how wrapped sublines are placed. Default is fixed. -set void SetWrapIndentMode=2472(int wrapIndentMode,) +set void SetWrapIndentMode=2472(WrapIndentMode wrapIndentMode,) # Retrieve how wrapped sublines are placed. Default is fixed. -get int GetWrapIndentMode=2473(,) +get WrapIndentMode GetWrapIndentMode=2473(,) enu LineCache=SC_CACHE_ val SC_CACHE_NONE=0 @@ -1369,10 +1552,10 @@ val SC_CACHE_PAGE=2 val SC_CACHE_DOCUMENT=3 # Sets the degree of caching of layout information. -set void SetLayoutCache=2272(int cacheMode,) +set void SetLayoutCache=2272(LineCache cacheMode,) # Retrieve the degree of caching of layout information. -get int GetLayoutCache=2273(,) +get LineCache GetLayoutCache=2273(,) # Sets the document width assumed for scrolling. set void SetScrollWidth=2274(int pixelWidth,) @@ -1401,7 +1584,7 @@ set void SetEndAtLastLine=2277(bool endAtLastLine,) get bool GetEndAtLastLine=2278(,) # Retrieve the height of a particular line of text in pixels. -fun int TextHeight=2279(int line,) +fun int TextHeight=2279(line line,) # Show or hide the vertical scroll bar. set void SetVScrollBar=2280(bool visible,) @@ -1410,7 +1593,7 @@ set void SetVScrollBar=2280(bool visible,) get bool GetVScrollBar=2281(,) # Append a string to the end of the document without changing the selection. -fun void AppendText=2282(int length, string text) +fun void AppendText=2282(position length, string text) # Is drawing done in two phases with backgrounds drawn before foregrounds? get bool GetTwoPhaseDraw=2283(,) @@ -1425,13 +1608,13 @@ val SC_PHASES_TWO=1 val SC_PHASES_MULTIPLE=2 # How many phases is drawing done in? -get int GetPhasesDraw=2673(,) +get PhasesDraw GetPhasesDraw=2673(,) # In one phase draw, text is drawn in a series of rectangular blocks with no overlap. # In two phase draw, text is drawn in a series of lines allowing runs to overlap horizontally. # In multiple phase draw, each element is drawn over the whole drawing area, allowing text # to overlap from one line to the next. -set void SetPhasesDraw=2674(int phases,) +set void SetPhasesDraw=2674(PhasesDraw phases,) # Control font anti-aliasing. @@ -1443,23 +1626,23 @@ val SC_EFF_QUALITY_ANTIALIASED=2 val SC_EFF_QUALITY_LCD_OPTIMIZED=3 # Choose the quality level for text from the FontQuality enumeration. -set void SetFontQuality=2611(int fontQuality,) +set void SetFontQuality=2611(FontQuality fontQuality,) # Retrieve the quality level for text. -get int GetFontQuality=2612(,) +get FontQuality GetFontQuality=2612(,) # Scroll so that a display line is at the top of the display. -set void SetFirstVisibleLine=2613(int displayLine,) +set void SetFirstVisibleLine=2613(line displayLine,) enu MultiPaste=SC_MULTIPASTE_ val SC_MULTIPASTE_ONCE=0 val SC_MULTIPASTE_EACH=1 # Change the effect of pasting when there are multiple selections. -set void SetMultiPaste=2614(int multiPaste,) +set void SetMultiPaste=2614(MultiPaste multiPaste,) # Retrieve the effect of pasting when there are multiple selections. -get int GetMultiPaste=2615(,) +get MultiPaste GetMultiPaste=2615(,) # Retrieve the value of a tag from a regular expression search. # Result is NUL-terminated. @@ -1477,6 +1660,16 @@ fun void SetFoldMarginColour=2290(bool useSetting, colour back) # Set the other colour used as a chequerboard pattern in the fold margin fun void SetFoldMarginHiColour=2291(bool useSetting, colour fore) +enu Accessibility=SC_ACCESSIBILITY_ +val SC_ACCESSIBILITY_DISABLED=0 +val SC_ACCESSIBILITY_ENABLED=1 + +# Enable or disable accessibility. +set void SetAccessibility=2702(Accessibility accessibility,) + +# Report accessibility status. +get Accessibility GetAccessibility=2703(,) + ## New messages go here ## Start of key messages @@ -1605,6 +1798,9 @@ fun void LineDelete=2338(,) # Switch the current line with the previous. fun void LineTranspose=2339(,) +# Reverse order of selected lines. +fun void LineReverse=2354(,) + # Duplicate the current line. fun void LineDuplicate=2404(,) @@ -1669,7 +1865,7 @@ fun void LineCopy=2455(,) fun void MoveCaretInsideView=2401(,) # How many characters are on a line, including end of line characters? -fun int LineLength=2350(int line,) +fun position LineLength=2350(line line,) # Highlight the characters at two positions. fun void BraceHighlight=2351(position posA, position posB) @@ -1687,6 +1883,9 @@ fun void BraceBadLightIndicator=2499(bool useSetting, int indicator) # The maxReStyle must be 0 for now. It may be defined in a future release. fun position BraceMatch=2353(position pos, int maxReStyle) +# Similar to BraceMatch, but matching starts at the explicit start position. +fun position BraceMatchNext=2369(position pos, position startPos) + # Are the end of line characters visible? get bool GetViewEOL=2355(,) @@ -1694,13 +1893,13 @@ get bool GetViewEOL=2355(,) set void SetViewEOL=2356(bool visible,) # Retrieve a pointer to the document object. -get int GetDocPointer=2357(,) +get pointer GetDocPointer=2357(,) # Change the document object used. -set void SetDocPointer=2358(, int doc) +set void SetDocPointer=2358(, pointer doc) # Set which document modification events are sent to the container. -set void SetModEventMask=2359(int eventMask,) +set void SetModEventMask=2359(ModificationFlags eventMask,) enu EdgeVisualStyle=EDGE_ val EDGE_NONE=0 @@ -1708,19 +1907,21 @@ val EDGE_LINE=1 val EDGE_BACKGROUND=2 val EDGE_MULTILINE=3 +ali EDGE_MULTILINE=MULTI_LINE + # Retrieve the column number which text should be kept within. -get int GetEdgeColumn=2360(,) +get position GetEdgeColumn=2360(,) # Set the column number of the edge. # If text goes past the edge then it is highlighted. -set void SetEdgeColumn=2361(int column,) +set void SetEdgeColumn=2361(position column,) # Retrieve the edge highlight mode. -get int GetEdgeMode=2362(,) +get EdgeVisualStyle GetEdgeMode=2362(,) # The edge may be displayed by a line (EDGE_LINE/EDGE_MULTILINE) or by highlighting text that # goes beyond it (EDGE_BACKGROUND) or not displayed at all (EDGE_NONE). -set void SetEdgeMode=2363(int edgeMode,) +set void SetEdgeMode=2363(EdgeVisualStyle edgeMode,) # Retrieve the colour used in edge indication. get colour GetEdgeColour=2364(,) @@ -1729,24 +1930,27 @@ get colour GetEdgeColour=2364(,) set void SetEdgeColour=2365(colour edgeColour,) # Add a new vertical edge to the view. -fun void MultiEdgeAddLine=2694(int column, colour edgeColour) +fun void MultiEdgeAddLine=2694(position column, colour edgeColour) # Clear all vertical edges. fun void MultiEdgeClearAll=2695(,) +# Get multi edge positions. +get position GetMultiEdgeColumn=2749(int which,) + # Sets the current caret position to be the search anchor. fun void SearchAnchor=2366(,) # Find some text starting at the search anchor. # Does not ensure the selection is visible. -fun int SearchNext=2367(int searchFlags, string text) +fun position SearchNext=2367(FindOption searchFlags, string text) # Find some text starting at the search anchor and moving backwards. # Does not ensure the selection is visible. -fun int SearchPrev=2368(int searchFlags, string text) +fun position SearchPrev=2368(FindOption searchFlags, string text) # Retrieves the number of lines completely visible. -get int LinesOnScreen=2370(,) +get line LinesOnScreen=2370(,) enu PopUp=SC_POPUP_ val SC_POPUP_NEVER=0 @@ -1755,7 +1959,7 @@ val SC_POPUP_TEXT=2 # Set whether a pop up menu is displayed automatically when the user presses # the wrong mouse button on certain areas. -fun void UsePopUp=2371(int popUpMode,) +fun void UsePopUp=2371(PopUp popUpMode,) # Is the selection rectangular? The alternative is the more common stream selection. get bool SelectionIsRectangle=2372(,) @@ -1766,16 +1970,30 @@ set void SetZoom=2373(int zoomInPoints,) # Retrieve the zoom level. get int GetZoom=2374(,) +enu DocumentOption=SC_DOCUMENTOPTION_ +val SC_DOCUMENTOPTION_DEFAULT=0 +val SC_DOCUMENTOPTION_STYLES_NONE=0x1 +val SC_DOCUMENTOPTION_TEXT_LARGE=0x100 + # Create a new document object. # Starts with reference count of 1 and not selected into editor. -fun int CreateDocument=2375(,) +fun pointer CreateDocument=2375(position bytes, DocumentOption documentOptions) # Extend life of document. -fun void AddRefDocument=2376(, int doc) +fun void AddRefDocument=2376(, pointer doc) # Release a reference to the document, deleting document if it fades to black. -fun void ReleaseDocument=2377(, int doc) +fun void ReleaseDocument=2377(, pointer doc) + +# Get which document options are set. +get DocumentOption GetDocumentOptions=2379(,) # Get which document modification events are sent to the container. -get int GetModEventMask=2378(,) +get ModificationFlags GetModEventMask=2378(,) + +# Set whether command events are sent to the container. +set void SetCommandEvents=2717(bool commandEvents,) + +# Get whether command events are sent to the container. +get bool GetCommandEvents=2718(,) # Change internal focus flag. set void SetFocus=2380(bool focus,) @@ -1789,10 +2007,13 @@ val SC_STATUS_BADALLOC=2 val SC_STATUS_WARN_START=1000 val SC_STATUS_WARN_REGEX=1001 +ali SC_STATUS_BADALLOC=BAD_ALLOC +ali SC_STATUS_WARN_REGEX=REG_EX + # Change error status - 0 = OK. -set void SetStatus=2382(int status,) +set void SetStatus=2382(Status status,) # Get error status. -get int GetStatus=2383(,) +get Status GetStatus=2383(,) # Set whether the mouse is captured when its button is pressed. set void SetMouseDownCaptures=2384(bool captures,) @@ -1804,15 +2025,10 @@ set void SetMouseWheelCaptures=2696(bool captures,) # Get whether mouse wheel can be active outside the window. get bool GetMouseWheelCaptures=2697(,) -enu CursorShape=SC_CURSOR -val SC_CURSORNORMAL=-1 -val SC_CURSORARROW=2 -val SC_CURSORWAIT=4 -val SC_CURSORREVERSEARROW=7 # Sets the cursor to one of the SC_CURSOR* values. -set void SetCursor=2386(int cursorType,) +set void SetCursor=2386(CursorShape cursorType,) # Get cursor type. -get int GetCursor=2387(,) +get CursorShape GetCursor=2387(,) # Change the way control characters are displayed: # If symbol is < 32, keep the drawn way, else, use the given character. @@ -1832,11 +2048,13 @@ fun void WordPartRight=2392(,) fun void WordPartRightExtend=2393(,) # Constants for use with SetVisiblePolicy, similar to SetCaretPolicy. +enu VisiblePolicy=VISIBLE_ val VISIBLE_SLOP=0x01 val VISIBLE_STRICT=0x04 + # Set the way the display area is determined when a particular line # is to be moved to by Find, FindNext, GotoLine, etc. -fun void SetVisiblePolicy=2394(int visiblePolicy, int visibleSlop) +fun void SetVisiblePolicy=2394(VisiblePolicy visiblePolicy, int visibleSlop) # Delete back from the current position to the start of the line. fun void DelLineLeft=2395(,) @@ -1844,8 +2062,10 @@ fun void DelLineLeft=2395(,) # Delete forwards from the current position to the end of the line. fun void DelLineRight=2396(,) -# Get and Set the xOffset (ie, horizontal scroll position). +# Set the xOffset (ie, horizontal scroll position). set void SetXOffset=2397(int xOffset,) + +# Get the xOffset (ie, horizontal scroll position). get int GetXOffset=2398(,) # Set the last x chosen value to be the caret x position. @@ -1880,17 +2100,17 @@ val CARET_EVEN=0x08 # Set the way the caret is kept visible when going sideways. # The exclusion zone is given in pixels. -fun void SetXCaretPolicy=2402(int caretPolicy, int caretSlop) +fun void SetXCaretPolicy=2402(CaretPolicy caretPolicy, int caretSlop) # Set the way the line the caret is on is kept visible. # The exclusion zone is given in lines. -fun void SetYCaretPolicy=2403(int caretPolicy, int caretSlop) +fun void SetYCaretPolicy=2403(CaretPolicy caretPolicy, int caretSlop) # Set printing to line wrapped (SC_WRAP_WORD) or not line wrapped (SC_WRAP_NONE). -set void SetPrintWrapMode=2406(int wrapMode,) +set void SetPrintWrapMode=2406(Wrap wrapMode,) # Is printing line wrapped? -get int GetPrintWrapMode=2407(,) +get Wrap GetPrintWrapMode=2407(,) # Set a fore colour for active hotspots. set void SetHotspotActiveFore=2410(bool useSetting, colour fore) @@ -1918,10 +2138,13 @@ get bool GetHotspotSingleLine=2497(,) # Move caret down one paragraph (delimited by empty lines). fun void ParaDown=2413(,) + # Extend selection down one paragraph (delimited by empty lines). fun void ParaDownExtend=2414(,) + # Move caret up one paragraph (delimited by empty lines). fun void ParaUp=2415(,) + # Extend selection up one paragraph (delimited by empty lines). fun void ParaUpExtend=2416(,) @@ -1935,13 +2158,18 @@ fun position PositionAfter=2418(position pos,) # Given a valid document position, return a position that differs in a number # of characters. Returned value is always between 0 and last position in document. -fun position PositionRelative=2670(position pos, int relative) +fun position PositionRelative=2670(position pos, position relative) + +# Given a valid document position, return a position that differs in a number +# of UTF-16 code units. Returned value is always between 0 and last position in document. +# The result may point half way (2 bytes) inside a non-BMP character. +fun position PositionRelativeCodeUnits=2716(position pos, position relative) # Copy a range of text to the clipboard. Positions are clipped into the document. fun void CopyRange=2419(position start, position end) # Copy argument text to the clipboard. -fun void CopyText=2420(int length, string text) +fun void CopyText=2420(position length, string text) enu SelectionMode=SC_SEL_ val SC_SEL_STREAM=0 @@ -1951,16 +2179,19 @@ val SC_SEL_THIN=3 # Set the selection mode to stream (SC_SEL_STREAM) or rectangular (SC_SEL_RECTANGLE/SC_SEL_THIN) or # by lines (SC_SEL_LINES). -set void SetSelectionMode=2422(int selectionMode,) +set void SetSelectionMode=2422(SelectionMode selectionMode,) # Get the mode of the current selection. -get int GetSelectionMode=2423(,) +get SelectionMode GetSelectionMode=2423(,) + +# Get whether or not regular caret moves will extend or reduce the selection. +get bool GetMoveExtendsSelection=2706(,) # Retrieve the position of the start of the selection at the given line (INVALID_POSITION if no selection on this line). -fun position GetLineSelStartPosition=2424(int line,) +fun position GetLineSelStartPosition=2424(line line,) # Retrieve the position of the end of the selection at the given line (INVALID_POSITION if no selection on this line). -fun position GetLineSelEndPosition=2425(int line,) +fun position GetLineSelEndPosition=2425(line line,) ## RectExtended rectangular selection moves # Move caret down one line, extending rectangular selection to new caret position. @@ -2047,64 +2278,72 @@ enu CaseInsensitiveBehaviour=SC_CASEINSENSITIVEBEHAVIOUR_ val SC_CASEINSENSITIVEBEHAVIOUR_RESPECTCASE=0 val SC_CASEINSENSITIVEBEHAVIOUR_IGNORECASE=1 +ali SC_CASEINSENSITIVEBEHAVIOUR_RESPECTCASE=RESPECT_CASE +ali SC_CASEINSENSITIVEBEHAVIOUR_IGNORECASE=IGNORE_CASE + # Set auto-completion case insensitive behaviour to either prefer case-sensitive matches or have no preference. -set void AutoCSetCaseInsensitiveBehaviour=2634(int behaviour,) +set void AutoCSetCaseInsensitiveBehaviour=2634(CaseInsensitiveBehaviour behaviour,) # Get auto-completion case insensitive behaviour. -get int AutoCGetCaseInsensitiveBehaviour=2635(,) +get CaseInsensitiveBehaviour AutoCGetCaseInsensitiveBehaviour=2635(,) enu MultiAutoComplete=SC_MULTIAUTOC_ val SC_MULTIAUTOC_ONCE=0 val SC_MULTIAUTOC_EACH=1 # Change the effect of autocompleting when there are multiple selections. -set void AutoCSetMulti=2636(int multi,) +set void AutoCSetMulti=2636(MultiAutoComplete multi,) # Retrieve the effect of autocompleting when there are multiple selections. -get int AutoCGetMulti=2637(,) +get MultiAutoComplete AutoCGetMulti=2637(,) enu Ordering=SC_ORDER_ val SC_ORDER_PRESORTED=0 val SC_ORDER_PERFORMSORT=1 val SC_ORDER_CUSTOM=2 +ali SC_ORDER_PRESORTED=PRE_SORTED +ali SC_ORDER_PERFORMSORT=PERFORM_SORT + # Set the way autocompletion lists are ordered. -set void AutoCSetOrder=2660(int order,) +set void AutoCSetOrder=2660(Ordering order,) # Get the way autocompletion lists are ordered. -get int AutoCGetOrder=2661(,) +get Ordering AutoCGetOrder=2661(,) # Enlarge the document to a particular size of text bytes. -fun void Allocate=2446(int bytes,) +fun void Allocate=2446(position bytes,) # Returns the target converted to UTF8. # Return the length in bytes. -fun int TargetAsUTF8=2447(, stringresult s) +fun position TargetAsUTF8=2447(, stringresult s) # Set the length of the utf8 argument for calling EncodedFromUTF8. # Set to -1 and the string will be measured to the first nul. -fun void SetLengthForEncode=2448(int bytes,) +fun void SetLengthForEncode=2448(position bytes,) # Translates a UTF8 string into the document encoding. # Return the length of the result in bytes. # On error return 0. -fun int EncodedFromUTF8=2449(string utf8, stringresult encoded) +fun position EncodedFromUTF8=2449(string utf8, stringresult encoded) # Find the position of a column on a line taking into account tabs and # multi-byte characters. If beyond end of line, return line end position. -fun int FindColumn=2456(int line, int column) - -# Can the caret preferred x position only be changed by explicit movement commands? -get int GetCaretSticky=2457(,) - -# Stop the caret preferred x position changing when the user types. -set void SetCaretSticky=2458(int useCaretStickyBehaviour,) +fun position FindColumn=2456(line line, position column) enu CaretSticky=SC_CARETSTICKY_ val SC_CARETSTICKY_OFF=0 val SC_CARETSTICKY_ON=1 val SC_CARETSTICKY_WHITESPACE=2 +ali SC_CARETSTICKY_WHITESPACE=WHITE_SPACE + +# Can the caret preferred x position only be changed by explicit movement commands? +get CaretSticky GetCaretSticky=2457(,) + +# Stop the caret preferred x position changing when the user types. +set void SetCaretSticky=2458(CaretSticky useCaretStickyBehaviour,) + # Switch between sticky and non-sticky: meant to be bound to a key. fun void ToggleCaretSticky=2459(,) @@ -2117,26 +2356,26 @@ get bool GetPasteConvertEndings=2468(,) # Duplicate the selection. If selection empty duplicate the line containing the caret. fun void SelectionDuplicate=2469(,) -val SC_ALPHA_TRANSPARENT=0 -val SC_ALPHA_OPAQUE=255 -val SC_ALPHA_NOALPHA=256 - # Set background alpha of the caret line. -set void SetCaretLineBackAlpha=2470(int alpha,) +set void SetCaretLineBackAlpha=2470(Alpha alpha,) # Get the background alpha of the caret line. -get int GetCaretLineBackAlpha=2471(,) +get Alpha GetCaretLineBackAlpha=2471(,) enu CaretStyle=CARETSTYLE_ val CARETSTYLE_INVISIBLE=0 val CARETSTYLE_LINE=1 val CARETSTYLE_BLOCK=2 +val CARETSTYLE_OVERSTRIKE_BAR=0 +val CARETSTYLE_OVERSTRIKE_BLOCK=0x10 +val CARETSTYLE_INS_MASK=0xF +val CARETSTYLE_BLOCK_AFTER=0x100 # Set the style of the caret to be drawn. -set void SetCaretStyle=2512(int caretStyle,) +set void SetCaretStyle=2512(CaretStyle caretStyle,) # Returns the current style of the caret. -get int GetCaretStyle=2513(,) +get CaretStyle GetCaretStyle=2513(,) # Set the indicator used for IndicatorFillRange and IndicatorClearRange set void SetIndicatorCurrent=2500(int indicator,) @@ -2150,11 +2389,11 @@ set void SetIndicatorValue=2502(int value,) # Get the current indicator value get int GetIndicatorValue=2503(,) -# Turn an indicator on over a range. -fun void IndicatorFillRange=2504(position start, int lengthFill) +# Turn a indicator on over a range. +fun void IndicatorFillRange=2504(position start, position lengthFill) -# Turn an indicator off over a range. -fun void IndicatorClearRange=2505(position start, int lengthClear) +# Turn a indicator off over a range. +fun void IndicatorClearRange=2505(position start, position lengthClear) # Are any indicators present at pos? fun int IndicatorAllOnFor=2506(position pos,) @@ -2163,10 +2402,10 @@ fun int IndicatorAllOnFor=2506(position pos,) fun int IndicatorValueAt=2507(int indicator, position pos) # Where does a particular indicator start? -fun int IndicatorStart=2508(int indicator, position pos) +fun position IndicatorStart=2508(int indicator, position pos) # Where does a particular indicator end? -fun int IndicatorEnd=2509(int indicator, position pos) +fun position IndicatorEnd=2509(int indicator, position pos) # Set number of entries in position cache set void SetPositionCache=2514(int size,) @@ -2179,28 +2418,28 @@ fun void CopyAllowLine=2519(,) # Compact the document buffer and return a read-only pointer to the # characters in the document. -get int GetCharacterPointer=2520(,) +get pointer GetCharacterPointer=2520(,) # Return a read-only pointer to a range of characters in the document. # May move the gap so that the range is contiguous, but will only move up # to lengthRange bytes. -get int GetRangePointer=2643(position start, int lengthRange) +get pointer GetRangePointer=2643(position start, position lengthRange) # Return a position which, to avoid performance costs, should not be within # the range of a call to GetRangePointer. get position GetGapPosition=2644(,) # Set the alpha fill colour of the given indicator. -set void IndicSetAlpha=2523(int indicator, int alpha) +set void IndicSetAlpha=2523(int indicator, Alpha alpha) # Get the alpha fill colour of the given indicator. -get int IndicGetAlpha=2524(int indicator,) +get Alpha IndicGetAlpha=2524(int indicator,) # Set the alpha outline colour of the given indicator. -set void IndicSetOutlineAlpha=2558(int indicator, int alpha) +set void IndicSetOutlineAlpha=2558(int indicator, Alpha alpha) # Get the alpha outline colour of the given indicator. -get int IndicGetOutlineAlpha=2559(int indicator,) +get Alpha IndicGetOutlineAlpha=2559(int indicator,) # Set extra ascent for each line set void SetExtraAscent=2525(int extraAscent,) @@ -2218,22 +2457,22 @@ get int GetExtraDescent=2528(,) fun int MarkerSymbolDefined=2529(int markerNumber,) # Set the text in the text margin for a line -set void MarginSetText=2530(int line, string text) +set void MarginSetText=2530(line line, string text) # Get the text in the text margin for a line -get int MarginGetText=2531(int line, stringresult text) +get int MarginGetText=2531(line line, stringresult text) # Set the style number for the text margin for a line -set void MarginSetStyle=2532(int line, int style) +set void MarginSetStyle=2532(line line, int style) # Get the style number for the text margin for a line -get int MarginGetStyle=2533(int line,) +get int MarginGetStyle=2533(line line,) # Set the style in the text margin for a line -set void MarginSetStyles=2534(int line, string styles) +set void MarginSetStyles=2534(line line, string styles) # Get the styles in the text margin for a line -get int MarginGetStyles=2535(int line, stringresult styles) +get int MarginGetStyles=2535(line line, stringresult styles) # Clear the margin text on all lines fun void MarginTextClearAll=2536(,) @@ -2248,32 +2487,34 @@ enu MarginOption=SC_MARGINOPTION_ val SC_MARGINOPTION_NONE=0 val SC_MARGINOPTION_SUBLINESELECT=1 +ali SC_MARGINOPTION_SUBLINESELECT=SUB_LINE_SELECT + # Set the margin options. -set void SetMarginOptions=2539(int marginOptions,) +set void SetMarginOptions=2539(MarginOption marginOptions,) # Get the margin options. -get int GetMarginOptions=2557(,) +get MarginOption GetMarginOptions=2557(,) # Set the annotation text for a line -set void AnnotationSetText=2540(int line, string text) +set void AnnotationSetText=2540(line line, string text) # Get the annotation text for a line -get int AnnotationGetText=2541(int line, stringresult text) +get int AnnotationGetText=2541(line line, stringresult text) # Set the style number for the annotations for a line -set void AnnotationSetStyle=2542(int line, int style) +set void AnnotationSetStyle=2542(line line, int style) # Get the style number for the annotations for a line -get int AnnotationGetStyle=2543(int line,) +get int AnnotationGetStyle=2543(line line,) # Set the annotation styles for a line -set void AnnotationSetStyles=2544(int line, string styles) +set void AnnotationSetStyles=2544(line line, string styles) # Get the annotation styles for a line -get int AnnotationGetStyles=2545(int line, stringresult styles) +get int AnnotationGetStyles=2545(line line, stringresult styles) # Get the number of annotation lines for a line -get int AnnotationGetLines=2546(int line,) +get int AnnotationGetLines=2546(line line,) # Clear the annotations from all lines fun void AnnotationClearAll=2547(,) @@ -2285,10 +2526,10 @@ val ANNOTATION_BOXED=2 val ANNOTATION_INDENTED=3 # Set the visibility for the annotations for a view -set void AnnotationSetVisible=2548(int visible,) +set void AnnotationSetVisible=2548(AnnotationVisible visible,) # Get the visibility for the annotations for a view -get int AnnotationGetVisible=2549(,) +get AnnotationVisible AnnotationGetVisible=2549(,) # Get the start of the range of style numbers used for annotations set void AnnotationSetStyleOffset=2550(int style,) @@ -2302,10 +2543,12 @@ fun void ReleaseAllExtendedStyles=2552(,) # Allocate some extended (>255) style numbers and return the start of the range fun int AllocateExtendedStyles=2553(int numberStyles,) +enu UndoFlags=UNDO_ +val UNDO_NONE=0 val UNDO_MAY_COALESCE=1 # Add a container action to the undo stack -fun void AddUndoAction=2560(int token, int flags) +fun void AddUndoAction=2560(int token, UndoFlags flags) # Find the position of a character from a point within the window. fun position CharPositionFromPoint=2561(int x, int y) @@ -2354,10 +2597,10 @@ get bool GetSelectionEmpty=2650(,) fun void ClearSelections=2571(,) # Set a simple selection -fun int SetSelection=2572(position caret, position anchor) +fun void SetSelection=2572(position caret, position anchor) # Add a selection -fun int AddSelection=2573(position caret, position anchor) +fun void AddSelection=2573(position caret, position anchor) # Drop one selection fun void DropSelectionN=2671(int selection,) @@ -2370,20 +2613,27 @@ get int GetMainSelection=2575(,) # Set the caret position of the nth selection. set void SetSelectionNCaret=2576(int selection, position caret) + # Return the caret position of the nth selection. get position GetSelectionNCaret=2577(int selection,) + # Set the anchor position of the nth selection. set void SetSelectionNAnchor=2578(int selection, position anchor) + # Return the anchor position of the nth selection. get position GetSelectionNAnchor=2579(int selection,) + # Set the virtual space of the caret of the nth selection. -set void SetSelectionNCaretVirtualSpace=2580(int selection, int space) +set void SetSelectionNCaretVirtualSpace=2580(int selection, position space) + # Return the virtual space of the caret of the nth selection. -get int GetSelectionNCaretVirtualSpace=2581(int selection,) +get position GetSelectionNCaretVirtualSpace=2581(int selection,) + # Set the virtual space of the anchor of the nth selection. -set void SetSelectionNAnchorVirtualSpace=2582(int selection, int space) +set void SetSelectionNAnchorVirtualSpace=2582(int selection, position space) + # Return the virtual space of the anchor of the nth selection. -get int GetSelectionNAnchorVirtualSpace=2583(int selection,) +get position GetSelectionNAnchorVirtualSpace=2583(int selection,) # Sets the position that starts the selection - this becomes the anchor. set void SetSelectionNStart=2584(int selection, position anchor) @@ -2391,28 +2641,41 @@ set void SetSelectionNStart=2584(int selection, position anchor) # Returns the position at the start of the selection. get position GetSelectionNStart=2585(int selection,) +# Returns the virtual space at the start of the selection. +get position GetSelectionNStartVirtualSpace=2726(int selection,) + # Sets the position that ends the selection - this becomes the currentPosition. set void SetSelectionNEnd=2586(int selection, position caret) +# Returns the virtual space at the end of the selection. +get position GetSelectionNEndVirtualSpace=2727(int selection,) + # Returns the position at the end of the selection. get position GetSelectionNEnd=2587(int selection,) # Set the caret position of the rectangular selection. set void SetRectangularSelectionCaret=2588(position caret,) + # Return the caret position of the rectangular selection. get position GetRectangularSelectionCaret=2589(,) + # Set the anchor position of the rectangular selection. set void SetRectangularSelectionAnchor=2590(position anchor,) + # Return the anchor position of the rectangular selection. get position GetRectangularSelectionAnchor=2591(,) + # Set the virtual space of the caret of the rectangular selection. -set void SetRectangularSelectionCaretVirtualSpace=2592(int space,) +set void SetRectangularSelectionCaretVirtualSpace=2592(position space,) + # Return the virtual space of the caret of the rectangular selection. -get int GetRectangularSelectionCaretVirtualSpace=2593(,) +get position GetRectangularSelectionCaretVirtualSpace=2593(,) + # Set the virtual space of the anchor of the rectangular selection. -set void SetRectangularSelectionAnchorVirtualSpace=2594(int space,) +set void SetRectangularSelectionAnchorVirtualSpace=2594(position space,) + # Return the virtual space of the anchor of the rectangular selection. -get int GetRectangularSelectionAnchorVirtualSpace=2595(,) +get position GetRectangularSelectionAnchorVirtualSpace=2595(,) enu VirtualSpace=SCVS_ val SCVS_NONE=0 @@ -2420,12 +2683,17 @@ val SCVS_RECTANGULARSELECTION=1 val SCVS_USERACCESSIBLE=2 val SCVS_NOWRAPLINESTART=4 -# Set options for virtual space behaviour. -set void SetVirtualSpaceOptions=2596(int virtualSpaceOptions,) -# Return options for virtual space behaviour. -get int GetVirtualSpaceOptions=2597(,) +ali SCVS_RECTANGULARSELECTION=RECTANGULAR_SELECTION +ali SCVS_USERACCESSIBLE=USER_ACCESSIBLE +ali SCVS_NOWRAPLINESTART=NO_WRAP_LINE_START -# On GTK+, allow selecting the modifier key to use for mouse-based +# Set options for virtual space behaviour. +set void SetVirtualSpaceOptions=2596(VirtualSpace virtualSpaceOptions,) + +# Return options for virtual space behaviour. +get VirtualSpace GetVirtualSpaceOptions=2597(,) + +# On GTK, allow selecting the modifier key to use for mouse-based # rectangular selection. Often the window manager requires Alt+Mouse Drag # for moving windows. # Valid values are SCMOD_CTRL(default), SCMOD_ALT, or SCMOD_SUPER. @@ -2444,10 +2712,10 @@ set void SetAdditionalSelFore=2600(colour fore,) set void SetAdditionalSelBack=2601(colour back,) # Set the alpha of the selection. -set void SetAdditionalSelAlpha=2602(int alpha,) +set void SetAdditionalSelAlpha=2602(Alpha alpha,) # Get the alpha of the selection. -get int GetAdditionalSelAlpha=2603(,) +get Alpha GetAdditionalSelAlpha=2603(,) # Set the foreground colour of additional carets. set void SetAdditionalCaretFore=2604(colour fore,) @@ -2475,7 +2743,7 @@ fun int ChangeLexerState=2617(position start, position end) # Find the next line at or after lineStart that is a contracted fold header line. # Return -1 when no more lines. -fun int ContractedFoldNext=2618(int lineStart,) +fun line ContractedFoldNext=2618(line lineStart,) # Centre current line in window. fun void VerticalCentreCaret=2619(,) @@ -2515,19 +2783,24 @@ fun void ScrollToStart=2628(,) # Scroll to end of document. fun void ScrollToEnd=2629(,) +enu Technology=SC_TECHNOLOGY_ val SC_TECHNOLOGY_DEFAULT=0 val SC_TECHNOLOGY_DIRECTWRITE=1 val SC_TECHNOLOGY_DIRECTWRITERETAIN=2 val SC_TECHNOLOGY_DIRECTWRITEDC=3 +ali SC_TECHNOLOGY_DIRECTWRITE=DIRECT_WRITE +ali SC_TECHNOLOGY_DIRECTWRITERETAIN=DIRECT_WRITE_RETAIN +ali SC_TECHNOLOGY_DIRECTWRITEDC=DIRECT_WRITE_D_C + # Set the technology used. -set void SetTechnology=2630(int technology,) +set void SetTechnology=2630(Technology technology,) # Get the tech. -get int GetTechnology=2631(,) +get Technology GetTechnology=2631(,) # Create an ILoader*. -fun int CreateLoader=2632(int bytes,) +fun pointer CreateLoader=2632(position bytes, DocumentOption documentOptions) # On OS X, show a find indicator. fun void FindIndicatorShow=2640(position start, position end) @@ -2559,13 +2832,13 @@ val SC_LINE_END_TYPE_DEFAULT=0 val SC_LINE_END_TYPE_UNICODE=1 # Set the line end types that the application wants to use. May not be used if incompatible with lexer or encoding. -set void SetLineEndTypesAllowed=2656(int lineEndBitSet,) +set void SetLineEndTypesAllowed=2656(LineEndType lineEndBitSet,) # Get the line end types currently allowed. -get int GetLineEndTypesAllowed=2657(,) +get LineEndType GetLineEndTypesAllowed=2657(,) # Get the line end types currently recognised. May be a subset of the allowed types due to lexer limitation. -get int GetLineEndTypesActive=2658(,) +get LineEndType GetLineEndTypesActive=2658(,) # Set the way a character is drawn. set void SetRepresentation=2665(string encodedCharacter, string representation) @@ -2577,6 +2850,38 @@ get int GetRepresentation=2666(string encodedCharacter, stringresult representat # Remove a character representation. fun void ClearRepresentation=2667(string encodedCharacter,) +# Set the end of line annotation text for a line +set void EOLAnnotationSetText=2740(line line, string text) + +# Get the end of line annotation text for a line +get int EOLAnnotationGetText=2741(line line, stringresult text) + +# Set the style number for the end of line annotations for a line +set void EOLAnnotationSetStyle=2742(line line, int style) + +# Get the style number for the end of line annotations for a line +get int EOLAnnotationGetStyle=2743(line line,) + +# Clear the end of annotations from all lines +fun void EOLAnnotationClearAll=2744(,) + +enu EOLAnnotationVisible=EOLANNOTATION_ +val EOLANNOTATION_HIDDEN=0 +val EOLANNOTATION_STANDARD=1 +val EOLANNOTATION_BOXED=2 + +# Set the visibility for the end of line annotations for a view +set void EOLAnnotationSetVisible=2745(EOLAnnotationVisible visible,) + +# Get the visibility for the end of line annotations for a view +get EOLAnnotationVisible EOLAnnotationGetVisible=2746(,) + +# Get the start of the range of style numbers used for end of line annotations +set void EOLAnnotationSetStyleOffset=2747(int style,) + +# Get the start of the range of style numbers used for end of line annotations +get int EOLAnnotationGetStyleOffset=2748(,) + # Start notifying the container of all key presses and commands. fun void StartRecord=3001(,) @@ -2620,16 +2925,13 @@ get int GetPropertyExpanded=4009(string key, stringresult value) # interpreted as an int AFTER any "$()" variable replacement. get int GetPropertyInt=4010(string key, int defaultValue) -# Retrieve the number of bits the current lexer needs for styling. -get int GetStyleBitsNeeded=4011(,) - # Retrieve the name of the lexer. # Return the length of the text. # Result is NUL-terminated. get int GetLexerLanguage=4012(, stringresult language) # For private communication between an application and a known lexer. -fun int PrivateLexerCall=4013(int operation, int pointer) +fun pointer PrivateLexerCall=4013(int operation, pointer pointer) # Retrieve a '\n' separated list of properties understood by the current lexer. # Result is NUL-terminated. @@ -2641,7 +2943,7 @@ val SC_TYPE_INTEGER=1 val SC_TYPE_STRING=2 # Retrieve the type of a property. -fun int PropertyType=4015(string name,) +fun TypeProperty PropertyType=4015(string name,) # Describe a property. # Result is NUL-terminated. @@ -2684,11 +2986,27 @@ 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 name) + +# Retrieve a ' ' separated list of style tags like "literal quoted string". +# Result is NUL-terminated. +fun int TagsOfStyle=4031(int style, stringresult tags) + +# Retrieve a description of a style. +# Result is NUL-terminated. +fun int DescriptionOfStyle=4032(int style, stringresult description) + # 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. # One bit is set from each of SC_MOD_* and SC_PERFORMED_*. enu ModificationFlags=SC_MOD_ SC_PERFORMED_ SC_MULTISTEPUNDOREDO SC_LASTSTEPINUNDOREDO SC_MULTILINEUNDOREDO SC_STARTACTION SC_MODEVENTMASKALL +val SC_MOD_NONE=0x0 val SC_MOD_INSERTTEXT=0x1 val SC_MOD_DELETETEXT=0x2 val SC_MOD_CHANGESTYLE=0x4 @@ -2711,7 +3029,29 @@ val SC_MOD_CONTAINER=0x40000 val SC_MOD_LEXERSTATE=0x80000 val SC_MOD_INSERTCHECK=0x100000 val SC_MOD_CHANGETABSTOPS=0x200000 -val SC_MODEVENTMASKALL=0x3FFFFF +val SC_MOD_CHANGEEOLANNOTATION=0x400000 +val SC_MODEVENTMASKALL=0x7FFFFF + +ali SC_MOD_INSERTTEXT=INSERT_TEXT +ali SC_MOD_DELETETEXT=DELETE_TEXT +ali SC_MOD_CHANGESTYLE=CHANGE_STYLE +ali SC_MOD_CHANGEFOLD=CHANGE_FOLD +ali SC_MULTISTEPUNDOREDO=MULTI_STEP_UNDO_REDO +ali SC_LASTSTEPINUNDOREDO=LAST_STEP_IN_UNDO_REDO +ali SC_MOD_CHANGEMARKER=CHANGE_MARKER +ali SC_MOD_BEFOREINSERT=BEFORE_INSERT +ali SC_MOD_BEFOREDELETE=BEFORE_DELETE +ali SC_MULTILINEUNDOREDO=MULTILINE_UNDO_REDO +ali SC_STARTACTION=START_ACTION +ali SC_MOD_CHANGEINDICATOR=CHANGE_INDICATOR +ali SC_MOD_CHANGELINESTATE=CHANGE_LINE_STATE +ali SC_MOD_CHANGEMARGIN=CHANGE_MARGIN +ali SC_MOD_CHANGEANNOTATION=CHANGE_ANNOTATION +ali SC_MOD_LEXERSTATE=LEXER_STATE +ali SC_MOD_INSERTCHECK=INSERT_CHECK +ali SC_MOD_CHANGETABSTOPS=CHANGE_TAB_STOPS +ali SC_MOD_CHANGEEOLANNOTATION=CHANGE_E_O_L_ANNOTATION +ali SC_MODEVENTMASKALL=EVENT_MASK_ALL enu Update=SC_UPDATE_ val SC_UPDATE_CONTENT=0x1 @@ -2753,6 +3093,8 @@ val SCK_WIN=313 val SCK_RWIN=314 val SCK_MENU=315 +ali SCK_RWIN=R_WIN + enu KeyMod=SCMOD_ val SCMOD_NORM=0 val SCMOD_SHIFT=1 @@ -2768,6 +3110,18 @@ val SC_AC_TAB=3 val SC_AC_NEWLINE=4 val SC_AC_COMMAND=5 +ali SC_AC_FILLUP=FILL_UP +ali SC_AC_DOUBLECLICK=DOUBLE_CLICK + +# characterSource for SCN_CHARADDED +enu CharacterSource=SC_CHARACTERSOURCE_ +# Direct input characters. +val SC_CHARACTERSOURCE_DIRECT_INPUT=0 +# IME (inline mode) or dead key tentative input characters. +val SC_CHARACTERSOURCE_TENTATIVE_INPUT=1 +# IME (either inline or windowed mode) full composited string. +val SC_CHARACTERSOURCE_IME_RESULT=2 + ################################################ # For SciLexer.h enu Lexer=SCLEX_ @@ -2891,6 +3245,17 @@ val SCLEX_IHEX=118 val SCLEX_TEHEX=119 val SCLEX_JSON=120 val SCLEX_EDIFACT=121 +val SCLEX_INDENT=122 +val SCLEX_MAXIMA=123 +val SCLEX_STATA=124 +val SCLEX_SAS=125 +val SCLEX_NIM=126 +val SCLEX_CIL=127 +val SCLEX_X12=128 +val SCLEX_DATAFLEX=129 +val SCLEX_HOLLYWOOD=130 +val SCLEX_RAKU=131 +val SCLEX_LPEG=999 # When a lexer specifies its language as SCLEX_AUTOMATIC it receives a # value assigned in sequence from SCLEX_AUTOMATIC+1. @@ -2914,7 +3279,15 @@ val SCE_P_COMMENTBLOCK=12 val SCE_P_STRINGEOL=13 val SCE_P_WORD2=14 val SCE_P_DECORATOR=15 -# Lexical states for SCLEX_CPP, SCLEX_BULLANT, SCLEX_COBOL, SCLEX_TACL, SCLEX_TAL +val SCE_P_FSTRING=16 +val SCE_P_FCHARACTER=17 +val SCE_P_FTRIPLE=18 +val SCE_P_FTRIPLEDOUBLE=19 +# Lexical states for SCLEX_CPP +# Lexical states for SCLEX_BULLANT +# Lexical states for SCLEX_COBOL +# Lexical states for SCLEX_TACL +# Lexical states for SCLEX_TAL lex Cpp=SCLEX_CPP SCE_C_ lex BullAnt=SCLEX_BULLANT SCE_C_ lex COBOL=SCLEX_COBOL SCE_C_ @@ -3309,6 +3682,7 @@ val SCE_ERR_VALUE=21 val SCE_ERR_GCC_INCLUDED_FROM=22 val SCE_ERR_ESCSEQ=23 val SCE_ERR_ESCSEQ_UNKNOWN=24 +val SCE_ERR_GCC_EXCERPT=25 val SCE_ERR_ES_BLACK=40 val SCE_ERR_ES_RED=41 val SCE_ERR_ES_GREEN=42 @@ -3367,6 +3741,10 @@ val SCE_DIFF_POSITION=4 val SCE_DIFF_DELETED=5 val SCE_DIFF_ADDED=6 val SCE_DIFF_CHANGED=7 +val SCE_DIFF_PATCH_ADD=8 +val SCE_DIFF_PATCH_DELETE=9 +val SCE_DIFF_REMOVED_PATCH_ADD=10 +val SCE_DIFF_REMOVED_PATCH_DELETE=11 # Lexical states for SCLEX_CONF (Apache Configuration Files Lexer) lex Conf=SCLEX_CONF SCE_CONF_ val SCE_CONF_DEFAULT=0 @@ -3502,6 +3880,16 @@ val SCE_MATLAB_STRING=5 val SCE_MATLAB_OPERATOR=6 val SCE_MATLAB_IDENTIFIER=7 val SCE_MATLAB_DOUBLEQUOTESTRING=8 +# Lexical states for SCLEX_MAXIMA +lex Maxima=SCLEX_MAXIMA SCE_MAXIMA_ +val SCE_MAXIMA_OPERATOR=0 +val SCE_MAXIMA_COMMANDENDING=1 +val SCE_MAXIMA_COMMENT=2 +val SCE_MAXIMA_NUMBER=3 +val SCE_MAXIMA_STRING=4 +val SCE_MAXIMA_COMMAND=5 +val SCE_MAXIMA_VARIABLE=6 +val SCE_MAXIMA_UNKNOWN=7 # Lexical states for SCLEX_SCRIPTOL lex Sol=SCLEX_SCRIPTOL SCE_SCRIPTOL_ val SCE_SCRIPTOL_DEFAULT=0 @@ -4790,15 +5178,155 @@ val SCE_EDI_SEP_RELEASE=5 val SCE_EDI_UNA=6 val SCE_EDI_UNH=7 val SCE_EDI_BADSEGMENT=8 +# Lexical states for SCLEX_STATA +lex STATA=SCLEX_STATA SCE_STATA_ +val SCE_STATA_DEFAULT=0 +val SCE_STATA_COMMENT=1 +val SCE_STATA_COMMENTLINE=2 +val SCE_STATA_COMMENTBLOCK=3 +val SCE_STATA_NUMBER=4 +val SCE_STATA_OPERATOR=5 +val SCE_STATA_IDENTIFIER=6 +val SCE_STATA_STRING=7 +val SCE_STATA_TYPE=8 +val SCE_STATA_WORD=9 +val SCE_STATA_GLOBAL_MACRO=10 +val SCE_STATA_MACRO=11 +# Lexical states for SCLEX_SAS +lex SAS=SCLEX_SAS SCE_SAS_ +val SCE_SAS_DEFAULT=0 +val SCE_SAS_COMMENT=1 +val SCE_SAS_COMMENTLINE=2 +val SCE_SAS_COMMENTBLOCK=3 +val SCE_SAS_NUMBER=4 +val SCE_SAS_OPERATOR=5 +val SCE_SAS_IDENTIFIER=6 +val SCE_SAS_STRING=7 +val SCE_SAS_TYPE=8 +val SCE_SAS_WORD=9 +val SCE_SAS_GLOBAL_MACRO=10 +val SCE_SAS_MACRO=11 +val SCE_SAS_MACRO_KEYWORD=12 +val SCE_SAS_BLOCK_KEYWORD=13 +val SCE_SAS_MACRO_FUNCTION=14 +val SCE_SAS_STATEMENT=15 +# Lexical states for SCLEX_NIM +lex Nim=SCLEX_NIM SCE_NIM_ +val SCE_NIM_DEFAULT=0 +val SCE_NIM_COMMENT=1 +val SCE_NIM_COMMENTDOC=2 +val SCE_NIM_COMMENTLINE=3 +val SCE_NIM_COMMENTLINEDOC=4 +val SCE_NIM_NUMBER=5 +val SCE_NIM_STRING=6 +val SCE_NIM_CHARACTER=7 +val SCE_NIM_WORD=8 +val SCE_NIM_TRIPLE=9 +val SCE_NIM_TRIPLEDOUBLE=10 +val SCE_NIM_BACKTICKS=11 +val SCE_NIM_FUNCNAME=12 +val SCE_NIM_STRINGEOL=13 +val SCE_NIM_NUMERROR=14 +val SCE_NIM_OPERATOR=15 +val SCE_NIM_IDENTIFIER=16 +# Lexical states for SCLEX_CIL +lex CIL=SCLEX_CIL SCE_CIL_ +val SCE_CIL_DEFAULT=0 +val SCE_CIL_COMMENT=1 +val SCE_CIL_COMMENTLINE=2 +val SCE_CIL_WORD=3 +val SCE_CIL_WORD2=4 +val SCE_CIL_WORD3=5 +val SCE_CIL_STRING=6 +val SCE_CIL_LABEL=7 +val SCE_CIL_OPERATOR=8 +val SCE_CIL_IDENTIFIER=9 +val SCE_CIL_STRINGEOL=10 +# Lexical states for SCLEX_X12 +lex X12=SCLEX_X12 SCE_X12_ +val SCE_X12_DEFAULT=0 +val SCE_X12_BAD=1 +val SCE_X12_ENVELOPE=2 +val SCE_X12_FUNCTIONGROUP=3 +val SCE_X12_TRANSACTIONSET=4 +val SCE_X12_SEGMENTHEADER=5 +val SCE_X12_SEGMENTEND=6 +val SCE_X12_SEP_ELEMENT=7 +val SCE_X12_SEP_SUBELEMENT=8 +# Lexical states for SCLEX_DATAFLEX +lex Dataflex=SCLEX_DATAFLEX SCE_DF_ +val SCE_DF_DEFAULT=0 +val SCE_DF_IDENTIFIER=1 +val SCE_DF_METATAG=2 +val SCE_DF_IMAGE=3 +val SCE_DF_COMMENTLINE=4 +val SCE_DF_PREPROCESSOR=5 +val SCE_DF_PREPROCESSOR2=6 +val SCE_DF_NUMBER=7 +val SCE_DF_HEXNUMBER=8 +val SCE_DF_WORD=9 +val SCE_DF_STRING=10 +val SCE_DF_STRINGEOL=11 +val SCE_DF_SCOPEWORD=12 +val SCE_DF_OPERATOR=13 +val SCE_DF_ICODE=14 +# Lexical states for SCLEX_HOLLYWOOD +lex Hollywood=SCLEX_HOLLYWOOD SCE_HOLLYWOOD_ +val SCE_HOLLYWOOD_DEFAULT=0 +val SCE_HOLLYWOOD_COMMENT=1 +val SCE_HOLLYWOOD_COMMENTBLOCK=2 +val SCE_HOLLYWOOD_NUMBER=3 +val SCE_HOLLYWOOD_KEYWORD=4 +val SCE_HOLLYWOOD_STDAPI=5 +val SCE_HOLLYWOOD_PLUGINAPI=6 +val SCE_HOLLYWOOD_PLUGINMETHOD=7 +val SCE_HOLLYWOOD_STRING=8 +val SCE_HOLLYWOOD_STRINGBLOCK=9 +val SCE_HOLLYWOOD_PREPROCESSOR=10 +val SCE_HOLLYWOOD_OPERATOR=11 +val SCE_HOLLYWOOD_IDENTIFIER=12 +val SCE_HOLLYWOOD_CONSTANT=13 +val SCE_HOLLYWOOD_HEXNUMBER=14 +# Lexical states for SCLEX_RAKU +lex Raku=SCLEX_RAKU SCE_RAKU_ +val SCE_RAKU_DEFAULT=0 +val SCE_RAKU_ERROR=1 +val SCE_RAKU_COMMENTLINE=2 +val SCE_RAKU_COMMENTEMBED=3 +val SCE_RAKU_POD=4 +val SCE_RAKU_CHARACTER=5 +val SCE_RAKU_HEREDOC_Q=6 +val SCE_RAKU_HEREDOC_QQ=7 +val SCE_RAKU_STRING=8 +val SCE_RAKU_STRING_Q=9 +val SCE_RAKU_STRING_QQ=10 +val SCE_RAKU_STRING_Q_LANG=11 +val SCE_RAKU_STRING_VAR=12 +val SCE_RAKU_REGEX=13 +val SCE_RAKU_REGEX_VAR=14 +val SCE_RAKU_ADVERB=15 +val SCE_RAKU_NUMBER=16 +val SCE_RAKU_PREPROCESSOR=17 +val SCE_RAKU_OPERATOR=18 +val SCE_RAKU_WORD=19 +val SCE_RAKU_FUNCTION=20 +val SCE_RAKU_IDENTIFIER=21 +val SCE_RAKU_TYPEDEF=22 +val SCE_RAKU_MU=23 +val SCE_RAKU_POSITIONAL=24 +val SCE_RAKU_ASSOCIATIVE=25 +val SCE_RAKU_CALLABLE=26 +val SCE_RAKU_GRAMMAR=27 +val SCE_RAKU_CLASS=28 # Events evt void StyleNeeded=2000(int position) -evt void CharAdded=2001(int ch) +evt void CharAdded=2001(int ch, int characterSource) evt void SavePointReached=2002(void) evt void SavePointLeft=2003(void) evt void ModifyAttemptRO=2004(void) -# GTK+ Specific to work around focus and accelerator problems: +# GTK Specific to work around focus and accelerator problems: evt void Key=2005(int ch, int modifiers) evt void DoubleClick=2006(int modifiers, int position, int line) evt void UpdateUI=2007(int updated) @@ -4807,7 +5335,7 @@ evt void MacroRecord=2009(int message, int wParam, int lParam) evt void MarginClick=2010(int modifiers, int position, int margin) evt void NeedShown=2011(int position, int length) evt void Painted=2013(void) -evt void UserListSelection=2014(int listType, string text, int positionint, int ch, CompletionMethods listCompletionMethod) +evt void UserListSelection=2014(int listType, string text, int position, int ch, CompletionMethods listCompletionMethod) evt void URIDropped=2015(string text) evt void DwellStart=2016(int position, int x, int y) evt void DwellEnd=2017(int position, int x, int y) @@ -4825,13 +5353,43 @@ evt void FocusIn=2028(void) evt void FocusOut=2029(void) evt void AutoCCompleted=2030(string text, int position, int ch, CompletionMethods listCompletionMethod) evt void MarginRightClick=2031(int modifiers, int position, int margin) - -# There are no provisional APIs currently, but some arguments to SCI_SETTECHNOLOGY are provisional. +evt void AutoCSelectionChange=2032(int listType, string text, int position) cat Provisional +enu LineCharacterIndexType=SC_LINECHARACTERINDEX_ +val SC_LINECHARACTERINDEX_NONE=0 +val SC_LINECHARACTERINDEX_UTF32=1 +val SC_LINECHARACTERINDEX_UTF16=2 + +# Retrieve line character index state. +get LineCharacterIndexType GetLineCharacterIndex=2710(,) + +# Request line character index be created or its use count increased. +fun void AllocateLineCharacterIndex=2711(LineCharacterIndexType lineCharacterIndex,) + +# Decrease use count of line character index and remove if 0. +fun void ReleaseLineCharacterIndex=2712(LineCharacterIndexType lineCharacterIndex,) + +# Retrieve the document line containing a position measured in index units. +fun line LineFromIndexPosition=2713(position pos, LineCharacterIndexType lineCharacterIndex) + +# Retrieve the position measured in index units at the start of a document line. +fun position IndexPositionFromLine=2714(line line, LineCharacterIndexType lineCharacterIndex) + cat Deprecated +# Divide each styling byte into lexical class bits (default: 5) and indicator +# bits (default: 3). If a lexer requires more than 32 lexical states, then this +# is used to expand the possible states. +set void SetStyleBits=2090(int bits,) + +# Retrieve number of bits in style bytes used to hold the lexical state. +get int GetStyleBits=2091(,) + +# Retrieve the number of bits the current lexer needs for styling. +get int GetStyleBitsNeeded=4011(,) + # Deprecated in 3.5.5 # Always interpret keyboard input as Unicode @@ -4839,3 +5397,8 @@ set void SetKeysUnicode=2521(bool keysUnicode,) # Are keys always interpreted as Unicode? get bool GetKeysUnicode=2522(,) + +val INDIC0_MASK=0x20 +val INDIC1_MASK=0x40 +val INDIC2_MASK=0x80 +val INDICS_MASK=0xE0 diff --git a/src/stc/scintilla/lexers/LexA68k.cxx b/src/stc/scintilla/lexers/LexA68k.cxx index b5f48987ec..1475ad078e 100644 --- a/src/stc/scintilla/lexers/LexA68k.cxx +++ b/src/stc/scintilla/lexers/LexA68k.cxx @@ -26,9 +26,7 @@ #include "CharacterSet.h" #include "LexerModule.h" -#ifdef SCI_NAMESPACE using namespace Scintilla; -#endif // Return values for GetOperatorType diff --git a/src/stc/scintilla/lexers/LexAPDL.cxx b/src/stc/scintilla/lexers/LexAPDL.cxx index 873ec9d13b..447e40d58b 100644 --- a/src/stc/scintilla/lexers/LexAPDL.cxx +++ b/src/stc/scintilla/lexers/LexAPDL.cxx @@ -24,9 +24,7 @@ #include "CharacterSet.h" #include "LexerModule.h" -#ifdef SCI_NAMESPACE using namespace Scintilla; -#endif static inline bool IsAWordChar(const int ch) { return (ch < 0x80 && (isalnum(ch) || ch == '_')); diff --git a/src/stc/scintilla/lexers/LexASY.cxx b/src/stc/scintilla/lexers/LexASY.cxx index b49975e706..612d24b40d 100644 --- a/src/stc/scintilla/lexers/LexASY.cxx +++ b/src/stc/scintilla/lexers/LexASY.cxx @@ -1,4 +1,5 @@ // Scintilla source code edit control +// @file LexASY.cxx //Author: instanton (email: soft_share126com) // The License.txt file describes the conditions under which this software may be distributed. @@ -19,9 +20,7 @@ #include "CharacterSet.h" #include "LexerModule.h" -#ifdef SCI_NAMESPACE using namespace Scintilla; -#endif static void ColouriseAsyDoc(Sci_PositionU startPos, Sci_Position length, int initStyle, WordList *keywordlists[], Accessor &styler) { diff --git a/src/stc/scintilla/lexers/LexAU3.cxx b/src/stc/scintilla/lexers/LexAU3.cxx index c8ab9d7008..417c832e03 100644 --- a/src/stc/scintilla/lexers/LexAU3.cxx +++ b/src/stc/scintilla/lexers/LexAU3.cxx @@ -1,6 +1,6 @@ // Scintilla source code edit control // @file LexAU3.cxx -// Lexer for AutoIt3 http://www.hiddensoft.com/autoit3 +// Lexer for AutoIt3 https://www.autoitscript.com/site/ // by Jos van der Zande, jvdzande@yahoo.com // // Changes: @@ -68,9 +68,7 @@ #include "CharacterSet.h" #include "LexerModule.h" -#ifdef SCI_NAMESPACE using namespace Scintilla; -#endif static inline bool IsTypeCharacter(const int ch) { diff --git a/src/stc/scintilla/lexers/LexAVE.cxx b/src/stc/scintilla/lexers/LexAVE.cxx index fd99273797..b976734ae7 100644 --- a/src/stc/scintilla/lexers/LexAVE.cxx +++ b/src/stc/scintilla/lexers/LexAVE.cxx @@ -25,9 +25,7 @@ #include "CharacterSet.h" #include "LexerModule.h" -#ifdef SCI_NAMESPACE using namespace Scintilla; -#endif static inline bool IsAWordChar(const int ch) { diff --git a/src/stc/scintilla/lexers/LexAVS.cxx b/src/stc/scintilla/lexers/LexAVS.cxx index 129c3563b3..df5223f8db 100644 --- a/src/stc/scintilla/lexers/LexAVS.cxx +++ b/src/stc/scintilla/lexers/LexAVS.cxx @@ -24,9 +24,7 @@ #include "CharacterSet.h" #include "LexerModule.h" -#ifdef SCI_NAMESPACE using namespace Scintilla; -#endif static inline bool IsAWordChar(const int ch) { return (ch < 0x80) && (isalnum(ch) || ch == '_'); diff --git a/src/stc/scintilla/lexers/LexAbaqus.cxx b/src/stc/scintilla/lexers/LexAbaqus.cxx index 5f265c7228..0b9bfb62a7 100644 --- a/src/stc/scintilla/lexers/LexAbaqus.cxx +++ b/src/stc/scintilla/lexers/LexAbaqus.cxx @@ -1,5 +1,5 @@ // Scintilla source code edit control -/** @file LexABAQUS.cxx +/** @file LexAbaqus.cxx ** Lexer for ABAQUS. Based on the lexer for APDL by Hadar Raz. ** By Sergio Lucato. ** Sort of completely rewritten by Gertjan Kloosterman @@ -26,9 +26,7 @@ #include "CharacterSet.h" #include "LexerModule.h" -#ifdef SCI_NAMESPACE using namespace Scintilla; -#endif static inline bool IsAKeywordChar(const int ch) { return (ch < 0x80 && (isalnum(ch) || (ch == '_') || (ch == ' '))); diff --git a/src/stc/scintilla/lexers/LexAda.cxx b/src/stc/scintilla/lexers/LexAda.cxx index df26d75784..9d7f5d0f72 100644 --- a/src/stc/scintilla/lexers/LexAda.cxx +++ b/src/stc/scintilla/lexers/LexAda.cxx @@ -25,9 +25,7 @@ #include "CharacterSet.h" #include "LexerModule.h" -#ifdef SCI_NAMESPACE using namespace Scintilla; -#endif /* * Interface diff --git a/src/stc/scintilla/lexers/LexAsm.cxx b/src/stc/scintilla/lexers/LexAsm.cxx index 0b8e438a8f..7f9c7d50b4 100644 --- a/src/stc/scintilla/lexers/LexAsm.cxx +++ b/src/stc/scintilla/lexers/LexAsm.cxx @@ -30,10 +30,9 @@ #include "CharacterSet.h" #include "LexerModule.h" #include "OptionSet.h" +#include "DefaultLexer.h" -#ifdef SCI_NAMESPACE using namespace Scintilla; -#endif static inline bool IsAWordChar(const int ch) { return (ch < 0x80) && (isalnum(ch) || ch == '.' || @@ -81,6 +80,7 @@ struct OptionsAsm { std::string foldExplicitEnd; bool foldExplicitAnywhere; bool foldCompact; + std::string commentChar; OptionsAsm() { delimiter = ""; fold = false; @@ -91,6 +91,7 @@ struct OptionsAsm { foldExplicitEnd = ""; foldExplicitAnywhere = false; foldCompact = true; + commentChar = ""; } }; @@ -135,11 +136,14 @@ struct OptionSetAsm : public OptionSet { DefineProperty("fold.compact", &OptionsAsm::foldCompact); + DefineProperty("lexer.as.comment.character", &OptionsAsm::commentChar, + "Overrides the default comment character (which is ';' for asm and '#' for as)."); + DefineWordListSets(asmWordListDesc); } }; -class LexerAsm : public ILexer { +class LexerAsm : public DefaultLexer { WordList cpuInstruction; WordList mathInstruction; WordList registers; @@ -152,44 +156,47 @@ class LexerAsm : public ILexer { OptionSetAsm osAsm; int commentChar; public: - LexerAsm(int commentChar_) { + LexerAsm(const char *languageName_, int language_, int commentChar_) : DefaultLexer(languageName_, language_) { commentChar = commentChar_; } virtual ~LexerAsm() { } - void SCI_METHOD Release() { + void SCI_METHOD Release() override { delete this; } - int SCI_METHOD Version() const { - return lvOriginal; + int SCI_METHOD Version() const override { + return lvIdentity; } - const char * SCI_METHOD PropertyNames() { + const char * SCI_METHOD PropertyNames() override { return osAsm.PropertyNames(); } - int SCI_METHOD PropertyType(const char *name) { + int SCI_METHOD PropertyType(const char *name) override { return osAsm.PropertyType(name); } - const char * SCI_METHOD DescribeProperty(const char *name) { + const char * SCI_METHOD DescribeProperty(const char *name) override { return osAsm.DescribeProperty(name); } - Sci_Position SCI_METHOD PropertySet(const char *key, const char *val); - const char * SCI_METHOD DescribeWordListSets() { + Sci_Position SCI_METHOD PropertySet(const char *key, const char *val) override; + const char * SCI_METHOD PropertyGet(const char *key) override { + return osAsm.PropertyGet(key); + } + const char * SCI_METHOD DescribeWordListSets() override { return osAsm.DescribeWordListSets(); } - Sci_Position SCI_METHOD WordListSet(int n, const char *wl); - void SCI_METHOD Lex(Sci_PositionU startPos, Sci_Position length, int initStyle, IDocument *pAccess); - void SCI_METHOD Fold(Sci_PositionU startPos, Sci_Position length, int initStyle, IDocument *pAccess); + Sci_Position SCI_METHOD WordListSet(int n, const char *wl) override; + void SCI_METHOD Lex(Sci_PositionU startPos, Sci_Position length, int initStyle, IDocument *pAccess) override; + void SCI_METHOD Fold(Sci_PositionU startPos, Sci_Position length, int initStyle, IDocument *pAccess) override; - void * SCI_METHOD PrivateCall(int, void *) { + void * SCI_METHOD PrivateCall(int, void *) override { return 0; } static ILexer *LexerFactoryAsm() { - return new LexerAsm(';'); + return new LexerAsm("asm", SCLEX_ASM, ';'); } static ILexer *LexerFactoryAs() { - return new LexerAsm('#'); + return new LexerAsm("as", SCLEX_AS, '#'); } }; @@ -243,6 +250,9 @@ Sci_Position SCI_METHOD LexerAsm::WordListSet(int n, const char *wl) { void SCI_METHOD LexerAsm::Lex(Sci_PositionU startPos, Sci_Position length, int initStyle, IDocument *pAccess) { LexAccessor styler(pAccess); + const char commentCharacter = options.commentChar.empty() ? + commentChar : options.commentChar.front(); + // Do not leak onto next line if (initStyle == SCE_ASM_STRINGEOL) initStyle = SCE_ASM_DEFAULT; @@ -348,7 +358,7 @@ void SCI_METHOD LexerAsm::Lex(Sci_PositionU startPos, Sci_Position length, int i // Determine if a new state should be entered. if (sc.state == SCE_ASM_DEFAULT) { - if (sc.ch == commentChar){ + if (sc.ch == commentCharacter) { sc.SetState(SCE_ASM_COMMENT); } else if (IsASCII(sc.ch) && (isdigit(sc.ch) || (sc.ch == '.' && IsASCII(sc.chNext) && isdigit(sc.chNext)))) { sc.SetState(SCE_ASM_NUMBER); diff --git a/src/stc/scintilla/lexers/LexAsn1.cxx b/src/stc/scintilla/lexers/LexAsn1.cxx index 7c5f48e75d..0ec2a0636c 100644 --- a/src/stc/scintilla/lexers/LexAsn1.cxx +++ b/src/stc/scintilla/lexers/LexAsn1.cxx @@ -23,9 +23,7 @@ #include "CharacterSet.h" #include "LexerModule.h" -#ifdef SCI_NAMESPACE using namespace Scintilla; -#endif // Some char test functions static bool isAsn1Number(int ch) diff --git a/src/stc/scintilla/lexers/LexBaan.cxx b/src/stc/scintilla/lexers/LexBaan.cxx index 4587ecc4fb..2fb1debd02 100644 --- a/src/stc/scintilla/lexers/LexBaan.cxx +++ b/src/stc/scintilla/lexers/LexBaan.cxx @@ -4,6 +4,7 @@ ** Based heavily on LexCPP.cxx **/ // Copyright 2001- by Vamsi Potluru & Praveen Ambekar +// Maintainer Email: oirfeodent@yahoo.co.in // The License.txt file describes the conditions under which this software may be distributed. // C standard library @@ -33,10 +34,9 @@ #include "CharacterSet.h" #include "LexerModule.h" #include "OptionSet.h" +#include "DefaultLexer.h" -# ifdef SCI_NAMESPACE using namespace Scintilla; -# endif namespace { // Use an unnamed namespace to protect the functions and classes from name conflicts @@ -129,7 +129,7 @@ static inline bool IsAnOperator(int ch) { return false; } -static inline int IsAnyOtherIdentifier(char *s, int sLength) { +static inline int IsAnyOtherIdentifier(char *s, Sci_Position sLength) { /* IsAnyOtherIdentifier uses standard templates used in baan. The matching template is shown as comments just above the return condition. @@ -380,7 +380,7 @@ public: } -class LexerBaan : public ILexer { +class LexerBaan : public DefaultLexer { WordListAbridged keywords; WordListAbridged keywords2; WordListAbridged keywords3; @@ -393,45 +393,49 @@ class LexerBaan : public ILexer { OptionsBaan options; OptionSetBaan osBaan; public: - LexerBaan() { + LexerBaan() : DefaultLexer("baan", SCLEX_BAAN) { } virtual ~LexerBaan() { } - int SCI_METHOD Version() const { - return lvOriginal; + int SCI_METHOD Version() const override { + return lvIdentity; } - void SCI_METHOD Release() { + void SCI_METHOD Release() override { delete this; } - const char * SCI_METHOD PropertyNames() { + const char * SCI_METHOD PropertyNames() override { return osBaan.PropertyNames(); } - int SCI_METHOD PropertyType(const char * name) { + int SCI_METHOD PropertyType(const char * name) override { return osBaan.PropertyType(name); } - const char * SCI_METHOD DescribeProperty(const char * name) { + const char * SCI_METHOD DescribeProperty(const char * name) override { return osBaan.DescribeProperty(name); } - Sci_Position SCI_METHOD PropertySet(const char *key, const char *val); + Sci_Position SCI_METHOD PropertySet(const char *key, const char *val) override; - const char * SCI_METHOD DescribeWordListSets() { + const char * SCI_METHOD PropertyGet(const char *key) override { + return osBaan.PropertyGet(key); + } + + const char * SCI_METHOD DescribeWordListSets() override { return osBaan.DescribeWordListSets(); } - Sci_Position SCI_METHOD WordListSet(int n, const char *wl); + Sci_Position SCI_METHOD WordListSet(int n, const char *wl) override; - void SCI_METHOD Lex(Sci_PositionU startPos, Sci_Position length, int initStyle, IDocument *pAccess); + void SCI_METHOD Lex(Sci_PositionU startPos, Sci_Position length, int initStyle, IDocument *pAccess) override; - void SCI_METHOD Fold(Sci_PositionU startPos, Sci_Position length, int initStyle, IDocument *pAccess); + void SCI_METHOD Fold(Sci_PositionU startPos, Sci_Position length, int initStyle, IDocument *pAccess) override; - void * SCI_METHOD PrivateCall(int, void *) { + void * SCI_METHOD PrivateCall(int, void *) override { return NULL; } @@ -504,10 +508,12 @@ void SCI_METHOD LexerBaan::Lex(Sci_PositionU startPos, Sci_Position length, int bool lineHasPreProc = false; bool lineIgnoreString = false; bool lineHasDefines = false; + bool numberIsHex = false; char word[1000]; int wordlen = 0; - std::string preProcessorTags[11] = { "#define", "#elif", "#else", "#endif", + std::string preProcessorTags[13] = { "#context_off", "#context_on", + "#define", "#elif", "#else", "#endif", "#ident", "#if", "#ifdef", "#ifndef", "#include", "#pragma", "#undef" }; LexAccessor styler(pAccess); @@ -521,9 +527,18 @@ void SCI_METHOD LexerBaan::Lex(Sci_PositionU startPos, Sci_Position length, int sc.SetState(SCE_BAAN_DEFAULT); break; case SCE_BAAN_NUMBER: - if (!IsAWordChar(sc.ch)) { + if (IsASpaceOrTab(sc.ch) || sc.ch == '\r' || sc.ch == '\n' || IsAnOperator(sc.ch)) { sc.SetState(SCE_BAAN_DEFAULT); } + else if ((numberIsHex && !(MakeLowerCase(sc.ch) == 'x' || MakeLowerCase(sc.ch) == 'e' || + IsADigit(sc.ch, 16) || sc.ch == '.' || sc.ch == '-' || sc.ch == '+')) || + (!numberIsHex && !(MakeLowerCase(sc.ch) == 'e' || IsADigit(sc.ch) + || sc.ch == '.' || sc.ch == '-' || sc.ch == '+'))) { + // check '-' for possible -10e-5. Add '+' as well. + numberIsHex = false; + sc.ChangeState(SCE_BAAN_IDENTIFIER); + sc.SetState(SCE_BAAN_DEFAULT); + } break; case SCE_BAAN_IDENTIFIER: if (!IsAWordChar(sc.ch)) { @@ -556,7 +571,10 @@ void SCI_METHOD LexerBaan::Lex(Sci_PositionU startPos, Sci_Position length, int sc.ChangeState(SCE_BAAN_WORD2); } else if ((keywords3.kwHasSection && (sc.ch == ':')) ? keywords3.Contains(s1) : keywords3.Contains(s)) { - sc.ChangeState(SCE_BAAN_WORD3); + if (sc.ch == '(') + sc.ChangeState(SCE_BAAN_WORD3); + else + sc.ChangeState(SCE_BAAN_IDENTIFIER); } else if ((keywords4.kwHasSection && (sc.ch == ':')) ? keywords4.Contains(s1) : keywords4.Contains(s)) { sc.ChangeState(SCE_BAAN_WORD4); @@ -606,7 +624,7 @@ void SCI_METHOD LexerBaan::Lex(Sci_PositionU startPos, Sci_Position length, int } break; case SCE_BAAN_COMMENT: - if (sc.atLineEnd) { + if (sc.ch == '\r' || sc.ch == '\n') { sc.SetState(SCE_BAAN_DEFAULT); } break; @@ -638,7 +656,13 @@ void SCI_METHOD LexerBaan::Lex(Sci_PositionU startPos, Sci_Position length, int // Determine if a new state should be entered. if (sc.state == SCE_BAAN_DEFAULT) { - if (IsADigit(sc.ch) || (sc.ch == '.' && IsADigit(sc.chNext))) { + if (IsADigit(sc.ch) || (sc.ch == '.' && IsADigit(sc.chNext)) + || ((sc.ch == '-' || sc.ch == '+') && (IsADigit(sc.chNext) || sc.chNext == '.')) + || (MakeLowerCase(sc.ch) == 'e' && (IsADigit(sc.chNext) || sc.chNext == '+' || sc.chNext == '-'))) { + if ((sc.ch == '0' && MakeLowerCase(sc.chNext) == 'x') || + ((sc.ch == '-' || sc.ch == '+') && sc.chNext == '0' && MakeLowerCase(sc.GetRelativeCharacter(2)) == 'x')){ + numberIsHex = true; + } sc.SetState(SCE_BAAN_NUMBER); } else if (sc.MatchIgnoreCase("dllusage") || sc.MatchIgnoreCase("functionusage")) { @@ -670,7 +694,7 @@ void SCI_METHOD LexerBaan::Lex(Sci_PositionU startPos, Sci_Position length, int word[wordlen++] = sc.ch; word[wordlen++] = '\0'; } - if (!wordInArray(word, preProcessorTags, 11)) + if (!wordInArray(word, preProcessorTags, 13)) // Colorise only preprocessor built in Baan. sc.ChangeState(SCE_BAAN_IDENTIFIER); if (strcmp(word, "#pragma") == 0 || strcmp(word, "#include") == 0) { @@ -697,6 +721,7 @@ void SCI_METHOD LexerBaan::Lex(Sci_PositionU startPos, Sci_Position length, int lineHasPreProc = false; lineIgnoreString = false; lineHasDefines = false; + numberIsHex = false; } if (!IsASpace(sc.ch)) { visibleChars++; @@ -781,9 +806,10 @@ void SCI_METHOD LexerBaan::Fold(Sci_PositionU startPos, Sci_Position length, int else if (style == SCE_BAAN_PREPROCESSOR) { // folds #ifdef/#if/#ifndef - they are not part of the IsPreProcLine folding. if (ch == '#') { - if (styler.Match(i, "#ifdef") || styler.Match(i, "#if") || styler.Match(i, "#ifndef")) + if (styler.Match(i, "#ifdef") || styler.Match(i, "#if") || styler.Match(i, "#ifndef") + || styler.Match(i, "#context_on")) levelCurrent++; - else if (styler.Match(i, "#endif")) + else if (styler.Match(i, "#endif") || styler.Match(i, "#context_off")) levelCurrent--; } } diff --git a/src/stc/scintilla/lexers/LexBash.cxx b/src/stc/scintilla/lexers/LexBash.cxx index af8507d7de..66bec38469 100644 --- a/src/stc/scintilla/lexers/LexBash.cxx +++ b/src/stc/scintilla/lexers/LexBash.cxx @@ -12,20 +12,25 @@ #include #include +#include +#include +#include + #include "ILexer.h" #include "Scintilla.h" #include "SciLexer.h" +#include "StringCopy.h" #include "WordList.h" #include "LexAccessor.h" -#include "Accessor.h" #include "StyleContext.h" #include "CharacterSet.h" #include "LexerModule.h" +#include "OptionSet.h" +#include "SubStyles.h" +#include "DefaultLexer.h" -#ifdef SCI_NAMESPACE using namespace Scintilla; -#endif #define HERE_DELIM_MAX 256 @@ -60,7 +65,9 @@ using namespace Scintilla; #define BASH_DELIM_STACK_MAX 7 -static inline int translateBashDigit(int ch) { +namespace { + +inline int translateBashDigit(int ch) { if (ch >= '0' && ch <= '9') { return ch - '0'; } else if (ch >= 'a' && ch <= 'z') { @@ -75,7 +82,7 @@ static inline int translateBashDigit(int ch) { return BASH_BASE_ERROR; } -static inline int getBashNumberBase(char *s) { +inline int getBashNumberBase(char *s) { int i = 0; int base = 0; while (*s) { @@ -88,7 +95,7 @@ static inline int getBashNumberBase(char *s) { return base; } -static int opposite(int ch) { +int opposite(int ch) { if (ch == '(') return ')'; if (ch == '[') return ']'; if (ch == '{') return '}'; @@ -96,23 +103,200 @@ static int opposite(int ch) { return ch; } -static int GlobScan(StyleContext &sc) { - // forward scan for a glob-like (...), no whitespace allowed +int GlobScan(StyleContext &sc) { + // forward scan for zsh globs, disambiguate versus bash arrays + // complex expressions may still fail, e.g. unbalanced () '' "" etc int c, sLen = 0; + int pCount = 0; + int hash = 0; while ((c = sc.GetRelativeCharacter(++sLen)) != 0) { if (IsASpace(c)) { return 0; + } else if (c == '\'' || c == '\"') { + if (hash != 2) return 0; + } else if (c == '#' && hash == 0) { + hash = (sLen == 1) ? 2:1; + } else if (c == '(') { + pCount++; } else if (c == ')') { - return sLen; + if (pCount == 0) { + if (hash) return sLen; + return 0; + } + pCount--; } } return 0; } -static void ColouriseBashDoc(Sci_PositionU startPos, Sci_Position length, int initStyle, - WordList *keywordlists[], Accessor &styler) { +bool IsCommentLine(Sci_Position line, LexAccessor &styler) { + Sci_Position pos = styler.LineStart(line); + Sci_Position eol_pos = styler.LineStart(line + 1) - 1; + for (Sci_Position i = pos; i < eol_pos; i++) { + char ch = styler[i]; + if (ch == '#') + return true; + else if (ch != ' ' && ch != '\t') + return false; + } + return false; +} - WordList &keywords = *keywordlists[0]; +struct OptionsBash { + bool fold; + bool foldComment; + bool foldCompact; + + OptionsBash() { + fold = false; + foldComment = false; + foldCompact = true; + } +}; + +const char * const bashWordListDesc[] = { + "Keywords", + 0 +}; + +struct OptionSetBash : public OptionSet { + OptionSetBash() { + DefineProperty("fold", &OptionsBash::fold); + + DefineProperty("fold.comment", &OptionsBash::foldComment); + + DefineProperty("fold.compact", &OptionsBash::foldCompact); + + DefineWordListSets(bashWordListDesc); + } +}; + +const char styleSubable[] = { SCE_SH_IDENTIFIER, SCE_SH_SCALAR, 0 }; + +LexicalClass lexicalClasses[] = { + // Lexer Bash SCLEX_BASH SCE_SH_: + 0, "SCE_SH_DEFAULT", "default", "White space", + 1, "SCE_SH_ERROR", "error", "Error", + 2, "SCE_SH_COMMENTLINE", "comment line", "Line comment: #", + 3, "SCE_SH_NUMBER", "literal numeric", "Number", + 4, "SCE_SH_WORD", "keyword", "Keyword", + 5, "SCE_SH_STRING", "literal string", "String", + 6, "SCE_SH_CHARACTER", "literal string", "Single quoted string", + 7, "SCE_SH_OPERATOR", "operator", "Operators", + 8, "SCE_SH_IDENTIFIER", "identifier", "Identifiers", + 9, "SCE_SH_SCALAR", "identifier", "Scalar variable", + 10, "SCE_SH_PARAM", "identifier", "Parameter", + 11, "SCE_SH_BACKTICKS", "literal string", "Backtick quoted command", + 12, "SCE_SH_HERE_DELIM", "operator", "Heredoc delimiter", + 13, "SCE_SH_HERE_Q", "literal string", "Heredoc quoted string", +}; + +} + +class LexerBash : public DefaultLexer { + WordList keywords; + OptionsBash options; + OptionSetBash osBash; + enum { ssIdentifier, ssScalar }; + SubStyles subStyles; +public: + LexerBash() : + DefaultLexer("bash", SCLEX_BASH, lexicalClasses, ELEMENTS(lexicalClasses)), + subStyles(styleSubable, 0x80, 0x40, 0) { + } + virtual ~LexerBash() { + } + void SCI_METHOD Release() override { + delete this; + } + int SCI_METHOD Version() const override { + return lvIdentity; + } + const char * SCI_METHOD PropertyNames() override { + return osBash.PropertyNames(); + } + int SCI_METHOD PropertyType(const char* name) override { + return osBash.PropertyType(name); + } + const char * SCI_METHOD DescribeProperty(const char *name) override { + return osBash.DescribeProperty(name); + } + Sci_Position SCI_METHOD PropertySet(const char *key, const char *val) override; + const char * SCI_METHOD PropertyGet(const char* key) override { + return osBash.PropertyGet(key); + } + const char * SCI_METHOD DescribeWordListSets() override { + return osBash.DescribeWordListSets(); + } + Sci_Position SCI_METHOD WordListSet(int n, const char *wl) override; + void SCI_METHOD Lex(Sci_PositionU startPos, Sci_Position length, int initStyle, IDocument *pAccess) override; + void SCI_METHOD Fold(Sci_PositionU startPos, Sci_Position length, int initStyle, IDocument *pAccess) override; + + void * SCI_METHOD PrivateCall(int, void *) override { + return 0; + } + + int SCI_METHOD AllocateSubStyles(int styleBase, int numberStyles) override { + return subStyles.Allocate(styleBase, numberStyles); + } + int SCI_METHOD SubStylesStart(int styleBase) override { + return subStyles.Start(styleBase); + } + int SCI_METHOD SubStylesLength(int styleBase) override { + return subStyles.Length(styleBase); + } + int SCI_METHOD StyleFromSubStyle(int subStyle) override { + const int styleBase = subStyles.BaseStyle(subStyle); + return styleBase; + } + int SCI_METHOD PrimaryStyleFromStyle(int style) override { + return style; + } + void SCI_METHOD FreeSubStyles() override { + subStyles.Free(); + } + void SCI_METHOD SetIdentifiers(int style, const char *identifiers) override { + subStyles.SetIdentifiers(style, identifiers); + } + int SCI_METHOD DistanceToSecondaryStyles() override { + return 0; + } + const char *SCI_METHOD GetSubStyleBases() override { + return styleSubable; + } + + static ILexer *LexerFactoryBash() { + return new LexerBash(); + } +}; + +Sci_Position SCI_METHOD LexerBash::PropertySet(const char *key, const char *val) { + if (osBash.PropertySet(&options, key, val)) { + return 0; + } + return -1; +} + +Sci_Position SCI_METHOD LexerBash::WordListSet(int n, const char *wl) { + WordList *wordListN = 0; + switch (n) { + case 0: + wordListN = &keywords; + break; + } + Sci_Position firstModification = -1; + if (wordListN) { + WordList wlNew; + wlNew.Set(wl); + if (*wordListN != wlNew) { + wordListN->Set(wl); + firstModification = 0; + } + } + return firstModification; +} + +void SCI_METHOD LexerBash::Lex(Sci_PositionU startPos, Sci_Position length, int initStyle, IDocument *pAccess) { WordList cmdDelimiter, bashStruct, bashStruct_in; cmdDelimiter.Set("| || |& & && ; ;; ( ) { }"); bashStruct.Set("if elif fi while until else then do done esac eval"); @@ -226,11 +410,15 @@ static void ColouriseBashDoc(Sci_PositionU startPos, Sci_Position length, int in }; QuoteStackCls QuoteStack; + const WordClassifier &classifierIdentifiers = subStyles.Classifier(SCE_SH_IDENTIFIER); + const WordClassifier &classifierScalars = subStyles.Classifier(SCE_SH_SCALAR); + int numBase = 0; int digit; Sci_PositionU endPos = startPos + length; int cmdState = BASH_CMD_START; int testExprType = 0; + LexAccessor styler(pAccess); // Always backtracks to the start of a line that is not a continuation // of the previous line (i.e. start of a bash command segment) @@ -295,6 +483,11 @@ static void ColouriseBashDoc(Sci_PositionU startPos, Sci_Position length, int in char s[500]; char s2[10]; sc.GetCurrent(s, sizeof(s)); + int identifierStyle = SCE_SH_IDENTIFIER; + int subStyle = classifierIdentifiers.ValueFor(s); + if (subStyle >= 0) { + identifierStyle = subStyle; + } // allow keywords ending in a whitespace or command delimiter s2[0] = static_cast(sc.ch); s2[1] = '\0'; @@ -306,7 +499,7 @@ static void ColouriseBashDoc(Sci_PositionU startPos, Sci_Position length, int in else if (strcmp(s, "do") == 0 && keywordEnds) cmdStateNew = BASH_CMD_START; else - sc.ChangeState(SCE_SH_IDENTIFIER); + sc.ChangeState(identifierStyle); sc.SetState(SCE_SH_DEFAULT); break; } @@ -316,42 +509,49 @@ static void ColouriseBashDoc(Sci_PositionU startPos, Sci_Position length, int in cmdStateNew = BASH_CMD_TEST; testExprType = 0; } else - sc.ChangeState(SCE_SH_IDENTIFIER); + sc.ChangeState(identifierStyle); } // detect bash construct keywords else if (bashStruct.InList(s)) { if (cmdState == BASH_CMD_START && keywordEnds) cmdStateNew = BASH_CMD_START; else - sc.ChangeState(SCE_SH_IDENTIFIER); + sc.ChangeState(identifierStyle); } // 'for'|'case'|'select' needs 'in'|'do' to be highlighted later else if (bashStruct_in.InList(s)) { if (cmdState == BASH_CMD_START && keywordEnds) cmdStateNew = BASH_CMD_WORD; else - sc.ChangeState(SCE_SH_IDENTIFIER); + sc.ChangeState(identifierStyle); } // disambiguate option items and file test operators else if (s[0] == '-') { if (cmdState != BASH_CMD_TEST) - sc.ChangeState(SCE_SH_IDENTIFIER); + sc.ChangeState(identifierStyle); } // disambiguate keywords and identifiers else if (cmdState != BASH_CMD_START || !(keywords.InList(s) && keywordEnds)) { - sc.ChangeState(SCE_SH_IDENTIFIER); + sc.ChangeState(identifierStyle); } sc.SetState(SCE_SH_DEFAULT); } break; case SCE_SH_IDENTIFIER: - if (sc.chPrev == '\\') { // for escaped chars - sc.ForwardSetState(SCE_SH_DEFAULT); - } else if (!setWord.Contains(sc.ch)) { - sc.SetState(SCE_SH_DEFAULT); - } else if (cmdState == BASH_CMD_ARITH && !setWordStart.Contains(sc.ch)) { - sc.SetState(SCE_SH_DEFAULT); + if (sc.chPrev == '\\' || !setWord.Contains(sc.ch) || + (cmdState == BASH_CMD_ARITH && !setWordStart.Contains(sc.ch))) { + char s[500]; + sc.GetCurrent(s, sizeof(s)); + int subStyle = classifierIdentifiers.ValueFor(s); + if (subStyle >= 0) { + sc.ChangeState(subStyle); + } + if (sc.chPrev == '\\') { // for escaped chars + sc.ForwardSetState(SCE_SH_DEFAULT); + } else { + sc.SetState(SCE_SH_DEFAULT); + } } break; case SCE_SH_NUMBER: @@ -505,6 +705,12 @@ static void ColouriseBashDoc(Sci_PositionU startPos, Sci_Position length, int in break; case SCE_SH_SCALAR: // variable names if (!setParam.Contains(sc.ch)) { + char s[500]; + sc.GetCurrent(s, sizeof(s)); + int subStyle = classifierScalars.ValueFor(&s[1]); // skip the $ + if (subStyle >= 0) { + sc.ChangeState(subStyle); + } if (sc.LengthCurrent() == 1) { // Special variable: $(, $_ etc. sc.ForwardSetState(SCE_SH_DEFAULT); @@ -788,23 +994,12 @@ static void ColouriseBashDoc(Sci_PositionU startPos, Sci_Position length, int in sc.Complete(); } -static bool IsCommentLine(Sci_Position line, Accessor &styler) { - Sci_Position pos = styler.LineStart(line); - Sci_Position eol_pos = styler.LineStart(line + 1) - 1; - for (Sci_Position i = pos; i < eol_pos; i++) { - char ch = styler[i]; - if (ch == '#') - return true; - else if (ch != ' ' && ch != '\t') - return false; - } - return false; -} +void SCI_METHOD LexerBash::Fold(Sci_PositionU startPos, Sci_Position length, int, IDocument *pAccess) { + if(!options.fold) + return; + + LexAccessor styler(pAccess); -static void FoldBashDoc(Sci_PositionU startPos, Sci_Position length, int, WordList *[], - Accessor &styler) { - bool foldComment = styler.GetPropertyInt("fold.comment") != 0; - bool foldCompact = styler.GetPropertyInt("fold.compact", 1) != 0; Sci_PositionU endPos = startPos + length; int visibleChars = 0; int skipHereCh = 0; @@ -813,6 +1008,8 @@ static void FoldBashDoc(Sci_PositionU startPos, Sci_Position length, int, WordLi int levelCurrent = levelPrev; char chNext = styler[startPos]; int styleNext = styler.StyleAt(startPos); + char word[8] = { '\0' }; // we're not interested in long words anyway + unsigned int wordlen = 0; for (Sci_PositionU i = startPos; i < endPos; i++) { char ch = chNext; chNext = styler.SafeGetCharAt(i + 1); @@ -820,7 +1017,7 @@ static void FoldBashDoc(Sci_PositionU startPos, Sci_Position length, int, WordLi styleNext = styler.StyleAt(i + 1); bool atEOL = (ch == '\r' && chNext != '\n') || (ch == '\n'); // Comment folding - if (foldComment && atEOL && IsCommentLine(lineCurrent, styler)) + if (options.foldComment && atEOL && IsCommentLine(lineCurrent, styler)) { if (!IsCommentLine(lineCurrent - 1, styler) && IsCommentLine(lineCurrent + 1, styler)) @@ -829,6 +1026,19 @@ static void FoldBashDoc(Sci_PositionU startPos, Sci_Position length, int, WordLi && !IsCommentLine(lineCurrent + 1, styler)) levelCurrent--; } + if (style == SCE_SH_WORD) { + if ((wordlen + 1) < sizeof(word)) + word[wordlen++] = ch; + if (styleNext != style) { + word[wordlen] = '\0'; + wordlen = 0; + if (strcmp(word, "if") == 0 || strcmp(word, "case") == 0 || strcmp(word, "do") == 0) { + levelCurrent++; + } else if (strcmp(word, "fi") == 0 || strcmp(word, "esac") == 0 || strcmp(word, "done") == 0) { + levelCurrent--; + } + } + } if (style == SCE_SH_OPERATOR) { if (ch == '{') { levelCurrent++; @@ -854,7 +1064,7 @@ static void FoldBashDoc(Sci_PositionU startPos, Sci_Position length, int, WordLi } if (atEOL) { int lev = levelPrev; - if (visibleChars == 0 && foldCompact) + if (visibleChars == 0 && options.foldCompact) lev |= SC_FOLDLEVELWHITEFLAG; if ((levelCurrent > levelPrev) && (visibleChars > 0)) lev |= SC_FOLDLEVELHEADERFLAG; @@ -873,9 +1083,4 @@ static void FoldBashDoc(Sci_PositionU startPos, Sci_Position length, int, WordLi styler.SetLevel(lineCurrent, levelPrev | flagsNext); } -static const char * const bashWordListDesc[] = { - "Keywords", - 0 -}; - -LexerModule lmBash(SCLEX_BASH, ColouriseBashDoc, "bash", FoldBashDoc, bashWordListDesc); +LexerModule lmBash(SCLEX_BASH, LexerBash::LexerFactoryBash, "bash", bashWordListDesc); diff --git a/src/stc/scintilla/lexers/LexBasic.cxx b/src/stc/scintilla/lexers/LexBasic.cxx index 7fa5b5498b..a288f9daa7 100644 --- a/src/stc/scintilla/lexers/LexBasic.cxx +++ b/src/stc/scintilla/lexers/LexBasic.cxx @@ -37,10 +37,9 @@ #include "CharacterSet.h" #include "LexerModule.h" #include "OptionSet.h" +#include "DefaultLexer.h" -#ifdef SCI_NAMESPACE using namespace Scintilla; -#endif /* Bits: * 1 - whitespace @@ -226,54 +225,59 @@ struct OptionSetBasic : public OptionSet { } }; -class LexerBasic : public ILexer { +class LexerBasic : public DefaultLexer { char comment_char; int (*CheckFoldPoint)(char const *, int &); WordList keywordlists[4]; OptionsBasic options; OptionSetBasic osBasic; public: - LexerBasic(char comment_char_, int (*CheckFoldPoint_)(char const *, int &), const char * const wordListDescriptions[]) : + LexerBasic(const char *languageName_, int language_, char comment_char_, + int (*CheckFoldPoint_)(char const *, int &), const char * const wordListDescriptions[]) : + DefaultLexer(languageName_, language_), comment_char(comment_char_), CheckFoldPoint(CheckFoldPoint_), osBasic(wordListDescriptions) { } virtual ~LexerBasic() { } - void SCI_METHOD Release() { + void SCI_METHOD Release() override { delete this; } - int SCI_METHOD Version() const { - return lvOriginal; + int SCI_METHOD Version() const override { + return lvIdentity; } - const char * SCI_METHOD PropertyNames() { + const char * SCI_METHOD PropertyNames() override { return osBasic.PropertyNames(); } - int SCI_METHOD PropertyType(const char *name) { + int SCI_METHOD PropertyType(const char *name) override { return osBasic.PropertyType(name); } - const char * SCI_METHOD DescribeProperty(const char *name) { + const char * SCI_METHOD DescribeProperty(const char *name) override { return osBasic.DescribeProperty(name); } - Sci_Position SCI_METHOD PropertySet(const char *key, const char *val); - const char * SCI_METHOD DescribeWordListSets() { + Sci_Position SCI_METHOD PropertySet(const char *key, const char *val) override; + const char * SCI_METHOD PropertyGet(const char *key) override { + return osBasic.PropertyGet(key); + } + const char * SCI_METHOD DescribeWordListSets() override { return osBasic.DescribeWordListSets(); } - Sci_Position SCI_METHOD WordListSet(int n, const char *wl); - void SCI_METHOD Lex(Sci_PositionU startPos, Sci_Position length, int initStyle, IDocument *pAccess); - void SCI_METHOD Fold(Sci_PositionU startPos, Sci_Position length, int initStyle, IDocument *pAccess); + Sci_Position SCI_METHOD WordListSet(int n, const char *wl) override; + void SCI_METHOD Lex(Sci_PositionU startPos, Sci_Position length, int initStyle, IDocument *pAccess) override; + void SCI_METHOD Fold(Sci_PositionU startPos, Sci_Position length, int initStyle, IDocument *pAccess) override; - void * SCI_METHOD PrivateCall(int, void *) { + void * SCI_METHOD PrivateCall(int, void *) override { return 0; } static ILexer *LexerFactoryBlitzBasic() { - return new LexerBasic(';', CheckBlitzFoldPoint, blitzbasicWordListDesc); + return new LexerBasic("blitzbasic", SCLEX_BLITZBASIC, ';', CheckBlitzFoldPoint, blitzbasicWordListDesc); } static ILexer *LexerFactoryPureBasic() { - return new LexerBasic(';', CheckPureFoldPoint, purebasicWordListDesc); + return new LexerBasic("purebasic", SCLEX_PUREBASIC, ';', CheckPureFoldPoint, purebasicWordListDesc); } static ILexer *LexerFactoryFreeBasic() { - return new LexerBasic('\'', CheckFreeFoldPoint, freebasicWordListDesc ); + return new LexerBasic("freebasic", SCLEX_FREEBASIC, '\'', CheckFreeFoldPoint, freebasicWordListDesc ); } }; diff --git a/src/stc/scintilla/lexers/LexBatch.cxx b/src/stc/scintilla/lexers/LexBatch.cxx index 377b2cbf1e..857b60ce69 100644 --- a/src/stc/scintilla/lexers/LexBatch.cxx +++ b/src/stc/scintilla/lexers/LexBatch.cxx @@ -23,9 +23,7 @@ #include "CharacterSet.h" #include "LexerModule.h" -#ifdef SCI_NAMESPACE using namespace Scintilla; -#endif static bool Is0To9(char ch) { return (ch >= '0') && (ch <= '9'); @@ -43,7 +41,8 @@ static inline bool AtEOL(Accessor &styler, Sci_PositionU i) { // Tests for BATCH Operators static bool IsBOperator(char ch) { return (ch == '=') || (ch == '+') || (ch == '>') || (ch == '<') || - (ch == '|') || (ch == '?') || (ch == '*'); + (ch == '|') || (ch == '?') || (ch == '*')|| + (ch == '&') || (ch == '(') || (ch == ')'); } // Tests for BATCH Separators @@ -52,413 +51,35 @@ static bool IsBSeparator(char ch) { (ch == '\"') || (ch == '\'') || (ch == '/'); } -static void ColouriseBatchLine( - char *lineBuffer, - Sci_PositionU lengthLine, - Sci_PositionU startLine, - Sci_PositionU endPos, - WordList *keywordlists[], - Accessor &styler) { - - Sci_PositionU offset = 0; // Line Buffer Offset - Sci_PositionU cmdLoc; // External Command / Program Location - char wordBuffer[81]; // Word Buffer - large to catch long paths - Sci_PositionU wbl; // Word Buffer Length - Sci_PositionU wbo; // Word Buffer Offset - also Special Keyword Buffer Length - WordList &keywords = *keywordlists[0]; // Internal Commands - WordList &keywords2 = *keywordlists[1]; // External Commands (optional) - - // CHOICE, ECHO, GOTO, PROMPT and SET have Default Text that may contain Regular Keywords - // Toggling Regular Keyword Checking off improves readability - // Other Regular Keywords and External Commands / Programs might also benefit from toggling - // Need a more robust algorithm to properly toggle Regular Keyword Checking - bool continueProcessing = true; // Used to toggle Regular Keyword Checking - // Special Keywords are those that allow certain characters without whitespace after the command - // Examples are: cd. cd\ md. rd. dir| dir> echo: echo. path= - // Special Keyword Buffer used to determine if the first n characters is a Keyword - char sKeywordBuffer[10]; // Special Keyword Buffer - bool sKeywordFound; // Exit Special Keyword for-loop if found - - // Skip initial spaces - while ((offset < lengthLine) && (isspacechar(lineBuffer[offset]))) { - offset++; +// Tests for escape character +static bool IsEscaped(char* wordStr, Sci_PositionU pos) { + bool isQoted=false; + while (pos>0){ + pos--; + if (wordStr[pos]=='^') + isQoted=!isQoted; + else + break; } - // Colorize Default Text - styler.ColourTo(startLine + offset - 1, SCE_BAT_DEFAULT); - // Set External Command / Program Location - cmdLoc = offset; + return isQoted; +} - // Check for Fake Label (Comment) or Real Label - return if found - if (lineBuffer[offset] == ':') { - if (lineBuffer[offset + 1] == ':') { - // Colorize Fake Label (Comment) - :: is similar to REM, see http://content.techweb.com/winmag/columns/explorer/2000/21.htm - styler.ColourTo(endPos, SCE_BAT_COMMENT); - } else { - // Colorize Real Label - styler.ColourTo(endPos, SCE_BAT_LABEL); +// Tests for quote character +static bool textQuoted(char *lineBuffer, Sci_PositionU endPos) { + char strBuffer[1024]; + strncpy(strBuffer, lineBuffer, endPos); + strBuffer[endPos] = '\0'; + char *pQuote; + pQuote = strchr(strBuffer, '"'); + bool CurrentStatus = false; + while (pQuote != NULL) + { + if (!IsEscaped(strBuffer, pQuote - strBuffer)) { + CurrentStatus = !CurrentStatus; } - return; - // Check for Drive Change (Drive Change is internal command) - return if found - } else if ((IsAlphabetic(lineBuffer[offset])) && - (lineBuffer[offset + 1] == ':') && - ((isspacechar(lineBuffer[offset + 2])) || - (((lineBuffer[offset + 2] == '\\')) && - (isspacechar(lineBuffer[offset + 3]))))) { - // Colorize Regular Keyword - styler.ColourTo(endPos, SCE_BAT_WORD); - return; + pQuote = strchr(pQuote + 1, '"'); } - - // Check for Hide Command (@ECHO OFF/ON) - if (lineBuffer[offset] == '@') { - styler.ColourTo(startLine + offset, SCE_BAT_HIDE); - offset++; - } - // Skip next spaces - while ((offset < lengthLine) && (isspacechar(lineBuffer[offset]))) { - offset++; - } - - // Read remainder of line word-at-a-time or remainder-of-word-at-a-time - while (offset < lengthLine) { - if (offset > startLine) { - // Colorize Default Text - styler.ColourTo(startLine + offset - 1, SCE_BAT_DEFAULT); - } - // Copy word from Line Buffer into Word Buffer - wbl = 0; - for (; offset < lengthLine && wbl < 80 && - !isspacechar(lineBuffer[offset]); wbl++, offset++) { - wordBuffer[wbl] = static_cast(tolower(lineBuffer[offset])); - } - wordBuffer[wbl] = '\0'; - wbo = 0; - - // Check for Comment - return if found - if (CompareCaseInsensitive(wordBuffer, "rem") == 0) { - styler.ColourTo(endPos, SCE_BAT_COMMENT); - return; - } - // Check for Separator - if (IsBSeparator(wordBuffer[0])) { - // Check for External Command / Program - if ((cmdLoc == offset - wbl) && - ((wordBuffer[0] == ':') || - (wordBuffer[0] == '\\') || - (wordBuffer[0] == '.'))) { - // Reset Offset to re-process remainder of word - offset -= (wbl - 1); - // Colorize External Command / Program - if (!keywords2) { - styler.ColourTo(startLine + offset - 1, SCE_BAT_COMMAND); - } else if (keywords2.InList(wordBuffer)) { - styler.ColourTo(startLine + offset - 1, SCE_BAT_COMMAND); - } else { - styler.ColourTo(startLine + offset - 1, SCE_BAT_DEFAULT); - } - // Reset External Command / Program Location - cmdLoc = offset; - } else { - // Reset Offset to re-process remainder of word - offset -= (wbl - 1); - // Colorize Default Text - styler.ColourTo(startLine + offset - 1, SCE_BAT_DEFAULT); - } - // Check for Regular Keyword in list - } else if ((keywords.InList(wordBuffer)) && - (continueProcessing)) { - // ECHO, GOTO, PROMPT and SET require no further Regular Keyword Checking - if ((CompareCaseInsensitive(wordBuffer, "echo") == 0) || - (CompareCaseInsensitive(wordBuffer, "goto") == 0) || - (CompareCaseInsensitive(wordBuffer, "prompt") == 0) || - (CompareCaseInsensitive(wordBuffer, "set") == 0)) { - continueProcessing = false; - } - // Identify External Command / Program Location for ERRORLEVEL, and EXIST - if ((CompareCaseInsensitive(wordBuffer, "errorlevel") == 0) || - (CompareCaseInsensitive(wordBuffer, "exist") == 0)) { - // Reset External Command / Program Location - cmdLoc = offset; - // Skip next spaces - while ((cmdLoc < lengthLine) && - (isspacechar(lineBuffer[cmdLoc]))) { - cmdLoc++; - } - // Skip comparison - while ((cmdLoc < lengthLine) && - (!isspacechar(lineBuffer[cmdLoc]))) { - cmdLoc++; - } - // Skip next spaces - while ((cmdLoc < lengthLine) && - (isspacechar(lineBuffer[cmdLoc]))) { - cmdLoc++; - } - // Identify External Command / Program Location for CALL, DO, LOADHIGH and LH - } else if ((CompareCaseInsensitive(wordBuffer, "call") == 0) || - (CompareCaseInsensitive(wordBuffer, "do") == 0) || - (CompareCaseInsensitive(wordBuffer, "loadhigh") == 0) || - (CompareCaseInsensitive(wordBuffer, "lh") == 0)) { - // Reset External Command / Program Location - cmdLoc = offset; - // Skip next spaces - while ((cmdLoc < lengthLine) && - (isspacechar(lineBuffer[cmdLoc]))) { - cmdLoc++; - } - } - // Colorize Regular keyword - styler.ColourTo(startLine + offset - 1, SCE_BAT_WORD); - // No need to Reset Offset - // Check for Special Keyword in list, External Command / Program, or Default Text - } else if ((wordBuffer[0] != '%') && - (wordBuffer[0] != '!') && - (!IsBOperator(wordBuffer[0])) && - (continueProcessing)) { - // Check for Special Keyword - // Affected Commands are in Length range 2-6 - // Good that ERRORLEVEL, EXIST, CALL, DO, LOADHIGH, and LH are unaffected - sKeywordFound = false; - for (Sci_PositionU keywordLength = 2; keywordLength < wbl && keywordLength < 7 && !sKeywordFound; keywordLength++) { - wbo = 0; - // Copy Keyword Length from Word Buffer into Special Keyword Buffer - for (; wbo < keywordLength; wbo++) { - sKeywordBuffer[wbo] = static_cast(wordBuffer[wbo]); - } - sKeywordBuffer[wbo] = '\0'; - // Check for Special Keyword in list - if ((keywords.InList(sKeywordBuffer)) && - ((IsBOperator(wordBuffer[wbo])) || - (IsBSeparator(wordBuffer[wbo])))) { - sKeywordFound = true; - // ECHO requires no further Regular Keyword Checking - if (CompareCaseInsensitive(sKeywordBuffer, "echo") == 0) { - continueProcessing = false; - } - // Colorize Special Keyword as Regular Keyword - styler.ColourTo(startLine + offset - 1 - (wbl - wbo), SCE_BAT_WORD); - // Reset Offset to re-process remainder of word - offset -= (wbl - wbo); - } - } - // Check for External Command / Program or Default Text - if (!sKeywordFound) { - wbo = 0; - // Check for External Command / Program - if (cmdLoc == offset - wbl) { - // Read up to %, Operator or Separator - while ((wbo < wbl) && - (wordBuffer[wbo] != '%') && - (wordBuffer[wbo] != '!') && - (!IsBOperator(wordBuffer[wbo])) && - (!IsBSeparator(wordBuffer[wbo]))) { - wbo++; - } - // Reset External Command / Program Location - cmdLoc = offset - (wbl - wbo); - // Reset Offset to re-process remainder of word - offset -= (wbl - wbo); - // CHOICE requires no further Regular Keyword Checking - if (CompareCaseInsensitive(wordBuffer, "choice") == 0) { - continueProcessing = false; - } - // Check for START (and its switches) - What follows is External Command \ Program - if (CompareCaseInsensitive(wordBuffer, "start") == 0) { - // Reset External Command / Program Location - cmdLoc = offset; - // Skip next spaces - while ((cmdLoc < lengthLine) && - (isspacechar(lineBuffer[cmdLoc]))) { - cmdLoc++; - } - // Reset External Command / Program Location if command switch detected - if (lineBuffer[cmdLoc] == '/') { - // Skip command switch - while ((cmdLoc < lengthLine) && - (!isspacechar(lineBuffer[cmdLoc]))) { - cmdLoc++; - } - // Skip next spaces - while ((cmdLoc < lengthLine) && - (isspacechar(lineBuffer[cmdLoc]))) { - cmdLoc++; - } - } - } - // Colorize External Command / Program - if (!keywords2) { - styler.ColourTo(startLine + offset - 1, SCE_BAT_COMMAND); - } else if (keywords2.InList(wordBuffer)) { - styler.ColourTo(startLine + offset - 1, SCE_BAT_COMMAND); - } else { - styler.ColourTo(startLine + offset - 1, SCE_BAT_DEFAULT); - } - // No need to Reset Offset - // Check for Default Text - } else { - // Read up to %, Operator or Separator - while ((wbo < wbl) && - (wordBuffer[wbo] != '%') && - (wordBuffer[wbo] != '!') && - (!IsBOperator(wordBuffer[wbo])) && - (!IsBSeparator(wordBuffer[wbo]))) { - wbo++; - } - // Colorize Default Text - styler.ColourTo(startLine + offset - 1 - (wbl - wbo), SCE_BAT_DEFAULT); - // Reset Offset to re-process remainder of word - offset -= (wbl - wbo); - } - } - // Check for Argument (%n), Environment Variable (%x...%) or Local Variable (%%a) - } else if (wordBuffer[0] == '%') { - // Colorize Default Text - styler.ColourTo(startLine + offset - 1 - wbl, SCE_BAT_DEFAULT); - wbo++; - // Search to end of word for second % (can be a long path) - while ((wbo < wbl) && - (wordBuffer[wbo] != '%') && - (!IsBOperator(wordBuffer[wbo])) && - (!IsBSeparator(wordBuffer[wbo]))) { - wbo++; - } - // Check for Argument (%n) or (%*) - if (((Is0To9(wordBuffer[1])) || (wordBuffer[1] == '*')) && - (wordBuffer[wbo] != '%')) { - // Check for External Command / Program - if (cmdLoc == offset - wbl) { - cmdLoc = offset - (wbl - 2); - } - // Colorize Argument - styler.ColourTo(startLine + offset - 1 - (wbl - 2), SCE_BAT_IDENTIFIER); - // Reset Offset to re-process remainder of word - offset -= (wbl - 2); - // Check for Expanded Argument (%~...) / Variable (%%~...) - } else if (((wbl > 1) && (wordBuffer[1] == '~')) || - ((wbl > 2) && (wordBuffer[1] == '%') && (wordBuffer[2] == '~'))) { - // Check for External Command / Program - if (cmdLoc == offset - wbl) { - cmdLoc = offset - (wbl - wbo); - } - // Colorize Expanded Argument / Variable - styler.ColourTo(startLine + offset - 1 - (wbl - wbo), SCE_BAT_IDENTIFIER); - // Reset Offset to re-process remainder of word - offset -= (wbl - wbo); - // Check for Environment Variable (%x...%) - } else if ((wordBuffer[1] != '%') && - (wordBuffer[wbo] == '%')) { - wbo++; - // Check for External Command / Program - if (cmdLoc == offset - wbl) { - cmdLoc = offset - (wbl - wbo); - } - // Colorize Environment Variable - styler.ColourTo(startLine + offset - 1 - (wbl - wbo), SCE_BAT_IDENTIFIER); - // Reset Offset to re-process remainder of word - offset -= (wbl - wbo); - // Check for Local Variable (%%a) - } else if ( - (wbl > 2) && - (wordBuffer[1] == '%') && - (wordBuffer[2] != '%') && - (!IsBOperator(wordBuffer[2])) && - (!IsBSeparator(wordBuffer[2]))) { - // Check for External Command / Program - if (cmdLoc == offset - wbl) { - cmdLoc = offset - (wbl - 3); - } - // Colorize Local Variable - styler.ColourTo(startLine + offset - 1 - (wbl - 3), SCE_BAT_IDENTIFIER); - // Reset Offset to re-process remainder of word - offset -= (wbl - 3); - } - // Check for Environment Variable (!x...!) - } else if (wordBuffer[0] == '!') { - // Colorize Default Text - styler.ColourTo(startLine + offset - 1 - wbl, SCE_BAT_DEFAULT); - wbo++; - // Search to end of word for second ! (can be a long path) - while ((wbo < wbl) && - (wordBuffer[wbo] != '!') && - (!IsBOperator(wordBuffer[wbo])) && - (!IsBSeparator(wordBuffer[wbo]))) { - wbo++; - } - if (wordBuffer[wbo] == '!') { - wbo++; - // Check for External Command / Program - if (cmdLoc == offset - wbl) { - cmdLoc = offset - (wbl - wbo); - } - // Colorize Environment Variable - styler.ColourTo(startLine + offset - 1 - (wbl - wbo), SCE_BAT_IDENTIFIER); - // Reset Offset to re-process remainder of word - offset -= (wbl - wbo); - } - // Check for Operator - } else if (IsBOperator(wordBuffer[0])) { - // Colorize Default Text - styler.ColourTo(startLine + offset - 1 - wbl, SCE_BAT_DEFAULT); - // Check for Comparison Operator - if ((wordBuffer[0] == '=') && (wordBuffer[1] == '=')) { - // Identify External Command / Program Location for IF - cmdLoc = offset; - // Skip next spaces - while ((cmdLoc < lengthLine) && - (isspacechar(lineBuffer[cmdLoc]))) { - cmdLoc++; - } - // Colorize Comparison Operator - styler.ColourTo(startLine + offset - 1 - (wbl - 2), SCE_BAT_OPERATOR); - // Reset Offset to re-process remainder of word - offset -= (wbl - 2); - // Check for Pipe Operator - } else if (wordBuffer[0] == '|') { - // Reset External Command / Program Location - cmdLoc = offset - wbl + 1; - // Skip next spaces - while ((cmdLoc < lengthLine) && - (isspacechar(lineBuffer[cmdLoc]))) { - cmdLoc++; - } - // Colorize Pipe Operator - styler.ColourTo(startLine + offset - 1 - (wbl - 1), SCE_BAT_OPERATOR); - // Reset Offset to re-process remainder of word - offset -= (wbl - 1); - // Check for Other Operator - } else { - // Check for > Operator - if (wordBuffer[0] == '>') { - // Turn Keyword and External Command / Program checking back on - continueProcessing = true; - } - // Colorize Other Operator - styler.ColourTo(startLine + offset - 1 - (wbl - 1), SCE_BAT_OPERATOR); - // Reset Offset to re-process remainder of word - offset -= (wbl - 1); - } - // Check for Default Text - } else { - // Read up to %, Operator or Separator - while ((wbo < wbl) && - (wordBuffer[wbo] != '%') && - (wordBuffer[wbo] != '!') && - (!IsBOperator(wordBuffer[wbo])) && - (!IsBSeparator(wordBuffer[wbo]))) { - wbo++; - } - // Colorize Default Text - styler.ColourTo(startLine + offset - 1 - (wbl - wbo), SCE_BAT_DEFAULT); - // Reset Offset to re-process remainder of word - offset -= (wbl - wbo); - } - // Skip next spaces - nothing happens if Offset was Reset - while ((offset < lengthLine) && (isspacechar(lineBuffer[offset]))) { - offset++; - } - } - // Colorize Default Text for remainder of line - currently not lexed - styler.ColourTo(endPos, SCE_BAT_DEFAULT); + return CurrentStatus; } static void ColouriseBatchDoc( @@ -467,6 +88,23 @@ static void ColouriseBatchDoc( int /*initStyle*/, WordList *keywordlists[], Accessor &styler) { + // Always backtracks to the start of a line that is not a continuation + // of the previous line + if (startPos > 0) { + Sci_Position ln = styler.GetLine(startPos); // Current line number + while (startPos > 0) { + ln--; + if ((styler.SafeGetCharAt(startPos-3) == '^' && styler.SafeGetCharAt(startPos-2) == '\r' && styler.SafeGetCharAt(startPos-1) == '\n') + || styler.SafeGetCharAt(startPos-2) == '^') { // handle '^' line continuation + // When the line continuation is found, + // set the Start Position to the Start of the previous line + length+=startPos-styler.LineStart(ln); + startPos=styler.LineStart(ln); + } + else + break; + } + } char lineBuffer[1024]; @@ -474,21 +112,459 @@ static void ColouriseBatchDoc( styler.StartSegment(startPos); Sci_PositionU linePos = 0; Sci_PositionU startLine = startPos; + bool continueProcessing = true; // Used to toggle Regular Keyword Checking + bool isNotAssigned=false; // Used to flag Assignment in Set operation + for (Sci_PositionU i = startPos; i < startPos + length; i++) { lineBuffer[linePos++] = styler[i]; - if (AtEOL(styler, i) || (linePos >= sizeof(lineBuffer) - 1)) { - // End of line (or of line buffer) met, colourise it + if (AtEOL(styler, i) || (linePos >= sizeof(lineBuffer) - 1) || (i==startPos + length-1)) { + // End of line (or of line buffer) (or End of Last Line) met, colourise it lineBuffer[linePos] = '\0'; - ColouriseBatchLine(lineBuffer, linePos, startLine, i, keywordlists, styler); + Sci_PositionU lengthLine=linePos; + Sci_PositionU endPos=i; + Sci_PositionU offset = 0; // Line Buffer Offset + Sci_PositionU cmdLoc; // External Command / Program Location + char wordBuffer[81]; // Word Buffer - large to catch long paths + Sci_PositionU wbl; // Word Buffer Length + Sci_PositionU wbo; // Word Buffer Offset - also Special Keyword Buffer Length + WordList &keywords = *keywordlists[0]; // Internal Commands + WordList &keywords2 = *keywordlists[1]; // External Commands (optional) + + // CHOICE, ECHO, GOTO, PROMPT and SET have Default Text that may contain Regular Keywords + // Toggling Regular Keyword Checking off improves readability + // Other Regular Keywords and External Commands / Programs might also benefit from toggling + // Need a more robust algorithm to properly toggle Regular Keyword Checking + bool stopLineProcessing=false; // Used to stop line processing if Comment or Drive Change found + // Special Keywords are those that allow certain characters without whitespace after the command + // Examples are: cd. cd\ md. rd. dir| dir> echo: echo. path= + // Special Keyword Buffer used to determine if the first n characters is a Keyword + char sKeywordBuffer[10]; // Special Keyword Buffer + bool sKeywordFound; // Exit Special Keyword for-loop if found + + // Skip initial spaces + while ((offset < lengthLine) && (isspacechar(lineBuffer[offset]))) { + offset++; + } + // Colorize Default Text + styler.ColourTo(startLine + offset - 1, SCE_BAT_DEFAULT); + // Set External Command / Program Location + cmdLoc = offset; + + // Check for Fake Label (Comment) or Real Label - return if found + if (lineBuffer[offset] == ':') { + if (lineBuffer[offset + 1] == ':') { + // Colorize Fake Label (Comment) - :: is similar to REM, see http://content.techweb.com/winmag/columns/explorer/2000/21.htm + styler.ColourTo(endPos, SCE_BAT_COMMENT); + } else { + // Colorize Real Label + styler.ColourTo(endPos, SCE_BAT_LABEL); + } + stopLineProcessing=true; + // Check for Drive Change (Drive Change is internal command) - return if found + } else if ((IsAlphabetic(lineBuffer[offset])) && + (lineBuffer[offset + 1] == ':') && + ((isspacechar(lineBuffer[offset + 2])) || + (((lineBuffer[offset + 2] == '\\')) && + (isspacechar(lineBuffer[offset + 3]))))) { + // Colorize Regular Keyword + styler.ColourTo(endPos, SCE_BAT_WORD); + stopLineProcessing=true; + } + + // Check for Hide Command (@ECHO OFF/ON) + if (lineBuffer[offset] == '@') { + styler.ColourTo(startLine + offset, SCE_BAT_HIDE); + offset++; + } + // Skip next spaces + while ((offset < lengthLine) && (isspacechar(lineBuffer[offset]))) { + offset++; + } + + // Read remainder of line word-at-a-time or remainder-of-word-at-a-time + while (offset < lengthLine && !stopLineProcessing) { + if (offset > startLine) { + // Colorize Default Text + styler.ColourTo(startLine + offset - 1, SCE_BAT_DEFAULT); + } + // Copy word from Line Buffer into Word Buffer + wbl = 0; + for (; offset < lengthLine && wbl < 80 && + !isspacechar(lineBuffer[offset]); wbl++, offset++) { + wordBuffer[wbl] = static_cast(tolower(lineBuffer[offset])); + } + wordBuffer[wbl] = '\0'; + wbo = 0; + + // Check for Comment - return if found + if ((CompareCaseInsensitive(wordBuffer, "rem") == 0) && continueProcessing) { + styler.ColourTo(endPos, SCE_BAT_COMMENT); + break; + } + // Check for Separator + if (IsBSeparator(wordBuffer[0])) { + // Check for External Command / Program + if ((cmdLoc == offset - wbl) && + ((wordBuffer[0] == ':') || + (wordBuffer[0] == '\\') || + (wordBuffer[0] == '.'))) { + // Reset Offset to re-process remainder of word + offset -= (wbl - 1); + // Colorize External Command / Program + if (!keywords2) { + styler.ColourTo(startLine + offset - 1, SCE_BAT_COMMAND); + } else if (keywords2.InList(wordBuffer)) { + styler.ColourTo(startLine + offset - 1, SCE_BAT_COMMAND); + } else { + styler.ColourTo(startLine + offset - 1, SCE_BAT_DEFAULT); + } + // Reset External Command / Program Location + cmdLoc = offset; + } else { + // Reset Offset to re-process remainder of word + offset -= (wbl - 1); + // Colorize Default Text + styler.ColourTo(startLine + offset - 1, SCE_BAT_DEFAULT); + } + // Check for Regular Keyword in list + } else if ((keywords.InList(wordBuffer)) && + (continueProcessing)) { + // ECHO, GOTO, PROMPT and SET require no further Regular Keyword Checking + if ((CompareCaseInsensitive(wordBuffer, "echo") == 0) || + (CompareCaseInsensitive(wordBuffer, "goto") == 0) || + (CompareCaseInsensitive(wordBuffer, "prompt") == 0)) { + continueProcessing = false; + } + // SET requires additional processing for the assignment operator + if (CompareCaseInsensitive(wordBuffer, "set") == 0) { + continueProcessing = false; + isNotAssigned=true; + } + // Identify External Command / Program Location for ERRORLEVEL, and EXIST + if ((CompareCaseInsensitive(wordBuffer, "errorlevel") == 0) || + (CompareCaseInsensitive(wordBuffer, "exist") == 0)) { + // Reset External Command / Program Location + cmdLoc = offset; + // Skip next spaces + while ((cmdLoc < lengthLine) && + (isspacechar(lineBuffer[cmdLoc]))) { + cmdLoc++; + } + // Skip comparison + while ((cmdLoc < lengthLine) && + (!isspacechar(lineBuffer[cmdLoc]))) { + cmdLoc++; + } + // Skip next spaces + while ((cmdLoc < lengthLine) && + (isspacechar(lineBuffer[cmdLoc]))) { + cmdLoc++; + } + // Identify External Command / Program Location for CALL, DO, LOADHIGH and LH + } else if ((CompareCaseInsensitive(wordBuffer, "call") == 0) || + (CompareCaseInsensitive(wordBuffer, "do") == 0) || + (CompareCaseInsensitive(wordBuffer, "loadhigh") == 0) || + (CompareCaseInsensitive(wordBuffer, "lh") == 0)) { + // Reset External Command / Program Location + cmdLoc = offset; + // Skip next spaces + while ((cmdLoc < lengthLine) && + (isspacechar(lineBuffer[cmdLoc]))) { + cmdLoc++; + } + } + // Colorize Regular keyword + styler.ColourTo(startLine + offset - 1, SCE_BAT_WORD); + // No need to Reset Offset + // Check for Special Keyword in list, External Command / Program, or Default Text + } else if ((wordBuffer[0] != '%') && + (wordBuffer[0] != '!') && + (!IsBOperator(wordBuffer[0])) && + (continueProcessing)) { + // Check for Special Keyword + // Affected Commands are in Length range 2-6 + // Good that ERRORLEVEL, EXIST, CALL, DO, LOADHIGH, and LH are unaffected + sKeywordFound = false; + for (Sci_PositionU keywordLength = 2; keywordLength < wbl && keywordLength < 7 && !sKeywordFound; keywordLength++) { + wbo = 0; + // Copy Keyword Length from Word Buffer into Special Keyword Buffer + for (; wbo < keywordLength; wbo++) { + sKeywordBuffer[wbo] = static_cast(wordBuffer[wbo]); + } + sKeywordBuffer[wbo] = '\0'; + // Check for Special Keyword in list + if ((keywords.InList(sKeywordBuffer)) && + ((IsBOperator(wordBuffer[wbo])) || + (IsBSeparator(wordBuffer[wbo])))) { + sKeywordFound = true; + // ECHO requires no further Regular Keyword Checking + if (CompareCaseInsensitive(sKeywordBuffer, "echo") == 0) { + continueProcessing = false; + } + // Colorize Special Keyword as Regular Keyword + styler.ColourTo(startLine + offset - 1 - (wbl - wbo), SCE_BAT_WORD); + // Reset Offset to re-process remainder of word + offset -= (wbl - wbo); + } + } + // Check for External Command / Program or Default Text + if (!sKeywordFound) { + wbo = 0; + // Check for External Command / Program + if (cmdLoc == offset - wbl) { + // Read up to %, Operator or Separator + while ((wbo < wbl) && + (((wordBuffer[wbo] != '%') && + (wordBuffer[wbo] != '!') && + (!IsBOperator(wordBuffer[wbo])) && + (!IsBSeparator(wordBuffer[wbo]))))) { + wbo++; + } + // Reset External Command / Program Location + cmdLoc = offset - (wbl - wbo); + // Reset Offset to re-process remainder of word + offset -= (wbl - wbo); + // CHOICE requires no further Regular Keyword Checking + if (CompareCaseInsensitive(wordBuffer, "choice") == 0) { + continueProcessing = false; + } + // Check for START (and its switches) - What follows is External Command \ Program + if (CompareCaseInsensitive(wordBuffer, "start") == 0) { + // Reset External Command / Program Location + cmdLoc = offset; + // Skip next spaces + while ((cmdLoc < lengthLine) && + (isspacechar(lineBuffer[cmdLoc]))) { + cmdLoc++; + } + // Reset External Command / Program Location if command switch detected + if (lineBuffer[cmdLoc] == '/') { + // Skip command switch + while ((cmdLoc < lengthLine) && + (!isspacechar(lineBuffer[cmdLoc]))) { + cmdLoc++; + } + // Skip next spaces + while ((cmdLoc < lengthLine) && + (isspacechar(lineBuffer[cmdLoc]))) { + cmdLoc++; + } + } + } + // Colorize External Command / Program + if (!keywords2) { + styler.ColourTo(startLine + offset - 1, SCE_BAT_COMMAND); + } else if (keywords2.InList(wordBuffer)) { + styler.ColourTo(startLine + offset - 1, SCE_BAT_COMMAND); + } else { + styler.ColourTo(startLine + offset - 1, SCE_BAT_DEFAULT); + } + // No need to Reset Offset + // Check for Default Text + } else { + // Read up to %, Operator or Separator + while ((wbo < wbl) && + (((wordBuffer[wbo] != '%') && + (wordBuffer[wbo] != '!') && + (!IsBOperator(wordBuffer[wbo])) && + (!IsBSeparator(wordBuffer[wbo]))))) { + wbo++; + } + // Colorize Default Text + styler.ColourTo(startLine + offset - 1 - (wbl - wbo), SCE_BAT_DEFAULT); + // Reset Offset to re-process remainder of word + offset -= (wbl - wbo); + } + } + // Check for Argument (%n), Environment Variable (%x...%) or Local Variable (%%a) + } else if (wordBuffer[0] == '%') { + // Colorize Default Text + styler.ColourTo(startLine + offset - 1 - wbl, SCE_BAT_DEFAULT); + wbo++; + // Search to end of word for second % (can be a long path) + while ((wbo < wbl) && + (wordBuffer[wbo] != '%')) { + wbo++; + } + // Check for Argument (%n) or (%*) + if (((Is0To9(wordBuffer[1])) || (wordBuffer[1] == '*')) && + (wordBuffer[wbo] != '%')) { + // Check for External Command / Program + if (cmdLoc == offset - wbl) { + cmdLoc = offset - (wbl - 2); + } + // Colorize Argument + styler.ColourTo(startLine + offset - 1 - (wbl - 2), SCE_BAT_IDENTIFIER); + // Reset Offset to re-process remainder of word + offset -= (wbl - 2); + // Check for Expanded Argument (%~...) / Variable (%%~...) + } else if (((wbl > 1) && (wordBuffer[1] == '~')) || + ((wbl > 2) && (wordBuffer[1] == '%') && (wordBuffer[2] == '~'))) { + // Check for External Command / Program + if (cmdLoc == offset - wbl) { + cmdLoc = offset - (wbl - wbo); + } + // Colorize Expanded Argument / Variable + styler.ColourTo(startLine + offset - 1 - (wbl - wbo), SCE_BAT_IDENTIFIER); + // Reset Offset to re-process remainder of word + offset -= (wbl - wbo); + // Check for Environment Variable (%x...%) + } else if ((wordBuffer[1] != '%') && + (wordBuffer[wbo] == '%')) { + wbo++; + // Check for External Command / Program + if (cmdLoc == offset - wbl) { + cmdLoc = offset - (wbl - wbo); + } + // Colorize Environment Variable + styler.ColourTo(startLine + offset - 1 - (wbl - wbo), SCE_BAT_IDENTIFIER); + // Reset Offset to re-process remainder of word + offset -= (wbl - wbo); + // Check for Local Variable (%%a) + } else if ( + (wbl > 2) && + (wordBuffer[1] == '%') && + (wordBuffer[2] != '%') && + (!IsBOperator(wordBuffer[2])) && + (!IsBSeparator(wordBuffer[2]))) { + // Check for External Command / Program + if (cmdLoc == offset - wbl) { + cmdLoc = offset - (wbl - 3); + } + // Colorize Local Variable + styler.ColourTo(startLine + offset - 1 - (wbl - 3), SCE_BAT_IDENTIFIER); + // Reset Offset to re-process remainder of word + offset -= (wbl - 3); + } + // Check for Environment Variable (!x...!) + } else if (wordBuffer[0] == '!') { + // Colorize Default Text + styler.ColourTo(startLine + offset - 1 - wbl, SCE_BAT_DEFAULT); + wbo++; + // Search to end of word for second ! (can be a long path) + while ((wbo < wbl) && + (wordBuffer[wbo] != '!')) { + wbo++; + } + if (wordBuffer[wbo] == '!') { + wbo++; + // Check for External Command / Program + if (cmdLoc == offset - wbl) { + cmdLoc = offset - (wbl - wbo); + } + // Colorize Environment Variable + styler.ColourTo(startLine + offset - 1 - (wbl - wbo), SCE_BAT_IDENTIFIER); + // Reset Offset to re-process remainder of word + offset -= (wbl - wbo); + } + // Check for Operator + } else if (IsBOperator(wordBuffer[0])) { + // Colorize Default Text + styler.ColourTo(startLine + offset - 1 - wbl, SCE_BAT_DEFAULT); + // Check for Comparison Operator + if ((wordBuffer[0] == '=') && (wordBuffer[1] == '=')) { + // Identify External Command / Program Location for IF + cmdLoc = offset; + // Skip next spaces + while ((cmdLoc < lengthLine) && + (isspacechar(lineBuffer[cmdLoc]))) { + cmdLoc++; + } + // Colorize Comparison Operator + if (continueProcessing) + styler.ColourTo(startLine + offset - 1 - (wbl - 2), SCE_BAT_OPERATOR); + else + styler.ColourTo(startLine + offset - 1 - (wbl - 2), SCE_BAT_DEFAULT); + // Reset Offset to re-process remainder of word + offset -= (wbl - 2); + // Check for Pipe Operator + } else if ((wordBuffer[0] == '|') && + !(IsEscaped(lineBuffer,offset - wbl + wbo) || textQuoted(lineBuffer, offset - wbl) )) { + // Reset External Command / Program Location + cmdLoc = offset - wbl + 1; + // Skip next spaces + while ((cmdLoc < lengthLine) && + (isspacechar(lineBuffer[cmdLoc]))) { + cmdLoc++; + } + // Colorize Pipe Operator + styler.ColourTo(startLine + offset - 1 - (wbl - 1), SCE_BAT_OPERATOR); + // Reset Offset to re-process remainder of word + offset -= (wbl - 1); + continueProcessing = true; + // Check for Other Operator + } else { + // Check for Operators: >, |, & + if (((wordBuffer[0] == '>')|| + (wordBuffer[0] == ')')|| + (wordBuffer[0] == '(')|| + (wordBuffer[0] == '&' )) && + !(!continueProcessing && (IsEscaped(lineBuffer,offset - wbl + wbo) + || textQuoted(lineBuffer, offset - wbl) ))){ + // Turn Keyword and External Command / Program checking back on + continueProcessing = true; + isNotAssigned=false; + } + // Colorize Other Operators + // Do not Colorize Paranthesis, quoted text and escaped operators + if (((wordBuffer[0] != ')') && (wordBuffer[0] != '(') + && !textQuoted(lineBuffer, offset - wbl) && !IsEscaped(lineBuffer,offset - wbl + wbo)) + && !((wordBuffer[0] == '=') && !isNotAssigned )) + styler.ColourTo(startLine + offset - 1 - (wbl - 1), SCE_BAT_OPERATOR); + else + styler.ColourTo(startLine + offset - 1 - (wbl - 1), SCE_BAT_DEFAULT); + // Reset Offset to re-process remainder of word + offset -= (wbl - 1); + + if ((wordBuffer[0] == '=') && isNotAssigned ){ + isNotAssigned=false; + } + } + // Check for Default Text + } else { + // Read up to %, Operator or Separator + while ((wbo < wbl) && + ((wordBuffer[wbo] != '%') && + (wordBuffer[wbo] != '!') && + (!IsBOperator(wordBuffer[wbo])) && + (!IsBSeparator(wordBuffer[wbo])))) { + wbo++; + } + // Colorize Default Text + styler.ColourTo(startLine + offset - 1 - (wbl - wbo), SCE_BAT_DEFAULT); + // Reset Offset to re-process remainder of word + offset -= (wbl - wbo); + } + // Skip next spaces - nothing happens if Offset was Reset + while ((offset < lengthLine) && (isspacechar(lineBuffer[offset]))) { + offset++; + } + } + // Colorize Default Text for remainder of line - currently not lexed + styler.ColourTo(endPos, SCE_BAT_DEFAULT); + + // handle line continuation for SET and ECHO commands except the last line + if (!continueProcessing && (i2) && lineBuffer[linePos-2]=='\r') // Windows EOL + lineContinuationPos=linePos-3; + else + lineContinuationPos=linePos-2; // Unix or Mac EOL + // Reset continueProcessing if line continuation was not found + if ((lineBuffer[lineContinuationPos]!='^') + || IsEscaped(lineBuffer, lineContinuationPos) + || textQuoted(lineBuffer, lineContinuationPos)) + continueProcessing=true; + } + } + linePos = 0; startLine = i + 1; } } - if (linePos > 0) { // Last line does not have ending characters - lineBuffer[linePos] = '\0'; - ColouriseBatchLine(lineBuffer, linePos, startLine, startPos + length - 1, - keywordlists, styler); - } } static const char *const batchWordListDesc[] = { diff --git a/src/stc/scintilla/lexers/LexBibTeX.cxx b/src/stc/scintilla/lexers/LexBibTeX.cxx index fef58a9b0f..7e4cb9fc19 100644 --- a/src/stc/scintilla/lexers/LexBibTeX.cxx +++ b/src/stc/scintilla/lexers/LexBibTeX.cxx @@ -30,9 +30,7 @@ #include "CharacterSet.h" #include "LexerModule.h" -#ifdef SCI_NAMESPACE using namespace Scintilla; -#endif namespace { bool IsAlphabetic(unsigned int ch) diff --git a/src/stc/scintilla/lexers/LexBullant.cxx b/src/stc/scintilla/lexers/LexBullant.cxx index 4041887699..2386d22528 100644 --- a/src/stc/scintilla/lexers/LexBullant.cxx +++ b/src/stc/scintilla/lexers/LexBullant.cxx @@ -19,9 +19,7 @@ #include "CharacterSet.h" #include "LexerModule.h" -#ifdef SCI_NAMESPACE using namespace Scintilla; -#endif static int classifyWordBullant(Sci_PositionU start, Sci_PositionU end, WordList &keywords, Accessor &styler) { char s[100]; diff --git a/src/stc/scintilla/lexers/LexCIL.cxx b/src/stc/scintilla/lexers/LexCIL.cxx new file mode 100644 index 0000000000..f396acb726 --- /dev/null +++ b/src/stc/scintilla/lexers/LexCIL.cxx @@ -0,0 +1,407 @@ +// Scintilla source code edit control +/** @file LexCIL.cxx + ** Lexer for Common Intermediate Language + ** Written by Jad Altahan (github.com/xv) + ** CIL manual: https://www.ecma-international.org/publications/standards/Ecma-335.htm + **/ +// Copyright 1998-2001 by Neil Hodgson +// The License.txt file describes the conditions under which this software may be distributed. + +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +#include "ILexer.h" +#include "Scintilla.h" +#include "SciLexer.h" + +#include "StringCopy.h" +#include "WordList.h" +#include "LexAccessor.h" +#include "Accessor.h" +#include "StyleContext.h" +#include "CharacterSet.h" +#include "LexerModule.h" +#include "OptionSet.h" +#include "DefaultLexer.h" + +using namespace Scintilla; + +namespace { + // Use an unnamed namespace to protect the functions and classes from name conflicts + +bool IsAWordChar(const int ch) { + return (ch < 0x80) && (isalnum(ch) || ch == '_' || ch == '.'); +} + +bool IsOperator(const int ch) { + if ((ch < 0x80) && (isalnum(ch))) + return false; + + if (strchr("!%&*+-/<=>@^|~()[]{}", ch)) { + return true; + } + + return false; +} + +constexpr bool IsStreamCommentStyle(const int style) noexcept { + return style == SCE_CIL_COMMENT; +} + +struct OptionsCIL { + bool fold; + bool foldComment; + bool foldCommentMultiline; + bool foldCompact; + + OptionsCIL() { + fold = true; + foldComment = false; + foldCommentMultiline = true; + foldCompact = true; + } +}; + +static const char *const cilWordListDesc[] = { + "Primary CIL keywords", + "Metadata", + "Opcode instructions", + 0 +}; + +struct OptionSetCIL : public OptionSet { + OptionSetCIL() { + DefineProperty("fold", &OptionsCIL::fold); + DefineProperty("fold.comment", &OptionsCIL::foldComment); + + DefineProperty("fold.cil.comment.multiline", &OptionsCIL::foldCommentMultiline, + "Set this property to 0 to disable folding multi-line comments when fold.comment=1."); + + DefineProperty("fold.compact", &OptionsCIL::foldCompact); + + DefineWordListSets(cilWordListDesc); + } +}; + +LexicalClass lexicalClasses[] = { + // Lexer CIL SCLEX_CIL SCE_CIL_: + 0, "SCE_CIL_DEFAULT", "default", "White space", + 1, "SCE_CIL_COMMENT", "comment", "Multi-line comment", + 2, "SCE_CIL_COMMENTLINE", "comment line", "Line comment", + 3, "SCE_CIL_WORD", "keyword", "Keyword 1", + 4, "SCE_CIL_WORD2", "keyword", "Keyword 2", + 5, "SCE_CIL_WORD3", "keyword", "Keyword 3", + 6, "SCE_CIL_STRING", "literal string", "Double quoted string", + 7, "SCE_CIL_LABEL", "label", "Code label", + 8, "SCE_CIL_OPERATOR", "operator", "Operators", + 9, "SCE_CIL_STRINGEOL", "error literal string", "String is not closed", + 10, "SCE_CIL_IDENTIFIER", "identifier", "Identifiers", +}; + +} + +class LexerCIL : public DefaultLexer { + WordList keywords, keywords2, keywords3; + OptionsCIL options; + OptionSetCIL osCIL; + +public: + LexerCIL() : DefaultLexer("cil", SCLEX_CIL, lexicalClasses, ELEMENTS(lexicalClasses)) { } + + virtual ~LexerCIL() { } + + void SCI_METHOD Release() override { + delete this; + } + + int SCI_METHOD Version() const override { + return lvIdentity; + } + + const char * SCI_METHOD PropertyNames() override { + return osCIL.PropertyNames(); + } + + int SCI_METHOD PropertyType(const char *name) override { + return osCIL.PropertyType(name); + } + + const char * SCI_METHOD DescribeProperty(const char *name) override { + return osCIL.DescribeProperty(name); + } + + Sci_Position SCI_METHOD PropertySet(const char *key, const char *val) override; + + const char * SCI_METHOD PropertyGet(const char* key) override { + return osCIL.PropertyGet(key); + } + + const char * SCI_METHOD DescribeWordListSets() override { + return osCIL.DescribeWordListSets(); + } + + Sci_Position SCI_METHOD WordListSet(int n, const char *wl) override; + + void SCI_METHOD Lex(Sci_PositionU startPos, Sci_Position length, int initStyle, IDocument *pAccess) override; + void SCI_METHOD Fold(Sci_PositionU startPos, Sci_Position length, int initStyle, IDocument *pAccess) override; + + void * SCI_METHOD PrivateCall(int, void *) override { + return 0; + } + + int SCI_METHOD LineEndTypesSupported() override { + return SC_LINE_END_TYPE_UNICODE; + } + + int SCI_METHOD PrimaryStyleFromStyle(int style) override { + return style; + } + + static ILexer *LexerFactoryCIL() { + return new LexerCIL(); + } +}; + +Sci_Position SCI_METHOD LexerCIL::PropertySet(const char *key, const char *val) { + if (osCIL.PropertySet(&options, key, val)) { + return 0; + } + + return -1; +} + +Sci_Position SCI_METHOD LexerCIL::WordListSet(int n, const char *wl) { + WordList *wordListN = 0; + + switch (n) { + case 0: + wordListN = &keywords; + break; + case 1: + wordListN = &keywords2; + break; + case 2: + wordListN = &keywords3; + break; + } + + Sci_Position firstModification = -1; + + if (wordListN) { + WordList wlNew; + wlNew.Set(wl); + + if (*wordListN != wlNew) { + wordListN->Set(wl); + firstModification = 0; + } + } + + return firstModification; +} + +void SCI_METHOD LexerCIL::Lex(Sci_PositionU startPos, Sci_Position length, + int initStyle, IDocument *pAccess) { + if (initStyle == SCE_CIL_STRINGEOL) { + initStyle = SCE_CIL_DEFAULT; + } + + Accessor styler(pAccess, NULL); + StyleContext sc(startPos, length, initStyle, styler); + + bool identAtLineStart = false, // Checks if an identifier is at line start (ignoring spaces) + canStyleLabels = false; // Checks if conditions are met to style SCE_CIL_LABEL + + for (; sc.More(); sc.Forward()) { + if (sc.atLineStart) { + if (sc.state == SCE_CIL_STRING) { + sc.SetState(SCE_CIL_STRING); + } + + identAtLineStart = true; + } + + // Handle string line continuation + if (sc.ch == '\\' && (sc.chNext == '\n' || sc.chNext == '\r') && + (sc.state == SCE_CIL_STRING)) { + sc.Forward(); + + if (sc.ch == '\r' && sc.chNext == '\n') { + sc.Forward(); + } + + continue; + } + + switch (sc.state) { + case SCE_CIL_OPERATOR: + sc.SetState(SCE_CIL_DEFAULT); + break; + case SCE_CIL_IDENTIFIER: + if (!IsAWordChar(sc.ch)) { + if (canStyleLabels && (sc.ch == ':' && sc.chNext != ':')) { + sc.ChangeState(SCE_CIL_LABEL); + sc.ForwardSetState(SCE_CIL_DEFAULT); + } else { + char kwSize[100]; + sc.GetCurrent(kwSize, sizeof(kwSize)); + int style = SCE_CIL_IDENTIFIER; + + if (keywords.InList(kwSize)) { + style = SCE_CIL_WORD; + } else if (keywords2.InList(kwSize)) { + style = SCE_CIL_WORD2; + } else if (keywords3.InList(kwSize)) { + style = SCE_CIL_WORD3; + } + + sc.ChangeState(style); + sc.SetState(SCE_CIL_DEFAULT); + } + } + break; + case SCE_CIL_COMMENT: + if (sc.Match('*', '/')) { + sc.Forward(); + sc.ForwardSetState(SCE_CIL_DEFAULT); + } + break; + case SCE_CIL_COMMENTLINE: + if (sc.atLineStart) { + sc.SetState(SCE_CIL_DEFAULT); + } + break; + case SCE_CIL_STRING: + if (sc.ch == '\\') { + if (sc.chNext == '"' || sc.chNext == '\\') { + sc.Forward(); + } + } else if (sc.ch == '"') { + sc.ForwardSetState(SCE_CIL_DEFAULT); + } else if (sc.atLineEnd) { + sc.ChangeState(SCE_CIL_STRINGEOL); + sc.ForwardSetState(SCE_CIL_DEFAULT); + } + break; + } + + if (sc.state == SCE_CIL_DEFAULT) { + // String + if (sc.ch == '"') { + sc.SetState(SCE_CIL_STRING); + } + // Keyword + else if (IsAWordChar(sc.ch)) { + // Allow setting SCE_CIL_LABEL style only if the label is the + // first token in the line and does not start with a dot or a digit + canStyleLabels = identAtLineStart && !(sc.ch == '.' || IsADigit(sc.ch)); + sc.SetState(SCE_CIL_IDENTIFIER); + } + // Multi-line comment + else if (sc.Match('/', '*')) { + sc.SetState(SCE_CIL_COMMENT); + sc.Forward(); + } + // Line comment + else if (sc.Match('/', '/')) { + sc.SetState(SCE_CIL_COMMENTLINE); + } + // Operators + else if (IsOperator(sc.ch)) { + sc.SetState(SCE_CIL_OPERATOR); + } + } + + if (!IsASpace(sc.ch)) { + identAtLineStart = false; + } + } + + sc.Complete(); +} + +void SCI_METHOD LexerCIL::Fold(Sci_PositionU startPos, Sci_Position length, + int initStyle, IDocument *pAccess) { + if (!options.fold) { + return; + } + + LexAccessor styler(pAccess); + + const Sci_PositionU endPos = startPos + length; + Sci_Position lineCurrent = styler.GetLine(startPos); + + int levelCurrent = SC_FOLDLEVELBASE; + if (lineCurrent > 0) + levelCurrent = styler.LevelAt(lineCurrent - 1) >> 16; + + int style = initStyle; + int styleNext = styler.StyleAt(startPos); + int levelNext = levelCurrent; + int visibleChars = 0; + + char chNext = styler[startPos]; + + for (Sci_PositionU i = startPos; i < endPos; i++) { + const char ch = chNext; + int stylePrev = style; + + chNext = styler.SafeGetCharAt(i + 1); + style = styleNext; + styleNext = styler.StyleAt(i + 1); + + const bool atEOL = (ch == '\r' && chNext != '\n') || (ch == '\n'); + + if (options.foldComment && + options.foldCommentMultiline && IsStreamCommentStyle(style)) { + if (!IsStreamCommentStyle(stylePrev)) { + levelNext++; + } else if (!IsStreamCommentStyle(styleNext) && !atEOL) { + levelNext--; + } + } + + if (style == SCE_CIL_OPERATOR) { + if (ch == '{') { + levelNext++; + } else if (ch == '}') { + levelNext--; + } + } + + if (!IsASpace(ch)) { + visibleChars++; + } + + if (atEOL || (i == endPos - 1)) { + int lev = levelCurrent | levelNext << 16; + if (visibleChars == 0 && options.foldCompact) + lev |= SC_FOLDLEVELWHITEFLAG; + if (levelCurrent < levelNext) + lev |= SC_FOLDLEVELHEADERFLAG; + if (lev != styler.LevelAt(lineCurrent)) { + styler.SetLevel(lineCurrent, lev); + } + + lineCurrent++; + levelCurrent = levelNext; + + if (options.foldCompact && + i == static_cast(styler.Length() - 1)) { + styler.SetLevel(lineCurrent, lev | SC_FOLDLEVELWHITEFLAG); + } + + visibleChars = 0; + } + } +} + +LexerModule lmCIL(SCLEX_CIL, LexerCIL::LexerFactoryCIL, "cil", cilWordListDesc); \ No newline at end of file diff --git a/src/stc/scintilla/lexers/LexCLW.cxx b/src/stc/scintilla/lexers/LexCLW.cxx index af2ca151ad..fbc86e6c0f 100644 --- a/src/stc/scintilla/lexers/LexCLW.cxx +++ b/src/stc/scintilla/lexers/LexCLW.cxx @@ -1,5 +1,5 @@ // Scintilla source code edit control -/** @file LexClw.cxx +/** @file LexCLW.cxx ** Lexer for Clarion. ** 2004/12/17 Updated Lexer **/ @@ -24,9 +24,7 @@ #include "CharacterSet.h" #include "LexerModule.h" -#ifdef SCI_NAMESPACE using namespace Scintilla; -#endif // Is an end of line character inline bool IsEOL(const int ch) { diff --git a/src/stc/scintilla/lexers/LexCOBOL.cxx b/src/stc/scintilla/lexers/LexCOBOL.cxx index 3150e33385..f0374824fc 100644 --- a/src/stc/scintilla/lexers/LexCOBOL.cxx +++ b/src/stc/scintilla/lexers/LexCOBOL.cxx @@ -26,9 +26,7 @@ #include "CharacterSet.h" #include "LexerModule.h" -#ifdef SCI_NAMESPACE using namespace Scintilla; -#endif #define IN_DIVISION 0x01 #define IN_DECLARATIVES 0x02 diff --git a/src/stc/scintilla/lexers/LexCPP.cxx b/src/stc/scintilla/lexers/LexCPP.cxx index d4cffd118f..c7d09a7a3b 100644 --- a/src/stc/scintilla/lexers/LexCPP.cxx +++ b/src/stc/scintilla/lexers/LexCPP.cxx @@ -6,22 +6,22 @@ // Copyright 1998-2005 by Neil Hodgson // The License.txt file describes the conditions under which this software may be distributed. -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include #include #include #include #include +#include #include "ILexer.h" #include "Scintilla.h" #include "SciLexer.h" +#include "StringCopy.h" #include "WordList.h" #include "LexAccessor.h" #include "Accessor.h" @@ -32,14 +32,12 @@ #include "SparseState.h" #include "SubStyles.h" -#ifdef SCI_NAMESPACE using namespace Scintilla; -#endif namespace { // Use an unnamed namespace to protect the functions and classes from name conflicts -bool IsSpaceEquiv(int state) { +constexpr bool IsSpaceEquiv(int state) noexcept { return (state <= SCE_C_COMMENTDOC) || // including SCE_C_DEFAULT, SCE_C_COMMENT, SCE_C_COMMENTLINE (state == SCE_C_COMMENTLINEDOC) || (state == SCE_C_COMMENTDOCKEYWORD) || @@ -53,10 +51,10 @@ bool IsSpaceEquiv(int state) { // a = b+++/ptn/... // Putting a space between the '++' post-inc operator and the '+' binary op // fixes this, and is highly recommended for readability anyway. -bool FollowsPostfixOperator(StyleContext &sc, LexAccessor &styler) { - Sci_Position pos = (Sci_Position) sc.currentPos; +bool FollowsPostfixOperator(const StyleContext &sc, LexAccessor &styler) { + Sci_Position pos = sc.currentPos; while (--pos > 0) { - char ch = styler[pos]; + const char ch = styler[pos]; if (ch == '+' || ch == '-') { return styler[pos - 1] == ch; } @@ -64,13 +62,13 @@ bool FollowsPostfixOperator(StyleContext &sc, LexAccessor &styler) { return false; } -bool followsReturnKeyword(StyleContext &sc, LexAccessor &styler) { +bool followsReturnKeyword(const StyleContext &sc, LexAccessor &styler) { // Don't look at styles, so no need to flush. - Sci_Position pos = (Sci_Position) sc.currentPos; - Sci_Position currentLine = styler.GetLine(pos); - Sci_Position lineStartPos = styler.LineStart(currentLine); + Sci_Position pos = sc.currentPos; + const Sci_Position currentLine = styler.GetLine(pos); + const Sci_Position lineStartPos = styler.LineStart(currentLine); while (--pos > lineStartPos) { - char ch = styler.SafeGetCharAt(pos); + const char ch = styler.SafeGetCharAt(pos); if (ch != ' ' && ch != '\t') { break; } @@ -86,13 +84,13 @@ bool followsReturnKeyword(StyleContext &sc, LexAccessor &styler) { return !*s; } -bool IsSpaceOrTab(int ch) { +constexpr bool IsSpaceOrTab(int ch) noexcept { return ch == ' ' || ch == '\t'; } -bool OnlySpaceOrTab(const std::string &s) { - for (std::string::const_iterator it = s.begin(); it != s.end(); ++it) { - if (!IsSpaceOrTab(*it)) +bool OnlySpaceOrTab(const std::string &s) noexcept { + for (const char ch : s) { + if (!IsSpaceOrTab(ch)) return false; } return true; @@ -100,11 +98,11 @@ bool OnlySpaceOrTab(const std::string &s) { std::vector StringSplit(const std::string &text, int separator) { std::vector vs(text.empty() ? 0 : 1); - for (std::string::const_iterator it = text.begin(); it != text.end(); ++it) { - if (*it == separator) { - vs.push_back(std::string()); + for (const char ch : text) { + if (ch == separator) { + vs.emplace_back(); } else { - vs.back() += *it; + vs.back() += ch; } } return vs; @@ -141,21 +139,21 @@ BracketPair FindBracketPair(std::vector &tokens) { } void highlightTaskMarker(StyleContext &sc, LexAccessor &styler, - int activity, WordList &markerList, bool caseSensitive){ + int activity, const WordList &markerList, bool caseSensitive){ if ((isoperator(sc.chPrev) || IsASpace(sc.chPrev)) && markerList.Length()) { - const int lengthMarker = 50; - char marker[lengthMarker+1]; - Sci_Position currPos = (Sci_Position) sc.currentPos; - int i = 0; + constexpr Sci_PositionU lengthMarker = 50; + char marker[lengthMarker+1] = ""; + const Sci_PositionU currPos = sc.currentPos; + Sci_PositionU i = 0; while (i < lengthMarker) { - char ch = styler.SafeGetCharAt(currPos + i); + const char ch = styler.SafeGetCharAt(currPos + i); if (IsASpace(ch) || isoperator(ch)) { break; } if (caseSensitive) marker[i] = ch; else - marker[i] = static_cast(tolower(ch)); + marker[i] = MakeLowerCase(ch); i++; } marker[i] = '\0'; @@ -165,18 +163,14 @@ void highlightTaskMarker(StyleContext &sc, LexAccessor &styler, } } -struct EscapeSequence { - int digitsLeft; - CharacterSet setHexDigits; - CharacterSet setOctDigits; - CharacterSet setNoneNumeric; - CharacterSet *escapeSetValid; - EscapeSequence() { - digitsLeft = 0; - escapeSetValid = 0; - setHexDigits = CharacterSet(CharacterSet::setDigits, "ABCDEFabcdef"); - setOctDigits = CharacterSet(CharacterSet::setNone, "01234567"); - } +class EscapeSequence { + const CharacterSet setHexDigits = CharacterSet(CharacterSet::setDigits, "ABCDEFabcdef"); + const CharacterSet setOctDigits = CharacterSet(CharacterSet::setNone, "01234567"); + const CharacterSet setNoneNumeric; + const CharacterSet *escapeSetValid = nullptr; + int digitsLeft = 0; +public: + EscapeSequence() = default; void resetEscapeState(int nextChar) { digitsLeft = 0; escapeSetValid = &setNoneNumeric; @@ -197,26 +191,39 @@ struct EscapeSequence { bool atEscapeEnd(int currChar) const { return (digitsLeft <= 0) || !escapeSetValid->Contains(currChar); } + void consumeDigit() noexcept { + digitsLeft--; + } }; std::string GetRestOfLine(LexAccessor &styler, Sci_Position start, bool allowSpace) { std::string restOfLine; - Sci_Position i =0; + Sci_Position line = styler.GetLine(start); + Sci_Position pos = start; + Sci_Position endLine = styler.LineEnd(line); char ch = styler.SafeGetCharAt(start, '\n'); - Sci_Position endLine = styler.LineEnd(styler.GetLine(start)); - while (((start+i) < endLine) && (ch != '\r')) { - char chNext = styler.SafeGetCharAt(start + i + 1, '\n'); - if (ch == '/' && (chNext == '/' || chNext == '*')) - break; - if (allowSpace || (ch != ' ')) - restOfLine += ch; - i++; - ch = chNext; + while (pos < endLine) { + if (ch == '\\' && ((pos + 1) == endLine)) { + // Continuation line + line++; + pos = styler.LineStart(line); + endLine = styler.LineEnd(line); + ch = styler.SafeGetCharAt(pos, '\n'); + } else { + const char chNext = styler.SafeGetCharAt(pos + 1, '\n'); + if (ch == '/' && (chNext == '/' || chNext == '*')) + break; + if (allowSpace || (ch != ' ')) { + restOfLine += ch; + } + pos++; + ch = chNext; + } } return restOfLine; } -bool IsStreamCommentStyle(int style) { +constexpr bool IsStreamCommentStyle(int style) noexcept { return style == SCE_C_COMMENT || style == SCE_C_COMMENTDOC || style == SCE_C_COMMENTDOCKEYWORD || @@ -234,26 +241,48 @@ struct PPDefinition { } }; +constexpr int inactiveFlag = 0x40; + class LinePPState { - int state; - int ifTaken; - int level; - bool ValidLevel() const { - return level >= 0 && level < 32; + // Track the state of preprocessor conditionals to allow showing active and inactive + // code in different styles. + // Only works up to 31 levels of conditional nesting. + + // state is a bit mask with 1 bit per level + // bit is 1 for level if section inactive, so any bits set = inactive style + int state = 0; + // ifTaken is a bit mask with 1 bit per level + // bit is 1 for level if some branch at this level has been taken + int ifTaken = 0; + // level is the nesting level of #if constructs + int level = -1; + static const int maximumNestingLevel = 31; + bool ValidLevel() const noexcept { + return level >= 0 && level < maximumNestingLevel; } - int maskLevel() const { - return 1 << level; + int maskLevel() const noexcept { + if (level >= 0) { + return 1 << level; + } else { + return 1; + } } public: - LinePPState() : state(0), ifTaken(0), level(-1) { + LinePPState() noexcept { } - bool IsInactive() const { + bool IsActive() const noexcept { + return state == 0; + } + bool IsInactive() const noexcept { return state != 0; } - bool CurrentIfTaken() const { + int ActiveState() const noexcept { + return state ? inactiveFlag : 0; + } + bool CurrentIfTaken() const noexcept { return (ifTaken & maskLevel()) != 0; } - void StartSection(bool on) { + void StartSection(bool on) noexcept { level++; if (ValidLevel()) { if (on) { @@ -265,14 +294,14 @@ public: } } } - void EndSection() { + void EndSection() noexcept { if (ValidLevel()) { state &= ~maskLevel(); ifTaken &= ~maskLevel(); } level--; } - void InvertCurrentLevel() { + void InvertCurrentLevel() noexcept { if (ValidLevel()) { state ^= maskLevel(); ifTaken |= maskLevel(); @@ -285,7 +314,7 @@ public: class PPStates { std::vector vlls; public: - LinePPState ForLine(Sci_Position line) const { + LinePPState ForLine(Sci_Position line) const noexcept { if ((line > 0) && (vlls.size() > static_cast(line))) { return vlls[line]; } else { @@ -355,7 +384,7 @@ const char *const cppWordLists[] = { "Global classes and typedefs", "Preprocessor definitions", "Task marker and error marker keywords", - 0, + nullptr, }; struct OptionSetCPP : public OptionSet { @@ -432,13 +461,48 @@ struct OptionSetCPP : public OptionSet { const char styleSubable[] = {SCE_C_IDENTIFIER, SCE_C_COMMENTDOCKEYWORD, 0}; +LexicalClass lexicalClasses[] = { + // Lexer Cpp SCLEX_CPP SCE_C_: + 0, "SCE_C_DEFAULT", "default", "White space", + 1, "SCE_C_COMMENT", "comment", "Comment: /* */.", + 2, "SCE_C_COMMENTLINE", "comment line", "Line Comment: //.", + 3, "SCE_C_COMMENTDOC", "comment documentation", "Doc comment: block comments beginning with /** or /*!", + 4, "SCE_C_NUMBER", "literal numeric", "Number", + 5, "SCE_C_WORD", "keyword", "Keyword", + 6, "SCE_C_STRING", "literal string", "Double quoted string", + 7, "SCE_C_CHARACTER", "literal string character", "Single quoted string", + 8, "SCE_C_UUID", "literal uuid", "UUIDs (only in IDL)", + 9, "SCE_C_PREPROCESSOR", "preprocessor", "Preprocessor", + 10, "SCE_C_OPERATOR", "operator", "Operators", + 11, "SCE_C_IDENTIFIER", "identifier", "Identifiers", + 12, "SCE_C_STRINGEOL", "error literal string", "End of line where string is not closed", + 13, "SCE_C_VERBATIM", "literal string multiline raw", "Verbatim strings for C#", + 14, "SCE_C_REGEX", "literal regex", "Regular expressions for JavaScript", + 15, "SCE_C_COMMENTLINEDOC", "comment documentation line", "Doc Comment Line: line comments beginning with /// or //!.", + 16, "SCE_C_WORD2", "identifier", "Keywords2", + 17, "SCE_C_COMMENTDOCKEYWORD", "comment documentation keyword", "Comment keyword", + 18, "SCE_C_COMMENTDOCKEYWORDERROR", "error comment documentation keyword", "Comment keyword error", + 19, "SCE_C_GLOBALCLASS", "identifier", "Global class", + 20, "SCE_C_STRINGRAW", "literal string multiline raw", "Raw strings for C++0x", + 21, "SCE_C_TRIPLEVERBATIM", "literal string multiline raw", "Triple-quoted strings for Vala", + 22, "SCE_C_HASHQUOTEDSTRING", "literal string", "Hash-quoted strings for Pike", + 23, "SCE_C_PREPROCESSORCOMMENT", "comment preprocessor", "Preprocessor stream comment", + 24, "SCE_C_PREPROCESSORCOMMENTDOC", "comment preprocessor documentation", "Preprocessor stream doc comment", + 25, "SCE_C_USERLITERAL", "literal", "User defined literals", + 26, "SCE_C_TASKMARKER", "comment taskmarker", "Task Marker", + 27, "SCE_C_ESCAPESEQUENCE", "literal string escapesequence", "Escape sequence", +}; + +const int sizeLexicalClasses = static_cast(Sci::size(lexicalClasses)); + } -class LexerCPP : public ILexerWithSubStyles { +class LexerCPP : public ILexerWithIdentity { bool caseSensitive; CharacterSet setWord; CharacterSet setNegationOp; - CharacterSet setArithmethicOp; + CharacterSet setAddOp; + CharacterSet setMultOp; CharacterSet setRelOp; CharacterSet setLogicalOp; CharacterSet setWordStart; @@ -453,14 +517,15 @@ class LexerCPP : public ILexerWithSubStyles { struct SymbolValue { std::string value; std::string arguments; - SymbolValue(const std::string &value_="", const std::string &arguments_="") : value(value_), arguments(arguments_) { + SymbolValue() = default; + SymbolValue(const std::string &value_, const std::string &arguments_) : value(value_), arguments(arguments_) { } SymbolValue &operator = (const std::string &value_) { value = value_; arguments.clear(); return *this; } - bool IsMacro() const { + bool IsMacro() const noexcept { return !arguments.empty(); } }; @@ -470,81 +535,149 @@ class LexerCPP : public ILexerWithSubStyles { OptionSetCPP osCPP; EscapeSequence escapeSeq; SparseState rawStringTerminators; - enum { activeFlag = 0x40 }; enum { ssIdentifier, ssDocKeyword }; SubStyles subStyles; + std::string returnBuffer; public: explicit LexerCPP(bool caseSensitive_) : caseSensitive(caseSensitive_), setWord(CharacterSet::setAlphaNum, "._", 0x80, true), setNegationOp(CharacterSet::setNone, "!"), - setArithmethicOp(CharacterSet::setNone, "+-/*%"), + setAddOp(CharacterSet::setNone, "+-"), + setMultOp(CharacterSet::setNone, "*/%"), setRelOp(CharacterSet::setNone, "=!<>"), setLogicalOp(CharacterSet::setNone, "|&"), - subStyles(styleSubable, 0x80, 0x40, activeFlag) { + subStyles(styleSubable, 0x80, 0x40, inactiveFlag) { } + // Deleted so LexerCPP objects can not be copied. + LexerCPP(const LexerCPP &) = delete; + LexerCPP(LexerCPP &&) = delete; + void operator=(const LexerCPP &) = delete; + void operator=(LexerCPP &&) = delete; virtual ~LexerCPP() { } - void SCI_METHOD Release() { + void SCI_METHOD Release() noexcept override { delete this; } - int SCI_METHOD Version() const { - return lvSubStyles; + int SCI_METHOD Version() const noexcept override { + return lvIdentity; } - const char * SCI_METHOD PropertyNames() { + const char * SCI_METHOD PropertyNames() override { return osCPP.PropertyNames(); } - int SCI_METHOD PropertyType(const char *name) { + int SCI_METHOD PropertyType(const char *name) override { return osCPP.PropertyType(name); } - const char * SCI_METHOD DescribeProperty(const char *name) { + const char * SCI_METHOD DescribeProperty(const char *name) override { return osCPP.DescribeProperty(name); } - Sci_Position SCI_METHOD PropertySet(const char *key, const char *val); - const char * SCI_METHOD DescribeWordListSets() { + Sci_Position SCI_METHOD PropertySet(const char *key, const char *val) override; + const char * SCI_METHOD DescribeWordListSets() override { return osCPP.DescribeWordListSets(); } - Sci_Position SCI_METHOD WordListSet(int n, const char *wl); - void SCI_METHOD Lex(Sci_PositionU startPos, Sci_Position length, int initStyle, IDocument *pAccess); - void SCI_METHOD Fold(Sci_PositionU startPos, Sci_Position length, int initStyle, IDocument *pAccess); + Sci_Position SCI_METHOD WordListSet(int n, const char *wl) override; + void SCI_METHOD Lex(Sci_PositionU startPos, Sci_Position length, int initStyle, IDocument *pAccess) override; + void SCI_METHOD Fold(Sci_PositionU startPos, Sci_Position length, int initStyle, IDocument *pAccess) override; - void * SCI_METHOD PrivateCall(int, void *) { - return 0; + void * SCI_METHOD PrivateCall(int, void *) noexcept override { + return nullptr; } - int SCI_METHOD LineEndTypesSupported() { + int SCI_METHOD LineEndTypesSupported() noexcept override { return SC_LINE_END_TYPE_UNICODE; } - int SCI_METHOD AllocateSubStyles(int styleBase, int numberStyles) { + int SCI_METHOD AllocateSubStyles(int styleBase, int numberStyles) override { return subStyles.Allocate(styleBase, numberStyles); } - int SCI_METHOD SubStylesStart(int styleBase) { + int SCI_METHOD SubStylesStart(int styleBase) override { return subStyles.Start(styleBase); } - int SCI_METHOD SubStylesLength(int styleBase) { + int SCI_METHOD SubStylesLength(int styleBase) override { return subStyles.Length(styleBase); } - int SCI_METHOD StyleFromSubStyle(int subStyle) { - int styleBase = subStyles.BaseStyle(MaskActive(subStyle)); - int active = subStyle & activeFlag; - return styleBase | active; + int SCI_METHOD StyleFromSubStyle(int subStyle) override { + const int styleBase = subStyles.BaseStyle(MaskActive(subStyle)); + const int inactive = subStyle & inactiveFlag; + return styleBase | inactive; } - int SCI_METHOD PrimaryStyleFromStyle(int style) { + int SCI_METHOD PrimaryStyleFromStyle(int style) noexcept override { return MaskActive(style); - } - void SCI_METHOD FreeSubStyles() { + } + void SCI_METHOD FreeSubStyles() override { subStyles.Free(); } - void SCI_METHOD SetIdentifiers(int style, const char *identifiers) { + void SCI_METHOD SetIdentifiers(int style, const char *identifiers) override { subStyles.SetIdentifiers(style, identifiers); } - int SCI_METHOD DistanceToSecondaryStyles() { - return activeFlag; + int SCI_METHOD DistanceToSecondaryStyles() noexcept override { + return inactiveFlag; } - const char * SCI_METHOD GetSubStyleBases() { + const char * SCI_METHOD GetSubStyleBases() noexcept override { return styleSubable; } + int SCI_METHOD NamedStyles() override { + return std::max(subStyles.LastAllocated() + 1, + sizeLexicalClasses) + + inactiveFlag; + } + const char * SCI_METHOD NameOfStyle(int style) override { + if (style >= NamedStyles()) + return ""; + if (style < sizeLexicalClasses) + return lexicalClasses[style].name; + // TODO: inactive and substyles + return ""; + } + const char * SCI_METHOD TagsOfStyle(int style) override { + if (style >= NamedStyles()) + return "Excess"; + returnBuffer.clear(); + const int firstSubStyle = subStyles.FirstAllocated(); + if (firstSubStyle >= 0) { + const int lastSubStyle = subStyles.LastAllocated(); + if (((style >= firstSubStyle) && (style <= (lastSubStyle))) || + ((style >= firstSubStyle + inactiveFlag) && (style <= (lastSubStyle + inactiveFlag)))) { + int styleActive = style; + if (style > lastSubStyle) { + returnBuffer = "inactive "; + styleActive -= inactiveFlag; + } + const int styleMain = StyleFromSubStyle(styleActive); + returnBuffer += lexicalClasses[styleMain].tags; + return returnBuffer.c_str(); + } + } + if (style < sizeLexicalClasses) + return lexicalClasses[style].tags; + if (style >= inactiveFlag) { + returnBuffer = "inactive "; + const int styleActive = style - inactiveFlag; + if (styleActive < sizeLexicalClasses) + returnBuffer += lexicalClasses[styleActive].tags; + else + returnBuffer = ""; + return returnBuffer.c_str(); + } + return ""; + } + const char * SCI_METHOD DescriptionOfStyle(int style) override { + if (style >= NamedStyles()) + return ""; + if (style < sizeLexicalClasses) + return lexicalClasses[style].description; + // TODO: inactive and substyles + return ""; + } + + // ILexerWithIdentity methods + const char * SCI_METHOD GetName() override { + return caseSensitive ? "cpp" : "cppnocase"; + } + int SCI_METHOD GetIdentifier() override { + return caseSensitive ? SCLEX_CPP : SCLEX_CPPNOCASE; + } + const char * SCI_METHOD PropertyGet(const char *key) override; static ILexer *LexerFactoryCPP() { return new LexerCPP(true); @@ -552,8 +685,8 @@ public: static ILexer *LexerFactoryCPPInsensitive() { return new LexerCPP(false); } - static int MaskActive(int style) { - return style & ~activeFlag; + constexpr static int MaskActive(int style) noexcept { + return style & ~inactiveFlag; } void EvaluateTokens(std::vector &tokens, const SymbolTable &preprocessorDefinitions); std::vector Tokenize(const std::string &expr) const; @@ -573,8 +706,12 @@ Sci_Position SCI_METHOD LexerCPP::PropertySet(const char *key, const char *val) return -1; } +const char * SCI_METHOD LexerCPP::PropertyGet(const char *key) { + return osCPP.PropertyGet(key); +} + Sci_Position SCI_METHOD LexerCPP::WordListSet(int n, const char *wl) { - WordList *wordListN = 0; + WordList *wordListN = nullptr; switch (n) { case 0: wordListN = &keywords; @@ -611,8 +748,8 @@ Sci_Position SCI_METHOD LexerCPP::WordListSet(int n, const char *wl) { if (cpEquals) { std::string name(cpDefinition, cpEquals - cpDefinition); std::string val(cpEquals+1); - size_t bracket = name.find('('); - size_t bracketEnd = name.find(')'); + const size_t bracket = name.find('('); + const size_t bracketEnd = name.find(')'); if ((bracket != std::string::npos) && (bracketEnd != std::string::npos)) { // Macro std::string args = name.substr(bracket + 1, bracketEnd - bracket - 1); @@ -633,15 +770,6 @@ Sci_Position SCI_METHOD LexerCPP::WordListSet(int n, const char *wl) { return firstModification; } -// Functor used to truncate history -struct After { - Sci_Position line; - explicit After(Sci_Position line_) : line(line_) {} - bool operator()(PPDefinition &p) const { - return p.line > line; - } -}; - void SCI_METHOD LexerCPP::Lex(Sci_PositionU startPos, Sci_Position length, int initStyle, IDocument *pAccess) { LexAccessor styler(pAccess); @@ -675,7 +803,7 @@ void SCI_METHOD LexerCPP::Lex(Sci_PositionU startPos, Sci_Position length, int i (MaskActive(initStyle) == SCE_C_COMMENTLINEDOC)) { // Set continuationLine if last character of previous line is '\' if (lineCurrent > 0) { - Sci_Position endLinePrevious = styler.LineEnd(lineCurrent - 1); + const Sci_Position endLinePrevious = styler.LineEnd(lineCurrent - 1); if (endLinePrevious > 0) { continuationLine = styler.SafeGetCharAt(endLinePrevious-1) == '\\'; } @@ -702,29 +830,30 @@ void SCI_METHOD LexerCPP::Lex(Sci_PositionU startPos, Sci_Position length, int i if (!options.updatePreprocessor) ppDefineHistory.clear(); - std::vector::iterator itInvalid = std::find_if(ppDefineHistory.begin(), ppDefineHistory.end(), After(lineCurrent-1)); + std::vector::iterator itInvalid = std::find_if(ppDefineHistory.begin(), ppDefineHistory.end(), + [lineCurrent](const PPDefinition &p) noexcept { return p.line >= lineCurrent; }); if (itInvalid != ppDefineHistory.end()) { ppDefineHistory.erase(itInvalid, ppDefineHistory.end()); definitionsChanged = true; } SymbolTable preprocessorDefinitions = preprocessorDefinitionsStart; - for (std::vector::iterator itDef = ppDefineHistory.begin(); itDef != ppDefineHistory.end(); ++itDef) { - if (itDef->isUndef) - preprocessorDefinitions.erase(itDef->key); + for (const PPDefinition &ppDef : ppDefineHistory) { + if (ppDef.isUndef) + preprocessorDefinitions.erase(ppDef.key); else - preprocessorDefinitions[itDef->key] = SymbolValue(itDef->value, itDef->arguments); + preprocessorDefinitions[ppDef.key] = SymbolValue(ppDef.value, ppDef.arguments); } std::string rawStringTerminator = rawStringTerminators.ValueAt(lineCurrent-1); SparseState rawSTNew(lineCurrent); - int activitySet = preproc.IsInactive() ? activeFlag : 0; + int activitySet = preproc.ActiveState(); const WordClassifier &classifierIdentifiers = subStyles.Classifier(SCE_C_IDENTIFIER); const WordClassifier &classifierDocKeyWords = subStyles.Classifier(SCE_C_COMMENTDOCKEYWORD); - Sci_Position lineEndNext = styler.LineEnd(lineCurrent); + Sci_PositionU lineEndNext = styler.LineEnd(lineCurrent); for (; sc.More();) { @@ -746,7 +875,7 @@ void SCI_METHOD LexerCPP::Lex(Sci_PositionU startPos, Sci_Position length, int i isIncludePreprocessor = false; inRERange = false; if (preproc.IsInactive()) { - activitySet = activeFlag; + activitySet = inactiveFlag; sc.SetState(sc.state | activitySet); } } @@ -762,7 +891,7 @@ void SCI_METHOD LexerCPP::Lex(Sci_PositionU startPos, Sci_Position length, int i // Handle line continuation generically. if (sc.ch == '\\') { - if (static_cast((sc.currentPos+1)) >= lineEndNext) { + if ((sc.currentPos+1) >= lineEndNext) { lineCurrent++; lineEndNext = styler.LineEnd(lineCurrent); vlls.Add(lineCurrent, preproc); @@ -829,7 +958,7 @@ void SCI_METHOD LexerCPP::Lex(Sci_PositionU startPos, Sci_Position length, int i const bool raw = literalString && sc.chPrev == 'R' && !setInvalidRawFirst.Contains(sc.chNext); if (raw) s[lenS--] = '\0'; - bool valid = + const bool valid = (lenS == 0) || ((lenS == 1) && ((s[0] == 'L') || (s[0] == 'u') || (s[0] == 'U'))) || ((lenS == 2) && literalString && (s[0] == 'u') && (s[1] == '8')); @@ -856,7 +985,7 @@ void SCI_METHOD LexerCPP::Lex(Sci_PositionU startPos, Sci_Position length, int i break; case SCE_C_PREPROCESSOR: if (options.stylingWithinPreprocessor) { - if (IsASpace(sc.ch)) { + if (IsASpace(sc.ch) || (sc.ch == '(')) { sc.SetState(SCE_C_DEFAULT|activitySet); } } else if (isStringInPreprocessor && (sc.Match('>') || sc.Match('\"') || sc.atLineEnd)) { @@ -977,7 +1106,7 @@ void SCI_METHOD LexerCPP::Lex(Sci_PositionU startPos, Sci_Position length, int i } break; case SCE_C_ESCAPESEQUENCE: - escapeSeq.digitsLeft--; + escapeSeq.consumeDigit(); if (!escapeSeq.atEscapeEnd(sc.ch)) { break; } @@ -1029,12 +1158,12 @@ void SCI_METHOD LexerCPP::Lex(Sci_PositionU startPos, Sci_Position length, int i case SCE_C_REGEX: if (sc.atLineStart) { sc.SetState(SCE_C_DEFAULT|activitySet); - } else if (! inRERange && sc.ch == '/') { + } else if (!inRERange && sc.ch == '/') { sc.Forward(); - while ((sc.ch < 0x80) && islower(sc.ch)) + while (IsLowerCase(sc.ch)) sc.Forward(); // gobble regex flags sc.SetState(SCE_C_DEFAULT|activitySet); - } else if (sc.ch == '\\' && (static_cast(sc.currentPos+1) < lineEndNext)) { + } else if (sc.ch == '\\' && ((sc.currentPos+1) < lineEndNext)) { // Gobble up the escaped character sc.Forward(); } else if (sc.ch == '[') { @@ -1060,7 +1189,7 @@ void SCI_METHOD LexerCPP::Lex(Sci_PositionU startPos, Sci_Position length, int i } break; case SCE_C_TRIPLEVERBATIM: - if (sc.Match("\"\"\"")) { + if (sc.Match(R"(""")")) { while (sc.Match('"')) { sc.Forward(); } @@ -1091,7 +1220,7 @@ void SCI_METHOD LexerCPP::Lex(Sci_PositionU startPos, Sci_Position length, int i if (sc.Match('@', '\"')) { sc.SetState(SCE_C_VERBATIM|activitySet); sc.Forward(); - } else if (options.triplequotedStrings && sc.Match("\"\"\"")) { + } else if (options.triplequotedStrings && sc.Match(R"(""")")) { sc.SetState(SCE_C_TRIPLEVERBATIM|activitySet); sc.Forward(2); } else if (options.hashquotedStrings && sc.Match('#', '\"')) { @@ -1141,7 +1270,7 @@ void SCI_METHOD LexerCPP::Lex(Sci_PositionU startPos, Sci_Position length, int i sc.SetState(SCE_C_STRINGRAW|activitySet); rawStringTerminator = ")"; for (Sci_Position termPos = sc.currentPos + 1;; termPos++) { - char chTerminator = styler.SafeGetCharAt(termPos, '('); + const char chTerminator = styler.SafeGetCharAt(termPos, '('); if (chTerminator == '(') break; rawStringTerminator += chTerminator; @@ -1171,58 +1300,71 @@ void SCI_METHOD LexerCPP::Lex(Sci_PositionU startPos, Sci_Position length, int i isIncludePreprocessor = true; } else { if (options.trackPreprocessor) { + // If #if is nested too deeply (>31 levels) the active/inactive appearance + // will stop reflecting the code. if (sc.Match("ifdef") || sc.Match("ifndef")) { - bool isIfDef = sc.Match("ifdef"); - int i = isIfDef ? 5 : 6; - std::string restOfLine = GetRestOfLine(styler, sc.currentPos + i + 1, false); + const bool isIfDef = sc.Match("ifdef"); + const int startRest = isIfDef ? 5 : 6; + std::string restOfLine = GetRestOfLine(styler, sc.currentPos + startRest + 1, false); bool foundDef = preprocessorDefinitions.find(restOfLine) != preprocessorDefinitions.end(); preproc.StartSection(isIfDef == foundDef); } else if (sc.Match("if")) { std::string restOfLine = GetRestOfLine(styler, sc.currentPos + 2, true); - bool ifGood = EvaluateExpression(restOfLine, preprocessorDefinitions); + const bool ifGood = EvaluateExpression(restOfLine, preprocessorDefinitions); preproc.StartSection(ifGood); } else if (sc.Match("else")) { + // #else is shown as active if either preceding or following section is active + // as that means that it contributed to the result. if (!preproc.CurrentIfTaken()) { + // Inactive, may become active if parent scope active + assert(sc.state == (SCE_C_PREPROCESSOR|inactiveFlag)); preproc.InvertCurrentLevel(); - activitySet = preproc.IsInactive() ? activeFlag : 0; + activitySet = preproc.ActiveState(); + // If following is active then show "else" as active if (!activitySet) - sc.ChangeState(SCE_C_PREPROCESSOR|activitySet); - } else if (!preproc.IsInactive()) { + sc.ChangeState(SCE_C_PREPROCESSOR); + } else if (preproc.IsActive()) { + // Active -> inactive + assert(sc.state == SCE_C_PREPROCESSOR); preproc.InvertCurrentLevel(); - activitySet = preproc.IsInactive() ? activeFlag : 0; - if (!activitySet) - sc.ChangeState(SCE_C_PREPROCESSOR|activitySet); + activitySet = preproc.ActiveState(); + // Continue to show "else" as active as it ends active section. } } else if (sc.Match("elif")) { // Ensure only one chosen out of #if .. #elif .. #elif .. #else .. #endif + // #elif is shown as active if either preceding or following section is active + // as that means that it contributed to the result. if (!preproc.CurrentIfTaken()) { + // Inactive, if expression true then may become active if parent scope active + assert(sc.state == (SCE_C_PREPROCESSOR|inactiveFlag)); // Similar to #if - std::string restOfLine = GetRestOfLine(styler, sc.currentPos + 2, true); - bool ifGood = EvaluateExpression(restOfLine, preprocessorDefinitions); + std::string restOfLine = GetRestOfLine(styler, sc.currentPos + 4, true); + const bool ifGood = EvaluateExpression(restOfLine, preprocessorDefinitions); if (ifGood) { preproc.InvertCurrentLevel(); - activitySet = preproc.IsInactive() ? activeFlag : 0; + activitySet = preproc.ActiveState(); if (!activitySet) - sc.ChangeState(SCE_C_PREPROCESSOR|activitySet); + sc.ChangeState(SCE_C_PREPROCESSOR); } - } else if (!preproc.IsInactive()) { + } else if (preproc.IsActive()) { + // Active -> inactive + assert(sc.state == SCE_C_PREPROCESSOR); preproc.InvertCurrentLevel(); - activitySet = preproc.IsInactive() ? activeFlag : 0; - if (!activitySet) - sc.ChangeState(SCE_C_PREPROCESSOR|activitySet); + activitySet = preproc.ActiveState(); + // Continue to show "elif" as active as it ends active section. } } else if (sc.Match("endif")) { preproc.EndSection(); - activitySet = preproc.IsInactive() ? activeFlag : 0; + activitySet = preproc.ActiveState(); sc.ChangeState(SCE_C_PREPROCESSOR|activitySet); } else if (sc.Match("define")) { - if (options.updatePreprocessor && !preproc.IsInactive()) { + if (options.updatePreprocessor && preproc.IsActive()) { std::string restOfLine = GetRestOfLine(styler, sc.currentPos + 6, true); size_t startName = 0; while ((startName < restOfLine.length()) && IsSpaceOrTab(restOfLine[startName])) startName++; size_t endName = startName; - while ((endName < restOfLine.length()) && setWord.Contains(static_cast(restOfLine[endName]))) + while ((endName < restOfLine.length()) && setWord.Contains(restOfLine[endName])) endName++; std::string key = restOfLine.substr(startName, endName-startName); if ((endName < restOfLine.length()) && (restOfLine.at(endName) == '(')) { @@ -1246,13 +1388,15 @@ void SCI_METHOD LexerCPP::Lex(Sci_PositionU startPos, Sci_Position length, int i while ((startValue < restOfLine.length()) && IsSpaceOrTab(restOfLine[startValue])) startValue++; std::string value = restOfLine.substr(startValue); + if (OnlySpaceOrTab(value)) + value = "1"; // No value defaults to 1 preprocessorDefinitions[key] = value; ppDefineHistory.push_back(PPDefinition(lineCurrent, key, value)); definitionsChanged = true; } } } else if (sc.Match("undef")) { - if (options.updatePreprocessor && !preproc.IsInactive()) { + if (options.updatePreprocessor && preproc.IsActive()) { const std::string restOfLine = GetRestOfLine(styler, sc.currentPos + 5, false); std::vector tokens = Tokenize(restOfLine); if (tokens.size() >= 1) { @@ -1294,7 +1438,7 @@ void SCI_METHOD LexerCPP::Fold(Sci_PositionU startPos, Sci_Position length, int LexAccessor styler(pAccess); - Sci_PositionU endPos = startPos + length; + const Sci_PositionU endPos = startPos + length; int visibleChars = 0; bool inLineComment = false; Sci_Position lineCurrent = styler.GetLine(startPos); @@ -1309,12 +1453,12 @@ void SCI_METHOD LexerCPP::Fold(Sci_PositionU startPos, Sci_Position length, int int style = MaskActive(initStyle); const bool userDefinedFoldMarkers = !options.foldExplicitStart.empty() && !options.foldExplicitEnd.empty(); for (Sci_PositionU i = startPos; i < endPos; i++) { - char ch = chNext; + const char ch = chNext; chNext = styler.SafeGetCharAt(i + 1); - int stylePrev = style; + const int stylePrev = style; style = styleNext; styleNext = MaskActive(styler.StyleAt(i + 1)); - bool atEOL = i == (lineStartNext-1); + const bool atEOL = i == (lineStartNext-1); if ((style == SCE_C_COMMENTLINE) || (style == SCE_C_COMMENTLINEDOC)) inLineComment = true; if (options.foldComment && options.foldCommentMultiline && IsStreamCommentStyle(style) && !inLineComment) { @@ -1334,7 +1478,7 @@ void SCI_METHOD LexerCPP::Fold(Sci_PositionU startPos, Sci_Position length, int } } else { if ((ch == '/') && (chNext == '/')) { - char chNext2 = styler.SafeGetCharAt(i + 2); + const char chNext2 = styler.SafeGetCharAt(i + 2); if (chNext2 == '{') { levelNext++; } else if (chNext2 == '}') { @@ -1433,6 +1577,7 @@ void LexerCPP::EvaluateTokens(std::vector &tokens, const SymbolTabl if (it != preprocessorDefinitions.end()) { val = "1"; } + tokens.erase(tokens.begin() + i + 1, tokens.begin() + i + 2); } tokens[i] = val; } else { @@ -1441,11 +1586,11 @@ void LexerCPP::EvaluateTokens(std::vector &tokens, const SymbolTabl } // Evaluate identifiers - const size_t maxIterations = 100; + constexpr size_t maxIterations = 100; size_t iterations = 0; // Limit number of iterations in case there is a recursive macro. for (size_t i = 0; (i(tokens[i][0]))) { + if (setWordStart.Contains(tokens[i][0])) { SymbolTable::const_iterator it = preprocessorDefinitions.find(tokens[i]); if (it != preprocessorDefinitions.end()) { // Tokenize value @@ -1472,7 +1617,7 @@ void LexerCPP::EvaluateTokens(std::vector &tokens, const SymbolTabl macroTokens.erase(std::remove_if(macroTokens.begin(), macroTokens.end(), OnlySpaceOrTab), macroTokens.end()); for (size_t iMacro = 0; iMacro < macroTokens.size();) { - if (setWordStart.Contains(static_cast(macroTokens[iMacro][0]))) { + if (setWordStart.Contains(macroTokens[iMacro][0])) { std::map::const_iterator itFind = arguments.find(macroTokens[iMacro]); if (itFind != arguments.end()) { // TODO: Possible that value will be expression so should insert tokenized form @@ -1495,8 +1640,8 @@ void LexerCPP::EvaluateTokens(std::vector &tokens, const SymbolTabl tokens.insert(tokens.begin() + i, macroTokens.begin(), macroTokens.end()); } } else { - // Identifier not found - tokens.erase(tokens.begin() + i); + // Identifier not found and value defaults to zero + tokens[i] = "0"; } } else { i++; @@ -1533,18 +1678,20 @@ void LexerCPP::EvaluateTokens(std::vector &tokens, const SymbolTabl } // Evaluate expressions in precedence order - enum precedence { precArithmetic, precRelative, precLogical }; - for (int prec=precArithmetic; prec <= precLogical; prec++) { + enum precedence { precMult, precAdd, precRelative + , precLogical, /* end marker */ precLast }; + for (int prec = precMult; prec < precLast; prec++) { // Looking at 3 tokens at a time so end at 2 before end for (size_t k=0; (k+2) &tokens, const SymbolTabl result = valA || valB; else if (tokens[k+1] == "&&") result = valA && valB; - char sResult[30]; - sprintf(sResult, "%d", result); std::vector::iterator itInsert = tokens.erase(tokens.begin() + k, tokens.begin() + k + 3); - tokens.insert(itInsert, sResult); + tokens.insert(itInsert, std::to_string(result)); } else { k++; } @@ -1590,9 +1735,9 @@ std::vector LexerCPP::Tokenize(const std::string &expr) const { const char *cp = expr.c_str(); while (*cp) { std::string word; - if (setWord.Contains(static_cast(*cp))) { + if (setWord.Contains(*cp)) { // Identifiers and numbers - while (setWord.Contains(static_cast(*cp))) { + while (setWord.Contains(*cp)) { word += *cp; cp++; } @@ -1601,17 +1746,17 @@ std::vector LexerCPP::Tokenize(const std::string &expr) const { word += *cp; cp++; } - } else if (setRelOp.Contains(static_cast(*cp))) { + } else if (setRelOp.Contains(*cp)) { word += *cp; cp++; - if (setRelOp.Contains(static_cast(*cp))) { + if (setRelOp.Contains(*cp)) { word += *cp; cp++; } - } else if (setLogicalOp.Contains(static_cast(*cp))) { + } else if (setLogicalOp.Contains(*cp)) { word += *cp; cp++; - if (setLogicalOp.Contains(static_cast(*cp))) { + if (setLogicalOp.Contains(*cp)) { word += *cp; cp++; } @@ -1631,7 +1776,7 @@ bool LexerCPP::EvaluateExpression(const std::string &expr, const SymbolTable &pr EvaluateTokens(tokens, preprocessorDefinitions); // "0" or "" -> false else true - bool isFalse = tokens.empty() || + const bool isFalse = tokens.empty() || ((tokens.size() == 1) && ((tokens[0] == "") || tokens[0] == "0")); return !isFalse; } diff --git a/src/stc/scintilla/lexers/LexCSS.cxx b/src/stc/scintilla/lexers/LexCSS.cxx index 19345af547..c1a86f5371 100644 --- a/src/stc/scintilla/lexers/LexCSS.cxx +++ b/src/stc/scintilla/lexers/LexCSS.cxx @@ -1,7 +1,8 @@ // Scintilla source code edit control +// Encoding: UTF-8 /** @file LexCSS.cxx ** Lexer for Cascading Style Sheets - ** Written by Jakub Vrána + ** Written by Jakub Vrána ** Improved by Philippe Lhoste (CSS2) ** Improved by Ross McKay (SCSS mode; see http://sass-lang.com/ ) **/ @@ -31,9 +32,7 @@ #include "CharacterSet.h" #include "LexerModule.h" -#ifdef SCI_NAMESPACE using namespace Scintilla; -#endif static inline bool IsAWordChar(const unsigned int ch) { @@ -347,6 +346,7 @@ static void ColouriseCssDoc(Sci_PositionU startPos, Sci_Position length, int ini case SCE_CSS_DEFAULT: if (isLessDocument) // give priority to pseudo elements break; + // Falls through. case SCE_CSS_VALUE: lastStateVar = sc.state; sc.SetState(SCE_CSS_VARIABLE); diff --git a/src/stc/scintilla/lexers/LexCaml.cxx b/src/stc/scintilla/lexers/LexCaml.cxx index df87815419..1339b5dcc7 100644 --- a/src/stc/scintilla/lexers/LexCaml.cxx +++ b/src/stc/scintilla/lexers/LexCaml.cxx @@ -37,6 +37,10 @@ #include "CharacterSet.h" #include "LexerModule.h" +#if defined(__clang__) +#pragma clang diagnostic ignored "-Wcomma" +#endif + // Since the Microsoft __iscsym[f] funcs are not ANSI... inline int iscaml(int c) {return isalnum(c) || c == '_';} inline int iscamlf(int c) {return isalpha(c) || c == '_';} @@ -46,9 +50,7 @@ static const int baseT[24] = { 0, 0, 8, 0, 0, 0, 0, 0, 0, 0, 0,16 /* M - X */ }; -#ifdef SCI_NAMESPACE using namespace Scintilla; -#endif #ifdef BUILD_AS_EXTERNAL_LEXER /* @@ -368,6 +370,7 @@ void ColouriseCamlDoc( break; }/* else // fall through for SML char literal (handle like string) */ + // Falls through. case SCE_CAML_STRING: // [try to] interpret as [additional] [SML char/] string literal char diff --git a/src/stc/scintilla/lexers/LexCmake.cxx b/src/stc/scintilla/lexers/LexCmake.cxx index 1cbca36113..e3835c5c35 100644 --- a/src/stc/scintilla/lexers/LexCmake.cxx +++ b/src/stc/scintilla/lexers/LexCmake.cxx @@ -24,9 +24,7 @@ #include "CharacterSet.h" #include "LexerModule.h" -#ifdef SCI_NAMESPACE using namespace Scintilla; -#endif static bool isCmakeNumber(char ch) { @@ -87,10 +85,11 @@ static int calculateFoldCmake(Sci_PositionU start, Sci_PositionU end, int foldle if ( CompareCaseInsensitive(s, "IF") == 0 || CompareCaseInsensitive(s, "WHILE") == 0 || CompareCaseInsensitive(s, "MACRO") == 0 || CompareCaseInsensitive(s, "FOREACH") == 0 - || CompareCaseInsensitive(s, "ELSEIF") == 0 ) + || CompareCaseInsensitive(s, "FUNCTION") == 0 || CompareCaseInsensitive(s, "ELSEIF") == 0) newFoldlevel++; else if ( CompareCaseInsensitive(s, "ENDIF") == 0 || CompareCaseInsensitive(s, "ENDWHILE") == 0 - || CompareCaseInsensitive(s, "ENDMACRO") == 0 || CompareCaseInsensitive(s, "ENDFOREACH") == 0) + || CompareCaseInsensitive(s, "ENDMACRO") == 0 || CompareCaseInsensitive(s, "ENDFOREACH") == 0 + || CompareCaseInsensitive(s, "ENDFUNCTION") == 0) newFoldlevel--; else if ( bElse && CompareCaseInsensitive(s, "ELSEIF") == 0 ) newFoldlevel++; diff --git a/src/stc/scintilla/lexers/LexCoffeeScript.cxx b/src/stc/scintilla/lexers/LexCoffeeScript.cxx index 63ee172e22..a001623354 100644 --- a/src/stc/scintilla/lexers/LexCoffeeScript.cxx +++ b/src/stc/scintilla/lexers/LexCoffeeScript.cxx @@ -14,7 +14,8 @@ #include #include -#include "Platform.h" +#include + #include "ILexer.h" #include "Scintilla.h" #include "SciLexer.h" @@ -26,9 +27,7 @@ #include "CharacterSet.h" #include "LexerModule.h" -#ifdef SCI_NAMESPACE using namespace Scintilla; -#endif static bool IsSpaceEquiv(int state) { return (state == SCE_COFFEESCRIPT_DEFAULT @@ -427,7 +426,7 @@ static void FoldCoffeeScriptDoc(Sci_PositionU startPos, Sci_Position length, int } const int levelAfterComments = indentNext & SC_FOLDLEVELNUMBERMASK; - const int levelBeforeComments = Platform::Maximum(indentCurrentLevel,levelAfterComments); + const int levelBeforeComments = std::max(indentCurrentLevel,levelAfterComments); // Now set all the indent levels on the lines we skipped // Do this from end to start. Once we encounter one line diff --git a/src/stc/scintilla/lexers/LexConf.cxx b/src/stc/scintilla/lexers/LexConf.cxx index 2eed51b714..73fbe46ef2 100644 --- a/src/stc/scintilla/lexers/LexConf.cxx +++ b/src/stc/scintilla/lexers/LexConf.cxx @@ -27,9 +27,7 @@ #include "CharacterSet.h" #include "LexerModule.h" -#ifdef SCI_NAMESPACE using namespace Scintilla; -#endif static void ColouriseConfDoc(Sci_PositionU startPos, Sci_Position length, int, WordList *keywordLists[], Accessor &styler) { diff --git a/src/stc/scintilla/lexers/LexCrontab.cxx b/src/stc/scintilla/lexers/LexCrontab.cxx index b500d2d282..7f6d5fb0c3 100644 --- a/src/stc/scintilla/lexers/LexCrontab.cxx +++ b/src/stc/scintilla/lexers/LexCrontab.cxx @@ -25,9 +25,7 @@ #include "CharacterSet.h" #include "LexerModule.h" -#ifdef SCI_NAMESPACE using namespace Scintilla; -#endif static void ColouriseNncrontabDoc(Sci_PositionU startPos, Sci_Position length, int, WordList *keywordLists[], Accessor &styler) diff --git a/src/stc/scintilla/lexers/LexCsound.cxx b/src/stc/scintilla/lexers/LexCsound.cxx index 6d065c8d1d..24603801e5 100644 --- a/src/stc/scintilla/lexers/LexCsound.cxx +++ b/src/stc/scintilla/lexers/LexCsound.cxx @@ -24,9 +24,7 @@ #include "CharacterSet.h" #include "LexerModule.h" -#ifdef SCI_NAMESPACE using namespace Scintilla; -#endif static inline bool IsAWordChar(const int ch) { return (ch < 0x80) && (isalnum(ch) || ch == '.' || diff --git a/src/stc/scintilla/lexers/LexD.cxx b/src/stc/scintilla/lexers/LexD.cxx index 7c0177e99d..a661b4f133 100644 --- a/src/stc/scintilla/lexers/LexD.cxx +++ b/src/stc/scintilla/lexers/LexD.cxx @@ -27,10 +27,9 @@ #include "CharacterSet.h" #include "LexerModule.h" #include "OptionSet.h" +#include "DefaultLexer.h" -#ifdef SCI_NAMESPACE using namespace Scintilla; -#endif /* Nested comments require keeping the value of the nesting level for every position in the document. But since scintilla always styles line by line, @@ -145,7 +144,7 @@ struct OptionSetD : public OptionSet { } }; -class LexerD : public ILexer { +class LexerD : public DefaultLexer { bool caseSensitive; WordList keywords; WordList keywords2; @@ -158,34 +157,38 @@ class LexerD : public ILexer { OptionSetD osD; public: LexerD(bool caseSensitive_) : + DefaultLexer("D", SCLEX_D), caseSensitive(caseSensitive_) { } virtual ~LexerD() { } - void SCI_METHOD Release() { + void SCI_METHOD Release() override { delete this; } - int SCI_METHOD Version() const { - return lvOriginal; + int SCI_METHOD Version() const override { + return lvIdentity; } - const char * SCI_METHOD PropertyNames() { + const char * SCI_METHOD PropertyNames() override { return osD.PropertyNames(); } - int SCI_METHOD PropertyType(const char *name) { + int SCI_METHOD PropertyType(const char *name) override { return osD.PropertyType(name); } - const char * SCI_METHOD DescribeProperty(const char *name) { + const char * SCI_METHOD DescribeProperty(const char *name) override { return osD.DescribeProperty(name); } - Sci_Position SCI_METHOD PropertySet(const char *key, const char *val); - const char * SCI_METHOD DescribeWordListSets() { + Sci_Position SCI_METHOD PropertySet(const char *key, const char *val) override; + const char * SCI_METHOD PropertyGet(const char *key) override { + return osD.PropertyGet(key); + } + const char * SCI_METHOD DescribeWordListSets() override { return osD.DescribeWordListSets(); } - Sci_Position SCI_METHOD WordListSet(int n, const char *wl); - void SCI_METHOD Lex(Sci_PositionU startPos, Sci_Position length, int initStyle, IDocument *pAccess); - void SCI_METHOD Fold(Sci_PositionU startPos, Sci_Position length, int initStyle, IDocument *pAccess); + Sci_Position SCI_METHOD WordListSet(int n, const char *wl) override; + void SCI_METHOD Lex(Sci_PositionU startPos, Sci_Position length, int initStyle, IDocument *pAccess) override; + void SCI_METHOD Fold(Sci_PositionU startPos, Sci_Position length, int initStyle, IDocument *pAccess) override; - void * SCI_METHOD PrivateCall(int, void *) { + void * SCI_METHOD PrivateCall(int, void *) override { return 0; } diff --git a/src/stc/scintilla/lexers/LexDMAP.cxx b/src/stc/scintilla/lexers/LexDMAP.cxx index eb43cde6d3..91b10c29bb 100644 --- a/src/stc/scintilla/lexers/LexDMAP.cxx +++ b/src/stc/scintilla/lexers/LexDMAP.cxx @@ -25,9 +25,7 @@ #include "LexerModule.h" /***************************************/ -#ifdef SCI_NAMESPACE using namespace Scintilla; -#endif /***********************************************/ static inline bool IsAWordChar(const int ch) { diff --git a/src/stc/scintilla/lexers/LexDMIS.cxx b/src/stc/scintilla/lexers/LexDMIS.cxx index 0493a69cab..66e68b0409 100644 --- a/src/stc/scintilla/lexers/LexDMIS.cxx +++ b/src/stc/scintilla/lexers/LexDMIS.cxx @@ -21,10 +21,9 @@ #include "StyleContext.h" #include "CharacterSet.h" #include "LexerModule.h" +#include "DefaultLexer.h" -#ifdef SCI_NAMESPACE using namespace Scintilla; -#endif static const char *const DMISWordListDesc[] = { @@ -38,7 +37,7 @@ static const char *const DMISWordListDesc[] = { }; -class LexerDMIS : public ILexer +class LexerDMIS : public DefaultLexer { private: char *m_wordListSets; @@ -56,33 +55,37 @@ class LexerDMIS : public ILexer LexerDMIS(void); virtual ~LexerDMIS(void); - int SCI_METHOD Version() const { - return lvOriginal; + int SCI_METHOD Version() const override { + return lvIdentity; } - void SCI_METHOD Release() { + void SCI_METHOD Release() override { delete this; } - const char * SCI_METHOD PropertyNames() { + const char * SCI_METHOD PropertyNames() override { return NULL; } - int SCI_METHOD PropertyType(const char *) { + int SCI_METHOD PropertyType(const char *) override { return -1; } - const char * SCI_METHOD DescribeProperty(const char *) { + const char * SCI_METHOD DescribeProperty(const char *) override { return NULL; } - Sci_Position SCI_METHOD PropertySet(const char *, const char *) { + Sci_Position SCI_METHOD PropertySet(const char *, const char *) override { return -1; } - Sci_Position SCI_METHOD WordListSet(int n, const char *wl); + const char * SCI_METHOD PropertyGet(const char *) override { + return NULL; + } - void * SCI_METHOD PrivateCall(int, void *) { + Sci_Position SCI_METHOD WordListSet(int n, const char *wl) override; + + void * SCI_METHOD PrivateCall(int, void *) override { return NULL; } @@ -90,9 +93,9 @@ class LexerDMIS : public ILexer return new LexerDMIS; } - const char * SCI_METHOD DescribeWordListSets(); - void SCI_METHOD Lex(Sci_PositionU startPos, Sci_Position lengthDoc, int initStyle, IDocument *pAccess); - void SCI_METHOD Fold(Sci_PositionU startPos, Sci_Position lengthDoc, int initStyle, IDocument *pAccess); + 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; }; @@ -130,7 +133,7 @@ void SCI_METHOD LexerDMIS::InitWordListSets(void) } -LexerDMIS::LexerDMIS(void) { +LexerDMIS::LexerDMIS(void) : DefaultLexer("DMIS", SCLEX_DMIS) { this->InitWordListSets(); this->m_majorWords.Clear(); diff --git a/src/stc/scintilla/lexers/LexDataflex.cxx b/src/stc/scintilla/lexers/LexDataflex.cxx new file mode 100644 index 0000000000..f1f9275999 --- /dev/null +++ b/src/stc/scintilla/lexers/LexDataflex.cxx @@ -0,0 +1,614 @@ +// Scintilla source code edit control +/** @file LexDataflex.cxx + ** Lexer for DataFlex. + ** Based on LexPascal.cxx + ** Written by Wil van Antwerpen, June 2019 + **/ + +/* +// The License.txt file describes the conditions under which this software may be distributed. + +A few words about features of LexDataflex... + +Generally speaking LexDataflex tries to support all available DataFlex features (up +to DataFlex 19.1 at this time). + +~ FOLDING: + +Folding is supported in the following cases: + +- Folding of stream-like comments +- Folding of groups of consecutive line comments +- Folding of preprocessor blocks (the following preprocessor blocks are +supported: #IFDEF, #IFNDEF, #ENDIF and #HEADER / #ENDHEADER +blocks), +- Folding of code blocks on appropriate keywords (the following code blocks are +supported: "begin, struct, type, case / end" blocks, class & object +declarations and interface declarations) + +Remarks: + +- We pass 4 arrays to the lexer: +1. The DataFlex keyword list, these are normal DataFlex keywords +2. The Scope Open list, for example, begin / procedure / while +3. The Scope Close list, for example, end / end_procedure / loop +4. Operator list, for ex. + / - / * / Lt / iand +These lists are all mutually exclusive, scope open words should not be in the keyword list and vice versa + +- Folding of code blocks tries to handle all special cases in which folding +should not occur. + +~ KEYWORDS: + +The list of keywords that can be used in dataflex.properties file (up to DataFlex +19.1): + +- Keywords: .. snipped .. see dataflex.properties file. + +*/ + +#include +#include +#include +#include +#include +#include + +#include "ILexer.h" +#include "Scintilla.h" +#include "SciLexer.h" + +#include "WordList.h" +#include "LexAccessor.h" +#include "Accessor.h" +#include "StyleContext.h" +#include "CharacterSet.h" +#include "LexerModule.h" + +using namespace Scintilla; + + +static void GetRangeLowered(Sci_PositionU start, + Sci_PositionU end, + Accessor &styler, + char *s, + Sci_PositionU len) { + Sci_PositionU i = 0; + while ((i < end - start + 1) && (i < len-1)) { + s[i] = static_cast(tolower(styler[start + i])); + i++; + } + s[i] = '\0'; +} + +static void GetForwardRangeLowered(Sci_PositionU start, + CharacterSet &charSet, + Accessor &styler, + char *s, + Sci_PositionU len) { + Sci_PositionU i = 0; + while ((i < len-1) && charSet.Contains(styler.SafeGetCharAt(start + i))) { + s[i] = static_cast(tolower(styler.SafeGetCharAt(start + i))); + i++; + } + s[i] = '\0'; + +} + +enum { + stateInICode = 0x1000, + stateSingleQuoteOpen = 0x2000, + stateDoubleQuoteOpen = 0x4000, + stateFoldInPreprocessor = 0x0100, + stateFoldInCaseStatement = 0x0200, + stateFoldInPreprocessorLevelMask = 0x00FF, + stateFoldMaskAll = 0x0FFF +}; + + +static bool IsFirstDataFlexWord(Sci_Position pos, Accessor &styler) { + Sci_Position line = styler.GetLine(pos); + Sci_Position start_pos = styler.LineStart(line); + for (Sci_Position i = start_pos; i < pos; i++) { + char ch = styler.SafeGetCharAt(i); + if (!(ch == ' ' || ch == '\t')) + return false; + } + return true; +} + + +inline bool IsADataFlexField(int ch) { + return (ch == '.'); +} + + +size_t _strnlen(const char *s, size_t max) { + const char *end = (const char*)memchr((void *)s, 0, max); + return end ? (size_t)(end - s) : max; +} + + +static void ClassifyDataFlexWord(WordList *keywordlists[], StyleContext &sc, Accessor &styler) { + WordList& keywords = *keywordlists[0]; + WordList& scopeOpen = *keywordlists[1]; + WordList& scopeClosed = *keywordlists[2]; + WordList& operators = *keywordlists[3]; + + char s[100]; + int oldState; + int newState; + size_t tokenlen; + + oldState = sc.state; + newState = oldState; + sc.GetCurrentLowered(s, sizeof(s)); + tokenlen = _strnlen(s,sizeof(s)); + if (keywords.InList(s)) { + // keywords in DataFlex can be used as table column names (file.field) and as such they + // should not be characterized as a keyword. So test for that. + // for ex. somebody using date as field name. + if (!IsADataFlexField(sc.GetRelative(-static_cast(tokenlen+1)))) { + newState = SCE_DF_WORD; + } + } + if (oldState == newState) { + if ((scopeOpen.InList(s) || scopeClosed.InList(s)) && (strcmp(s, "for") != 0) && (strcmp(s, "repeat") != 0)) { + // scope words in DataFlex can be used as table column names (file.field) and as such they + // should not be characterized as a scope word. So test for that. + // for ex. somebody using procedure for field name. + if (!IsADataFlexField(sc.GetRelative(-static_cast(tokenlen+1)))) { + newState = SCE_DF_SCOPEWORD; + } + } + // no code folding on the next words, but just want to paint them like keywords (as they are) (??? doesn't the code to the opposite?) + if (strcmp(s, "if") == 0 || + strcmp(s, "ifnot") == 0 || + strcmp(s, "case") == 0 || + strcmp(s, "else") == 0 ) { + newState = SCE_DF_SCOPEWORD; + } + } + if (oldState != newState && newState == SCE_DF_WORD) { + // a for loop must have for at the start of the line, for is also used in "define abc for 123" + if ( (strcmp(s, "for") == 0) && (IsFirstDataFlexWord(sc.currentPos-3, styler)) ) { + newState = SCE_DF_SCOPEWORD; + } + } + if (oldState != newState && newState == SCE_DF_WORD) { + // a repeat loop must have repeat at the start of the line, repeat is also used in 'move (repeat("d",5)) to sFoo' + if ( (strcmp(s, "repeat") == 0) && (IsFirstDataFlexWord(sc.currentPos-6, styler)) ) { + newState = SCE_DF_SCOPEWORD; + } + } + if (oldState == newState) { + if (operators.InList(s)) { + newState = SCE_DF_OPERATOR; + } + } + + if (oldState != newState) { + sc.ChangeState(newState); + } + sc.SetState(SCE_DF_DEFAULT); +} + +static void ColouriseDataFlexDoc(Sci_PositionU startPos, Sci_Position length, int initStyle, WordList *keywordlists[], + Accessor &styler) { +// bool bSmartHighlighting = styler.GetPropertyInt("lexer.dataflex.smart.highlighting", 1) != 0; + + CharacterSet setWordStart(CharacterSet::setAlpha, "_$#@", 0x80, true); + CharacterSet setWord(CharacterSet::setAlphaNum, "_$#@", 0x80, true); + CharacterSet setNumber(CharacterSet::setDigits, ".-+eE"); + CharacterSet setHexNumber(CharacterSet::setDigits, "abcdefABCDEF"); + CharacterSet setOperator(CharacterSet::setNone, "*+-/<=>^"); + + Sci_Position curLine = styler.GetLine(startPos); + int curLineState = curLine > 0 ? styler.GetLineState(curLine - 1) : 0; + + StyleContext sc(startPos, length, initStyle, styler); + + for (; sc.More(); sc.Forward()) { + if (sc.atLineEnd) { + // Update the line state, so it can be seen by next line + curLine = styler.GetLine(sc.currentPos); + styler.SetLineState(curLine, curLineState); + } + + // Determine if the current state should terminate. + switch (sc.state) { + case SCE_DF_NUMBER: + if (!setNumber.Contains(sc.ch) || (sc.ch == '.' && sc.chNext == '.')) { + sc.SetState(SCE_DF_DEFAULT); + } else if (sc.ch == '-' || sc.ch == '+') { + if (sc.chPrev != 'E' && sc.chPrev != 'e') { + sc.SetState(SCE_DF_DEFAULT); + } + } + break; + case SCE_DF_IDENTIFIER: + if (!setWord.Contains(sc.ch)) { + ClassifyDataFlexWord(keywordlists, sc, styler); + } + break; + case SCE_DF_HEXNUMBER: + if (!(setHexNumber.Contains(sc.ch) || sc.ch == 'I') ) { // in |CI$22a we also want to color the "I" + sc.SetState(SCE_DF_DEFAULT); + } + break; + case SCE_DF_METATAG: + if (sc.atLineStart || sc.chPrev == '}') { + sc.SetState(SCE_DF_DEFAULT); + } + break; + case SCE_DF_PREPROCESSOR: + if (sc.atLineStart || IsASpaceOrTab(sc.ch)) { + sc.SetState(SCE_DF_DEFAULT); + } + break; + case SCE_DF_IMAGE: + if (sc.atLineStart && sc.Match("/*")) { + sc.Forward(); // these characters are still part of the DF Image + sc.ForwardSetState(SCE_DF_DEFAULT); + } + break; + case SCE_DF_PREPROCESSOR2: + // we don't have inline comments or preprocessor2 commands + //if (sc.Match('*', ')')) { + // sc.Forward(); + // sc.ForwardSetState(SCE_DF_DEFAULT); + //} + break; + case SCE_DF_COMMENTLINE: + if (sc.atLineStart) { + sc.SetState(SCE_DF_DEFAULT); + } + break; + case SCE_DF_STRING: + if (sc.atLineEnd) { + sc.ChangeState(SCE_DF_STRINGEOL); + } else if (sc.ch == '\'' && sc.chNext == '\'') { + sc.Forward(); + } else if (sc.ch == '\"' && sc.chNext == '\"') { + sc.Forward(); + } else if (sc.ch == '\'' || sc.ch == '\"') { + if (sc.ch == '\'' && (curLineState & stateSingleQuoteOpen) ) { + curLineState &= ~(stateSingleQuoteOpen); + sc.ForwardSetState(SCE_DF_DEFAULT); + } + else if (sc.ch == '\"' && (curLineState & stateDoubleQuoteOpen) ) { + curLineState &= ~(stateDoubleQuoteOpen); + sc.ForwardSetState(SCE_DF_DEFAULT); + } + } + break; + case SCE_DF_STRINGEOL: + if (sc.atLineStart) { + sc.SetState(SCE_DF_DEFAULT); + } + break; + case SCE_DF_SCOPEWORD: + //if (!setHexNumber.Contains(sc.ch) && sc.ch != '$') { + // sc.SetState(SCE_DF_DEFAULT); + //} + break; + case SCE_DF_OPERATOR: +// if (bSmartHighlighting && sc.chPrev == ';') { +// curLineState &= ~(stateInProperty | stateInExport); +// } + sc.SetState(SCE_DF_DEFAULT); + break; + case SCE_DF_ICODE: + if (sc.atLineStart || IsASpace(sc.ch) || isoperator(sc.ch)) { + sc.SetState(SCE_DF_DEFAULT); + } + break; + } + + // Determine if a new state should be entered. + if (sc.state == SCE_DF_DEFAULT) { + if (IsADigit(sc.ch)) { + sc.SetState(SCE_DF_NUMBER); + } else if (sc.Match('/', '/') || sc.Match("#REM")) { + sc.SetState(SCE_DF_COMMENTLINE); + } else if ((sc.ch == '#' && !sc.Match("#REM")) && IsFirstDataFlexWord(sc.currentPos, styler)) { + sc.SetState(SCE_DF_PREPROCESSOR); + // || (sc.ch == '|' && sc.chNext == 'C' && sc.GetRelativeCharacter(2) == 'I' && sc.GetRelativeCharacter(3) == '$') ) { + } else if ((sc.ch == '$' && ((!setWord.Contains(sc.chPrev)) || sc.chPrev == 'I' ) ) || (sc.Match("|CI$")) ) { + sc.SetState(SCE_DF_HEXNUMBER); // start with $ and previous character not in a..zA..Z0..9 excluding "I" OR start with |CI$ + } else if (setWordStart.Contains(sc.ch)) { + sc.SetState(SCE_DF_IDENTIFIER); + } else if (sc.ch == '{') { + sc.SetState(SCE_DF_METATAG); + //} else if (sc.Match("(*$")) { + // sc.SetState(SCE_DF_PREPROCESSOR2); + } else if (sc.ch == '/' && setWord.Contains(sc.chNext) && sc.atLineStart) { + sc.SetState(SCE_DF_IMAGE); + // sc.Forward(); // Eat the * so it isn't used for the end of the comment + } else if (sc.ch == '\'' || sc.ch == '\"') { + if (sc.ch == '\'' && !(curLineState & stateDoubleQuoteOpen)) { + curLineState |= stateSingleQuoteOpen; + } else if (sc.ch == '\"' && !(curLineState & stateSingleQuoteOpen)) { + curLineState |= stateDoubleQuoteOpen; + } + sc.SetState(SCE_DF_STRING); + } else if (setOperator.Contains(sc.ch)) { + sc.SetState(SCE_DF_OPERATOR); +// } else if (curLineState & stateInICode) { + // ICode start ! in a string followed by close string mark is not icode + } else if ((sc.ch == '!') && !(sc.ch == '!' && ((sc.chNext == '\"') || (sc.ch == '\'')) )) { + sc.SetState(SCE_DF_ICODE); + } + } + } + + if (sc.state == SCE_DF_IDENTIFIER && setWord.Contains(sc.chPrev)) { + ClassifyDataFlexWord(keywordlists, sc, styler); + } + + sc.Complete(); +} + +static bool IsStreamCommentStyle(int style) { + return style == SCE_DF_IMAGE; +} + +static bool IsCommentLine(Sci_Position line, Accessor &styler) { + Sci_Position pos = styler.LineStart(line); + Sci_Position eolPos = styler.LineStart(line + 1) - 1; + for (Sci_Position i = pos; i < eolPos; i++) { + char ch = styler[i]; + char chNext = styler.SafeGetCharAt(i + 1); + int style = styler.StyleAt(i); + if (ch == '/' && chNext == '/' && style == SCE_DF_COMMENTLINE) { + return true; + } else if (!IsASpaceOrTab(ch)) { + return false; + } + } + return false; +} + + + +static unsigned int GetFoldInPreprocessorLevelFlag(int lineFoldStateCurrent) { + return lineFoldStateCurrent & stateFoldInPreprocessorLevelMask; +} + +static void SetFoldInPreprocessorLevelFlag(int &lineFoldStateCurrent, unsigned int nestLevel) { + lineFoldStateCurrent &= ~stateFoldInPreprocessorLevelMask; + lineFoldStateCurrent |= nestLevel & stateFoldInPreprocessorLevelMask; +} + +static int ClassifyDataFlexPreprocessorFoldPoint(int &levelCurrent, int &lineFoldStateCurrent, + Sci_PositionU startPos, Accessor &styler) { + CharacterSet setWord(CharacterSet::setAlpha); + + char s[100]; // Size of the longest possible keyword + one additional character + null + GetForwardRangeLowered(startPos, setWord, styler, s, sizeof(s)); + size_t iLen = _strnlen(s,sizeof(s)); + size_t iWordSize = 0; + + unsigned int nestLevel = GetFoldInPreprocessorLevelFlag(lineFoldStateCurrent); + + if (strcmp(s, "command") == 0 || + // The #if/#ifdef etcetera commands are not currently foldable as it is easy to write code that + // breaks the collaps logic, so we keep things simple and not include that for now. + strcmp(s, "header") == 0) { + nestLevel++; + SetFoldInPreprocessorLevelFlag(lineFoldStateCurrent, nestLevel); + lineFoldStateCurrent |= stateFoldInPreprocessor; + levelCurrent++; + iWordSize = iLen; + } else if (strcmp(s, "endcommand") == 0 || + strcmp(s, "endheader") == 0) { + nestLevel--; + SetFoldInPreprocessorLevelFlag(lineFoldStateCurrent, nestLevel); + if (nestLevel == 0) { + lineFoldStateCurrent &= ~stateFoldInPreprocessor; + } + levelCurrent--; + iWordSize = iLen; + if (levelCurrent < SC_FOLDLEVELBASE) { + levelCurrent = SC_FOLDLEVELBASE; + } + } + return static_cast(iWordSize); +} + + +static void ClassifyDataFlexWordFoldPoint(int &levelCurrent, int &lineFoldStateCurrent, + Sci_PositionU lastStart, Sci_PositionU currentPos, WordList *[], Accessor &styler) { + char s[100]; + + // property fold.dataflex.compilerlist + // Set to 1 for enabling the code folding feature in *.prn files + bool foldPRN = styler.GetPropertyInt("fold.dataflex.compilerlist",0) != 0; + + GetRangeLowered(lastStart, currentPos, styler, s, sizeof(s)); + + if (strcmp(s, "case") == 0) { + lineFoldStateCurrent |= stateFoldInCaseStatement; + } else if (strcmp(s, "begin") == 0) { + levelCurrent++; + } else if (strcmp(s, "for") == 0 || + strcmp(s, "while") == 0 || + strcmp(s, "repeat") == 0 || + strcmp(s, "for_all") == 0 || + strcmp(s, "struct") == 0 || + strcmp(s, "type") == 0 || + strcmp(s, "begin_row") == 0 || + strcmp(s, "item_list") == 0 || + strcmp(s, "begin_constraints") == 0 || + strcmp(s, "begin_transaction") == 0 || + strcmp(s, "enum_list") == 0 || + strcmp(s, "class") == 0 || + strcmp(s, "object") == 0 || + strcmp(s, "cd_popup_object") == 0 || + strcmp(s, "procedure") == 0 || + strcmp(s, "procedure_section") == 0 || + strcmp(s, "function") == 0 ) { + if ((IsFirstDataFlexWord(lastStart, styler )) || foldPRN) { + levelCurrent++; + } + } else if (strcmp(s, "end") == 0) { // end is not always the first keyword, for example "case end" + levelCurrent--; + if (levelCurrent < SC_FOLDLEVELBASE) { + levelCurrent = SC_FOLDLEVELBASE; + } + } else if (strcmp(s, "loop") == 0 || + strcmp(s, "until") == 0 || + strcmp(s, "end_class") == 0 || + strcmp(s, "end_object") == 0 || + strcmp(s, "cd_end_object") == 0 || + strcmp(s, "end_procedure") == 0 || + strcmp(s, "end_function") == 0 || + strcmp(s, "end_for_all") == 0 || + strcmp(s, "end_struct") == 0 || + strcmp(s, "end_type") == 0 || + strcmp(s, "end_row") == 0 || + strcmp(s, "end_item_list") == 0 || + strcmp(s, "end_constraints") == 0 || + strcmp(s, "end_transaction") == 0 || + strcmp(s, "end_enum_list") == 0 ) { + // lineFoldStateCurrent &= ~stateFoldInRecord; + if ((IsFirstDataFlexWord(lastStart, styler )) || foldPRN) { + levelCurrent--; + if (levelCurrent < SC_FOLDLEVELBASE) { + levelCurrent = SC_FOLDLEVELBASE; + } + } + } + +} + + +static void ClassifyDataFlexMetaDataFoldPoint(int &levelCurrent, + Sci_PositionU lastStart, Sci_PositionU currentPos, WordList *[], Accessor &styler) { + char s[100]; + + GetRangeLowered(lastStart, currentPos, styler, s, sizeof(s)); + + if (strcmp(s, "#beginsection") == 0) { + levelCurrent++; + } else if (strcmp(s, "#endsection") == 0) { + levelCurrent--; + if (levelCurrent < SC_FOLDLEVELBASE) { + levelCurrent = SC_FOLDLEVELBASE; + } + } + +} + +static void FoldDataFlexDoc(Sci_PositionU startPos, Sci_Position length, int initStyle, WordList *keywordlists[], + Accessor &styler) { + bool foldComment = styler.GetPropertyInt("fold.comment") != 0; + bool foldPreprocessor = styler.GetPropertyInt("fold.preprocessor") != 0; + bool foldCompact = styler.GetPropertyInt("fold.compact", 1) != 0; + Sci_PositionU endPos = startPos + length; + int visibleChars = 0; + Sci_Position lineCurrent = styler.GetLine(startPos); + int levelPrev = styler.LevelAt(lineCurrent) & SC_FOLDLEVELNUMBERMASK; + int levelCurrent = levelPrev; + int lineFoldStateCurrent = lineCurrent > 0 ? styler.GetLineState(lineCurrent - 1) & stateFoldMaskAll : 0; + char chNext = styler[startPos]; + int styleNext = styler.StyleAt(startPos); + int style = initStyle; + int iWordSize; + + Sci_Position lastStart = 0; + CharacterSet setWord(CharacterSet::setAlphaNum, "_$#@", 0x80, true); + + for (Sci_PositionU i = startPos; i < endPos; i++) { + char ch = chNext; + chNext = styler.SafeGetCharAt(i + 1); + int stylePrev = style; + style = styleNext; + styleNext = styler.StyleAt(i + 1); + bool atEOL = (ch == '\r' && chNext != '\n') || (ch == '\n'); + + if (foldComment && IsStreamCommentStyle(style)) { + if (!IsStreamCommentStyle(stylePrev)) { + levelCurrent++; + } else if (!IsStreamCommentStyle(styleNext)) { + levelCurrent--; + } + } + if (foldComment && atEOL && IsCommentLine(lineCurrent, styler)) + { + if (!IsCommentLine(lineCurrent - 1, styler) + && IsCommentLine(lineCurrent + 1, styler)) + levelCurrent++; + else if (IsCommentLine(lineCurrent - 1, styler) + && !IsCommentLine(lineCurrent+1, styler)) + levelCurrent--; + } + if (foldPreprocessor) { + if (style == SCE_DF_PREPROCESSOR) { + iWordSize = ClassifyDataFlexPreprocessorFoldPoint(levelCurrent, lineFoldStateCurrent, i + 1, styler); + //} else if (style == SCE_DF_PREPROCESSOR2 && ch == '(' && chNext == '*' + // && styler.SafeGetCharAt(i + 2) == '$') { + // ClassifyDataFlexPreprocessorFoldPoint(levelCurrent, lineFoldStateCurrent, i + 3, styler); + i = i + iWordSize; + } + } + + if (stylePrev != SCE_DF_SCOPEWORD && style == SCE_DF_SCOPEWORD) + { + // Store last word start point. + lastStart = i; + } + if (stylePrev == SCE_DF_SCOPEWORD) { + if(setWord.Contains(ch) && !setWord.Contains(chNext)) { + ClassifyDataFlexWordFoldPoint(levelCurrent, lineFoldStateCurrent, lastStart, i, keywordlists, styler); + } + } + + if (stylePrev == SCE_DF_METATAG && ch == '#') + { + // Store last word start point. + lastStart = i; + } + if (stylePrev == SCE_DF_METATAG) { + if(setWord.Contains(ch) && !setWord.Contains(chNext)) { + ClassifyDataFlexMetaDataFoldPoint(levelCurrent, lastStart, i, keywordlists, styler); + } + } + + if (!IsASpace(ch)) + visibleChars++; + + if (atEOL) { + int lev = levelPrev; + if (visibleChars == 0 && foldCompact) + lev |= SC_FOLDLEVELWHITEFLAG; + if ((levelCurrent > levelPrev) && (visibleChars > 0)) + lev |= SC_FOLDLEVELHEADERFLAG; + if (lev != styler.LevelAt(lineCurrent)) { + styler.SetLevel(lineCurrent, lev); + } + int newLineState = (styler.GetLineState(lineCurrent) & ~stateFoldMaskAll) | lineFoldStateCurrent; + styler.SetLineState(lineCurrent, newLineState); + lineCurrent++; + levelPrev = levelCurrent; + visibleChars = 0; + } + } + + // If we didn't reach the EOL in previous loop, store line level and whitespace information. + // The rest will be filled in later... + int lev = levelPrev; + if (visibleChars == 0 && foldCompact) + lev |= SC_FOLDLEVELWHITEFLAG; + styler.SetLevel(lineCurrent, lev); +} + +static const char * const dataflexWordListDesc[] = { + "Keywords", + "Scope open", + "Scope close", + "Operators", + 0 +}; + +LexerModule lmDataflex(SCLEX_DATAFLEX, ColouriseDataFlexDoc, "dataflex", FoldDataFlexDoc, dataflexWordListDesc); diff --git a/src/stc/scintilla/lexers/LexDiff.cxx b/src/stc/scintilla/lexers/LexDiff.cxx index baa8368f68..dd008c5cb4 100644 --- a/src/stc/scintilla/lexers/LexDiff.cxx +++ b/src/stc/scintilla/lexers/LexDiff.cxx @@ -23,9 +23,7 @@ #include "CharacterSet.h" #include "LexerModule.h" -#ifdef SCI_NAMESPACE using namespace Scintilla; -#endif static inline bool AtEOL(Accessor &styler, Sci_PositionU i) { return (styler[i] == '\n') || @@ -51,8 +49,10 @@ static void ColouriseDiffLine(char *lineBuffer, Sci_Position endLine, Accessor & styler.ColourTo(endLine, SCE_DIFF_POSITION); else if (lineBuffer[3] == '\r' || lineBuffer[3] == '\n') styler.ColourTo(endLine, SCE_DIFF_POSITION); - else + else if (lineBuffer[3] == ' ') styler.ColourTo(endLine, SCE_DIFF_HEADER); + else + styler.ColourTo(endLine, SCE_DIFF_DELETED); } else if (0 == strncmp(lineBuffer, "+++ ", 4)) { // I don't know of any diff where "+++ " is a position marker, but for // consistency, do the same as with "--- " and "*** ". @@ -78,6 +78,14 @@ static void ColouriseDiffLine(char *lineBuffer, Sci_Position endLine, Accessor & styler.ColourTo(endLine, SCE_DIFF_POSITION); } else if (lineBuffer[0] >= '0' && lineBuffer[0] <= '9') { styler.ColourTo(endLine, SCE_DIFF_POSITION); + } else if (0 == strncmp(lineBuffer, "++", 2)) { + styler.ColourTo(endLine, SCE_DIFF_PATCH_ADD); + } else if (0 == strncmp(lineBuffer, "+-", 2)) { + styler.ColourTo(endLine, SCE_DIFF_PATCH_DELETE); + } else if (0 == strncmp(lineBuffer, "-+", 2)) { + styler.ColourTo(endLine, SCE_DIFF_REMOVED_PATCH_ADD); + } else if (0 == strncmp(lineBuffer, "--", 2)) { + styler.ColourTo(endLine, SCE_DIFF_REMOVED_PATCH_DELETE); } else if (lineBuffer[0] == '-' || lineBuffer[0] == '<') { styler.ColourTo(endLine, SCE_DIFF_DELETED); } else if (lineBuffer[0] == '+' || lineBuffer[0] == '>') { @@ -124,7 +132,7 @@ static void FoldDiffDoc(Sci_PositionU startPos, Sci_Position length, int, WordLi int nextLevel; do { - int lineType = styler.StyleAt(curLineStart); + const int lineType = styler.StyleAt(curLineStart); if (lineType == SCE_DIFF_COMMAND) nextLevel = SC_FOLDLEVELBASE | SC_FOLDLEVELHEADERFLAG; else if (lineType == SCE_DIFF_HEADER) diff --git a/src/stc/scintilla/lexers/LexECL.cxx b/src/stc/scintilla/lexers/LexECL.cxx index 2e5433e6e2..6c916bce48 100644 --- a/src/stc/scintilla/lexers/LexECL.cxx +++ b/src/stc/scintilla/lexers/LexECL.cxx @@ -42,9 +42,7 @@ #define SET_UPPER "ABCDEFGHIJKLMNOPQRSTUVWXYZ" #define SET_DIGITS "0123456789" -#ifdef SCI_NAMESPACE using namespace Scintilla; -#endif static bool IsSpaceEquiv(int state) { switch (state) { diff --git a/src/stc/scintilla/lexers/LexEDIFACT.cxx b/src/stc/scintilla/lexers/LexEDIFACT.cxx index 07b48e9f05..efc9b58060 100644 --- a/src/stc/scintilla/lexers/LexEDIFACT.cxx +++ b/src/stc/scintilla/lexers/LexEDIFACT.cxx @@ -1,4 +1,5 @@ // Scintilla Lexer for EDIFACT +// @file LexEDIFACT.cxx // Written by Iain Clarke, IMCSoft & Inobiz AB. // EDIFACT documented here: https://www.unece.org/cefact/edifact/welcome.html // and more readably here: https://en.wikipedia.org/wiki/EDIFACT @@ -12,18 +13,19 @@ #include #include +#include + #include "ILexer.h" #include "Scintilla.h" #include "SciLexer.h" #include "LexAccessor.h" #include "LexerModule.h" +#include "DefaultLexer.h" -#ifdef SCI_NAMESPACE using namespace Scintilla; -#endif -class LexerEDIFACT : public ILexer +class LexerEDIFACT : public DefaultLexer { public: LexerEDIFACT(); @@ -33,48 +35,72 @@ public: return new LexerEDIFACT; } - virtual int SCI_METHOD Version() const + int SCI_METHOD Version() const override { - return lvOriginal; + return lvIdentity; } - virtual void SCI_METHOD Release() + void SCI_METHOD Release() override { delete this; } - const char * SCI_METHOD PropertyNames() + const char * SCI_METHOD PropertyNames() override { - return "fold"; + return "fold\nlexer.edifact.highlight.un.all"; } - int SCI_METHOD PropertyType(const char *) + int SCI_METHOD PropertyType(const char *) override { return SC_TYPE_BOOLEAN; // Only one property! } - const char * SCI_METHOD DescribeProperty(const char *name) + const char * SCI_METHOD DescribeProperty(const char *name) override { - if (strcmp(name, "fold")) - return NULL; - return "Whether to apply folding to document or not"; + if (!strcmp(name, "fold")) + return "Whether to apply folding to document or not"; + if (!strcmp(name, "lexer.edifact.highlight.un.all")) + return "Whether to apply UN* highlighting to all UN segments, or just to UNH"; + return NULL; } - virtual Sci_Position SCI_METHOD PropertySet(const char *key, const char *val) + Sci_Position SCI_METHOD PropertySet(const char *key, const char *val) override { - if (strcmp(key, "fold")) - return -1; - m_bFold = strcmp(val, "0") ? true : false; - return 0; + if (!strcmp(key, "fold")) + { + m_bFold = strcmp(val, "0") ? true : false; + return 0; + } + if (!strcmp(key, "lexer.edifact.highlight.un.all")) // GetProperty + { + m_bHighlightAllUN = strcmp(val, "0") ? true : false; + return 0; + } + return -1; } - const char * SCI_METHOD DescribeWordListSets() + + const char * SCI_METHOD PropertyGet(const char *key) override + { + m_lastPropertyValue = ""; + if (!strcmp(key, "fold")) + { + m_lastPropertyValue = m_bFold ? "1" : "0"; + } + if (!strcmp(key, "lexer.edifact.highlight.un.all")) // GetProperty + { + m_lastPropertyValue = m_bHighlightAllUN ? "1" : "0"; + } + return m_lastPropertyValue.c_str(); + } + + const char * SCI_METHOD DescribeWordListSets() override { return NULL; } - virtual Sci_Position SCI_METHOD WordListSet(int, const char *) + Sci_Position SCI_METHOD WordListSet(int, const char *) override { return -1; } - virtual void SCI_METHOD Lex(Sci_PositionU startPos, Sci_Position lengthDoc, int initStyle, IDocument *pAccess); - virtual void SCI_METHOD Fold(Sci_PositionU startPos, Sci_Position lengthDoc, int initStyle, IDocument *pAccess); - virtual void * SCI_METHOD PrivateCall(int, void *) + void SCI_METHOD Lex(Sci_PositionU startPos, Sci_Position length, int initStyle, IDocument *pAccess) override; + void SCI_METHOD Fold(Sci_PositionU startPos, Sci_Position length, int initStyle, IDocument *pAccess) override; + void * SCI_METHOD PrivateCall(int, void *) override { return NULL; } @@ -86,11 +112,18 @@ protected: int DetectSegmentHeader(char SegmentHeader[3]) const; bool m_bFold; + + // property lexer.edifact.highlight.un.all + // Set to 0 to highlight only UNA segments, or 1 to highlight all UNx segments. + bool m_bHighlightAllUN; + char m_chComponent; char m_chData; char m_chDecimal; char m_chRelease; char m_chSegment; + + std::string m_lastPropertyValue; }; LexerModule lmEDIFACT(SCLEX_EDIFACT, LexerEDIFACT::Factory, "edifact"); @@ -101,9 +134,10 @@ LexerModule lmEDIFACT(SCLEX_EDIFACT, LexerEDIFACT::Factory, "edifact"); /////////////////////////////////////////////////////////////////////////////// -LexerEDIFACT::LexerEDIFACT() +LexerEDIFACT::LexerEDIFACT() : DefaultLexer("edifact", SCLEX_EDIFACT) { m_bFold = false; + m_bHighlightAllUN = false; m_chComponent = ':'; m_chData = '+'; m_chDecimal = '.'; @@ -111,9 +145,9 @@ LexerEDIFACT::LexerEDIFACT() m_chSegment = '\''; } -void LexerEDIFACT::Lex(Sci_PositionU startPos, Sci_Position lengthDoc, int, IDocument *pAccess) +void LexerEDIFACT::Lex(Sci_PositionU startPos, Sci_Position length, int, IDocument *pAccess) { - Sci_PositionU posFinish = startPos + lengthDoc; + Sci_PositionU posFinish = startPos + length; InitialiseFromUNA(pAccess, posFinish); // Look backwards for a ' or a document beginning @@ -191,40 +225,85 @@ void LexerEDIFACT::Lex(Sci_PositionU startPos, Sci_Position lengthDoc, int, IDoc pAccess->SetStyleFor(posFinish - posSegmentStart, SCE_EDI_BADSEGMENT); } -void LexerEDIFACT::Fold(Sci_PositionU startPos, Sci_Position lengthDoc, int, IDocument *pAccess) +void LexerEDIFACT::Fold(Sci_PositionU startPos, Sci_Position length, int, IDocument *pAccess) { if (!m_bFold) return; - // Fold at UNx lines. ie, UNx segments = 0, other segments = 1. - // There's no sub folding, so we can be quite simple. - Sci_Position endPos = startPos + lengthDoc; + Sci_PositionU endPos = startPos + length; + startPos = FindPreviousEnd(pAccess, startPos); + char c; char SegmentHeader[4] = { 0 }; - int iIndentPrevious = 0; - Sci_Position lineLast = pAccess->LineFromPosition(endPos); + bool AwaitingSegment = true; + Sci_PositionU currLine = pAccess->LineFromPosition(startPos); + int levelCurrentStyle = SC_FOLDLEVELBASE; + if (currLine > 0) + levelCurrentStyle = pAccess->GetLevel(currLine - 1); // bottom 12 bits are level + int indentCurrent = levelCurrentStyle & SC_FOLDLEVELNUMBERMASK; + int indentNext = indentCurrent; - for (Sci_Position lineCurrent = pAccess->LineFromPosition(startPos); lineCurrent <= lineLast; lineCurrent++) + while (startPos < endPos) { - Sci_Position posLineStart = pAccess->LineStart(lineCurrent); - posLineStart = ForwardPastWhitespace(pAccess, posLineStart, endPos); - Sci_Position lineDataStart = pAccess->LineFromPosition(posLineStart); - // Fill in whitespace lines? - for (; lineCurrent < lineDataStart; lineCurrent++) - pAccess->SetLevel(lineCurrent, SC_FOLDLEVELBASE | SC_FOLDLEVELWHITEFLAG | iIndentPrevious); - pAccess->GetCharRange(SegmentHeader, posLineStart, 3); - //if (DetectSegmentHeader(SegmentHeader) == SCE_EDI_BADSEGMENT) // Abort if this is not a proper segment header + pAccess->GetCharRange(&c, startPos, 1); + switch (c) + { + case '\t': + case '\r': + case ' ': + startPos++; + continue; + case '\n': + currLine = pAccess->LineFromPosition(startPos); + pAccess->SetLevel(currLine, levelCurrentStyle | indentCurrent); + startPos++; + levelCurrentStyle = SC_FOLDLEVELBASE; + indentCurrent = indentNext; + continue; + } + if (c == m_chRelease) + { + startPos += 2; + continue; + } + if (c == m_chSegment) + { + AwaitingSegment = true; + startPos++; + continue; + } - int level = 0; - if (memcmp(SegmentHeader, "UNH", 3) == 0) // UNH starts blocks - level = SC_FOLDLEVELBASE | SC_FOLDLEVELHEADERFLAG; - // Check for UNA,B and Z. All others are inside messages - else if (!memcmp(SegmentHeader, "UNA", 3) || !memcmp(SegmentHeader, "UNB", 3) || !memcmp(SegmentHeader, "UNZ", 3)) - level = SC_FOLDLEVELBASE; - else - level = SC_FOLDLEVELBASE | 1; - pAccess->SetLevel(lineCurrent, level); - iIndentPrevious = level & SC_FOLDLEVELNUMBERMASK; + if (!AwaitingSegment) + { + startPos++; + continue; + } + + // Segment! + pAccess->GetCharRange(SegmentHeader, startPos, 3); + if (SegmentHeader[0] != 'U' || SegmentHeader[1] != 'N') + { + startPos++; + continue; + } + + AwaitingSegment = false; + switch (SegmentHeader[2]) + { + case 'H': + case 'G': + indentNext++; + levelCurrentStyle = SC_FOLDLEVELBASE | SC_FOLDLEVELHEADERFLAG; + break; + + case 'T': + case 'E': + if (indentNext > 0) + indentNext--; + break; + } + + startPos += 3; } } @@ -295,9 +374,14 @@ int LexerEDIFACT::DetectSegmentHeader(char SegmentHeader[3]) const SegmentHeader[2] < 'A' || SegmentHeader[2] > 'Z') return SCE_EDI_BADSEGMENT; - if (memcmp(SegmentHeader, "UNA", 3) == 0) + if (!memcmp(SegmentHeader, "UNA", 3)) return SCE_EDI_UNA; - if (memcmp(SegmentHeader, "UNH", 3) == 0) + + if (m_bHighlightAllUN && !memcmp(SegmentHeader, "UN", 2)) + return SCE_EDI_UNH; + else if (!memcmp(SegmentHeader, "UNH", 3)) + return SCE_EDI_UNH; + else if (!memcmp(SegmentHeader, "UNG", 3)) return SCE_EDI_UNH; return SCE_EDI_SEGMENTSTART; @@ -315,3 +399,5 @@ Sci_Position LexerEDIFACT::FindPreviousEnd(IDocument *pAccess, Sci_Position star // We didn't find a ', so just go with the beginning return 0; } + + diff --git a/src/stc/scintilla/lexers/LexEScript.cxx b/src/stc/scintilla/lexers/LexEScript.cxx index bc1fb3201b..79f99aedd8 100644 --- a/src/stc/scintilla/lexers/LexEScript.cxx +++ b/src/stc/scintilla/lexers/LexEScript.cxx @@ -1,5 +1,5 @@ // Scintilla source code edit control -/** @file LexESCRIPT.cxx +/** @file LexEScript.cxx ** Lexer for ESCRIPT **/ // Copyright 2003 by Patrizio Bekerle (patrizio@bekerle.com) @@ -22,9 +22,7 @@ #include "CharacterSet.h" #include "LexerModule.h" -#ifdef SCI_NAMESPACE using namespace Scintilla; -#endif static inline bool IsAWordChar(const int ch) { diff --git a/src/stc/scintilla/lexers/LexEiffel.cxx b/src/stc/scintilla/lexers/LexEiffel.cxx index 2e2813ef6a..d1d42a9605 100644 --- a/src/stc/scintilla/lexers/LexEiffel.cxx +++ b/src/stc/scintilla/lexers/LexEiffel.cxx @@ -23,9 +23,7 @@ #include "CharacterSet.h" #include "LexerModule.h" -#ifdef SCI_NAMESPACE using namespace Scintilla; -#endif static inline bool isEiffelOperator(unsigned int ch) { // '.' left out as it is used to make up numbers diff --git a/src/stc/scintilla/lexers/LexErlang.cxx b/src/stc/scintilla/lexers/LexErlang.cxx index 3d3c1e89ff..4ca5962c30 100644 --- a/src/stc/scintilla/lexers/LexErlang.cxx +++ b/src/stc/scintilla/lexers/LexErlang.cxx @@ -1,11 +1,12 @@ // Scintilla source code edit control +// Encoding: UTF-8 // Copyright 1998-2001 by Neil Hodgson // The License.txt file describes the conditions under which this software may be distributed. /** @file LexErlang.cxx ** Lexer for Erlang. ** Enhanced by Etienne 'Lenain' Girondel (lenaing@gmail.com) ** Originally wrote by Peter-Henry Mander, - ** based on Matlab lexer by José Fonseca. + ** based on Matlab lexer by José Fonseca. **/ #include @@ -26,9 +27,7 @@ #include "CharacterSet.h" #include "LexerModule.h" -#ifdef SCI_NAMESPACE using namespace Scintilla; -#endif static int is_radix(int radix, int ch) { int digit; @@ -116,6 +115,7 @@ static void ColouriseErlangDoc(Sci_PositionU startPos, Sci_Position length, int } } // V--- Falling through! + // Falls through. case COMMENT_FUNCTION : { if (sc.ch != '%') { to_late_to_comment = true; @@ -128,6 +128,7 @@ static void ColouriseErlangDoc(Sci_PositionU startPos, Sci_Position length, int } } // V--- Falling through! + // Falls through. case COMMENT_MODULE : { if (parse_state != COMMENT) { // Search for comment documentation diff --git a/src/stc/scintilla/lexers/LexErrorList.cxx b/src/stc/scintilla/lexers/LexErrorList.cxx index 6dc6b025e2..0fc389646b 100644 --- a/src/stc/scintilla/lexers/LexErrorList.cxx +++ b/src/stc/scintilla/lexers/LexErrorList.cxx @@ -12,6 +12,8 @@ #include #include +#include + #include "ILexer.h" #include "Scintilla.h" #include "SciLexer.h" @@ -23,32 +25,45 @@ #include "CharacterSet.h" #include "LexerModule.h" -#ifdef SCI_NAMESPACE using namespace Scintilla; -#endif -static bool strstart(const char *haystack, const char *needle) { +namespace { + +bool strstart(const char *haystack, const char *needle) noexcept { return strncmp(haystack, needle, strlen(needle)) == 0; } -static bool Is0To9(char ch) { +constexpr bool Is0To9(char ch) noexcept { return (ch >= '0') && (ch <= '9'); } -static bool Is1To9(char ch) { +constexpr bool Is1To9(char ch) noexcept { return (ch >= '1') && (ch <= '9'); } -static bool IsAlphabetic(int ch) { +bool IsAlphabetic(int ch) { return IsASCII(ch) && isalpha(ch); } -static inline bool AtEOL(Accessor &styler, Sci_PositionU i) { +inline bool AtEOL(Accessor &styler, Sci_PositionU i) { return (styler[i] == '\n') || ((styler[i] == '\r') && (styler.SafeGetCharAt(i + 1) != '\n')); } -static int RecogniseErrorListLine(const char *lineBuffer, Sci_PositionU lengthLine, Sci_Position &startValue) { +bool IsGccExcerpt(const char *s) noexcept { + while (*s) { + if (s[0] == ' ' && s[1] == '|' && (s[2] == ' ' || s[2] == '+')) { + return true; + } + if (!(s[0] == ' ' || s[0] == '+' || Is0To9(s[0]))) { + return false; + } + s++; + } + return true; +} + +int RecogniseErrorListLine(const char *lineBuffer, Sci_PositionU lengthLine, Sci_Position &startValue) { if (lineBuffer[0] == '>') { // Command or return status return SCE_ERR_CMD; @@ -106,7 +121,8 @@ static int RecogniseErrorListLine(const char *lineBuffer, Sci_PositionU lengthLi // perl error message: // at line return SCE_ERR_PERL; - } else if ((memcmp(lineBuffer, " at ", 6) == 0) && + } else if ((lengthLine >= 6) && + (memcmp(lineBuffer, " at ", 6) == 0) && strstr(lineBuffer, ":line ")) { // A .NET traceback return SCE_ERR_NET; @@ -131,6 +147,11 @@ static int RecogniseErrorListLine(const char *lineBuffer, Sci_PositionU lengthLi // Microsoft linker warning: // { : } warning LNK9999 return SCE_ERR_MS; + } else if (IsGccExcerpt(lineBuffer)) { + // GCC code excerpt and pointer to issue + // 73 | GTimeVal last_popdown; + // | ^~~~~~~~~~~~ + return SCE_ERR_GCC_EXCERPT; } else { // Look for one of the following formats: // GCC: :: @@ -141,7 +162,7 @@ static int RecogniseErrorListLine(const char *lineBuffer, Sci_PositionU lengthLi // CTags: \t\t // Lua 5 traceback: \t:: // Lua 5.1: : :: - bool initialTab = (lineBuffer[0] == '\t'); + const bool initialTab = (lineBuffer[0] == '\t'); bool initialColonPart = false; bool canBeCtags = !initialTab; // For ctags must have an identifier with no spaces then a tab enum { stInitial, @@ -151,7 +172,7 @@ static int RecogniseErrorListLine(const char *lineBuffer, Sci_PositionU lengthLi stUnrecognized } state = stInitial; for (Sci_PositionU i = 0; i < lengthLine; i++) { - char ch = lineBuffer[i]; + const char ch = lineBuffer[i]; char chNext = ' '; if ((i + 1) < lengthLine) chNext = lineBuffer[i + 1]; @@ -176,7 +197,7 @@ static int RecogniseErrorListLine(const char *lineBuffer, Sci_PositionU lengthLi canBeCtags = false; } } else if (state == stGccStart) { // : - state = Is0To9(ch) ? stGccDigit : stUnrecognized; + state = ((ch == '-') || Is0To9(ch)) ? stGccDigit : stUnrecognized; } else if (state == stGccDigit) { // : if (ch == ':') { state = stGccColumn; // :9.*: is GCC @@ -207,14 +228,13 @@ static int RecogniseErrorListLine(const char *lineBuffer, Sci_PositionU lengthLi } else if ((ch == ':' && chNext == ' ') || (ch == ' ')) { // Possibly Delphi.. don't test against chNext as it's one of the strings below. char word[512]; - Sci_PositionU j, chPos; unsigned numstep; - chPos = 0; if (ch == ' ') numstep = 1; // ch was ' ', handle as if it's a delphi errorline, only add 1 to i. else numstep = 2; // otherwise add 2. - for (j = i + numstep; j < lengthLine && IsAlphabetic(lineBuffer[j]) && chPos < sizeof(word) - 1; j++) + Sci_PositionU chPos = 0; + for (Sci_PositionU j = i + numstep; j < lengthLine && IsAlphabetic(lineBuffer[j]) && chPos < sizeof(word) - 1; j++) word[chPos++] = lineBuffer[j]; word[chPos] = 0; if (!CompareCaseInsensitive(word, "error") || !CompareCaseInsensitive(word, "warning") || @@ -269,13 +289,11 @@ static int RecogniseErrorListLine(const char *lineBuffer, Sci_PositionU lengthLi #define CSI "\033[" -namespace { - -bool SequenceEnd(int ch) { +constexpr bool SequenceEnd(int ch) noexcept { return (ch == 0) || ((ch >= '@') && (ch <= '~')); } -int StyleFromSequence(const char *seq) { +int StyleFromSequence(const char *seq) noexcept { int bold = 0; int colour = 0; while (!SequenceEnd(*seq)) { @@ -302,21 +320,19 @@ int StyleFromSequence(const char *seq) { return SCE_ERR_ES_BLACK + bold * 8 + colour; } -} - -static void ColouriseErrorListLine( - char *lineBuffer, - Sci_PositionU lengthLine, +void ColouriseErrorListLine( + const std::string &lineBuffer, Sci_PositionU endPos, Accessor &styler, bool valueSeparate, bool escapeSequences) { Sci_Position startValue = -1; - int style = RecogniseErrorListLine(lineBuffer, lengthLine, startValue); - if (escapeSequences && strstr(lineBuffer, CSI)) { - const int startPos = endPos - lengthLine; - const char *linePortion = lineBuffer; - int startPortion = startPos; + const Sci_PositionU lengthLine = lineBuffer.length(); + const int style = RecogniseErrorListLine(lineBuffer.c_str(), lengthLine, startValue); + if (escapeSequences && strstr(lineBuffer.c_str(), CSI)) { + const Sci_Position startPos = endPos - lengthLine; + const char *linePortion = lineBuffer.c_str(); + Sci_Position startPortion = startPos; int portionStyle = style; while (const char *startSeq = strstr(linePortion, CSI)) { if (startSeq > linePortion) { @@ -325,7 +341,7 @@ static void ColouriseErrorListLine( const char *endSeq = startSeq + 2; while (!SequenceEnd(*endSeq)) endSeq++; - const int endSeqPosition = startPortion + static_cast(endSeq - linePortion) + 1; + const Sci_Position endSeqPosition = startPortion + static_cast(endSeq - linePortion) + 1; switch (*endSeq) { case 0: styler.ColourTo(endPos, SCE_ERR_ESCSEQ_UNKNOWN); @@ -355,40 +371,39 @@ static void ColouriseErrorListLine( } } -static void ColouriseErrorListDoc(Sci_PositionU startPos, Sci_Position length, int, WordList *[], Accessor &styler) { - char lineBuffer[10000]; +void ColouriseErrorListDoc(Sci_PositionU startPos, Sci_Position length, int, WordList *[], Accessor &styler) { + std::string lineBuffer; styler.StartAt(startPos); styler.StartSegment(startPos); - Sci_PositionU linePos = 0; // property lexer.errorlist.value.separate // For lines in the output pane that are matches from Find in Files or GCC-style // diagnostics, style the path and line number separately from the rest of the // line with style 21 used for the rest of the line. // This allows matched text to be more easily distinguished from its location. - bool valueSeparate = styler.GetPropertyInt("lexer.errorlist.value.separate", 0) != 0; + const bool valueSeparate = styler.GetPropertyInt("lexer.errorlist.value.separate", 0) != 0; // property lexer.errorlist.escape.sequences // Set to 1 to interpret escape sequences. const bool escapeSequences = styler.GetPropertyInt("lexer.errorlist.escape.sequences") != 0; for (Sci_PositionU i = startPos; i < startPos + length; i++) { - lineBuffer[linePos++] = styler[i]; - if (AtEOL(styler, i) || (linePos >= sizeof(lineBuffer) - 1)) { - // End of line (or of line buffer) met, colourise it - lineBuffer[linePos] = '\0'; - ColouriseErrorListLine(lineBuffer, linePos, i, styler, valueSeparate, escapeSequences); - linePos = 0; + lineBuffer.push_back(styler[i]); + if (AtEOL(styler, i)) { + // End of line met, colourise it + ColouriseErrorListLine(lineBuffer, i, styler, valueSeparate, escapeSequences); + lineBuffer.clear(); } } - if (linePos > 0) { // Last line does not have ending characters - lineBuffer[linePos] = '\0'; - ColouriseErrorListLine(lineBuffer, linePos, startPos + length - 1, styler, valueSeparate, escapeSequences); + if (!lineBuffer.empty()) { // Last line does not have ending characters + ColouriseErrorListLine(lineBuffer, startPos + length - 1, styler, valueSeparate, escapeSequences); } } -static const char *const emptyWordListDesc[] = { - 0 +const char *const emptyWordListDesc[] = { + nullptr }; +} + LexerModule lmErrorList(SCLEX_ERRORLIST, ColouriseErrorListDoc, "errorlist", 0, emptyWordListDesc); diff --git a/src/stc/scintilla/lexers/LexFlagship.cxx b/src/stc/scintilla/lexers/LexFlagship.cxx index 6f6f4c0c73..2dfb687aaf 100644 --- a/src/stc/scintilla/lexers/LexFlagship.cxx +++ b/src/stc/scintilla/lexers/LexFlagship.cxx @@ -1,5 +1,5 @@ // Scintilla source code edit control -/** @file LexFlagShip.cxx +/** @file LexFlagship.cxx ** Lexer for Harbour and FlagShip. ** (Syntactically compatible to other xBase dialects, like Clipper, dBase, Clip, FoxPro etc.) **/ @@ -26,9 +26,7 @@ #include "CharacterSet.h" #include "LexerModule.h" -#ifdef SCI_NAMESPACE using namespace Scintilla; -#endif // Extended to accept accented characters static inline bool IsAWordChar(int ch) diff --git a/src/stc/scintilla/lexers/LexForth.cxx b/src/stc/scintilla/lexers/LexForth.cxx index 63d3f4f6de..80842097d1 100644 --- a/src/stc/scintilla/lexers/LexForth.cxx +++ b/src/stc/scintilla/lexers/LexForth.cxx @@ -23,9 +23,7 @@ #include "CharacterSet.h" #include "LexerModule.h" -#ifdef SCI_NAMESPACE using namespace Scintilla; -#endif static inline bool IsAWordStart(int ch) { return (ch < 0x80) && (isalnum(ch) || ch == '_' || ch == '.'); diff --git a/src/stc/scintilla/lexers/LexFortran.cxx b/src/stc/scintilla/lexers/LexFortran.cxx index 37e0b45c55..28298b3ed6 100644 --- a/src/stc/scintilla/lexers/LexFortran.cxx +++ b/src/stc/scintilla/lexers/LexFortran.cxx @@ -25,9 +25,7 @@ #include "LexerModule.h" /***************************************/ -#ifdef SCI_NAMESPACE using namespace Scintilla; -#endif /***********************************************/ static inline bool IsAWordChar(const int ch) { @@ -120,14 +118,6 @@ static void ColouriseFortranDoc(Sci_PositionU startPos, Sci_Position length, int continue; } /***************************************/ - // Hanndle preprocessor directives - if (sc.ch == '#' && numNonBlank == 1) - { - sc.SetState(SCE_F_PREPROCESSOR); - while (!sc.atLineEnd && sc.More()) - sc.Forward(); // Until line end - } - /***************************************/ // Handle line continuation generically. if (!isFixFormat && sc.ch == '&' && sc.state != SCE_F_COMMENT) { char chTemp = ' '; @@ -143,7 +133,11 @@ static void ColouriseFortranDoc(Sci_PositionU startPos, Sci_Position length, int int currentState = sc.state; sc.SetState(SCE_F_CONTINUATION); sc.ForwardSetState(SCE_F_DEFAULT); - while (IsASpace(sc.ch) && sc.More()) sc.Forward(); + while (IsASpace(sc.ch) && sc.More()) { + sc.Forward(); + if (sc.atLineStart) numNonBlank = 0; + if (!IsASpaceOrTab(sc.ch)) numNonBlank ++; + } if (sc.ch == '&') { sc.SetState(SCE_F_CONTINUATION); sc.Forward(); @@ -152,6 +146,14 @@ static void ColouriseFortranDoc(Sci_PositionU startPos, Sci_Position length, int } } /***************************************/ + // Hanndle preprocessor directives + if (sc.ch == '#' && numNonBlank == 1) + { + sc.SetState(SCE_F_PREPROCESSOR); + while (!sc.atLineEnd && sc.More()) + sc.Forward(); // Until line end + } + /***************************************/ // Determine if the current state should terminate. if (sc.state == SCE_F_OPERATOR) { sc.SetState(SCE_F_DEFAULT); @@ -223,7 +225,7 @@ static void ColouriseFortranDoc(Sci_PositionU startPos, Sci_Position length, int if (sc.state == SCE_F_DEFAULT) { if (sc.ch == '!') { if (sc.MatchIgnoreCase("!dec$") || sc.MatchIgnoreCase("!dir$") || - sc.MatchIgnoreCase("!ms$") || sc.chNext == '$') { + sc.MatchIgnoreCase("!ms$") || sc.chNext == '$') { sc.SetState(SCE_F_PREPROCESSOR); } else { sc.SetState(SCE_F_COMMENT); @@ -233,7 +235,7 @@ static void ColouriseFortranDoc(Sci_PositionU startPos, Sci_Position length, int } else if (IsADigit(sc.ch) || (sc.ch == '.' && IsADigit(sc.chNext))) { sc.SetState(SCE_F_NUMBER); } else if ((tolower(sc.ch) == 'b' || tolower(sc.ch) == 'o' || - tolower(sc.ch) == 'z') && (sc.chNext == '\"' || sc.chNext == '\'')) { + tolower(sc.ch) == 'z') && (sc.chNext == '\"' || sc.chNext == '\'')) { sc.SetState(SCE_F_NUMBER); sc.Forward(); } else if (sc.ch == '.' && isalpha(sc.chNext)) { @@ -252,6 +254,165 @@ static void ColouriseFortranDoc(Sci_PositionU startPos, Sci_Position length, int sc.Complete(); } /***************************************/ +static void CheckLevelCommentLine(const unsigned int nComL, + Sci_Position nComColB[], Sci_Position nComColF[], Sci_Position &nComCur, + bool comLineB[], bool comLineF[], bool &comLineCur, + int &levelDeltaNext) { + levelDeltaNext = 0; + if (!comLineCur) { + return; + } + + if (!comLineF[0] || nComColF[0] != nComCur) { + unsigned int i=0; + for (; i= nLineTotal) { + return; + } + + for (int i=nComL-2; i>=0; i--) { + nComColB[i+1] = nComColB[i]; + comLineB[i+1] = comLineB[i]; + } + nComColB[0] = nComCur; + comLineB[0] = comLineCur; + nComCur = nComColF[0]; + comLineCur = comLineF[0]; + for (unsigned int i=0; i+1 0) { lineCurrent--; startPos = styler.LineStart(lineCurrent); - levelCurrent = styler.LevelAt(lineCurrent) & SC_FOLDLEVELNUMBERMASK; isPrevLine = true; } else { - levelCurrent = styler.LevelAt(lineCurrent) & SC_FOLDLEVELNUMBERMASK; isPrevLine = false; } char chNext = styler[startPos]; int styleNext = styler.StyleAt(startPos); int style = initStyle; int levelDeltaNext = 0; + + const unsigned int nComL = 3; // defines how many comment lines should be before they are folded + Sci_Position nComColB[nComL] = {}; + Sci_Position nComColF[nComL] = {}; + Sci_Position nComCur = 0; + bool comLineB[nComL] = {}; + bool comLineF[nComL] = {}; + bool comLineCur; + Sci_Position nLineTotal = styler.GetLine(styler.Length()-1) + 1; + if (foldComment) { + for (unsigned int i=0; i= nLineTotal) { + comLineF[i] = false; + break; + } + GetIfLineComment(styler, isFixFormat, chL, comLineF[i], nComColF[i]); + } + GetIfLineComment(styler, isFixFormat, lineCurrent, comLineCur, nComCur); + CheckBackComLines(styler, isFixFormat, lineCurrent, nComL, nComColB, nComColF, nComCur, + comLineB, comLineF, comLineCur); + } + int levelCurrent = styler.LevelAt(lineCurrent) & SC_FOLDLEVELNUMBERMASK; + /***************************************/ Sci_Position lastStart = 0; char prevWord[32] = ""; @@ -463,6 +659,11 @@ static void FoldFortranDoc(Sci_PositionU startPos, Sci_Position length, int init } } if (atEOL) { + if (foldComment) { + int ldNext; + CheckLevelCommentLine(nComL, nComColB, nComColF, nComCur, comLineB, comLineF, comLineCur, ldNext); + levelDeltaNext += ldNext; + } int lev = levelCurrent; if (visibleChars == 0 && foldCompact) lev |= SC_FOLDLEVELWHITEFLAG; @@ -477,6 +678,11 @@ static void FoldFortranDoc(Sci_PositionU startPos, Sci_Position length, int init visibleChars = 0; strcpy(prevWord, ""); isPrevLine = false; + + if (foldComment) { + StepCommentLine(styler, isFixFormat, lineCurrent, nComL, nComColB, nComColF, nComCur, + comLineB, comLineF, comLineCur); + } } /***************************************/ if (!isspacechar(ch)) visibleChars++; diff --git a/src/stc/scintilla/lexers/LexGAP.cxx b/src/stc/scintilla/lexers/LexGAP.cxx index ee0a7ad69c..a2eca95abb 100644 --- a/src/stc/scintilla/lexers/LexGAP.cxx +++ b/src/stc/scintilla/lexers/LexGAP.cxx @@ -24,9 +24,7 @@ #include "CharacterSet.h" #include "LexerModule.h" -#ifdef SCI_NAMESPACE using namespace Scintilla; -#endif static inline bool IsGAPOperator(char ch) { if (IsASCII(ch) && isalnum(ch)) return false; diff --git a/src/stc/scintilla/lexers/LexGui4Cli.cxx b/src/stc/scintilla/lexers/LexGui4Cli.cxx index c1625160a9..664fa4f2f8 100644 --- a/src/stc/scintilla/lexers/LexGui4Cli.cxx +++ b/src/stc/scintilla/lexers/LexGui4Cli.cxx @@ -1,5 +1,6 @@ // Scintilla source code edit control // Copyright 1998-2002 by Neil Hodgson +// @file LexGui4Cli.cxx /* This is the Lexer for Gui4Cli, included in SciLexer.dll - by d. Keletsekis, 2/10/2003 @@ -39,9 +40,7 @@ val SCE_GC_OPERATOR=9 #include "CharacterSet.h" #include "LexerModule.h" -#ifdef SCI_NAMESPACE using namespace Scintilla; -#endif #define debug Platform::DebugPrintf @@ -68,7 +67,7 @@ inline bool isGCOperator(int ch) #define isFoldPoint(x) ((styler.LevelAt(x) & SC_FOLDLEVELNUMBERMASK) == 1024) static void colorFirstWord(WordList *keywordlists[], Accessor &styler, - StyleContext *sc, char *buff, Sci_Position length, int) + StyleContext *sc, char *buff, Sci_Position length, Sci_Position) { Sci_Position c = 0; while (sc->More() && isSpaceOrNL(sc->ch)) diff --git a/src/stc/scintilla/lexers/LexHTML.cxx b/src/stc/scintilla/lexers/LexHTML.cxx index bd14534d42..9d474fb0eb 100644 --- a/src/stc/scintilla/lexers/LexHTML.cxx +++ b/src/stc/scintilla/lexers/LexHTML.cxx @@ -11,11 +11,13 @@ #include #include #include +#include +#include +#include #include "ILexer.h" #include "Scintilla.h" #include "SciLexer.h" - #include "StringCopy.h" #include "WordList.h" #include "LexAccessor.h" @@ -23,10 +25,12 @@ #include "StyleContext.h" #include "CharacterSet.h" #include "LexerModule.h" +#include "OptionSet.h" +#include "DefaultLexer.h" -#ifdef SCI_NAMESPACE using namespace Scintilla; -#endif + +namespace { #define SCE_HA_JS (SCE_HJA_START - SCE_HJ_START) #define SCE_HA_VBS (SCE_HBA_START - SCE_HB_START) @@ -35,11 +39,11 @@ using namespace Scintilla; enum script_type { eScriptNone = 0, eScriptJS, eScriptVBS, eScriptPython, eScriptPHP, eScriptXML, eScriptSGML, eScriptSGMLblock, eScriptComment }; enum script_mode { eHtml = 0, eNonHtmlScript, eNonHtmlPreProc, eNonHtmlScriptPreProc }; -static inline bool IsAWordChar(const int ch) { +inline bool IsAWordChar(const int ch) { return (ch < 0x80) && (isalnum(ch) || ch == '.' || ch == '_'); } -static inline bool IsAWordStart(const int ch) { +inline bool IsAWordStart(const int ch) { return (ch < 0x80) && (isalnum(ch) || ch == '_'); } @@ -57,31 +61,38 @@ inline bool IsOperator(int ch) { return false; } -static void GetTextSegment(Accessor &styler, Sci_PositionU start, Sci_PositionU end, char *s, size_t len) { +void GetTextSegment(Accessor &styler, Sci_PositionU start, Sci_PositionU end, char *s, size_t len) { Sci_PositionU i = 0; for (; (i < end - start + 1) && (i < len-1); i++) { - s[i] = static_cast(MakeLowerCase(styler[start + i])); + s[i] = MakeLowerCase(styler[start + i]); } s[i] = '\0'; } -static const char *GetNextWord(Accessor &styler, Sci_PositionU start, char *s, size_t sLen) { - +std::string GetStringSegment(Accessor &styler, Sci_PositionU start, Sci_PositionU end) { + std::string s; Sci_PositionU i = 0; - for (; i < sLen-1; i++) { - char ch = static_cast(styler.SafeGetCharAt(start + i)); + for (; (i < end - start + 1); i++) { + s.push_back(MakeLowerCase(styler[start + i])); + } + return s; +} + +std::string GetNextWord(Accessor &styler, Sci_PositionU start) { + std::string ret; + Sci_PositionU i = 0; + for (; i < 200; i++) { // Put an upper limit to bound time taken for unexpected text. + const char ch = styler.SafeGetCharAt(start + i); if ((i == 0) && !IsAWordStart(ch)) break; if ((i > 0) && !IsAWordChar(ch)) break; - s[i] = ch; + ret.push_back(ch); } - s[i] = '\0'; - - return s; + return ret; } -static script_type segIsScriptingIndicator(Accessor &styler, Sci_PositionU start, Sci_PositionU end, script_type prevValue) { +script_type segIsScriptingIndicator(Accessor &styler, Sci_PositionU start, Sci_PositionU end, script_type prevValue) { char s[100]; GetTextSegment(styler, start, end, s, sizeof(s)); //Platform::DebugPrintf("Scripting indicator [%s]\n", s); @@ -110,18 +121,16 @@ static script_type segIsScriptingIndicator(Accessor &styler, Sci_PositionU start return prevValue; } -static int PrintScriptingIndicatorOffset(Accessor &styler, Sci_PositionU start, Sci_PositionU end) { +int PrintScriptingIndicatorOffset(Accessor &styler, Sci_PositionU start, Sci_PositionU end) { int iResult = 0; - char s[100]; - GetTextSegment(styler, start, end, s, sizeof(s)); - if (0 == strncmp(s, "php", 3)) { + std::string s = GetStringSegment(styler, start, end); + if (0 == strncmp(s.c_str(), "php", 3)) { iResult = 3; } - return iResult; } -static script_type ScriptOfState(int state) { +script_type ScriptOfState(int state) { if ((state >= SCE_HP_START) && (state <= SCE_HP_IDENTIFIER)) { return eScriptPython; } else if ((state >= SCE_HB_START) && (state <= SCE_HB_STRINGEOL)) { @@ -139,7 +148,7 @@ static script_type ScriptOfState(int state) { } } -static int statePrintForState(int state, script_mode inScriptType) { +int statePrintForState(int state, script_mode inScriptType) { int StateToPrint = state; if (state >= SCE_HJ_START) { @@ -155,7 +164,7 @@ static int statePrintForState(int state, script_mode inScriptType) { return StateToPrint; } -static int stateForPrintState(int StateToPrint) { +int stateForPrintState(int StateToPrint) { int state; if ((StateToPrint >= SCE_HPA_START) && (StateToPrint <= SCE_HPA_IDENTIFIER)) { @@ -171,12 +180,12 @@ static int stateForPrintState(int StateToPrint) { return state; } -static inline bool IsNumber(Sci_PositionU start, Accessor &styler) { +inline bool IsNumber(Sci_PositionU start, Accessor &styler) { return IsADigit(styler[start]) || (styler[start] == '.') || (styler[start] == '-') || (styler[start] == '#'); } -static inline bool isStringState(int state) { +inline bool isStringState(int state) { bool bResult; switch (state) { @@ -207,7 +216,7 @@ static inline bool isStringState(int state) { return bResult; } -static inline bool stateAllowsTermination(int state) { +inline bool stateAllowsTermination(int state) { bool allowTermination = !isStringState(state); if (allowTermination) { switch (state) { @@ -222,7 +231,7 @@ static inline bool stateAllowsTermination(int state) { } // not really well done, since it's only comments that should lex the %> and <% -static inline bool isCommentASPState(int state) { +inline bool isCommentASPState(int state) { bool bResult; switch (state) { @@ -242,15 +251,14 @@ static inline bool isCommentASPState(int state) { return bResult; } -static void classifyAttribHTML(Sci_PositionU start, Sci_PositionU end, WordList &keywords, Accessor &styler) { - bool wordIsNumber = IsNumber(start, styler); +void classifyAttribHTML(Sci_PositionU start, Sci_PositionU end, const WordList &keywords, Accessor &styler) { + const bool wordIsNumber = IsNumber(start, styler); char chAttr = SCE_H_ATTRIBUTEUNKNOWN; if (wordIsNumber) { chAttr = SCE_H_NUMBER; } else { - char s[100]; - GetTextSegment(styler, start, end, s, sizeof(s)); - if (keywords.InList(s)) + std::string s = GetStringSegment(styler, start, end); + if (keywords.InList(s.c_str())) chAttr = SCE_H_ATTRIBUTE; } if ((chAttr == SCE_H_ATTRIBUTEUNKNOWN) && !keywords) @@ -259,47 +267,56 @@ static void classifyAttribHTML(Sci_PositionU start, Sci_PositionU end, WordList styler.ColourTo(end, chAttr); } -static int classifyTagHTML(Sci_PositionU start, Sci_PositionU end, - WordList &keywords, Accessor &styler, bool &tagDontFold, - bool caseSensitive, bool isXml, bool allowScripts) { - char withSpace[30 + 2] = " "; - const char *s = withSpace + 1; - // Copy after the '<' - Sci_PositionU i = 1; - for (Sci_PositionU cPos = start; cPos <= end && i < 30; cPos++) { - char ch = styler[cPos]; +// https://html.spec.whatwg.org/multipage/custom-elements.html#custom-elements-core-concepts +bool isHTMLCustomElement(const std::string &tag) { + // check valid HTML custom element name: starts with an ASCII lower alpha and contains hyphen. + // IsUpperOrLowerCase() is used for `html.tags.case.sensitive=1`. + if (tag.length() < 2 || !IsUpperOrLowerCase(tag[0])) { + return false; + } + if (tag.find('-') == std::string::npos) { + return false; + } + return true; +} + +int classifyTagHTML(Sci_PositionU start, Sci_PositionU end, + const WordList &keywords, Accessor &styler, bool &tagDontFold, + bool caseSensitive, bool isXml, bool allowScripts, + const std::set &nonFoldingTags) { + std::string tag; + // Copy after the '<' and stop before ' ' + for (Sci_PositionU cPos = start; cPos <= end; cPos++) { + const char ch = styler[cPos]; + if (IsASpace(ch)) { + break; + } if ((ch != '<') && (ch != '/')) { - withSpace[i++] = caseSensitive ? ch : static_cast(MakeLowerCase(ch)); + tag.push_back(caseSensitive ? ch : MakeLowerCase(ch)); } } - - //The following is only a quick hack, to see if this whole thing would work - //we first need the tagname with a trailing space... - withSpace[i] = ' '; - withSpace[i+1] = '\0'; - // if the current language is XML, I can fold any tag // if the current language is HTML, I don't want to fold certain tags (input, meta, etc.) //...to find it in the list of no-container-tags - tagDontFold = (!isXml) && (NULL != strstr(" area base basefont br col command embed frame hr img input isindex keygen link meta param source track wbr ", withSpace)); - - //now we can remove the trailing space - withSpace[i] = '\0'; - + tagDontFold = (!isXml) && (nonFoldingTags.count(tag) > 0); // No keywords -> all are known char chAttr = SCE_H_TAGUNKNOWN; - if (s[0] == '!') { + if (!tag.empty() && (tag[0] == '!')) { chAttr = SCE_H_SGML_DEFAULT; - } else if (!keywords || keywords.InList(s)) { + } else if (!keywords || keywords.InList(tag.c_str())) { + chAttr = SCE_H_TAG; + } else if (!isXml && isHTMLCustomElement(tag)) { chAttr = SCE_H_TAG; } - styler.ColourTo(end, chAttr); + if (chAttr != SCE_H_TAGUNKNOWN) { + styler.ColourTo(end, chAttr); + } if (chAttr == SCE_H_TAG) { - if (allowScripts && 0 == strcmp(s, "script")) { + if (allowScripts && (tag == "script")) { // check to see if this is a self-closing tag by sniffing ahead bool isSelfClose = false; for (Sci_PositionU cPos = end; cPos <= end + 200; cPos++) { - char ch = styler.SafeGetCharAt(cPos, '\0'); + const char ch = styler.SafeGetCharAt(cPos, '\0'); if (ch == '\0' || ch == '>') break; else if (ch == '/' && styler.SafeGetCharAt(cPos + 1, '\0') == '>') { @@ -311,15 +328,15 @@ static int classifyTagHTML(Sci_PositionU start, Sci_PositionU end, // do not enter a script state if the tag self-closed if (!isSelfClose) chAttr = SCE_H_SCRIPT; - } else if (!isXml && 0 == strcmp(s, "comment")) { + } else if (!isXml && (tag == "comment")) { chAttr = SCE_H_COMMENT; } } return chAttr; } -static void classifyWordHTJS(Sci_PositionU start, Sci_PositionU end, - WordList &keywords, Accessor &styler, script_mode inScriptType) { +void classifyWordHTJS(Sci_PositionU start, Sci_PositionU end, + const WordList &keywords, Accessor &styler, script_mode inScriptType) { char s[30 + 1]; Sci_PositionU i = 0; for (; i < end - start + 1 && i < 30; i++) { @@ -328,7 +345,7 @@ static void classifyWordHTJS(Sci_PositionU start, Sci_PositionU end, s[i] = '\0'; char chAttr = SCE_HJ_WORD; - bool wordIsNumber = IsADigit(s[0]) || ((s[0] == '.') && IsADigit(s[1])); + const bool wordIsNumber = IsADigit(s[0]) || ((s[0] == '.') && IsADigit(s[1])); if (wordIsNumber) { chAttr = SCE_HJ_NUMBER; } else if (keywords.InList(s)) { @@ -337,17 +354,16 @@ static void classifyWordHTJS(Sci_PositionU start, Sci_PositionU end, styler.ColourTo(end, statePrintForState(chAttr, inScriptType)); } -static int classifyWordHTVB(Sci_PositionU start, Sci_PositionU end, WordList &keywords, Accessor &styler, script_mode inScriptType) { +int classifyWordHTVB(Sci_PositionU start, Sci_PositionU end, const WordList &keywords, Accessor &styler, script_mode inScriptType) { char chAttr = SCE_HB_IDENTIFIER; - bool wordIsNumber = IsADigit(styler[start]) || (styler[start] == '.'); + const bool wordIsNumber = IsADigit(styler[start]) || (styler[start] == '.'); if (wordIsNumber) { chAttr = SCE_HB_NUMBER; } else { - char s[100]; - GetTextSegment(styler, start, end, s, sizeof(s)); - if (keywords.InList(s)) { + std::string s = GetStringSegment(styler, start, end); + if (keywords.InList(s.c_str())) { chAttr = SCE_HB_WORD; - if (strcmp(s, "rem") == 0) + if (s == "rem") chAttr = SCE_HB_COMMENTLINE; } } @@ -358,67 +374,60 @@ static int classifyWordHTVB(Sci_PositionU start, Sci_PositionU end, WordList &ke return SCE_HB_DEFAULT; } -static void classifyWordHTPy(Sci_PositionU start, Sci_PositionU end, WordList &keywords, Accessor &styler, char *prevWord, script_mode inScriptType, bool isMako) { - bool wordIsNumber = IsADigit(styler[start]); - char s[30 + 1]; - Sci_PositionU i = 0; - for (; i < end - start + 1 && i < 30; i++) { - s[i] = styler[start + i]; +void classifyWordHTPy(Sci_PositionU start, Sci_PositionU end, const WordList &keywords, Accessor &styler, std::string &prevWord, script_mode inScriptType, bool isMako) { + const bool wordIsNumber = IsADigit(styler[start]); + std::string s; + for (Sci_PositionU i = 0; i < end - start + 1 && i < 30; i++) { + s.push_back(styler[start + i]); } - s[i] = '\0'; char chAttr = SCE_HP_IDENTIFIER; - if (0 == strcmp(prevWord, "class")) + if (prevWord == "class") chAttr = SCE_HP_CLASSNAME; - else if (0 == strcmp(prevWord, "def")) + else if (prevWord == "def") chAttr = SCE_HP_DEFNAME; else if (wordIsNumber) chAttr = SCE_HP_NUMBER; - else if (keywords.InList(s)) + else if (keywords.InList(s.c_str())) chAttr = SCE_HP_WORD; - else if (isMako && 0 == strcmp(s, "block")) + else if (isMako && (s == "block")) chAttr = SCE_HP_WORD; styler.ColourTo(end, statePrintForState(chAttr, inScriptType)); - strcpy(prevWord, s); + prevWord = s; } // Update the word colour to default or keyword // Called when in a PHP word -static void classifyWordHTPHP(Sci_PositionU start, Sci_PositionU end, WordList &keywords, Accessor &styler) { +void classifyWordHTPHP(Sci_PositionU start, Sci_PositionU end, const WordList &keywords, Accessor &styler) { char chAttr = SCE_HPHP_DEFAULT; - bool wordIsNumber = IsADigit(styler[start]) || (styler[start] == '.' && start+1 <= end && IsADigit(styler[start+1])); + const bool wordIsNumber = IsADigit(styler[start]) || (styler[start] == '.' && start+1 <= end && IsADigit(styler[start+1])); if (wordIsNumber) { chAttr = SCE_HPHP_NUMBER; } else { - char s[100]; - GetTextSegment(styler, start, end, s, sizeof(s)); - if (keywords.InList(s)) + std::string s = GetStringSegment(styler, start, end); + if (keywords.InList(s.c_str())) chAttr = SCE_HPHP_WORD; } styler.ColourTo(end, chAttr); } -static bool isWordHSGML(Sci_PositionU start, Sci_PositionU end, WordList &keywords, Accessor &styler) { - char s[30 + 1]; - Sci_PositionU i = 0; - for (; i < end - start + 1 && i < 30; i++) { - s[i] = styler[start + i]; +bool isWordHSGML(Sci_PositionU start, Sci_PositionU end, const WordList &keywords, Accessor &styler) { + std::string s; + for (Sci_PositionU i = 0; i < end - start + 1 && i < 30; i++) { + s.push_back(styler[start + i]); } - s[i] = '\0'; - return keywords.InList(s); + return keywords.InList(s.c_str()); } -static bool isWordCdata(Sci_PositionU start, Sci_PositionU end, Accessor &styler) { - char s[30 + 1]; - Sci_PositionU i = 0; - for (; i < end - start + 1 && i < 30; i++) { - s[i] = styler[start + i]; +bool isWordCdata(Sci_PositionU start, Sci_PositionU end, Accessor &styler) { + std::string s; + for (Sci_PositionU i = 0; i < end - start + 1 && i < 30; i++) { + s.push_back(styler[start + i]); } - s[i] = '\0'; - return (0 == strcmp(s, "[CDATA[")); + return s == "[CDATA["; } // Return the first state to reach when entering a scripting language -static int StateForScript(script_type scriptLanguage) { +int StateForScript(script_type scriptLanguage) { int Result; switch (scriptLanguage) { case eScriptVBS: @@ -446,20 +455,20 @@ static int StateForScript(script_type scriptLanguage) { return Result; } -static inline bool issgmlwordchar(int ch) { +inline bool issgmlwordchar(int ch) { return !IsASCII(ch) || (isalnum(ch) || ch == '.' || ch == '_' || ch == ':' || ch == '!' || ch == '#' || ch == '['); } -static inline bool IsPhpWordStart(int ch) { +inline bool IsPhpWordStart(int ch) { return (IsASCII(ch) && (isalpha(ch) || (ch == '_'))) || (ch >= 0x7f); } -static inline bool IsPhpWordChar(int ch) { +inline bool IsPhpWordChar(int ch) { return IsADigit(ch) || IsPhpWordStart(ch); } -static bool InTagState(int state) { +bool InTagState(int state) { return state == SCE_H_TAG || state == SCE_H_TAGUNKNOWN || state == SCE_H_SCRIPT || state == SCE_H_ATTRIBUTE || state == SCE_H_ATTRIBUTEUNKNOWN || @@ -467,52 +476,52 @@ static bool InTagState(int state) { state == SCE_H_DOUBLESTRING || state == SCE_H_SINGLESTRING; } -static bool IsCommentState(const int state) { +bool IsCommentState(const int state) { return state == SCE_H_COMMENT || state == SCE_H_SGML_COMMENT; } -static bool IsScriptCommentState(const int state) { +bool IsScriptCommentState(const int state) { return state == SCE_HJ_COMMENT || state == SCE_HJ_COMMENTLINE || state == SCE_HJA_COMMENT || state == SCE_HJA_COMMENTLINE || state == SCE_HB_COMMENTLINE || state == SCE_HBA_COMMENTLINE; } -static bool isLineEnd(int ch) { +bool isLineEnd(int ch) { return ch == '\r' || ch == '\n'; } -static bool isMakoBlockEnd(const int ch, const int chNext, const char *blockType) { - if (strlen(blockType) == 0) { +bool isMakoBlockEnd(const int ch, const int chNext, const std::string &blockType) { + if (blockType.empty()) { return ((ch == '%') && (chNext == '>')); - } else if ((0 == strcmp(blockType, "inherit")) || - (0 == strcmp(blockType, "namespace")) || - (0 == strcmp(blockType, "include")) || - (0 == strcmp(blockType, "page"))) { + } else if ((blockType == "inherit") || + (blockType == "namespace") || + (blockType == "include") || + (blockType == "page")) { return ((ch == '/') && (chNext == '>')); - } else if (0 == strcmp(blockType, "%")) { + } else if (blockType == "%") { if (ch == '/' && isLineEnd(chNext)) - return 1; + return true; else - return isLineEnd(ch); - } else if (0 == strcmp(blockType, "{")) { + return isLineEnd(ch); + } else if (blockType == "{") { return ch == '}'; } else { return (ch == '>'); } } -static bool isDjangoBlockEnd(const int ch, const int chNext, const char *blockType) { - if (strlen(blockType) == 0) { - return 0; - } else if (0 == strcmp(blockType, "%")) { +bool isDjangoBlockEnd(const int ch, const int chNext, const std::string &blockType) { + if (blockType.empty()) { + return false; + } else if (blockType == "%") { return ((ch == '%') && (chNext == '}')); - } else if (0 == strcmp(blockType, "{")) { + } else if (blockType == "{") { return ((ch == '}') && (chNext == '}')); } else { - return 0; + return false; } } -static bool isPHPStringState(int state) { +bool isPHPStringState(int state) { return (state == SCE_HPHP_HSTRING) || (state == SCE_HPHP_SIMPLESTRING) || @@ -520,29 +529,27 @@ static bool isPHPStringState(int state) { (state == SCE_HPHP_COMPLEX_VARIABLE); } -static Sci_Position FindPhpStringDelimiter(char *phpStringDelimiter, const int phpStringDelimiterSize, Sci_Position i, const Sci_Position lengthDoc, Accessor &styler, bool &isSimpleString) { +Sci_Position FindPhpStringDelimiter(std::string &phpStringDelimiter, Sci_Position i, const Sci_Position lengthDoc, Accessor &styler, bool &isSimpleString) { Sci_Position j; const Sci_Position beginning = i - 1; bool isValidSimpleString = false; while (i < lengthDoc && (styler[i] == ' ' || styler[i] == '\t')) i++; - char ch = styler.SafeGetCharAt(i); const char chNext = styler.SafeGetCharAt(i + 1); + phpStringDelimiter.clear(); if (!IsPhpWordStart(ch)) { if (ch == '\'' && IsPhpWordStart(chNext)) { i++; ch = chNext; isSimpleString = true; } else { - phpStringDelimiter[0] = '\0'; return beginning; } } - phpStringDelimiter[0] = ch; + phpStringDelimiter.push_back(ch); i++; - for (j = i; j < lengthDoc && !isLineEnd(styler[j]); j++) { if (!IsPhpWordChar(styler[j])) { if (isSimpleString && (styler[j] == '\'') && isLineEnd(styler.SafeGetCharAt(j + 1))) { @@ -550,49 +557,415 @@ static Sci_Position FindPhpStringDelimiter(char *phpStringDelimiter, const int p j++; break; } else { - phpStringDelimiter[0] = '\0'; + phpStringDelimiter.clear(); return beginning; } } - if (j - i < phpStringDelimiterSize - 2) - phpStringDelimiter[j-i+1] = styler[j]; - else - i++; + phpStringDelimiter.push_back(styler[j]); } if (isSimpleString && !isValidSimpleString) { - phpStringDelimiter[0] = '\0'; + phpStringDelimiter.clear(); return beginning; } - phpStringDelimiter[j-i+1 - (isSimpleString ? 1 : 0)] = '\0'; return j - 1; } -static void ColouriseHyperTextDoc(Sci_PositionU startPos, Sci_Position length, int initStyle, WordList *keywordlists[], - Accessor &styler, bool isXml) { - WordList &keywords = *keywordlists[0]; - WordList &keywords2 = *keywordlists[1]; - WordList &keywords3 = *keywordlists[2]; - WordList &keywords4 = *keywordlists[3]; - WordList &keywords5 = *keywordlists[4]; - WordList &keywords6 = *keywordlists[5]; // SGML (DTD) keywords +// Options used for LexerHTML +struct OptionsHTML { + int aspDefaultLanguage = eScriptJS; + bool caseSensitive = false; + bool allowScripts = true; + bool isMako = false; + bool isDjango = false; + bool fold = false; + bool foldHTML = false; + bool foldHTMLPreprocessor = true; + bool foldCompact = true; + bool foldComment = false; + bool foldHeredoc = false; + bool foldXmlAtTagOpen = false; + OptionsHTML() noexcept { + } +}; +const char * const htmlWordListDesc[] = { + "HTML elements and attributes", + "JavaScript keywords", + "VBScript keywords", + "Python keywords", + "PHP keywords", + "SGML and DTD keywords", + 0, +}; + +const char * const phpscriptWordListDesc[] = { + "", //Unused + "", //Unused + "", //Unused + "", //Unused + "PHP keywords", + "", //Unused + 0, +}; + +struct OptionSetHTML : public OptionSet { + OptionSetHTML(bool isPHPScript_) { + + DefineProperty("asp.default.language", &OptionsHTML::aspDefaultLanguage, + "Script in ASP code is initially assumed to be in JavaScript. " + "To change this to VBScript set asp.default.language to 2. Python is 3."); + + DefineProperty("html.tags.case.sensitive", &OptionsHTML::caseSensitive, + "For XML and HTML, setting this property to 1 will make tags match in a case " + "sensitive way which is the expected behaviour for XML and XHTML."); + + DefineProperty("lexer.xml.allow.scripts", &OptionsHTML::allowScripts, + "Set to 0 to disable scripts in XML."); + + DefineProperty("lexer.html.mako", &OptionsHTML::isMako, + "Set to 1 to enable the mako template language."); + + DefineProperty("lexer.html.django", &OptionsHTML::isDjango, + "Set to 1 to enable the django template language."); + + DefineProperty("fold", &OptionsHTML::fold); + + DefineProperty("fold.html", &OptionsHTML::foldHTML, + "Folding is turned on or off for HTML and XML files with this option. " + "The fold option must also be on for folding to occur."); + + DefineProperty("fold.html.preprocessor", &OptionsHTML::foldHTMLPreprocessor, + "Folding is turned on or off for scripts embedded in HTML files with this option. " + "The default is on."); + + DefineProperty("fold.compact", &OptionsHTML::foldCompact); + + DefineProperty("fold.hypertext.comment", &OptionsHTML::foldComment, + "Allow folding for comments in scripts embedded in HTML. " + "The default is off."); + + DefineProperty("fold.hypertext.heredoc", &OptionsHTML::foldHeredoc, + "Allow folding for heredocs in scripts embedded in HTML. " + "The default is off."); + + DefineProperty("fold.xml.at.tag.open", &OptionsHTML::foldXmlAtTagOpen, + "Enable folding for XML at the start of open tag. " + "The default is off."); + + DefineWordListSets(isPHPScript_ ? phpscriptWordListDesc : htmlWordListDesc); + } +}; + +LexicalClass lexicalClassesHTML[] = { + // Lexer HTML SCLEX_HTML SCE_H_ SCE_HJ_ SCE_HJA_ SCE_HB_ SCE_HBA_ SCE_HP_ SCE_HPHP_ SCE_HPA_: + 0, "SCE_H_DEFAULT", "default", "Text", + 1, "SCE_H_TAG", "tag", "Tags", + 2, "SCE_H_ERRORTAGUNKNOWN", "error tag", "Unknown Tags", + 3, "SCE_H_ATTRIBUTE", "attribute", "Attributes", + 4, "SCE_H_ATTRIBUTEUNKNOWN", "error attribute", "Unknown Attributes", + 5, "SCE_H_NUMBER", "literal numeric", "Numbers", + 6, "SCE_H_DOUBLESTRING", "literal string", "Double quoted strings", + 7, "SCE_H_SINGLESTRING", "literal string", "Single quoted strings", + 8, "SCE_H_OTHER", "tag operator", "Other inside tag, including space and '='", + 9, "SCE_H_COMMENT", "comment", "Comment", + 10, "SCE_H_ENTITY", "literal", "Entities", + 11, "SCE_H_TAGEND", "tag", "XML style tag ends '/>'", + 12, "SCE_H_XMLSTART", "identifier", "XML identifier start ''", + 14, "SCE_H_SCRIPT", "error", "Internal state which should never be visible", + 15, "SCE_H_ASP", "preprocessor", "ASP <% ... %>", + 16, "SCE_H_ASPAT", "preprocessor", "ASP <% ... %>", + 17, "SCE_H_CDATA", "literal", "CDATA", + 18, "SCE_H_QUESTION", "preprocessor", "PHP", + 19, "SCE_H_VALUE", "literal string", "Unquoted values", + 20, "SCE_H_XCCOMMENT", "comment", "JSP Comment <%-- ... --%>", + 21, "SCE_H_SGML_DEFAULT", "default", "SGML tags ", + 22, "SCE_H_SGML_COMMAND", "preprocessor", "SGML command", + 23, "SCE_H_SGML_1ST_PARAM", "preprocessor", "SGML 1st param", + 24, "SCE_H_SGML_DOUBLESTRING", "literal string", "SGML double string", + 25, "SCE_H_SGML_SIMPLESTRING", "literal string", "SGML single string", + 26, "SCE_H_SGML_ERROR", "error", "SGML error", + 27, "SCE_H_SGML_SPECIAL", "literal", "SGML special (#XXXX type)", + 28, "SCE_H_SGML_ENTITY", "literal", "SGML entity", + 29, "SCE_H_SGML_COMMENT", "comment", "SGML comment", + 30, "SCE_H_SGML_1ST_PARAM_COMMENT", "error comment", "SGML first parameter - lexer internal. It is an error if any text is in this style.", + 31, "SCE_H_SGML_BLOCK_DEFAULT", "default", "SGML block", + 32, "", "predefined", "", + 33, "", "predefined", "", + 34, "", "predefined", "", + 35, "", "predefined", "", + 36, "", "predefined", "", + 37, "", "predefined", "", + 38, "", "predefined", "", + 39, "", "predefined", "", + 40, "SCE_HJ_START", "client javascript default", "JS Start - allows eol filled background to not start on same line as SCRIPT tag", + 41, "SCE_HJ_DEFAULT", "client javascript default", "JS Default", + 42, "SCE_HJ_COMMENT", "client javascript comment", "JS Comment", + 43, "SCE_HJ_COMMENTLINE", "client javascript comment line", "JS Line Comment", + 44, "SCE_HJ_COMMENTDOC", "client javascript comment documentation", "JS Doc comment", + 45, "SCE_HJ_NUMBER", "client javascript literal numeric", "JS Number", + 46, "SCE_HJ_WORD", "client javascript identifier", "JS Word", + 47, "SCE_HJ_KEYWORD", "client javascript keyword", "JS Keyword", + 48, "SCE_HJ_DOUBLESTRING", "client javascript literal string", "JS Double quoted string", + 49, "SCE_HJ_SINGLESTRING", "client javascript literal string", "JS Single quoted string", + 50, "SCE_HJ_SYMBOLS", "client javascript operator", "JS Symbols", + 51, "SCE_HJ_STRINGEOL", "client javascript error literal string", "JavaScript EOL", + 52, "SCE_HJ_REGEX", "client javascript literal regex", "JavaScript RegEx", + 53, "", "unused", "", + 54, "", "unused", "", + 55, "SCE_HJA_START", "server javascript default", "JS Start - allows eol filled background to not start on same line as SCRIPT tag", + 56, "SCE_HJA_DEFAULT", "server javascript default", "JS Default", + 57, "SCE_HJA_COMMENT", "server javascript comment", "JS Comment", + 58, "SCE_HJA_COMMENTLINE", "server javascript comment line", "JS Line Comment", + 59, "SCE_HJA_COMMENTDOC", "server javascript comment documentation", "JS Doc comment", + 60, "SCE_HJA_NUMBER", "server javascript literal numeric", "JS Number", + 61, "SCE_HJA_WORD", "server javascript identifier", "JS Word", + 62, "SCE_HJA_KEYWORD", "server javascript keyword", "JS Keyword", + 63, "SCE_HJA_DOUBLESTRING", "server javascript literal string", "JS Double quoted string", + 64, "SCE_HJA_SINGLESTRING", "server javascript literal string", "JS Single quoted string", + 65, "SCE_HJA_SYMBOLS", "server javascript operator", "JS Symbols", + 66, "SCE_HJA_STRINGEOL", "server javascript error literal string", "JavaScript EOL", + 67, "SCE_HJA_REGEX", "server javascript literal regex", "JavaScript RegEx", + 68, "", "unused", "", + 69, "", "unused", "", + 70, "SCE_HB_START", "client basic default", "Start", + 71, "SCE_HB_DEFAULT", "client basic default", "Default", + 72, "SCE_HB_COMMENTLINE", "client basic comment line", "Comment", + 73, "SCE_HB_NUMBER", "client basic literal numeric", "Number", + 74, "SCE_HB_WORD", "client basic keyword", "KeyWord", + 75, "SCE_HB_STRING", "client basic literal string", "String", + 76, "SCE_HB_IDENTIFIER", "client basic identifier", "Identifier", + 77, "SCE_HB_STRINGEOL", "client basic literal string", "Unterminated string", + 78, "", "unused", "", + 79, "", "unused", "", + 80, "SCE_HBA_START", "server basic default", "Start", + 81, "SCE_HBA_DEFAULT", "server basic default", "Default", + 82, "SCE_HBA_COMMENTLINE", "server basic comment line", "Comment", + 83, "SCE_HBA_NUMBER", "server basic literal numeric", "Number", + 84, "SCE_HBA_WORD", "server basic keyword", "KeyWord", + 85, "SCE_HBA_STRING", "server basic literal string", "String", + 86, "SCE_HBA_IDENTIFIER", "server basic identifier", "Identifier", + 87, "SCE_HBA_STRINGEOL", "server basic literal string", "Unterminated string", + 88, "", "unused", "", + 89, "", "unused", "", + 90, "SCE_HP_START", "client python default", "Embedded Python", + 91, "SCE_HP_DEFAULT", "client python default", "Embedded Python", + 92, "SCE_HP_COMMENTLINE", "client python comment line", "Comment", + 93, "SCE_HP_NUMBER", "client python literal numeric", "Number", + 94, "SCE_HP_STRING", "client python literal string", "String", + 95, "SCE_HP_CHARACTER", "client python literal string character", "Single quoted string", + 96, "SCE_HP_WORD", "client python keyword", "Keyword", + 97, "SCE_HP_TRIPLE", "client python literal string", "Triple quotes", + 98, "SCE_HP_TRIPLEDOUBLE", "client python literal string", "Triple double quotes", + 99, "SCE_HP_CLASSNAME", "client python identifier", "Class name definition", + 100, "SCE_HP_DEFNAME", "client python identifier", "Function or method name definition", + 101, "SCE_HP_OPERATOR", "client python operator", "Operators", + 102, "SCE_HP_IDENTIFIER", "client python identifier", "Identifiers", + 103, "", "unused", "", + 104, "SCE_HPHP_COMPLEX_VARIABLE", "server php identifier", "PHP complex variable", + 105, "SCE_HPA_START", "server python default", "ASP Python", + 106, "SCE_HPA_DEFAULT", "server python default", "ASP Python", + 107, "SCE_HPA_COMMENTLINE", "server python comment line", "Comment", + 108, "SCE_HPA_NUMBER", "server python literal numeric", "Number", + 109, "SCE_HPA_STRING", "server python literal string", "String", + 110, "SCE_HPA_CHARACTER", "server python literal string character", "Single quoted string", + 111, "SCE_HPA_WORD", "server python keyword", "Keyword", + 112, "SCE_HPA_TRIPLE", "server python literal string", "Triple quotes", + 113, "SCE_HPA_TRIPLEDOUBLE", "server python literal string", "Triple double quotes", + 114, "SCE_HPA_CLASSNAME", "server python identifier", "Class name definition", + 115, "SCE_HPA_DEFNAME", "server python identifier", "Function or method name definition", + 116, "SCE_HPA_OPERATOR", "server python operator", "Operators", + 117, "SCE_HPA_IDENTIFIER", "server python identifier", "Identifiers", + 118, "SCE_HPHP_DEFAULT", "server php default", "Default", + 119, "SCE_HPHP_HSTRING", "server php literal string", "Double quoted String", + 120, "SCE_HPHP_SIMPLESTRING", "server php literal string", "Single quoted string", + 121, "SCE_HPHP_WORD", "server php keyword", "Keyword", + 122, "SCE_HPHP_NUMBER", "server php literal numeric", "Number", + 123, "SCE_HPHP_VARIABLE", "server php identifier", "Variable", + 124, "SCE_HPHP_COMMENT", "server php comment", "Comment", + 125, "SCE_HPHP_COMMENTLINE", "server php comment line", "One line comment", + 126, "SCE_HPHP_HSTRING_VARIABLE", "server php literal string identifier", "PHP variable in double quoted string", + 127, "SCE_HPHP_OPERATOR", "server php operator", "PHP operator", +}; + +LexicalClass lexicalClassesXML[] = { + // Lexer.Secondary XML SCLEX_XML SCE_H_: + 0, "SCE_H_DEFAULT", "default", "Default", + 1, "SCE_H_TAG", "tag", "Tags", + 2, "SCE_H_TAGUNKNOWN", "error tag", "Unknown Tags", + 3, "SCE_H_ATTRIBUTE", "attribute", "Attributes", + 4, "SCE_H_ERRORATTRIBUTEUNKNOWN", "error attribute", "Unknown Attributes", + 5, "SCE_H_NUMBER", "literal numeric", "Numbers", + 6, "SCE_H_DOUBLESTRING", "literal string", "Double quoted strings", + 7, "SCE_H_SINGLESTRING", "literal string", "Single quoted strings", + 8, "SCE_H_OTHER", "tag operator", "Other inside tag, including space and '='", + 9, "SCE_H_COMMENT", "comment", "Comment", + 10, "SCE_H_ENTITY", "literal", "Entities", + 11, "SCE_H_TAGEND", "tag", "XML style tag ends '/>'", + 12, "SCE_H_XMLSTART", "identifier", "XML identifier start ''", + 14, "", "unused", "", + 15, "", "unused", "", + 16, "", "unused", "", + 17, "SCE_H_CDATA", "literal", "CDATA", + 18, "SCE_H_QUESTION", "preprocessor", "Question", + 19, "SCE_H_VALUE", "literal string", "Unquoted Value", + 20, "", "unused", "", + 21, "SCE_H_SGML_DEFAULT", "default", "SGML tags ", + 22, "SCE_H_SGML_COMMAND", "preprocessor", "SGML command", + 23, "SCE_H_SGML_1ST_PARAM", "preprocessor", "SGML 1st param", + 24, "SCE_H_SGML_DOUBLESTRING", "literal string", "SGML double string", + 25, "SCE_H_SGML_SIMPLESTRING", "literal string", "SGML single string", + 26, "SCE_H_SGML_ERROR", "error", "SGML error", + 27, "SCE_H_SGML_SPECIAL", "literal", "SGML special (#XXXX type)", + 28, "SCE_H_SGML_ENTITY", "literal", "SGML entity", + 29, "SCE_H_SGML_COMMENT", "comment", "SGML comment", + 30, "", "unused", "", + 31, "SCE_H_SGML_BLOCK_DEFAULT", "default", "SGML block", +}; + +const char *tagsThatDoNotFold[] = { + "area", + "base", + "basefont", + "br", + "col", + "command", + "embed", + "frame", + "hr", + "img", + "input", + "isindex", + "keygen", + "link", + "meta", + "param", + "source", + "track", + "wbr" +}; + +} + +class LexerHTML : public DefaultLexer { + bool isXml; + bool isPHPScript; + WordList keywords; + WordList keywords2; + WordList keywords3; + WordList keywords4; + WordList keywords5; + WordList keywords6; // SGML (DTD) keywords + OptionsHTML options; + OptionSetHTML osHTML; + std::set nonFoldingTags; +public: + explicit LexerHTML(bool isXml_, bool isPHPScript_) : + DefaultLexer( + isXml_ ? "xml" : (isPHPScript_ ? "phpscript" : "hypertext"), + isXml_ ? SCLEX_XML : (isPHPScript_ ? SCLEX_PHPSCRIPT : SCLEX_HTML), + isXml_ ? lexicalClassesHTML : lexicalClassesXML, + isXml_ ? Sci::size(lexicalClassesHTML) : Sci::size(lexicalClassesXML)), + isXml(isXml_), + isPHPScript(isPHPScript_), + osHTML(isPHPScript_), + nonFoldingTags(std::begin(tagsThatDoNotFold), std::end(tagsThatDoNotFold)) { + } + ~LexerHTML() override { + } + void SCI_METHOD Release() override { + delete this; + } + const char *SCI_METHOD PropertyNames() override { + return osHTML.PropertyNames(); + } + int SCI_METHOD PropertyType(const char *name) override { + return osHTML.PropertyType(name); + } + const char *SCI_METHOD DescribeProperty(const char *name) override { + return osHTML.DescribeProperty(name); + } + Sci_Position SCI_METHOD PropertySet(const char *key, const char *val) override; + const char * SCI_METHOD PropertyGet(const char *key) override { + return osHTML.PropertyGet(key); + } + const char *SCI_METHOD DescribeWordListSets() override { + return osHTML.DescribeWordListSets(); + } + Sci_Position SCI_METHOD WordListSet(int n, const char *wl) override; + void SCI_METHOD Lex(Sci_PositionU startPos, Sci_Position length, int initStyle, IDocument *pAccess) override; + // No Fold as all folding performs in Lex. + + static ILexer *LexerFactoryHTML() { + return new LexerHTML(false, false); + } + static ILexer *LexerFactoryXML() { + return new LexerHTML(true, false); + } + static ILexer *LexerFactoryPHPScript() { + return new LexerHTML(false, true); + } +}; + +Sci_Position SCI_METHOD LexerHTML::PropertySet(const char *key, const char *val) { + if (osHTML.PropertySet(&options, key, val)) { + return 0; + } + return -1; +} + +Sci_Position SCI_METHOD LexerHTML::WordListSet(int n, const char *wl) { + WordList *wordListN = 0; + switch (n) { + case 0: + wordListN = &keywords; + break; + case 1: + wordListN = &keywords2; + break; + case 2: + wordListN = &keywords3; + break; + case 3: + wordListN = &keywords4; + break; + case 4: + wordListN = &keywords5; + break; + case 5: + wordListN = &keywords6; + break; + } + Sci_Position firstModification = -1; + if (wordListN) { + WordList wlNew; + wlNew.Set(wl); + if (*wordListN != wlNew) { + wordListN->Set(wl); + firstModification = 0; + } + } + return firstModification; +} + +void SCI_METHOD LexerHTML::Lex(Sci_PositionU startPos, Sci_Position length, int initStyle, IDocument *pAccess) { + Accessor styler(pAccess, nullptr); + if (isPHPScript && (startPos == 0)) { + initStyle = SCE_HPHP_DEFAULT; + } styler.StartAt(startPos); - char prevWord[200]; - prevWord[0] = '\0'; - char phpStringDelimiter[200]; // PHP is not limited in length, we are - phpStringDelimiter[0] = '\0'; + std::string prevWord; + std::string phpStringDelimiter; int StateToPrint = initStyle; int state = stateForPrintState(StateToPrint); - char makoBlockType[200]; - makoBlockType[0] = '\0'; + std::string makoBlockType; int makoComment = 0; - char djangoBlockType[2]; - djangoBlockType[0] = '\0'; - + std::string djangoBlockType; // If inside a tag, it may be a script tag, so reread from the start of line starting tag to ensure any language tags are seen if (InTagState(state)) { while ((startPos > 0) && (InTagState(styler.StyleAt(startPos - 1)))) { - Sci_Position backLineStart = styler.LineStart(styler.GetLine(startPos-1)); + const Sci_Position backLineStart = styler.LineStart(styler.GetLine(startPos-1)); length += startPos - backLineStart; startPos = backLineStart; } @@ -628,18 +1001,15 @@ static void ColouriseHyperTextDoc(Sci_PositionU startPos, Sci_Position length, i } else { // Default client and ASP scripting language is JavaScript lineState = eScriptJS << 8; - - // property asp.default.language - // Script in ASP code is initially assumed to be in JavaScript. - // To change this to VBScript set asp.default.language to 2. Python is 3. - lineState |= styler.GetPropertyInt("asp.default.language", eScriptJS) << 4; + lineState |= options.aspDefaultLanguage << 4; } - script_mode inScriptType = script_mode((lineState >> 0) & 0x03); // 2 bits of scripting mode + script_mode inScriptType = static_cast((lineState >> 0) & 0x03); // 2 bits of scripting mode + bool tagOpened = (lineState >> 2) & 0x01; // 1 bit to know if we are in an opened tag bool tagClosing = (lineState >> 3) & 0x01; // 1 bit to know if we are in a closing tag bool tagDontFold = false; //some HTML tags should not be folded - script_type aspScript = script_type((lineState >> 4) & 0x0F); // 4 bits of script name - script_type clientScript = script_type((lineState >> 8) & 0x0F); // 4 bits of script name + script_type aspScript = static_cast((lineState >> 4) & 0x0F); // 4 bits of script name + script_type clientScript = static_cast((lineState >> 8) & 0x0F); // 4 bits of script name int beforePreProc = (lineState >> 12) & 0xFF; // 8 bits of state script_type scriptLanguage = ScriptOfState(state); @@ -648,48 +1018,17 @@ static void ColouriseHyperTextDoc(Sci_PositionU startPos, Sci_Position length, i scriptLanguage = eScriptComment; } script_type beforeLanguage = ScriptOfState(beforePreProc); - - // property fold.html - // Folding is turned on or off for HTML and XML files with this option. - // The fold option must also be on for folding to occur. - const bool foldHTML = styler.GetPropertyInt("fold.html", 0) != 0; - - const bool fold = foldHTML && styler.GetPropertyInt("fold", 0); - - // property fold.html.preprocessor - // Folding is turned on or off for scripts embedded in HTML files with this option. - // The default is on. - const bool foldHTMLPreprocessor = foldHTML && styler.GetPropertyInt("fold.html.preprocessor", 1); - - const bool foldCompact = styler.GetPropertyInt("fold.compact", 1) != 0; - - // property fold.hypertext.comment - // Allow folding for comments in scripts embedded in HTML. - // The default is off. - const bool foldComment = fold && styler.GetPropertyInt("fold.hypertext.comment", 0) != 0; - - // property fold.hypertext.heredoc - // Allow folding for heredocs in scripts embedded in HTML. - // The default is off. - const bool foldHeredoc = fold && styler.GetPropertyInt("fold.hypertext.heredoc", 0) != 0; - - // property html.tags.case.sensitive - // For XML and HTML, setting this property to 1 will make tags match in a case - // sensitive way which is the expected behaviour for XML and XHTML. - const bool caseSensitive = styler.GetPropertyInt("html.tags.case.sensitive", 0) != 0; - - // property lexer.xml.allow.scripts - // Set to 0 to disable scripts in XML. - const bool allowScripts = styler.GetPropertyInt("lexer.xml.allow.scripts", 1) != 0; - - // property lexer.html.mako - // Set to 1 to enable the mako template language. - const bool isMako = styler.GetPropertyInt("lexer.html.mako", 0) != 0; - - // property lexer.html.django - // Set to 1 to enable the django template language. - const bool isDjango = styler.GetPropertyInt("lexer.html.django", 0) != 0; - + const bool foldHTML = options.foldHTML; + const bool fold = foldHTML && options.fold; + const bool foldHTMLPreprocessor = foldHTML && options.foldHTMLPreprocessor; + const bool foldCompact = options.foldCompact; + const bool foldComment = fold && options.foldComment; + const bool foldHeredoc = fold && options.foldHeredoc; + const bool foldXmlAtTagOpen = isXml && fold && options.foldXmlAtTagOpen; + const bool caseSensitive = options.caseSensitive; + const bool allowScripts = options.allowScripts; + const bool isMako = options.isMako; + const bool isDjango = options.isDjango; const CharacterSet setHTMLWord(CharacterSet::setAlphaNum, ".-_:!#", 0x80, true); const CharacterSet setTagContinue(CharacterSet::setAlphaNum, ".-_:!#[", 0x80, true); const CharacterSet setAttributeContinue(CharacterSet::setAlphaNum, ".-_:!#/", 0x80, true); @@ -781,7 +1120,7 @@ static void ColouriseHyperTextDoc(Sci_PositionU startPos, Sci_Position length, i // check if the number of tabs is lower than the level int Findlevel = (levelCurrent & ~SC_FOLDLEVELBASE) * 8; for (Sci_Position j = 0; Findlevel > 0; j++) { - char chTmp = styler.SafeGetCharAt(i + j + 1); + const char chTmp = styler.SafeGetCharAt(i + j + 1); if (chTmp == '\t') { Findlevel -= 8; } else if (chTmp == ' ') { @@ -846,10 +1185,9 @@ static void ColouriseHyperTextDoc(Sci_PositionU startPos, Sci_Position length, i state = SCE_H_DEFAULT; } } - // Allow falling through to mako handling code if newline is going to end a block if (((ch == '\r' && chNext != '\n') || (ch == '\n')) && - (!isMako || (0 != strcmp(makoBlockType, "%")))) { + (!isMako || (makoBlockType != "%"))) { } // Ignore everything in mako comment until the line ends else if (isMako && makoComment) { @@ -902,6 +1240,9 @@ static void ColouriseHyperTextDoc(Sci_PositionU startPos, Sci_Position length, i i += 2; visibleChars += 2; tagClosing = true; + if (foldXmlAtTagOpen) { + levelCurrent--; + } continue; } } @@ -948,13 +1289,13 @@ static void ColouriseHyperTextDoc(Sci_PositionU startPos, Sci_Position length, i (ch == '$' && chNext == '{') || (ch == '<' && chNext == '/' && chNext2 == '%'))) { if (ch == '%' || ch == '/') - StringCopy(makoBlockType, "%"); + makoBlockType = "%"; else if (ch == '$') - StringCopy(makoBlockType, "{"); + makoBlockType = "{"; else if (chNext == '/') - GetNextWord(styler, i+3, makoBlockType, sizeof(makoBlockType)); + makoBlockType = GetNextWord(styler, i+3); else - GetNextWord(styler, i+2, makoBlockType, sizeof(makoBlockType)); + makoBlockType = GetNextWord(styler, i+2); styler.ColourTo(i - 1, StateToPrint); beforePreProc = state; if (inScriptType == eNonHtmlScript) @@ -972,11 +1313,10 @@ static void ColouriseHyperTextDoc(Sci_PositionU startPos, Sci_Position length, i state = SCE_HP_START; scriptLanguage = eScriptPython; styler.ColourTo(i, SCE_H_ASP); - if (ch != '%' && ch != '$' && ch != '/') { - i += static_cast(strlen(makoBlockType)); - visibleChars += static_cast(strlen(makoBlockType)); - if (keywords4.InList(makoBlockType)) + i += makoBlockType.length(); + visibleChars += static_cast(makoBlockType.length()); + if (keywords4.InList(makoBlockType.c_str())) styler.ColourTo(i, SCE_HP_WORD); else styler.ColourTo(i, SCE_H_TAGUNKNOWN); @@ -1017,11 +1357,11 @@ static void ColouriseHyperTextDoc(Sci_PositionU startPos, Sci_Position length, i } // handle the start Django template code - else if (isDjango && scriptLanguage != eScriptPython && (ch == '{' && (chNext == '%' || chNext == '{'))) { + else if (isDjango && scriptLanguage != eScriptPython && scriptLanguage != eScriptComment && (ch == '{' && (chNext == '%' || chNext == '{'))) { if (chNext == '%') - StringCopy(djangoBlockType, "%"); + djangoBlockType = "%"; else - StringCopy(djangoBlockType, "{"); + djangoBlockType = "{"; styler.ColourTo(i - 1, StateToPrint); beforePreProc = state; if (inScriptType == eNonHtmlScript) @@ -1120,15 +1460,15 @@ static void ColouriseHyperTextDoc(Sci_PositionU startPos, Sci_Position length, i } else { styler.ColourTo(i - 1, StateToPrint); } - if (0 != strcmp(makoBlockType, "%") && (0 != strcmp(makoBlockType, "{")) && ch != '>') { + if ((makoBlockType != "%") && (makoBlockType != "{") && ch != '>') { i++; visibleChars++; } - else if (0 == strcmp(makoBlockType, "%") && ch == '/') { + else if ((makoBlockType == "%") && ch == '/') { i++; visibleChars++; } - if (0 != strcmp(makoBlockType, "%") || ch == '/') { + if ((makoBlockType != "%") || ch == '/') { styler.ColourTo(i, SCE_H_ASP); } state = beforePreProc; @@ -1228,6 +1568,12 @@ static void ColouriseHyperTextDoc(Sci_PositionU startPos, Sci_Position length, i // in HTML, fold on tag open and unfold on tag close tagOpened = true; tagClosing = (chNext == '/'); + if (foldXmlAtTagOpen && !(chNext == '/' || chNext == '?' || chNext == '!' || chNext == '-' || chNext == '%')) { + levelCurrent++; + } + if (foldXmlAtTagOpen && chNext == '/') { + levelCurrent--; + } styler.ColourTo(i - 1, StateToPrint); if (chNext != '!') state = SCE_H_TAGUNKNOWN; @@ -1406,7 +1752,7 @@ static void ColouriseHyperTextDoc(Sci_PositionU startPos, Sci_Position length, i case SCE_H_TAGUNKNOWN: if (!setTagContinue.Contains(ch) && !((ch == '/') && (chPrev == '<'))) { int eClass = classifyTagHTML(styler.GetStartSegment(), - i - 1, keywords, styler, tagDontFold, caseSensitive, isXml, allowScripts); + i - 1, keywords, styler, tagDontFold, caseSensitive, isXml, allowScripts, nonFoldingTags); if (eClass == SCE_H_SCRIPT || eClass == SCE_H_COMMENT) { if (!tagClosing) { inScriptType = eNonHtmlScript; @@ -1424,7 +1770,7 @@ static void ColouriseHyperTextDoc(Sci_PositionU startPos, Sci_Position length, i state = SCE_H_DEFAULT; } tagOpened = false; - if (!tagDontFold) { + if (!(foldXmlAtTagOpen || tagDontFold)) { if (tagClosing) { levelCurrent--; } else { @@ -1443,6 +1789,9 @@ static void ColouriseHyperTextDoc(Sci_PositionU startPos, Sci_Position length, i ch = chNext; state = SCE_H_DEFAULT; tagOpened = false; + if (foldXmlAtTagOpen) { + levelCurrent--; + } } else { if (eClass != SCE_H_TAGUNKNOWN) { if (eClass == SCE_H_SGML_DEFAULT) { @@ -1457,7 +1806,7 @@ static void ColouriseHyperTextDoc(Sci_PositionU startPos, Sci_Position length, i case SCE_H_ATTRIBUTE: if (!setAttributeContinue.Contains(ch)) { if (inScriptType == eNonHtmlScript) { - int scriptLanguagePrev = scriptLanguage; + const int scriptLanguagePrev = scriptLanguage; clientScript = segIsScriptingIndicator(styler, styler.GetStartSegment(), i - 1, scriptLanguage); scriptLanguage = clientScript; if ((scriptLanguagePrev != scriptLanguage) && (scriptLanguage == eScriptNone)) @@ -1472,7 +1821,7 @@ static void ColouriseHyperTextDoc(Sci_PositionU startPos, Sci_Position length, i state = SCE_H_DEFAULT; } tagOpened = false; - if (!tagDontFold) { + if (!(foldXmlAtTagOpen || tagDontFold)) { if (tagClosing) { levelCurrent--; } else { @@ -1498,7 +1847,7 @@ static void ColouriseHyperTextDoc(Sci_PositionU startPos, Sci_Position length, i state = SCE_H_DEFAULT; } tagOpened = false; - if (!tagDontFold) { + if (!(foldXmlAtTagOpen || tagDontFold)) { if (tagClosing) { levelCurrent--; } else { @@ -1522,6 +1871,9 @@ static void ColouriseHyperTextDoc(Sci_PositionU startPos, Sci_Position length, i ch = chNext; state = SCE_H_DEFAULT; tagOpened = false; + if (foldXmlAtTagOpen) { + levelCurrent--; + } } else if (ch == '?' && chNext == '>') { styler.ColourTo(i - 1, StateToPrint); styler.ColourTo(i + 1, SCE_H_XMLEND); @@ -1936,17 +2288,17 @@ static void ColouriseHyperTextDoc(Sci_PositionU startPos, Sci_Position length, i state = SCE_HPHP_COMMENTLINE; } else if (ch == '\"') { state = SCE_HPHP_HSTRING; - StringCopy(phpStringDelimiter, "\""); + phpStringDelimiter = "\""; } else if (styler.Match(i, "<<<")) { bool isSimpleString = false; - i = FindPhpStringDelimiter(phpStringDelimiter, sizeof(phpStringDelimiter), i + 3, lengthDoc, styler, isSimpleString); - if (strlen(phpStringDelimiter)) { + i = FindPhpStringDelimiter(phpStringDelimiter, i + 3, lengthDoc, styler, isSimpleString); + if (!phpStringDelimiter.empty()) { state = (isSimpleString ? SCE_HPHP_SIMPLESTRING : SCE_HPHP_HSTRING); if (foldHeredoc) levelCurrent++; } } else if (ch == '\'') { state = SCE_HPHP_SIMPLESTRING; - StringCopy(phpStringDelimiter, "\'"); + phpStringDelimiter = "\'"; } else if (ch == '$' && IsPhpWordStart(chNext)) { state = SCE_HPHP_VARIABLE; } else if (IsOperator(ch)) { @@ -1987,7 +2339,7 @@ static void ColouriseHyperTextDoc(Sci_PositionU startPos, Sci_Position length, i } break; case SCE_HPHP_HSTRING: - if (ch == '\\' && (phpStringDelimiter[0] == '\"' || chNext == '$' || chNext == '{')) { + if (ch == '\\' && ((phpStringDelimiter == "\"") || chNext == '$' || chNext == '{')) { // skip the next char i++; } else if (((ch == '{' && chNext == '$') || (ch == '$' && chNext == '{')) @@ -1997,12 +2349,12 @@ static void ColouriseHyperTextDoc(Sci_PositionU startPos, Sci_Position length, i } else if (ch == '$' && IsPhpWordStart(chNext)) { styler.ColourTo(i - 1, StateToPrint); state = SCE_HPHP_HSTRING_VARIABLE; - } else if (styler.Match(i, phpStringDelimiter)) { - if (phpStringDelimiter[0] == '\"') { + } else if (styler.Match(i, phpStringDelimiter.c_str())) { + if (phpStringDelimiter == "\"") { styler.ColourTo(i, StateToPrint); state = SCE_HPHP_DEFAULT; } else if (isLineEnd(chPrev)) { - const int psdLength = static_cast(strlen(phpStringDelimiter)); + const int psdLength = static_cast(phpStringDelimiter.length()); const char chAfterPsd = styler.SafeGetCharAt(i + psdLength); const char chAfterPsd2 = styler.SafeGetCharAt(i + psdLength + 1); if (isLineEnd(chAfterPsd) || @@ -2016,7 +2368,7 @@ static void ColouriseHyperTextDoc(Sci_PositionU startPos, Sci_Position length, i } break; case SCE_HPHP_SIMPLESTRING: - if (phpStringDelimiter[0] == '\'') { + if (phpStringDelimiter == "\'") { if (ch == '\\') { // skip the next char i++; @@ -2024,8 +2376,8 @@ static void ColouriseHyperTextDoc(Sci_PositionU startPos, Sci_Position length, i styler.ColourTo(i, StateToPrint); state = SCE_HPHP_DEFAULT; } - } else if (isLineEnd(chPrev) && styler.Match(i, phpStringDelimiter)) { - const int psdLength = static_cast(strlen(phpStringDelimiter)); + } else if (isLineEnd(chPrev) && styler.Match(i, phpStringDelimiter.c_str())) { + const int psdLength = static_cast(phpStringDelimiter.length()); const char chAfterPsd = styler.SafeGetCharAt(i + psdLength); const char chAfterPsd2 = styler.SafeGetCharAt(i + psdLength + 1); if (isLineEnd(chAfterPsd) || @@ -2066,17 +2418,17 @@ static void ColouriseHyperTextDoc(Sci_PositionU startPos, Sci_Position length, i state = SCE_HPHP_COMMENTLINE; } else if (ch == '\"') { state = SCE_HPHP_HSTRING; - StringCopy(phpStringDelimiter, "\""); + phpStringDelimiter = "\""; } else if (styler.Match(i, "<<<")) { bool isSimpleString = false; - i = FindPhpStringDelimiter(phpStringDelimiter, sizeof(phpStringDelimiter), i + 3, lengthDoc, styler, isSimpleString); - if (strlen(phpStringDelimiter)) { + i = FindPhpStringDelimiter(phpStringDelimiter, i + 3, lengthDoc, styler, isSimpleString); + if (!phpStringDelimiter.empty()) { state = (isSimpleString ? SCE_HPHP_SIMPLESTRING : SCE_HPHP_HSTRING); if (foldHeredoc) levelCurrent++; } } else if (ch == '\'') { state = SCE_HPHP_SIMPLESTRING; - StringCopy(phpStringDelimiter, "\'"); + phpStringDelimiter = "\'"; } else if (ch == '$' && IsPhpWordStart(chNext)) { state = SCE_HPHP_VARIABLE; } else if (IsOperator(ch)) { @@ -2091,7 +2443,7 @@ static void ColouriseHyperTextDoc(Sci_PositionU startPos, Sci_Position length, i // Some of the above terminated their lexeme but since the same character starts // the same class again, only reenter if non empty segment. - bool nonEmptySegment = i >= static_cast(styler.GetStartSegment()); + const bool nonEmptySegment = i >= static_cast(styler.GetStartSegment()); if (state == SCE_HB_DEFAULT) { // One of the above succeeded if ((ch == '\"') && (nonEmptySegment)) { state = SCE_HB_STRING; @@ -2154,50 +2506,12 @@ static void ColouriseHyperTextDoc(Sci_PositionU startPos, Sci_Position length, i // Fill in the real level of the next line, keeping the current flags as they will be filled in later if (fold) { - int flagsNext = styler.LevelAt(lineCurrent) & ~SC_FOLDLEVELNUMBERMASK; + const int flagsNext = styler.LevelAt(lineCurrent) & ~SC_FOLDLEVELNUMBERMASK; styler.SetLevel(lineCurrent, levelPrev | flagsNext); } + styler.Flush(); } -static void ColouriseXMLDoc(Sci_PositionU startPos, Sci_Position length, int initStyle, WordList *keywordlists[], - Accessor &styler) { - // Passing in true because we're lexing XML - ColouriseHyperTextDoc(startPos, length, initStyle, keywordlists, styler, true); -} - -static void ColouriseHTMLDoc(Sci_PositionU startPos, Sci_Position length, int initStyle, WordList *keywordlists[], - Accessor &styler) { - // Passing in false because we're notlexing XML - ColouriseHyperTextDoc(startPos, length, initStyle, keywordlists, styler, false); -} - -static void ColourisePHPScriptDoc(Sci_PositionU startPos, Sci_Position length, int initStyle, WordList *keywordlists[], - Accessor &styler) { - if (startPos == 0) - initStyle = SCE_HPHP_DEFAULT; - ColouriseHTMLDoc(startPos, length, initStyle, keywordlists, styler); -} - -static const char * const htmlWordListDesc[] = { - "HTML elements and attributes", - "JavaScript keywords", - "VBScript keywords", - "Python keywords", - "PHP keywords", - "SGML and DTD keywords", - 0, -}; - -static const char * const phpscriptWordListDesc[] = { - "", //Unused - "", //Unused - "", //Unused - "", //Unused - "PHP keywords", - "", //Unused - 0, -}; - -LexerModule lmHTML(SCLEX_HTML, ColouriseHTMLDoc, "hypertext", 0, htmlWordListDesc); -LexerModule lmXML(SCLEX_XML, ColouriseXMLDoc, "xml", 0, htmlWordListDesc); -LexerModule lmPHPSCRIPT(SCLEX_PHPSCRIPT, ColourisePHPScriptDoc, "phpscript", 0, phpscriptWordListDesc); +LexerModule lmHTML(SCLEX_HTML, LexerHTML::LexerFactoryHTML, "hypertext", htmlWordListDesc); +LexerModule lmXML(SCLEX_XML, LexerHTML::LexerFactoryXML, "xml", htmlWordListDesc); +LexerModule lmPHPSCRIPT(SCLEX_PHPSCRIPT, LexerHTML::LexerFactoryPHPScript, "phpscript", phpscriptWordListDesc); diff --git a/src/stc/scintilla/lexers/LexHaskell.cxx b/src/stc/scintilla/lexers/LexHaskell.cxx index 0dd67d0ae3..93c670a0cd 100644 --- a/src/stc/scintilla/lexers/LexHaskell.cxx +++ b/src/stc/scintilla/lexers/LexHaskell.cxx @@ -26,6 +26,7 @@ #include #include +#include #include #include "ILexer.h" @@ -41,10 +42,9 @@ #include "CharacterCategory.h" #include "LexerModule.h" #include "OptionSet.h" +#include "DefaultLexer.h" -#ifdef SCI_NAMESPACE using namespace Scintilla; -#endif // See https://github.com/ghc/ghc/blob/master/compiler/parser/Lexer.x#L1682 // Note, letter modifiers are prohibited. @@ -269,7 +269,7 @@ struct OptionSetHaskell : public OptionSet { } }; -class LexerHaskell : public ILexer { +class LexerHaskell : public DefaultLexer { bool literate; Sci_Position firstImportLine; int firstImportIndent; @@ -390,45 +390,50 @@ class LexerHaskell : public ILexer { public: LexerHaskell(bool literate_) - : literate(literate_) + : DefaultLexer(literate_ ? "literatehaskell" : "haskell", literate_ ? SCLEX_LITERATEHASKELL : SCLEX_HASKELL) + , literate(literate_) , firstImportLine(-1) , firstImportIndent(0) {} virtual ~LexerHaskell() {} - void SCI_METHOD Release() { + void SCI_METHOD Release() override { delete this; } - int SCI_METHOD Version() const { - return lvOriginal; + int SCI_METHOD Version() const override { + return lvIdentity; } - const char * SCI_METHOD PropertyNames() { + const char * SCI_METHOD PropertyNames() override { return osHaskell.PropertyNames(); } - int SCI_METHOD PropertyType(const char *name) { + int SCI_METHOD PropertyType(const char *name) override { return osHaskell.PropertyType(name); } - const char * SCI_METHOD DescribeProperty(const char *name) { + const char * SCI_METHOD DescribeProperty(const char *name) override { return osHaskell.DescribeProperty(name); } - Sci_Position SCI_METHOD PropertySet(const char *key, const char *val); + Sci_Position SCI_METHOD PropertySet(const char *key, const char *val) override; - const char * SCI_METHOD DescribeWordListSets() { + const char * SCI_METHOD PropertyGet(const char *key) override { + return osHaskell.PropertyGet(key); + } + + const char * SCI_METHOD DescribeWordListSets() override { return osHaskell.DescribeWordListSets(); } - Sci_Position SCI_METHOD WordListSet(int n, const char *wl); + Sci_Position SCI_METHOD WordListSet(int n, const char *wl) override; - void SCI_METHOD Lex(Sci_PositionU startPos, Sci_Position length, int initStyle, IDocument *pAccess); + void SCI_METHOD Lex(Sci_PositionU startPos, Sci_Position length, int initStyle, IDocument *pAccess) override; - void SCI_METHOD Fold(Sci_PositionU startPos, Sci_Position length, int initStyle, IDocument *pAccess); + void SCI_METHOD Fold(Sci_PositionU startPos, Sci_Position length, int initStyle, IDocument *pAccess) override; - void * SCI_METHOD PrivateCall(int, void *) { + void * SCI_METHOD PrivateCall(int, void *) override { return 0; } diff --git a/src/stc/scintilla/lexers/LexHex.cxx b/src/stc/scintilla/lexers/LexHex.cxx index d549881cb6..6e10997860 100644 --- a/src/stc/scintilla/lexers/LexHex.cxx +++ b/src/stc/scintilla/lexers/LexHex.cxx @@ -118,9 +118,7 @@ #include "CharacterSet.h" #include "LexerModule.h" -#ifdef SCI_NAMESPACE using namespace Scintilla; -#endif // prototypes for general helper functions static inline bool IsNewline(const int ch); @@ -651,7 +649,9 @@ static void ColouriseSrecDoc(Sci_PositionU startPos, Sci_Position length, int in while (sc.More()) { Sci_PositionU recStartPos; - int byteCount, reqByteCount, addrFieldSize, addrFieldType, dataFieldSize, dataFieldType; + Sci_Position reqByteCount; + Sci_Position dataFieldSize; + int byteCount, addrFieldSize, addrFieldType, dataFieldType; int cs1, cs2; switch (sc.state) { diff --git a/src/stc/scintilla/lexers/LexHollywood.cxx b/src/stc/scintilla/lexers/LexHollywood.cxx new file mode 100644 index 0000000000..8d306c9fab --- /dev/null +++ b/src/stc/scintilla/lexers/LexHollywood.cxx @@ -0,0 +1,516 @@ +// Scintilla source code edit control +/** @file LexHollywood.cxx + ** Lexer for Hollywood + ** Written by Andreas Falkenhahn, based on the BlitzBasic/PureBasic/Lua lexers + ** Thanks to Nicholai Benalal + ** For more information on Hollywood, see http://www.hollywood-mal.com/ + ** Mail me (andreas airsoftsoftwair de) for any bugs. + ** This code is subject to the same license terms as the rest of the Scintilla project: + ** The License.txt file describes the conditions under which this software may be distributed. + **/ + +#include +#include +#include +#include +#include +#include + +#include +#include + +#include "ILexer.h" +#include "Scintilla.h" +#include "SciLexer.h" + +#include "WordList.h" +#include "LexAccessor.h" +#include "StyleContext.h" +#include "CharacterSet.h" +#include "LexerModule.h" +#include "OptionSet.h" +#include "DefaultLexer.h" + +using namespace Scintilla; + +/* Bits: + * 1 - whitespace + * 2 - operator + * 4 - identifier + * 8 - decimal digit + * 16 - hex digit + * 32 - bin digit + * 64 - letter + */ +static int character_classification[128] = +{ + 0, // NUL ($0) + 0, // SOH ($1) + 0, // STX ($2) + 0, // ETX ($3) + 0, // EOT ($4) + 0, // ENQ ($5) + 0, // ACK ($6) + 0, // BEL ($7) + 0, // BS ($8) + 1, // HT ($9) + 1, // LF ($A) + 0, // VT ($B) + 0, // FF ($C) + 1, // CR ($D) + 0, // SO ($E) + 0, // SI ($F) + 0, // DLE ($10) + 0, // DC1 ($11) + 0, // DC2 ($12) + 0, // DC3 ($13) + 0, // DC4 ($14) + 0, // NAK ($15) + 0, // SYN ($16) + 0, // ETB ($17) + 0, // CAN ($18) + 0, // EM ($19) + 0, // SUB ($1A) + 0, // ESC ($1B) + 0, // FS ($1C) + 0, // GS ($1D) + 0, // RS ($1E) + 0, // US ($1F) + 1, // space ($20) + 4, // ! ($21) + 0, // " ($22) + 0, // # ($23) + 4, // $ ($24) + 2, // % ($25) + 2, // & ($26) + 2, // ' ($27) + 2, // ( ($28) + 2, // ) ($29) + 2, // * ($2A) + 2, // + ($2B) + 2, // , ($2C) + 2, // - ($2D) + // NB: we treat "." as an identifier although it is also an operator and a decimal digit + // the reason why we treat it as an identifier is to support syntax highlighting for + // plugin commands which always use a "." in their names, e.g. pdf.OpenDocument(); + // we handle the decimal digit case manually below so that 3.1415 and .123 is styled correctly + // the collateral damage of treating "." as an identifier is that "." is never styled + // SCE_HOLLYWOOD_OPERATOR + 4, // . ($2E) + 2, // / ($2F) + 28, // 0 ($30) + 28, // 1 ($31) + 28, // 2 ($32) + 28, // 3 ($33) + 28, // 4 ($34) + 28, // 5 ($35) + 28, // 6 ($36) + 28, // 7 ($37) + 28, // 8 ($38) + 28, // 9 ($39) + 2, // : ($3A) + 2, // ; ($3B) + 2, // < ($3C) + 2, // = ($3D) + 2, // > ($3E) + 2, // ? ($3F) + 0, // @ ($40) + 84, // A ($41) + 84, // B ($42) + 84, // C ($43) + 84, // D ($44) + 84, // E ($45) + 84, // F ($46) + 68, // G ($47) + 68, // H ($48) + 68, // I ($49) + 68, // J ($4A) + 68, // K ($4B) + 68, // L ($4C) + 68, // M ($4D) + 68, // N ($4E) + 68, // O ($4F) + 68, // P ($50) + 68, // Q ($51) + 68, // R ($52) + 68, // S ($53) + 68, // T ($54) + 68, // U ($55) + 68, // V ($56) + 68, // W ($57) + 68, // X ($58) + 68, // Y ($59) + 68, // Z ($5A) + 2, // [ ($5B) + 2, // \ ($5C) + 2, // ] ($5D) + 2, // ^ ($5E) + 68, // _ ($5F) + 2, // ` ($60) + 84, // a ($61) + 84, // b ($62) + 84, // c ($63) + 84, // d ($64) + 84, // e ($65) + 84, // f ($66) + 68, // g ($67) + 68, // h ($68) + 68, // i ($69) + 68, // j ($6A) + 68, // k ($6B) + 68, // l ($6C) + 68, // m ($6D) + 68, // n ($6E) + 68, // o ($6F) + 68, // p ($70) + 68, // q ($71) + 68, // r ($72) + 68, // s ($73) + 68, // t ($74) + 68, // u ($75) + 68, // v ($76) + 68, // w ($77) + 68, // x ($78) + 68, // y ($79) + 68, // z ($7A) + 2, // { ($7B) + 2, // | ($7C) + 2, // } ($7D) + 2, // ~ ($7E) + 0, //  ($7F) +}; + +static bool IsSpace(int c) { + return c < 128 && (character_classification[c] & 1); +} + +static bool IsOperator(int c) { + return c < 128 && (character_classification[c] & 2); +} + +static bool IsIdentifier(int c) { + return c < 128 && (character_classification[c] & 4); +} + +static bool IsDigit(int c) { + return c < 128 && (character_classification[c] & 8); +} + +static bool IsHexDigit(int c) { + return c < 128 && (character_classification[c] & 16); +} + +static int LowerCase(int c) +{ + if (c >= 'A' && c <= 'Z') + return 'a' + c - 'A'; + return c; +} + +static int CheckHollywoodFoldPoint(char const *token) { + if (!strcmp(token, "function")) { + return 1; + } + if (!strcmp(token, "endfunction")) { + return -1; + } + return 0; +} + +// An individual named option for use in an OptionSet + +// Options used for LexerHollywood +struct OptionsHollywood { + bool fold; + bool foldCompact; + OptionsHollywood() { + fold = false; + foldCompact = false; + } +}; + +static const char * const hollywoodWordListDesc[] = { + "Hollywood keywords", + "Hollywood standard API functions", + "Hollywood plugin API functions", + "Hollywood plugin methods", + 0 +}; + +struct OptionSetHollywood : public OptionSet { + OptionSetHollywood(const char * const wordListDescriptions[]) { + DefineProperty("fold", &OptionsHollywood::fold); + DefineProperty("fold.compact", &OptionsHollywood::foldCompact); + DefineWordListSets(wordListDescriptions); + } +}; + +class LexerHollywood : public DefaultLexer { + int (*CheckFoldPoint)(char const *); + WordList keywordlists[4]; + OptionsHollywood options; + OptionSetHollywood osHollywood; +public: + LexerHollywood(int (*CheckFoldPoint_)(char const *), const char * const wordListDescriptions[]) : + DefaultLexer("hollywood", SCLEX_HOLLYWOOD), + CheckFoldPoint(CheckFoldPoint_), + osHollywood(wordListDescriptions) { + } + virtual ~LexerHollywood() { + } + void SCI_METHOD Release() override { + delete this; + } + int SCI_METHOD Version() const override { + return lvIdentity; + } + const char * SCI_METHOD PropertyNames() override { + return osHollywood.PropertyNames(); + } + int SCI_METHOD PropertyType(const char *name) override { + return osHollywood.PropertyType(name); + } + const char * SCI_METHOD DescribeProperty(const char *name) override { + return osHollywood.DescribeProperty(name); + } + Sci_Position SCI_METHOD PropertySet(const char *key, const char *val) override; + const char * SCI_METHOD PropertyGet(const char* key) override { + return osHollywood.PropertyGet(key); + } + const char * SCI_METHOD DescribeWordListSets() override { + return osHollywood.DescribeWordListSets(); + } + Sci_Position SCI_METHOD WordListSet(int n, const char *wl) override; + void SCI_METHOD Lex(Sci_PositionU startPos, Sci_Position length, int initStyle, IDocument *pAccess) override; + void SCI_METHOD Fold(Sci_PositionU startPos, Sci_Position length, int initStyle, IDocument *pAccess) override; + + void * SCI_METHOD PrivateCall(int, void *) override { + return 0; + } + static ILexer *LexerFactoryHollywood() { + return new LexerHollywood(CheckHollywoodFoldPoint, hollywoodWordListDesc); + } +}; + +Sci_Position SCI_METHOD LexerHollywood::PropertySet(const char *key, const char *val) { + if (osHollywood.PropertySet(&options, key, val)) { + return 0; + } + return -1; +} + +Sci_Position SCI_METHOD LexerHollywood::WordListSet(int n, const char *wl) { + WordList *wordListN = 0; + switch (n) { + case 0: + wordListN = &keywordlists[0]; + break; + case 1: + wordListN = &keywordlists[1]; + break; + case 2: + wordListN = &keywordlists[2]; + break; + case 3: + wordListN = &keywordlists[3]; + break; + } + Sci_Position firstModification = -1; + if (wordListN) { + WordList wlNew; + wlNew.Set(wl); + if (*wordListN != wlNew) { + wordListN->Set(wl); + firstModification = 0; + } + } + return firstModification; +} + +void SCI_METHOD LexerHollywood::Lex(Sci_PositionU startPos, Sci_Position length, int initStyle, IDocument *pAccess) { + LexAccessor styler(pAccess); + + styler.StartAt(startPos); + bool inString = false; + + StyleContext sc(startPos, length, initStyle, styler); + + // Can't use sc.More() here else we miss the last character + for (; ; sc.Forward()) + { + if (sc.atLineStart) inString = false; + + if (sc.ch == '\"' && sc.chPrev != '\\') inString = !inString; + + if (sc.state == SCE_HOLLYWOOD_IDENTIFIER) { + if (!IsIdentifier(sc.ch)) { + char s[100]; + int kstates[4] = { + SCE_HOLLYWOOD_KEYWORD, + SCE_HOLLYWOOD_STDAPI, + SCE_HOLLYWOOD_PLUGINAPI, + SCE_HOLLYWOOD_PLUGINMETHOD, + }; + sc.GetCurrentLowered(s, sizeof(s)); + for (int i = 0; i < 4; i++) { + if (keywordlists[i].InList(s)) { + sc.ChangeState(kstates[i]); + } + } + sc.SetState(SCE_HOLLYWOOD_DEFAULT); + } + } else if (sc.state == SCE_HOLLYWOOD_OPERATOR) { + + // always reset to default on operators because otherwise + // comments won't be recognized in sequences like "+/* Hello*/" + // --> "+/*" would be recognized as a sequence of operators + + // if (!IsOperator(sc.ch)) sc.SetState(SCE_HOLLYWOOD_DEFAULT); + sc.SetState(SCE_HOLLYWOOD_DEFAULT); + + } else if (sc.state == SCE_HOLLYWOOD_PREPROCESSOR) { + if (!IsIdentifier(sc.ch)) + sc.SetState(SCE_HOLLYWOOD_DEFAULT); + } else if (sc.state == SCE_HOLLYWOOD_CONSTANT) { + if (!IsIdentifier(sc.ch)) + sc.SetState(SCE_HOLLYWOOD_DEFAULT); + } else if (sc.state == SCE_HOLLYWOOD_NUMBER) { + if (!IsDigit(sc.ch) && sc.ch != '.') + sc.SetState(SCE_HOLLYWOOD_DEFAULT); + } else if (sc.state == SCE_HOLLYWOOD_HEXNUMBER) { + if (!IsHexDigit(sc.ch)) + sc.SetState(SCE_HOLLYWOOD_DEFAULT); + } else if (sc.state == SCE_HOLLYWOOD_STRING) { + if (sc.ch == '"') { + sc.ForwardSetState(SCE_HOLLYWOOD_DEFAULT); + } + if (sc.atLineEnd) { + sc.SetState(SCE_HOLLYWOOD_DEFAULT); + } + } else if (sc.state == SCE_HOLLYWOOD_COMMENT) { + if (sc.atLineEnd) { + sc.SetState(SCE_HOLLYWOOD_DEFAULT); + } + } else if (sc.state == SCE_HOLLYWOOD_COMMENTBLOCK) { + if (sc.Match("*/") && !inString) { + sc.Forward(); + sc.ForwardSetState(SCE_HOLLYWOOD_DEFAULT); + } + } else if (sc.state == SCE_HOLLYWOOD_STRINGBLOCK) { + if (sc.Match("]]") && !inString) { + sc.Forward(); + sc.ForwardSetState(SCE_HOLLYWOOD_DEFAULT); + } + } + + if (sc.state == SCE_HOLLYWOOD_DEFAULT) { + if (sc.Match(';')) { + sc.SetState(SCE_HOLLYWOOD_COMMENT); + } else if (sc.Match("/*")) { + sc.SetState(SCE_HOLLYWOOD_COMMENTBLOCK); + sc.Forward(); + } else if (sc.Match("[[")) { + sc.SetState(SCE_HOLLYWOOD_STRINGBLOCK); + sc.Forward(); + } else if (sc.Match('"')) { + sc.SetState(SCE_HOLLYWOOD_STRING); + } else if (sc.Match('$')) { + sc.SetState(SCE_HOLLYWOOD_HEXNUMBER); + } else if (sc.Match("0x") || sc.Match("0X")) { // must be before IsDigit() because of 0x + sc.SetState(SCE_HOLLYWOOD_HEXNUMBER); + sc.Forward(); + } else if (sc.ch == '.' && (sc.chNext >= '0' && sc.chNext <= '9')) { // ".1234" style numbers + sc.SetState(SCE_HOLLYWOOD_NUMBER); + sc.Forward(); + } else if (IsDigit(sc.ch)) { + sc.SetState(SCE_HOLLYWOOD_NUMBER); + } else if (sc.Match('#')) { + sc.SetState(SCE_HOLLYWOOD_CONSTANT); + } else if (sc.Match('@')) { + sc.SetState(SCE_HOLLYWOOD_PREPROCESSOR); + } else if (IsOperator(sc.ch)) { + sc.SetState(SCE_HOLLYWOOD_OPERATOR); + } else if (IsIdentifier(sc.ch)) { + sc.SetState(SCE_HOLLYWOOD_IDENTIFIER); + } + } + + if (!sc.More()) + break; + } + sc.Complete(); +} + +void SCI_METHOD LexerHollywood::Fold(Sci_PositionU startPos, Sci_Position length, int /* initStyle */, IDocument *pAccess) { + + if (!options.fold) + return; + + LexAccessor styler(pAccess); + + Sci_PositionU lengthDoc = startPos + length; + int visibleChars = 0; + Sci_Position lineCurrent = styler.GetLine(startPos); + int levelPrev = styler.LevelAt(lineCurrent) & SC_FOLDLEVELNUMBERMASK; + int levelCurrent = levelPrev; + char chNext = styler[startPos]; + int styleNext = styler.StyleAt(startPos); + int done = 0; + char word[256]; + int wordlen = 0; + + for (Sci_PositionU i = startPos; i < lengthDoc; i++) { + char ch = chNext; + chNext = styler.SafeGetCharAt(i + 1); + int style = styleNext; + styleNext = styler.StyleAt(i + 1); + bool atEOL = (ch == '\r' && chNext != '\n') || (ch == '\n'); + if (!done) { + if (wordlen) { // are we scanning a token already? + word[wordlen] = static_cast(LowerCase(ch)); + if (!IsIdentifier(ch)) { // done with token + word[wordlen] = '\0'; + levelCurrent += CheckFoldPoint(word); + done = 1; + } else if (wordlen < 255) { + wordlen++; + } + } else { // start scanning at first non-whitespace character + if (!IsSpace(ch)) { + if (style != SCE_HOLLYWOOD_COMMENTBLOCK && IsIdentifier(ch)) { + word[0] = static_cast(LowerCase(ch)); + wordlen = 1; + } else // done with this line + done = 1; + } + } + } + + if (atEOL) { + int lev = levelPrev; + if (visibleChars == 0 && options.foldCompact) { + lev |= SC_FOLDLEVELWHITEFLAG; + } + if ((levelCurrent > levelPrev) && (visibleChars > 0)) { + lev |= SC_FOLDLEVELHEADERFLAG; + } + if (lev != styler.LevelAt(lineCurrent)) { + styler.SetLevel(lineCurrent, lev); + } + lineCurrent++; + levelPrev = levelCurrent; + visibleChars = 0; + done = 0; + wordlen = 0; + } + if (!IsSpace(ch)) { + visibleChars++; + } + } + // Fill in the real level of the next line, keeping the current flags as they will be filled in later + + int flagsNext = styler.LevelAt(lineCurrent) & ~SC_FOLDLEVELNUMBERMASK; + styler.SetLevel(lineCurrent, levelPrev | flagsNext); +} + +LexerModule lmHollywood(SCLEX_HOLLYWOOD, LexerHollywood::LexerFactoryHollywood, "hollywood", hollywoodWordListDesc); diff --git a/src/stc/scintilla/lexers/LexIndent.cxx b/src/stc/scintilla/lexers/LexIndent.cxx new file mode 100644 index 0000000000..053bdd928b --- /dev/null +++ b/src/stc/scintilla/lexers/LexIndent.cxx @@ -0,0 +1,71 @@ +// Scintilla source code edit control +/** @file LexIndent.cxx + ** Lexer for no language. Used for indentation-based folding of files. + **/ +// The License.txt file describes the conditions under which this software may be distributed. + +#include +#include +#include +#include +#include +#include + +#include "ILexer.h" +#include "Scintilla.h" +#include "SciLexer.h" + +#include "WordList.h" +#include "LexAccessor.h" +#include "Accessor.h" +#include "StyleContext.h" +#include "CharacterSet.h" +#include "LexerModule.h" + +using namespace Scintilla; + +static void ColouriseIndentDoc(Sci_PositionU startPos, Sci_Position length, int, WordList *[], + Accessor &styler) { + // Indent language means all style bytes are 0 so just mark the end - no need to fill in. + if (length > 0) { + styler.StartAt(startPos + length - 1); + styler.StartSegment(startPos + length - 1); + styler.ColourTo(startPos + length - 1, 0); + } +} + +static void FoldIndentDoc(Sci_PositionU startPos, Sci_Position length, int /* initStyle */, WordList *[], Accessor &styler) { + int visibleCharsCurrent, visibleCharsNext; + int levelCurrent, levelNext; + Sci_PositionU i, lineEnd; + Sci_PositionU lengthDoc = startPos + length; + Sci_Position lineCurrent = styler.GetLine(startPos); + + i = styler.LineStart(lineCurrent ); + lineEnd = styler.LineStart(lineCurrent+1)-1; + if(lineEnd>=lengthDoc) lineEnd = lengthDoc-1; + while(styler[lineEnd]=='\n' || styler[lineEnd]=='\r') lineEnd--; + for(visibleCharsCurrent=0, levelCurrent=SC_FOLDLEVELBASE; !visibleCharsCurrent && i<=lineEnd; i++){ + if(isspacechar(styler[i])) levelCurrent++; + else visibleCharsCurrent=1; + } + + for(; i=lengthDoc) lineEnd = lengthDoc-1; + while(styler[lineEnd]=='\n' || styler[lineEnd]=='\r') lineEnd--; + for(visibleCharsNext=0, levelNext=SC_FOLDLEVELBASE; !visibleCharsNext && i<=lineEnd; i++){ + if(isspacechar(styler[i])) levelNext++; + else visibleCharsNext=1; + } + int lev = levelCurrent; + if(!visibleCharsCurrent) lev |= SC_FOLDLEVELWHITEFLAG; + else if(levelNext > levelCurrent) lev |= SC_FOLDLEVELHEADERFLAG; + styler.SetLevel(lineCurrent, lev); + levelCurrent = levelNext; + visibleCharsCurrent = visibleCharsNext; + } +} + +LexerModule lmIndent(SCLEX_INDENT, ColouriseIndentDoc, "indent", FoldIndentDoc); diff --git a/src/stc/scintilla/lexers/LexInno.cxx b/src/stc/scintilla/lexers/LexInno.cxx index 50aa25d284..5d01c0588f 100644 --- a/src/stc/scintilla/lexers/LexInno.cxx +++ b/src/stc/scintilla/lexers/LexInno.cxx @@ -23,9 +23,7 @@ #include "CharacterSet.h" #include "LexerModule.h" -#ifdef SCI_NAMESPACE using namespace Scintilla; -#endif static void ColouriseInnoDoc(Sci_PositionU startPos, Sci_Position length, int, WordList *keywordLists[], Accessor &styler) { int state = SCE_INNO_DEFAULT; diff --git a/src/stc/scintilla/lexers/LexJSON.cxx b/src/stc/scintilla/lexers/LexJSON.cxx index 6c060611fb..2f76a103b7 100644 --- a/src/stc/scintilla/lexers/LexJSON.cxx +++ b/src/stc/scintilla/lexers/LexJSON.cxx @@ -27,10 +27,9 @@ #include "CharacterSet.h" #include "LexerModule.h" #include "OptionSet.h" +#include "DefaultLexer.h" -#ifdef SCI_NAMESPACE using namespace Scintilla; -#endif static const char *const JSONWordListDesc[] = { "JSON Keywords", @@ -128,7 +127,7 @@ struct OptionSetJSON : public OptionSet { } }; -class LexerJSON : public ILexer { +class LexerJSON : public DefaultLexer { OptionsJSON options; OptionSetJSON optSetJSON; EscapeSequence escapeSeq; @@ -202,34 +201,38 @@ class LexerJSON : public ILexer { public: LexerJSON() : + DefaultLexer("json", SCLEX_JSON), setOperators(CharacterSet::setNone, "[{}]:,"), setURL(CharacterSet::setAlphaNum, "-._~:/?#[]@!$&'()*+,),="), setKeywordJSONLD(CharacterSet::setAlpha, ":@"), setKeywordJSON(CharacterSet::setAlpha, "$_") { } virtual ~LexerJSON() {} - virtual int SCI_METHOD Version() const { - return lvOriginal; + int SCI_METHOD Version() const override { + return lvIdentity; } - virtual void SCI_METHOD Release() { + void SCI_METHOD Release() override { delete this; } - virtual const char *SCI_METHOD PropertyNames() { + const char *SCI_METHOD PropertyNames() override { return optSetJSON.PropertyNames(); } - virtual int SCI_METHOD PropertyType(const char *name) { + int SCI_METHOD PropertyType(const char *name) override { return optSetJSON.PropertyType(name); } - virtual const char *SCI_METHOD DescribeProperty(const char *name) { + const char *SCI_METHOD DescribeProperty(const char *name) override { return optSetJSON.DescribeProperty(name); } - virtual Sci_Position SCI_METHOD PropertySet(const char *key, const char *val) { + Sci_Position SCI_METHOD PropertySet(const char *key, const char *val) override { if (optSetJSON.PropertySet(&options, key, val)) { return 0; } return -1; } - virtual Sci_Position SCI_METHOD WordListSet(int n, const char *wl) { + const char * SCI_METHOD PropertyGet(const char *key) override { + return optSetJSON.PropertyGet(key); + } + Sci_Position SCI_METHOD WordListSet(int n, const char *wl) override { WordList *wordListN = 0; switch (n) { case 0: @@ -250,23 +253,23 @@ class LexerJSON : public ILexer { } return firstModification; } - virtual void *SCI_METHOD PrivateCall(int, void *) { + void *SCI_METHOD PrivateCall(int, void *) override { return 0; } static ILexer *LexerFactoryJSON() { return new LexerJSON; } - virtual const char *SCI_METHOD DescribeWordListSets() { + const char *SCI_METHOD DescribeWordListSets() override { return optSetJSON.DescribeWordListSets(); } - virtual void SCI_METHOD Lex(Sci_PositionU startPos, + void SCI_METHOD Lex(Sci_PositionU startPos, Sci_Position length, int initStyle, - IDocument *pAccess); - virtual void SCI_METHOD Fold(Sci_PositionU startPos, + IDocument *pAccess) override; + void SCI_METHOD Fold(Sci_PositionU startPos, Sci_Position length, int initStyle, - IDocument *pAccess); + IDocument *pAccess) override; }; void SCI_METHOD LexerJSON::Lex(Sci_PositionU startPos, diff --git a/src/stc/scintilla/lexers/LexKVIrc.cxx b/src/stc/scintilla/lexers/LexKVIrc.cxx index 75cb8331be..0cae2a2348 100644 --- a/src/stc/scintilla/lexers/LexKVIrc.cxx +++ b/src/stc/scintilla/lexers/LexKVIrc.cxx @@ -26,9 +26,7 @@ #include "CharacterSet.h" #include "LexerModule.h" -#ifdef SCI_NAMESPACE using namespace Scintilla; -#endif /* KVIrc Script syntactic rules: http://www.kvirc.net/doc/doc_syntactic_rules.html */ diff --git a/src/stc/scintilla/lexers/LexKix.cxx b/src/stc/scintilla/lexers/LexKix.cxx index 82ff9a54bf..bcd68137e4 100644 --- a/src/stc/scintilla/lexers/LexKix.cxx +++ b/src/stc/scintilla/lexers/LexKix.cxx @@ -24,9 +24,7 @@ #include "CharacterSet.h" #include "LexerModule.h" -#ifdef SCI_NAMESPACE using namespace Scintilla; -#endif // Extended to accept accented characters static inline bool IsAWordChar(int ch) { diff --git a/src/stc/scintilla/lexers/LexLPeg.cxx b/src/stc/scintilla/lexers/LexLPeg.cxx new file mode 100644 index 0000000000..915339423e --- /dev/null +++ b/src/stc/scintilla/lexers/LexLPeg.cxx @@ -0,0 +1,968 @@ +/** + * Copyright 2006-2020 Mitchell mitchell.att.foicica.com. See License.txt. + * + * Lua-powered dynamic language lexer for Scintilla. + * + * For documentation on writing lexers, see *../doc/LPegLexer.html*. + */ + +#if LPEG_LEXER + +#include +#include +#include +#include +#include +#if CURSES +#include +#endif + +#include +#include +#include + +#if !_WIN32 +#include +#else +#include +#endif + +#include "ILexer.h" +#include "Scintilla.h" +#include "SciLexer.h" + +#include "PropSetSimple.h" +#include "LexAccessor.h" +#include "LexerModule.h" +#include "DefaultLexer.h" + +extern "C" { +#include "lua.h" +#include "lualib.h" +#include "lauxlib.h" +LUALIB_API int luaopen_lpeg(lua_State *L); +} + +using namespace Scintilla; + +#ifndef NDEBUG +#define RECORD_STACK_TOP(l) int orig_stack_top = lua_gettop(l) +#define ASSERT_STACK_TOP(l) assert(lua_gettop(l) == orig_stack_top) +#else +#define RECORD_STACK_TOP(_) (void)0 +#define ASSERT_STACK_TOP(_) (void)0 +#endif +#if LUA_VERSION_NUM < 502 +#define luaL_traceback(_,__,___,____) (void)0 +#define luaL_requiref(l, s, f, _) \ + (lua_pushcfunction(l, f), lua_pushstring(l, s), lua_call(l, 1, 1)) +#define lua_rawlen lua_objlen +#define LUA_OK 0 +#define lua_rawgetp(l, i, p) \ + (lua_pushlightuserdata(l, p), lua_rawget(l, i), lua_type(l, -1)) +#define lua_rawsetp(l, i, p) \ + (lua_pushlightuserdata(l, p), lua_insert(l, -2), lua_rawset(l, i)) +#endif +#if LUA_VERSION_NUM < 503 +#define lua_getfield(l, i, k) (lua_getfield(l, i, k), lua_type(l, -1)) +#define lua_rawget(l, i) (lua_rawget(l, i), lua_type(l, -1)) +#endif + +/** The LPeg Scintilla lexer. */ +class LexerLPeg : public DefaultLexer { + // Lexer property keys. + const char * const LexerErrorKey = "lexer.lpeg.error"; + const char * const LexerHomeKey = "lexer.lpeg.home"; + const char * const LexerNameKey = "lexer.lpeg.name"; + const char * const LexerThemeKey = "lexer.lpeg.color.theme"; + + /** + * The lexer's Lua state. + * It is cleared each time the lexer language changes unless `ownLua` is + * `true`. + */ + lua_State *L; + /** + * The flag indicating whether or not the Lua State is owned by the lexer. + */ + bool ownLua = true; + /** + * The set of properties for the lexer. + * The LexerHomeKey and LexerNameKey properties must be defined before running + * the lexer. + */ + PropSetSimple props; + /** The function to send Scintilla messages with. */ + SciFnDirect SS = nullptr; + /** The Scintilla object the lexer belongs to. */ + sptr_t sci = 0; + /** + * The flag indicating whether or not the lexer needs to be re-initialized. + * Re-initialization is required after the lexer language changes. + */ + bool reinit = true; + /** + * The flag indicating whether or not the lexer language has embedded lexers. + */ + bool multilang = false; + /** + * The list of style numbers considered to be whitespace styles. + * This is used in multi-language lexers when backtracking to whitespace to + * determine which lexer grammar to use. + */ + bool ws[STYLE_MAX + 1]; + /** List of known lexer names. */ + std::set lexerNames; + /** Style name to return for `NameOfStyle()`. */ + std::string styleName; + + /** + * Searches the given directory for lexers and records their names. + * @param path Path to a directory containing lexers. + */ + void ReadLexerNames(const char *path); + + /** + * Logs the given error message or a Lua error message, prints it, and clears + * the stack. + * Error messages are logged to the LexerErrorKey property. + * @param L The Lua State. + * @param str The error message to log and print. If `nullptr`, logs and + * prints the Lua error message at the top of the stack. + */ + void LogError(lua_State *L, const char *str = nullptr); + + /** + * Parses the given style string to set the properties for the given style + * number. + * Style strings mimic SciTE's "style.*.stylenumber" properties. + * (https://scintilla.org/SciTEDoc.html) + * @param num The style number to set properties for. + * @param style The style string containing properties to set. + */ + void SetStyle(int num, const char *style); + + /** + * Iterates through the lexer's `_TOKENSTYLES`, setting the style properties + * for all defined styles. + */ + void SetStyles(); + + /** + * Initializes the lexer once the LexerHomeKey and LexerNameKey properties are + * set. + */ + bool Init(); + + /** + * When *lparam* is `0`, returns the size of the buffer needed to store the + * given string *str* in; otherwise copies *str* into the buffer *lparam* and + * returns the number of bytes copied. + * @param lparam `0` to get the number of bytes needed to store *str* or a + * pointer to a buffer large enough to copy *str* into. + * @param str The string to copy. + * @return number of bytes needed to hold *str* + */ + void *StringResult(long lparam, const char *str); + +public: + /** Constructor. */ + LexerLPeg(); + + /** Destructor. */ + virtual ~LexerLPeg() = default; + + /** Destroys the lexer object. */ + void SCI_METHOD Release() override; + + /** + * Lexes the Scintilla document. + * @param startPos The position in the document to start lexing at. + * @param lengthDoc The number of bytes in the document to lex. + * @param initStyle The initial style at position *startPos* in the document. + * @param buffer The document interface. + */ + void SCI_METHOD Lex( + Sci_PositionU startPos, Sci_Position lengthDoc, int initStyle, + IDocument *buffer) override; + + /** + * Folds the Scintilla document. + * @param startPos The position in the document to start folding at. + * @param lengthDoc The number of bytes in the document to fold. + * @param initStyle The initial style at position *startPos* in the document. + * @param buffer The document interface. + */ + void SCI_METHOD Fold( + Sci_PositionU startPos, Sci_Position lengthDoc, int, IDocument *buffer) + override; + + /** + * Sets the *key* lexer property to *value*. + * If *key* starts with "style.", also set the style for the token. + * @param key The string property key. + * @param val The string value. + */ + Sci_Position SCI_METHOD PropertySet( + const char *key, const char *value) override; + + /** + * Allows for direct communication between the application and the lexer. + * The application uses this to set `SS`, `sci`, `L`, and lexer properties, + * and to retrieve style names. + * @param code The communication code. + * @param arg The argument. + * @return void *data + */ + void * SCI_METHOD PrivateCall(int code, void *arg) override; + + /** + * Returns the style name for the given style number. + * Note: the returned pointer is not guaranteed to exist after the next call + * to `NameOfStyle()`, so its contents should be immediately copied. + * @param style The style number to get the style name for. + * @return style name or nullptr + */ + const char * SCI_METHOD NameOfStyle(int style) override; + + /** + * Returns the lexer property for *key*. + * @param key The string property key. + */ + const char * SCI_METHOD PropertyGet(const char *key) override; + + /** Constructs a new instance of the lexer. */ + static ILexer *LexerFactoryLPeg(); +}; + +/** Lua pcall error message handler that adds a traceback. */ +static int lua_error_handler(lua_State *L) { + luaL_traceback(L, L, lua_tostring(L, -1), 1); + return 1; +} + +/** lexer.property[key] metamethod. */ +static int lexer_property_index(lua_State *L) { + const char *property = lua_tostring(L, lua_upvalueindex(1)); + lua_getfield(L, LUA_REGISTRYINDEX, "sci_lexer_lpeg"); + LexerLPeg *lexer = reinterpret_cast(lua_touserdata(L, -1)); + lua_rawgetp(L, LUA_REGISTRYINDEX, lua_touserdata(L, -1)); + lua_getfield(L, -1, "_BUFFER"); + auto buffer = static_cast(lua_touserdata(L, -1)); + if (strcmp(property, "fold_level") == 0) { + luaL_argcheck(L, buffer, 1, "must be lexing or folding"); + lua_pushinteger(L, buffer->GetLevel(luaL_checkinteger(L, 2) - 1)); + } else if (strcmp(property, "indent_amount") == 0) { + luaL_argcheck(L, buffer, 1, "must be lexing or folding"); + lua_pushinteger(L, buffer->GetLineIndentation(luaL_checkinteger(L, 2) - 1)); + } else if (strcmp(property, "property") == 0) { + lua_pushstring(L, lexer->PropertyGet(luaL_checkstring(L, 2))); + } else if (strcmp(property, "property_int") == 0) { + lua_pushstring(L, lexer->PropertyGet(luaL_checkstring(L, 2))); + lua_pushinteger(L, lua_tointeger(L, -1)); + } else if (strcmp(property, "style_at") == 0) { + luaL_argcheck(L, buffer, 1, "must be lexing or folding"); + int style = buffer->StyleAt(luaL_checkinteger(L, 2) - 1); + lua_getfield(L, 4, "_TOKENSTYLES"); + for (lua_pushnil(L); lua_next(L, -2); lua_pop(L, 1)) + if (luaL_checkinteger(L, -1) - 1 == style) break; + lua_pop(L, 1); // style_num, leaving name on top + } else if (strcmp(property, "line_state") == 0) { + luaL_argcheck(L, buffer, 1, "must be lexing or folding"); + lua_pushinteger(L, buffer->GetLineState(luaL_checkinteger(L, 2) - 1)); + } + return 1; +} + +/** lexer.property[key] = value metamethod. */ +static int lexer_property_newindex(lua_State *L) { + const char *property = lua_tostring(L, lua_upvalueindex(1)); + luaL_argcheck( + L, strcmp(property, "fold_level") != 0 && + strcmp(property, "indent_amount") != 0 && + strcmp(property, "property_int") != 0 && + strcmp(property, "style_at") != 0 && + strcmp(property, "line_from_position") != 0, 3, "read-only property"); + lua_getfield(L, LUA_REGISTRYINDEX, "sci_lexer_lpeg"); + LexerLPeg *lexer = reinterpret_cast(lua_touserdata(L, -1)); + lua_rawgetp(L, LUA_REGISTRYINDEX, lua_touserdata(L, -1)); + if (strcmp(property, "property") == 0) + lexer->PropertySet(luaL_checkstring(L, 2), luaL_checkstring(L, 3)); + else if (strcmp(property, "line_state") == 0) { + luaL_argcheck( + L, lua_getfield(L, -1, "_BUFFER"), 1, "must be lexing or folding"); + auto buffer = static_cast(lua_touserdata(L, -1)); + buffer->SetLineState(luaL_checkinteger(L, 2) - 1, luaL_checkinteger(L, 3)); + } + return 0; +} + +/** The lexer's `line_from_position` Lua function. */ +static int line_from_position(lua_State *L) { + auto buffer = static_cast( + lua_touserdata(L, lua_upvalueindex(1))); + lua_pushinteger(L, buffer->LineFromPosition(luaL_checkinteger(L, 1) - 1) + 1); + return 1; +} + +/** lexer.property metamethod. */ +static int lexer_index(lua_State *L) { + const char *key = lua_tostring(L, 2); + if (strcmp(key, "fold_level") == 0 || strcmp(key, "indent_amount") == 0 || + strcmp(key, "property") == 0 || strcmp(key, "property_int") == 0 || + strcmp(key, "style_at") == 0 || strcmp(key, "line_state") == 0) { + lua_newtable(L); + lua_createtable(L, 0, 2); + lua_pushvalue(L, 2), lua_pushcclosure(L, lexer_property_index, 1); + lua_setfield(L, -2, "__index"); + lua_pushvalue(L, 2), lua_pushcclosure(L, lexer_property_newindex, 1); + lua_setfield(L, -2, "__newindex"); + lua_setmetatable(L, -2); + } else if (strcmp(key, "line_from_position") == 0) { + lua_getfield(L, LUA_REGISTRYINDEX, "sci_lexer_lpeg"); + lua_rawgetp(L, LUA_REGISTRYINDEX, lua_touserdata(L, -1)); + luaL_argcheck( + L, lua_getfield(L, -1, "_BUFFER"), 2, "must be lexing or folding"); + lua_pushcclosure(L, line_from_position, 1); + } else if (strncmp(key, "fold", 4) == 0) { + // Alias lexer.fold* to lexer.property['fold*']. + if (strcmp(key, "folding") == 0) key = "fold"; // lexer.fold() exists + lua_getfield(L, LUA_REGISTRYINDEX, "sci_lexer_lpeg"); + LexerLPeg *lexer = reinterpret_cast(lua_touserdata(L, -1)); + const char *value = lexer->PropertyGet(luaL_gsub(L, key, "_", ".")); + lua_pushboolean(L, strcmp(value, "1") == 0); + } else lua_rawget(L, 1); + return 1; +} + +/** lexer.property = value metamethod. */ +static int lexer_newindex(lua_State *L) { + const char *key = lua_tostring(L, 2); + luaL_argcheck( + L, strcmp(key, "fold_level") != 0 && strcmp(key, "indent_amount") != 0 && + strcmp(key, "property") != 0 && strcmp(key, "property_int") != 0 && + strcmp(key, "style_at") != 0 && strcmp(key, "line_state") != 0 && + strcmp(key, "line_from_position") != 0, 3, "read-only property"); + if (strncmp(key, "fold", 4) == 0 && strcmp(key, "fold_level") != 0) { + // Alias lexer.fold* to lexer.property['fold*']. + if (strcmp(key, "folding") == 0) key = "fold"; // lexer.fold() exists + key = luaL_gsub(L, key, "_", "."); + lua_getfield(L, LUA_REGISTRYINDEX, "sci_lexer_lpeg"); + LexerLPeg *lexer = reinterpret_cast(lua_touserdata(L, -1)); + if (lua_toboolean(L, 3)) + lexer->PropertySet( + key, (!lua_isnumber(L, 3) || lua_tonumber(L, 3) == 1) ? "1" : "0"); + else + lexer->PropertySet(key, "0"); + } else lua_rawset(L, 1); + return 0; +} + +/** + * Replaces the string property key the top of the stack with its expanded + * value. + * Invokes `lexer.property_expanded[]` to perform the expansion. + * @param L The Lua State. + */ +static void expand_property(lua_State *L) { + RECORD_STACK_TOP(L); + lua_getfield(L, LUA_REGISTRYINDEX, "_LOADED"), lua_getfield(L, -1, "lexer"); + lua_getfield(L, -1, "property_expanded"); + lua_pushvalue(L, -4), lua_gettable(L, -2), lua_replace(L, -5); + lua_pop(L, 3); // property_expanded, lexer, _LOADED + ASSERT_STACK_TOP(L); +} + +void LexerLPeg::ReadLexerNames(const char *path) { +#if !_WIN32 + DIR *dir = opendir(path); + if (!dir) return; + struct dirent *entry; + while ((entry = readdir(dir))) { + char *p = strstr(entry->d_name, ".lua"); + if (p) lexerNames.emplace(entry->d_name, p - entry->d_name); + } + closedir(dir); +#else + struct _finddata_t file; + std::string glob(path); + glob += "/*"; + intptr_t handle = _findfirst(glob.c_str(), &file); + if (handle == -1) return; + do { + char *p = strstr(file.name, ".lua"); + if (p) lexerNames.emplace(file.name, p - file.name); + } while (_findnext(handle, &file) != -1); + _findclose(handle); +#endif +} + +void LexerLPeg::LogError(lua_State *L, const char *str) { + const char *value = str ? str : lua_tostring(L, -1); + PropertySet(LexerErrorKey, value); + fprintf(stderr, "Lua Error: %s.\n", value); + lua_settop(L, 0); +} + +void LexerLPeg::SetStyle(int num, const char *style) { + auto style_copy = static_cast(malloc(strlen(style) + 1)); + char *key = strcpy(style_copy, style), *next = nullptr, *val = nullptr; + while (key) { + if ((next = strchr(key, ','))) *next++ = '\0'; + if ((val = strchr(key, ':'))) *val++ = '\0'; + if (strcmp(key, "font") == 0 && val) + SS(sci, SCI_STYLESETFONT, num, reinterpret_cast(val)); + else if (strcmp(key, "size") == 0 && val) + SS(sci, SCI_STYLESETSIZE, num, static_cast(atoi(val))); + else if (strcmp(key, "bold") == 0 || strcmp(key, "notbold") == 0 || + strcmp(key, "weight") == 0) { +#if !CURSES + int weight = SC_WEIGHT_NORMAL; + if (*key == 'b') + weight = SC_WEIGHT_BOLD; + else if (*key == 'w' && val) + weight = atoi(val); + SS(sci, SCI_STYLESETWEIGHT, num, weight); +#else + // Scintilla curses requires font attributes to be stored in the "font + // weight" style attribute. + // First, clear any existing SC_WEIGHT_NORMAL, SC_WEIGHT_SEMIBOLD, or + // SC_WEIGHT_BOLD values stored in the lower 16 bits. Then set the + // appropriate curses attr. + sptr_t weight = + SS(sci, SCI_STYLEGETWEIGHT, num, 0) & ~(A_COLOR | A_CHARTEXT); + int bold = + *key == 'b' || (*key == 'w' && val && atoi(val) > SC_WEIGHT_NORMAL); + SS( + sci, SCI_STYLESETWEIGHT, num, + bold ? weight | A_BOLD : weight & ~A_BOLD); +#endif + } else if (strcmp(key, "italics") == 0 || strcmp(key, "notitalics") == 0) + SS(sci, SCI_STYLESETITALIC, num, *key == 'i'); + else if (strcmp(key, "underlined") == 0 || + strcmp(key, "notunderlined") == 0) { +#if !CURSES + SS(sci, SCI_STYLESETUNDERLINE, num, *key == 'u'); +#else + // Scintilla curses requires font attributes to be stored in the "font + // weight" style attribute. + // First, clear any existing SC_WEIGHT_NORMAL, SC_WEIGHT_SEMIBOLD, or + // SC_WEIGHT_BOLD values stored in the lower 16 bits. Then set the + // appropriate curses attr. + sptr_t weight = + SS(sci, SCI_STYLEGETWEIGHT, num, 0) & ~(A_COLOR | A_CHARTEXT); + SS( + sci, SCI_STYLESETWEIGHT, num, + (*key == 'u') ? weight | A_UNDERLINE : weight & ~A_UNDERLINE); +#endif + } else if ((strcmp(key, "fore") == 0 || strcmp(key, "back") == 0) && + val) { + int msg = (*key == 'f') ? SCI_STYLESETFORE : SCI_STYLESETBACK; + int color = static_cast(strtol(val, nullptr, 0)); + if (*val == '#') { // #RRGGBB format; Scintilla format is 0xBBGGRR + color = static_cast(strtol(val + 1, nullptr, 16)); + color = + ((color & 0xFF0000) >> 16) | (color & 0xFF00) | + ((color & 0xFF) << 16); // convert to 0xBBGGRR + } + SS(sci, msg, num, color); + } else if (strcmp(key, "eolfilled") == 0 || + strcmp(key, "noteolfilled") == 0) + SS(sci, SCI_STYLESETEOLFILLED, num, *key == 'e'); + else if (strcmp(key, "characterset") == 0 && val) + SS(sci, SCI_STYLESETCHARACTERSET, num, static_cast(atoi(val))); + else if (strcmp(key, "case") == 0 && val) { + if (*val == 'u') + SS(sci, SCI_STYLESETCASE, num, SC_CASE_UPPER); + else if (*val == 'l') + SS(sci, SCI_STYLESETCASE, num, SC_CASE_LOWER); + } else if (strcmp(key, "visible") == 0 || strcmp(key, "notvisible") == 0) + SS(sci, SCI_STYLESETVISIBLE, num, *key == 'v'); + else if (strcmp(key, "changeable") == 0 || + strcmp(key, "notchangeable") == 0) + SS(sci, SCI_STYLESETCHANGEABLE, num, *key == 'c'); + else if (strcmp(key, "hotspot") == 0 || strcmp(key, "nothotspot") == 0) + SS(sci, SCI_STYLESETHOTSPOT, num, *key == 'h'); + key = next; + } + free(style_copy); +} + +void LexerLPeg::SetStyles() { + RECORD_STACK_TOP(L); + // If the lexer defines additional styles, set their properties first (if + // the user has not already defined them). + lua_rawgetp(L, LUA_REGISTRYINDEX, reinterpret_cast(this)); + lua_getfield(L, -1, "_EXTRASTYLES"); + for (lua_pushnil(L); lua_next(L, -2); lua_pop(L, 1)) + if (lua_isstring(L, -2) && lua_isstring(L, -1)) { + lua_pushstring(L, "style."), lua_pushvalue(L, -3), lua_concat(L, 2); + if (!*props.Get(lua_tostring(L, -1))) + PropertySet(lua_tostring(L, -1), lua_tostring(L, -2)); + lua_pop(L, 1); // style name + } + lua_pop(L, 1); // _EXTRASTYLES + + if (!SS || !sci) { + lua_pop(L, 1); // lexer object + // Skip, but do not report an error since `reinit` would remain `false` + // and subsequent calls to `Lex()` and `Fold()` would repeatedly call this + // function and error. + ASSERT_STACK_TOP(L); + return; + } + lua_pushstring(L, "style.default"), expand_property(L); + SetStyle(STYLE_DEFAULT, lua_tostring(L, -1)); + lua_pop(L, 1); // style + SS(sci, SCI_STYLECLEARALL, 0, 0); // set default styles + lua_getfield(L, -1, "_TOKENSTYLES"); + for (lua_pushnil(L); lua_next(L, -2); lua_pop(L, 1)) + if (lua_isstring(L, -2) && lua_isnumber(L, -1) && + lua_tointeger(L, -1) - 1 != STYLE_DEFAULT) { + lua_pushstring(L, "style."), lua_pushvalue(L, -3), lua_concat(L, 2); + expand_property(L); + SetStyle(lua_tointeger(L, -2) - 1, lua_tostring(L, -1)); + lua_pop(L, 1); // style + } + lua_pop(L, 2); // _TOKENSTYLES, lexer object + ASSERT_STACK_TOP(L); +} + +bool LexerLPeg::Init() { + if (!props.GetExpanded(LexerHomeKey, nullptr) || + !*props.Get(LexerNameKey) || !L) + return false; + char *_home = reinterpret_cast( + malloc(props.GetExpanded(LexerHomeKey, nullptr) + 1)); + props.GetExpanded(LexerHomeKey, _home); + std::string home(_home); + free(_home); + const char *lexer = props.Get(LexerNameKey); + RECORD_STACK_TOP(L); + + // Designate the currently running LexerLPeg instance. + // This needs to be done prior to calling any Lua lexer code, particularly + // when `ownLua` is `false`, as there may be multiple LexerLPeg instances + // floating around, and the lexer module methods and metamethods need to + // know which instance to use. + lua_pushlightuserdata(L, reinterpret_cast(this)); + lua_setfield(L, LUA_REGISTRYINDEX, "sci_lexer_lpeg"); + + // Determine where to look for the lexer module and themes. + std::vector dirs; + size_t start = 0, end; + while ((end = home.find(';', start)) != std::string::npos) { + dirs.emplace_back(home, start, end - start); + start = end + 1; + } + dirs.emplace_back(home, start); + + // If necessary, load the lexer module. + lua_getfield(L, LUA_REGISTRYINDEX, "_LOADED"); + if (lua_getfield(L, -1, "lexer") == LUA_TNIL) { + for (const std::string& dir : dirs) { + lua_pushstring(L, dir.c_str()); + lua_pushstring(L, "/lexer.lua"); + lua_concat(L, 2); + int status = luaL_loadfile(L, lua_tostring(L, -1)); + if (status == LUA_ERRFILE) { + lua_pop(L, 2); // error message, filename + continue; // try next directory + } + lua_remove(L, -2); // filename + lua_pushcfunction(L, lua_error_handler); + lua_insert(L, -2); + if (status == LUA_OK && lua_pcall(L, 0, 1, -2) == LUA_OK) break; + return (LogError(L), false); + } + if (lua_isnil(L, -1)) + return (LogError(L, "'lexer.lua' module not found"), false); + lua_remove(L, -2); // lua_error_handler + lua_replace(L, -2); // nil + lua_pushinteger(L, SC_FOLDLEVELBASE); + lua_setfield(L, -2, "FOLD_BASE"); + lua_pushinteger(L, SC_FOLDLEVELWHITEFLAG); + lua_setfield(L, -2, "FOLD_BLANK"); + lua_pushinteger(L, SC_FOLDLEVELHEADERFLAG); + lua_setfield(L, -2, "FOLD_HEADER"); + lua_createtable(L, 0, 2); + lua_pushcfunction(L, lexer_index), lua_setfield(L, -2, "__index"); + lua_pushcfunction(L, lexer_newindex), lua_setfield(L, -2, "__newindex"); + lua_setmetatable(L, -2); + lua_pushvalue(L, -1), lua_setfield(L, -3, "lexer"); + } + lua_replace(L, -2); + // Update the userdata needed by lexer metamethods. + lua_pushvalue(L, -1); + lua_rawsetp(L, LUA_REGISTRYINDEX, reinterpret_cast(this)); + + // Load the language lexer. + if (lua_getfield(L, -1, "load") != LUA_TFUNCTION) + return (LogError(L, "'lexer.load' function not found"), false); + lua_pushcfunction(L, lua_error_handler), lua_insert(L, -2); + lua_pushstring(L, lexer), lua_pushnil(L), lua_pushboolean(L, 1); + if (lua_pcall(L, 3, 1, -5) != LUA_OK) return (LogError(L), false); + lua_remove(L, -2); // lua_error_handler + lua_remove(L, -2); // lexer module + lua_rawsetp(L, LUA_REGISTRYINDEX, reinterpret_cast(this)); + + // Load the theme and set up styles. + if (props.GetExpanded(LexerThemeKey, nullptr)) { + char *theme = reinterpret_cast( + malloc(props.GetExpanded(LexerThemeKey, nullptr) + 1)); + props.GetExpanded(LexerThemeKey, theme); + if (!strstr(theme, "/") && !strstr(theme, "\\")) { // theme name + for (const std::string& dir : dirs) { + lua_pushstring(L, dir.c_str()); + lua_pushstring(L, "/themes/"); + lua_pushstring(L, theme); + lua_pushstring(L, ".lua"); + lua_concat(L, 4); + if (luaL_loadfile(L, lua_tostring(L, -1)) != LUA_ERRFILE || + dir == dirs.back()) { + lua_pop(L, 1); // function, leaving filename on top + break; + } + lua_pop(L, 2); // error message, filename + } + } else lua_pushstring(L, theme); // path to theme + lua_pushcfunction(L, lua_error_handler); + lua_insert(L, -2); + if (luaL_loadfile(L, lua_tostring(L, -1)) == LUA_OK && + lua_pcall(L, 0, 0, -3) == LUA_OK) + lua_pop(L, 2); // theme, lua_error_handler + else + LogError(L); + free(theme); + } + SetStyles(); + + // If the lexer is a parent, it will have children in its _CHILDREN table. + // In that case, determine which styles are language whitespace styles + // ([lang]_whitespace). This is necessary for determining which language + // to start lexing with. + lua_rawgetp(L, LUA_REGISTRYINDEX, reinterpret_cast(this)); + if (lua_getfield(L, -1, "_CHILDREN") == LUA_TTABLE) { + multilang = true; + for (int i = 0; i <= STYLE_MAX; i++) + ws[i] = strstr(NameOfStyle(i), "whitespace") ? true : false; + } + lua_pop(L, 2); // _CHILDREN, lexer object + + reinit = false; + PropertySet(LexerErrorKey, ""); + ASSERT_STACK_TOP(L); + return true; +} + +void *LexerLPeg::StringResult(long lparam, const char *str) { + if (lparam) strcpy(reinterpret_cast(lparam), str); + return reinterpret_cast(strlen(str)); +} + +LexerLPeg::LexerLPeg() : DefaultLexer("lpeg", SCLEX_LPEG), L(luaL_newstate()) { + // Initialize the Lua state, load libraries, and set platform variables. + if (!L) { + fprintf(stderr, "Lua failed to initialize.\n"); + return; + } +#if LUA_VERSION_NUM < 502 + luaL_requiref(L, "", luaopen_base, 1), lua_pop(L, 1); +#else + luaL_requiref(L, "_G", luaopen_base, 1), lua_pop(L, 1); +#endif + luaL_requiref(L, LUA_TABLIBNAME, luaopen_table, 1), lua_pop(L, 1); + luaL_requiref(L, LUA_STRLIBNAME, luaopen_string, 1), lua_pop(L, 1); + // TODO: figure out why lua_setglobal() is needed for lpeg. + luaL_requiref(L, "lpeg", luaopen_lpeg, 1), lua_setglobal(L, "lpeg"); +#if _WIN32 + lua_pushboolean(L, 1), lua_setglobal(L, "WIN32"); +#endif +#if __APPLE__ + lua_pushboolean(L, 1), lua_setglobal(L, "OSX"); +#endif +#if GTK + lua_pushboolean(L, 1), lua_setglobal(L, "GTK"); +#endif +#if CURSES + lua_pushboolean(L, 1), lua_setglobal(L, "CURSES"); +#endif +} + +void SCI_METHOD LexerLPeg::Release() { + if (ownLua && L) + lua_close(L); + else if (!ownLua) { + lua_pushnil(L); + lua_rawsetp(L, LUA_REGISTRYINDEX, reinterpret_cast(this)); + lua_pushnil(L), lua_setfield(L, LUA_REGISTRYINDEX, "sci_lexer_lpeg"); + } + delete this; +} + +void SCI_METHOD LexerLPeg::Lex( + Sci_PositionU startPos, Sci_Position lengthDoc, int initStyle, + IDocument *buffer) +{ + LexAccessor styler(buffer); + if ((reinit && !Init()) || !L) { + // Style everything in the default style. + styler.StartAt(startPos); + styler.StartSegment(startPos); + styler.ColourTo(startPos + lengthDoc - 1, STYLE_DEFAULT); + styler.Flush(); + return; + } + RECORD_STACK_TOP(L); + lua_pushlightuserdata(L, reinterpret_cast(this)); + lua_setfield(L, LUA_REGISTRYINDEX, "sci_lexer_lpeg"); + lua_rawgetp(L, LUA_REGISTRYINDEX, reinterpret_cast(this)); + lua_pushlightuserdata(L, reinterpret_cast(buffer)); + lua_setfield(L, -2, "_BUFFER"); + + // Ensure the lexer has a grammar. + // This could be done in the lexer module's `lex()`, but for large files, + // passing string arguments from C to Lua is expensive. + if (!lua_getfield(L, -1, "_GRAMMAR")) { + lua_pop(L, 2); // _GRAMMAR, lexer object + // Style everything in the default style. + styler.StartAt(startPos); + styler.StartSegment(startPos); + styler.ColourTo(startPos + lengthDoc - 1, STYLE_DEFAULT); + styler.Flush(); + return; + } else lua_pop(L, 1); // _GRAMMAR + + // Start from the beginning of the current style so LPeg matches it. + // For multilang lexers, start at whitespace since embedded languages have + // [lang]_whitespace styles. This is so LPeg can start matching child + // languages instead of parent ones if necessary. + if (startPos > 0) { + Sci_PositionU i = startPos; + while (i > 0 && styler.StyleAt(i - 1) == initStyle) i--; + if (multilang) + while (i > 0 && !ws[static_cast(styler.StyleAt(i))]) i--; + lengthDoc += startPos - i, startPos = i; + } + + if (lua_getfield(L, -1, "lex") != LUA_TFUNCTION) + return LogError(L, "'lexer.lex' function not found"); + lua_pushcfunction(L, lua_error_handler), lua_insert(L, -2); + lua_pushvalue(L, -3); + lua_pushlstring(L, buffer->BufferPointer() + startPos, lengthDoc); + lua_pushinteger(L, styler.StyleAt(startPos) + 1); + if (lua_pcall(L, 3, 1, -5) != LUA_OK) return LogError(L); + if (!lua_istable(L, -1)) + return LogError(L, "Table of tokens expected from 'lexer.lex'"); + // Style the text from the token table returned. + int len = lua_rawlen(L, -1); + if (len > 0) { + int style = STYLE_DEFAULT; + styler.StartAt(startPos); + styler.StartSegment(startPos); + lua_getfield(L, -3, "_TOKENSTYLES"); + // Loop through token-position pairs. + for (int i = 1; i < len; i += 2) { + style = STYLE_DEFAULT; + if (lua_rawgeti(L, -2, i), lua_rawget(L, -2)) + style = lua_tointeger(L, -1) - 1; + lua_pop(L, 1); // _TOKENSTYLES[token] + lua_rawgeti(L, -2, i + 1); // pos + unsigned int position = lua_tointeger(L, -1) - 1; + lua_pop(L, 1); // pos + if (style >= 0 && style <= STYLE_MAX) + styler.ColourTo(startPos + position - 1, style); + else + lua_pushfstring(L, "Bad style number: %d", style), LogError(L); + if (position > startPos + lengthDoc) break; + } + lua_pop(L, 1); // _TOKENSTYLES + styler.ColourTo(startPos + lengthDoc - 1, style); + styler.Flush(); + } + lua_pop(L, 3); // token table returned, lua_error_handler, lexer object + ASSERT_STACK_TOP(L); +} + +void SCI_METHOD LexerLPeg::Fold( + Sci_PositionU startPos, Sci_Position lengthDoc, int, IDocument *buffer) +{ + if ((reinit && !Init()) || !L) return; + RECORD_STACK_TOP(L); + lua_pushlightuserdata(L, reinterpret_cast(this)); + lua_setfield(L, LUA_REGISTRYINDEX, "sci_lexer_lpeg"); + lua_rawgetp(L, LUA_REGISTRYINDEX, reinterpret_cast(this)); + lua_pushlightuserdata(L, reinterpret_cast(buffer)); + lua_setfield(L, -2, "_BUFFER"); + LexAccessor styler(buffer); + + if (lua_getfield(L, -1, "fold") != LUA_TFUNCTION) + return LogError(L, "'lexer.fold' function not found"); + lua_pushcfunction(L, lua_error_handler), lua_insert(L, -2); + lua_pushvalue(L, -3); + Sci_Position currentLine = styler.GetLine(startPos); + lua_pushlstring(L, buffer->BufferPointer() + startPos, lengthDoc); + lua_pushinteger(L, startPos + 1); + lua_pushinteger(L, currentLine + 1); + lua_pushinteger(L, styler.LevelAt(currentLine) & SC_FOLDLEVELNUMBERMASK); + if (lua_pcall(L, 5, 1, -7) != LUA_OK) return LogError(L); + if (!lua_istable(L, -1)) + return LogError(L, "Table of folds expected from 'lexer.fold'"); + // Fold the text from the fold table returned. + for (lua_pushnil(L); lua_next(L, -2); lua_pop(L, 1)) // line = level + styler.SetLevel(lua_tointeger(L, -2) - 1, lua_tointeger(L, -1)); + lua_pop(L, 3); // fold table returned, lua_error_handler, lexer object + ASSERT_STACK_TOP(L); +} + +Sci_Position SCI_METHOD LexerLPeg::PropertySet( + const char *key, const char *value) +{ + props.Set(key, value, strlen(key), strlen(value)); + if (strcmp(key, LexerHomeKey) == 0 && lexerNames.empty()) + ReadLexerNames(value); // not using SCI_LOADLEXERLIBRARY private call + if (reinit && + (strcmp(key, LexerHomeKey) == 0 || strcmp(key, LexerNameKey) == 0)) + Init(); + else if (L && SS && sci && strncmp(key, "style.", 6) == 0) { + // The container is managing styles manually. + RECORD_STACK_TOP(L); + lua_pushlightuserdata(L, reinterpret_cast(this)); + lua_setfield(L, LUA_REGISTRYINDEX, "sci_lexer_lpeg"); + if (lua_rawgetp(L, LUA_REGISTRYINDEX, reinterpret_cast(this))) { + lua_getfield(L, -1, "_TOKENSTYLES"); + lua_pushstring(L, key + 6); + if (lua_rawget(L, -2) == LUA_TNUMBER) { + lua_pushstring(L, key), expand_property(L); + int style_num = lua_tointeger(L, -2) - 1; + SetStyle(style_num, lua_tostring(L, -1)); + if (style_num == STYLE_DEFAULT) + // Assume a theme change, with the default style being set first. + // Subsequent style settings will be based on the default. + SS(sci, SCI_STYLECLEARALL, 0, 0); + lua_pop(L, 1); // style + } + lua_pop(L, 2); // style number, _TOKENSTYLES + } + lua_pop(L, 1); // lexer object or nil + ASSERT_STACK_TOP(L); + } + return -1; // no need to re-lex +} + +void * SCI_METHOD LexerLPeg::PrivateCall(int code, void *arg) { + auto lParam = reinterpret_cast(arg); + switch(code) { + case SCI_GETDIRECTFUNCTION: + SS = reinterpret_cast(lParam); + return nullptr; + case SCI_SETDOCPOINTER: + sci = lParam; + return nullptr; + case SCI_CHANGELEXERSTATE: + if (ownLua) lua_close(L); + L = reinterpret_cast(arg), ownLua = false; + return nullptr; + case SCI_LOADLEXERLIBRARY: { + const char *path = reinterpret_cast(arg); + ReadLexerNames(path); + std::string home(props.Get(LexerHomeKey)); + if (!home.empty()) home.push_back(';'); + home.append(path); + PropertySet(LexerHomeKey, home.c_str()); + return nullptr; + } case SCI_PROPERTYNAMES: { + std::stringstream names; + for (const std::string& name : lexerNames) names << name << '\n'; + return StringResult(lParam, names.str().c_str()); + } case SCI_SETLEXERLANGUAGE: + if (strcmp( + props.Get(LexerNameKey), + reinterpret_cast(arg)) != 0) { + reinit = true; + PropertySet(LexerErrorKey, ""); + PropertySet(LexerNameKey, reinterpret_cast(arg)); + } else if (L) + ownLua ? SetStyles() : static_cast(Init()); + return nullptr; + case SCI_GETLEXERLANGUAGE: { + if (!L) return StringResult(lParam, "null"); + RECORD_STACK_TOP(L); + lua_rawgetp(L, LUA_REGISTRYINDEX, reinterpret_cast(this)); + lua_getfield(L, -1, "_NAME"); + std::string val(lua_tostring(L, -1)); + lua_pop(L, 2); // lexer name, lexer object + ASSERT_STACK_TOP(L); + if (!SS || !sci || !multilang) return StringResult(lParam, val.c_str()); + val.push_back('/'); + int pos = SS(sci, SCI_GETCURRENTPOS, 0, 0); + while (pos >= 0 && !ws[SS(sci, SCI_GETSTYLEAT, pos, 0)]) pos--; + if (pos >= 0) { + const char *name = NameOfStyle(SS(sci, SCI_GETSTYLEAT, pos, 0)), *p; + if (name && (p = strstr(name, "_whitespace"))) { + val.append(name, p - name); + return StringResult(lParam, val.c_str()); + } + } + val.append(val, 0, val.length() - 1); // "lexer/lexer" fallback + return StringResult(lParam, val.c_str()); + } case SCI_GETNAMEDSTYLES: + if (!L) return reinterpret_cast(STYLE_DEFAULT); + for (int i = 0; i < STYLE_MAX; i++) + if (strcmp(NameOfStyle(i), reinterpret_cast(arg)) == 0) + return reinterpret_cast(i); + return reinterpret_cast(STYLE_DEFAULT); + case SCI_GETSTATUS: + return StringResult(lParam, props.Get(LexerErrorKey)); + } + return nullptr; +} + +const char * SCI_METHOD LexerLPeg::NameOfStyle(int style) { + if (style < 0 || style > STYLE_MAX || !L) return nullptr; + RECORD_STACK_TOP(L); + styleName = "Not Available"; + lua_rawgetp(L, LUA_REGISTRYINDEX, reinterpret_cast(this)); + lua_getfield(L, -1, "_TOKENSTYLES"); + for (lua_pushnil(L); lua_next(L, -2); lua_pop(L, 1)) + if (lua_tointeger(L, -1) - 1 == style) { + styleName = lua_tostring(L, -2); + lua_pop(L, 2); // value and key + break; + } + lua_pop(L, 2); // _TOKENSTYLES, lexer object + ASSERT_STACK_TOP(L); + return styleName.c_str(); +} + +const char * SCI_METHOD LexerLPeg::PropertyGet(const char *key) { + return props.Get(key); +} + +ILexer *LexerLPeg::LexerFactoryLPeg() { return new LexerLPeg(); } + +LexerModule lmLPeg(SCLEX_LPEG, LexerLPeg::LexerFactoryLPeg, "lpeg"); + +#else + +#include +#include + +#include "ILexer.h" +#include "Scintilla.h" +#include "SciLexer.h" + +#include "WordList.h" +#include "LexAccessor.h" +#include "Accessor.h" +#include "LexerModule.h" + +using namespace Scintilla; + +static void LPegLex(Sci_PositionU, Sci_Position, int, WordList*[], Accessor&) { + return; +} + +LexerModule lmLPeg(SCLEX_LPEG, LPegLex, "lpeg"); + +#endif // LPEG_LEXER diff --git a/src/stc/scintilla/lexers/LexLaTeX.cxx b/src/stc/scintilla/lexers/LexLaTeX.cxx index 6dc0617e14..4b6cbdc6e2 100644 --- a/src/stc/scintilla/lexers/LexLaTeX.cxx +++ b/src/stc/scintilla/lexers/LexLaTeX.cxx @@ -26,11 +26,10 @@ #include "StyleContext.h" #include "CharacterSet.h" #include "LexerModule.h" +#include "DefaultLexer.h" #include "LexerBase.h" -#ifdef SCI_NAMESPACE using namespace Scintilla; -#endif using namespace std; @@ -41,8 +40,15 @@ struct latexFoldSave { latexFoldSave(const latexFoldSave &save) : structLev(save.structLev) { for (int i = 0; i < 8; ++i) openBegins[i] = save.openBegins[i]; } + latexFoldSave &operator=(const latexFoldSave &save) { + if (this != &save) { + structLev = save.structLev; + for (int i = 0; i < 8; ++i) openBegins[i] = save.openBegins[i]; + } + return *this; + } int openBegins[8]; - int structLev; + Sci_Position structLev; }; class LexerLaTeX : public LexerBase { @@ -81,8 +87,16 @@ public: static ILexer *LexerFactoryLaTeX() { return new LexerLaTeX(); } - void SCI_METHOD Lex(Sci_PositionU startPos, Sci_Position length, int initStyle, IDocument *pAccess); - void SCI_METHOD Fold(Sci_PositionU startPos, Sci_Position length, int initStyle, IDocument *pAccess); + void SCI_METHOD Lex(Sci_PositionU startPos, Sci_Position length, int initStyle, IDocument *pAccess) override; + void SCI_METHOD Fold(Sci_PositionU startPos, Sci_Position length, int initStyle, IDocument *pAccess) override; + + // ILexerWithIdentity methods + const char * SCI_METHOD GetName() override { + return "latex"; + } + int SCI_METHOD GetIdentifier() override { + return SCLEX_LATEX; + } }; static bool latexIsSpecial(int ch) { @@ -291,6 +305,8 @@ void SCI_METHOD LexerLaTeX::Lex(Sci_PositionU startPos, Sci_Position length, int latexStateReset(mode, state); if (latexLastWordIs(i, styler, "{verbatim}")) { state = SCE_L_VERBATIM; + } else if (latexLastWordIs(i, styler, "{lstlisting}")) { + state = SCE_L_VERBATIM; } else if (latexLastWordIs(i, styler, "{comment}")) { state = SCE_L_COMMENT2; } else if (latexLastWordIs(i, styler, "{math}") && mode == 0) { @@ -439,6 +455,9 @@ void SCI_METHOD LexerLaTeX::Lex(Sci_PositionU startPos, Sci_Position length, int if (latexLastWordIs(match, styler, "{verbatim}")) { styler.ColourTo(i - 1, state); state = SCE_L_COMMAND; + } else if (latexLastWordIs(match, styler, "{lstlisting}")) { + styler.ColourTo(i - 1, state); + state = SCE_L_COMMAND; } } } diff --git a/src/stc/scintilla/lexers/LexLisp.cxx b/src/stc/scintilla/lexers/LexLisp.cxx index 8d81eae2e2..8e75863558 100644 --- a/src/stc/scintilla/lexers/LexLisp.cxx +++ b/src/stc/scintilla/lexers/LexLisp.cxx @@ -24,9 +24,7 @@ #include "CharacterSet.h" #include "LexerModule.h" -#ifdef SCI_NAMESPACE using namespace Scintilla; -#endif #define SCE_LISP_CHARACTER 29 #define SCE_LISP_MACRO 30 diff --git a/src/stc/scintilla/lexers/LexLout.cxx b/src/stc/scintilla/lexers/LexLout.cxx index 39709827d9..abba91ad14 100644 --- a/src/stc/scintilla/lexers/LexLout.cxx +++ b/src/stc/scintilla/lexers/LexLout.cxx @@ -23,9 +23,7 @@ #include "CharacterSet.h" #include "LexerModule.h" -#ifdef SCI_NAMESPACE using namespace Scintilla; -#endif static inline bool IsAWordChar(const int ch) { return (ch < 0x80) && (isalpha(ch) || ch == '@' || ch == '_'); diff --git a/src/stc/scintilla/lexers/LexLua.cxx b/src/stc/scintilla/lexers/LexLua.cxx index 1e115ad18c..9e6e8a70c6 100644 --- a/src/stc/scintilla/lexers/LexLua.cxx +++ b/src/stc/scintilla/lexers/LexLua.cxx @@ -14,10 +14,13 @@ #include #include +#include + #include "ILexer.h" #include "Scintilla.h" #include "SciLexer.h" +#include "StringCopy.h" #include "WordList.h" #include "LexAccessor.h" #include "Accessor.h" @@ -25,9 +28,7 @@ #include "CharacterSet.h" #include "LexerModule.h" -#ifdef SCI_NAMESPACE using namespace Scintilla; -#endif // Test for [=[ ... ]=] delimiters, returns 0 if it's only a [ or ], // return 1 for [[ or ]], returns >=2 for [=[ or ]=] and so on. @@ -48,14 +49,14 @@ static void ColouriseLuaDoc( WordList *keywordlists[], Accessor &styler) { - WordList &keywords = *keywordlists[0]; - WordList &keywords2 = *keywordlists[1]; - WordList &keywords3 = *keywordlists[2]; - WordList &keywords4 = *keywordlists[3]; - WordList &keywords5 = *keywordlists[4]; - WordList &keywords6 = *keywordlists[5]; - WordList &keywords7 = *keywordlists[6]; - WordList &keywords8 = *keywordlists[7]; + const WordList &keywords = *keywordlists[0]; + const WordList &keywords2 = *keywordlists[1]; + const WordList &keywords3 = *keywordlists[2]; + const WordList &keywords4 = *keywordlists[3]; + const WordList &keywords5 = *keywordlists[4]; + const WordList &keywords6 = *keywordlists[5]; + const WordList &keywords7 = *keywordlists[6]; + const WordList &keywords8 = *keywordlists[7]; // Accepts accented characters CharacterSet setWordStart(CharacterSet::setAlpha, "_", 0x80, true); @@ -77,20 +78,26 @@ static void ColouriseLuaDoc( int stringWs = 0; if (initStyle == SCE_LUA_LITERALSTRING || initStyle == SCE_LUA_COMMENT || initStyle == SCE_LUA_STRING || initStyle == SCE_LUA_CHARACTER) { - int lineState = styler.GetLineState(currentLine - 1); + const int lineState = styler.GetLineState(currentLine - 1); nestLevel = lineState >> 9; sepCount = lineState & 0xFF; stringWs = lineState & 0x100; } + // results of identifier/keyword matching + Sci_Position idenPos = 0; + Sci_Position idenWordPos = 0; + int idenStyle = SCE_LUA_IDENTIFIER; + bool foundGoto = false; + // Do not leak onto next line if (initStyle == SCE_LUA_STRINGEOL || initStyle == SCE_LUA_COMMENTLINE || initStyle == SCE_LUA_PREPROCESSOR) { initStyle = SCE_LUA_DEFAULT; } StyleContext sc(startPos, length, initStyle, styler); - if (startPos == 0 && sc.ch == '#') { - // shbang line: # is a comment only if first char of the script + if (startPos == 0 && sc.ch == '#' && sc.chNext == '!') { + // shbang line: "#!" is a comment only if located at the start of the script sc.SetState(SCE_LUA_COMMENTLINE); } for (; sc.More(); sc.Forward()) { @@ -178,40 +185,32 @@ static void ColouriseLuaDoc( sc.SetState(SCE_LUA_DEFAULT); } } else if (sc.state == SCE_LUA_IDENTIFIER) { - if (!(setWord.Contains(sc.ch) || sc.ch == '.') || sc.Match('.', '.')) { - char s[100]; - sc.GetCurrent(s, sizeof(s)); - if (keywords.InList(s)) { - sc.ChangeState(SCE_LUA_WORD); - if (strcmp(s, "goto") == 0) { // goto