Branch: refs/heads/master Author: Jiří Techet techet@gmail.com Committer: Jiří Techet techet@gmail.com Date: Sun, 24 Nov 2024 14:21:06 UTC Commit: 13a5b085af525f6aa9e90aa1ae1484db9e7712f2 https://github.com/geany/geany/commit/13a5b085af525f6aa9e90aa1ae1484db9e7712...
Log Message: ----------- Add Nix support
Modified Paths: -------------- data/Makefile.am data/filedefs/filetypes.nix data/filetype_extensions.conf meson.build scintilla/Makefile.am scintilla/lexilla/include/SciLexer.h scintilla/lexilla/lexers/LexNix.cxx scintilla/lexilla/src/Lexilla.cxx scintilla/scintilla_changes.patch src/editor.c src/filetypes.c src/filetypes.h src/highlighting.c src/highlightingmappings.h
Modified: data/Makefile.am 1 lines changed, 1 insertions(+), 0 deletions(-) =================================================================== @@ -57,6 +57,7 @@ filetypes_dist = \ filedefs/filetypes.makefile \ filedefs/filetypes.markdown \ filedefs/filetypes.matlab \ + filedefs/filetypes.nix \ filedefs/filetypes.Meson.conf \ filedefs/filetypes.nim \ filedefs/filetypes.nsis \
Modified: data/filedefs/filetypes.nix 62 lines changed, 62 insertions(+), 0 deletions(-) =================================================================== @@ -0,0 +1,62 @@ +# For complete documentation of this file, please see Geany's main documentation +[styling] +# Edit these in the colorscheme .conf file instead + +default=default +commentline=comment_line +commentblock=comment +string=string_1 +stringmultiline=string_1 +escapechar=regex +identifier=default +operator=operator +operatorstring=regex +number=number_1 +key=tag +path=preprocessor +keyword1=keyword_1 +keyword2=keyword_1 +keyword3=keyword_2 +keyword4=keyword_2 + +[keywords] +# all items must be in one line +keywords1=assert else if in inherit let or rec then with +keywords2=false null true +keywords3=abort add addDrvOutputDependencies all any attrNames attrValues baseNameOf bitAnd bitOr bitXor break builtins catAttrs ceil compareVersions concatLists concatMap concatStringsSep convertHash currentSystem currentTime deepSeq derivation dirOf div elem elemAt fetchClosure fetchGit fetchTarball fetchTree fetchurl filter filterSource findFile flakeRefToString floor foldl' fromJSON fromTOML functionArgs genList genericClosure getAttr getContext getEnv getFlake groupBy hasAttr hasContext hashFile hashString head import intersectAttrs isAttrs isBool isFloat isFunction isInt isList isNull isPath isString langVersion length lessThan listToAttrs map mapAttrs match mul nixPath nixVersion outputOf parseDrvName parseFlakeRef partition path pathExists placeholder readDir readFile readFileType removeAttrs replaceStrings seq sort split splitVersion storeDir storePath stringLength sub substring tail throw toFile toJSON toPath toString toXML trace traceVerbose tryEval typeOf unsafeDiscardOu tputDependency unsafeDiscardStringContext warn zipAttrsWith +keywords4= + +[lexer_properties] + +[settings] +# default extension used when saving files +extension=nix + +# MIME type +mime_type=text/x-nix + +# these characters define word boundaries when making selections and searching +# using word matching options +#wordchars=_abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 + +# single comment char, like # in this file +comment_single=# +# multiline comments +#comment_open=/* +#comment_close=*/ + +# set to false if a comment character/string should start at column 0 of a line, true uses any +# indentation of the line, e.g. setting to true causes the following on pressing CTRL+d +# #command_example(); +# setting to false would generate this +# # command_example(); +# This setting works only for single line comments +comment_use_indent=true + +# context action command (please see Geany's main documentation for details) +context_action_cmd= + +[indentation] +#width=4 +# 0 is spaces, 1 is tabs, 2 is tab & spaces +#type=0
Modified: data/filetype_extensions.conf 1 lines changed, 1 insertions(+), 0 deletions(-) =================================================================== @@ -57,6 +57,7 @@ Markdown=*.mdml;*.markdown;*.md;*.mkd;*.mkdn;*.mdwn;*.mdown;*.mdtxt;*.mdtext; Matlab/Octave=*.m; Meson=meson.build;meson.options;meson_options.txt; Nim=*.nim; +Nix=*.nix; NSIS=*.nsi;*.nsh; Objective-C=*.m;*.mm;*.h; Pascal=*.pas;*.pp;*.inc;*.dpr;*.dpk;*.lpr;
Modified: meson.build 1 lines changed, 1 insertions(+), 0 deletions(-) =================================================================== @@ -274,6 +274,7 @@ lexilla = static_library('lexilla', 'scintilla/lexilla/lexers/LexMarkdown.cxx', 'scintilla/lexilla/lexers/LexMatlab.cxx', 'scintilla/lexilla/lexers/LexNim.cxx', + 'scintilla/lexilla/lexers/LexNix.cxx', 'scintilla/lexilla/lexers/LexNsis.cxx', 'scintilla/lexilla/lexers/LexNull.cxx', 'scintilla/lexilla/lexers/LexPascal.cxx',
Modified: scintilla/Makefile.am 1 lines changed, 1 insertions(+), 0 deletions(-) =================================================================== @@ -44,6 +44,7 @@ lexilla/lexers/LexMake.cxx \ lexilla/lexers/LexMarkdown.cxx \ lexilla/lexers/LexMatlab.cxx \ lexilla/lexers/LexNim.cxx \ +lexilla/lexers/LexNix.cxx \ lexilla/lexers/LexNsis.cxx \ lexilla/lexers/LexNull.cxx \ lexilla/lexers/LexPascal.cxx \
Modified: scintilla/lexilla/include/SciLexer.h 32 lines changed, 32 insertions(+), 0 deletions(-) =================================================================== @@ -152,6 +152,7 @@ #define SCLEX_TROFF 137 #define SCLEX_DART 138 #define SCLEX_ZIG 139 +#define SCLEX_NIX 140 #define SCLEX_AUTOMATIC 1000 #define SCE_P_DEFAULT 0 #define SCE_P_COMMENTLINE 1 @@ -202,6 +203,19 @@ #define SCE_C_USERLITERAL 25 #define SCE_C_TASKMARKER 26 #define SCE_C_ESCAPESEQUENCE 27 +#define SCE_COBOL_DEFAULT 0 +#define SCE_COBOL_COMMENT 1 +#define SCE_COBOL_COMMENTLINE 2 +#define SCE_COBOL_COMMENTDOC 3 +#define SCE_COBOL_NUMBER 4 +#define SCE_COBOL_WORD 5 +#define SCE_COBOL_STRING 6 +#define SCE_COBOL_CHARACTER 7 +#define SCE_COBOL_WORD3 8 +#define SCE_COBOL_PREPROCESSOR 9 +#define SCE_COBOL_OPERATOR 10 +#define SCE_COBOL_IDENTIFIER 11 +#define SCE_COBOL_WORD2 16 #define SCE_D_DEFAULT 0 #define SCE_D_COMMENT 1 #define SCE_D_COMMENTLINE 2 @@ -292,6 +306,7 @@ #define SCE_HJ_SYMBOLS 50 #define SCE_HJ_STRINGEOL 51 #define SCE_HJ_REGEX 52 +#define SCE_HJ_TEMPLATELITERAL 53 #define SCE_HJA_START 55 #define SCE_HJA_DEFAULT 56 #define SCE_HJA_COMMENT 57 @@ -305,6 +320,7 @@ #define SCE_HJA_SYMBOLS 65 #define SCE_HJA_STRINGEOL 66 #define SCE_HJA_REGEX 67 +#define SCE_HJA_TEMPLATELITERAL 68 #define SCE_HB_START 70 #define SCE_HB_DEFAULT 71 #define SCE_HB_COMMENTLINE 72 @@ -2150,6 +2166,22 @@ #define SCE_ZIG_KW_TERTIARY 15 #define SCE_ZIG_KW_TYPE 16 #define SCE_ZIG_IDENTIFIER_STRING 17 +#define SCE_NIX_DEFAULT 0 +#define SCE_NIX_COMMENTLINE 1 +#define SCE_NIX_COMMENTBLOCK 2 +#define SCE_NIX_STRING 3 +#define SCE_NIX_STRING_MULTILINE 4 +#define SCE_NIX_ESCAPECHAR 5 +#define SCE_NIX_IDENTIFIER 6 +#define SCE_NIX_OPERATOR 7 +#define SCE_NIX_OPERATOR_STRING 8 +#define SCE_NIX_NUMBER 9 +#define SCE_NIX_KEY 10 +#define SCE_NIX_PATH 11 +#define SCE_NIX_KEYWORD1 12 +#define SCE_NIX_KEYWORD2 13 +#define SCE_NIX_KEYWORD3 14 +#define SCE_NIX_KEYWORD4 15 /* --Autogenerated -- end of section automatically generated from Scintilla.iface */
#endif
Modified: scintilla/lexilla/lexers/LexNix.cxx 527 lines changed, 527 insertions(+), 0 deletions(-) =================================================================== @@ -0,0 +1,527 @@ +// Scintilla source code edit control +/** @file LexNix.cxx + ** Lexer for Nix. + **/ +// Based on Zufu Liu's Notepad4 Dart lexer +// Modified for Nix and Scintilla by Jiri Techet, 2024 +// The License.txt file describes the conditions under which this software may be distributed. + +#include <cassert> +#include <cstring> + +#include <string> +#include <string_view> +#include <vector> +#include <map> +#include <algorithm> + +#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" +#include "OptionSet.h" +#include "DefaultLexer.h" + +using namespace Scintilla; +using namespace Lexilla; + +namespace { +// Use an unnamed namespace to protect the functions and classes from name conflicts + +constexpr bool IsAGraphic(int ch) noexcept { + // excludes C0 control characters and whitespace + return ch > 32 && ch < 127; +} + +constexpr bool IsIdentifierChar(int ch) noexcept { + return IsAlphaNumeric(ch) || ch == '_' || ch == ''' || ch == '-'; +} + +constexpr bool IsIdentifierStart(int ch) noexcept { + return IsUpperOrLowerCase(ch) || ch == '_'; +} + +constexpr bool IsNumberContinue(int chPrev, int ch, int chNext) noexcept { + return ((ch == '+' || ch == '-') && (chPrev == 'e' || chPrev == 'E')) + || (ch == '.' && chNext != '.'); +} + +constexpr bool IsNumberStart(int ch, int chNext) noexcept { + return IsADigit(ch) || (ch == '.' && IsADigit(chNext)); +} + +constexpr bool IsDecimalNumber(int chPrev, int ch, int chNext) noexcept { + return IsIdentifierChar(ch) || IsNumberContinue(chPrev, ch, chNext); +} + +constexpr bool IsNixIdentifierStart(int ch) noexcept { + return IsIdentifierStart(ch); +} + +constexpr bool IsNixIdentifierChar(int ch) noexcept { + return IsIdentifierChar(ch); +} + +constexpr bool IsPathTerminator(int ch) noexcept { + return isspacechar(ch) || AnyOf(ch, ';', ',', ']', '}', ')'); +} + +bool IsKey(LexAccessor &styler, Sci_Position start) { + for (Sci_Position i = 0; i < 50; i++) { + char curr = styler.SafeGetCharAt(start+i, '\0'); + char next = styler.SafeGetCharAt(start+i+1, '\0'); + bool atEOL = (curr == '\r' && next != '\n') || (curr == '\n') || (curr == '\0'); + if (curr == '=') { + return true; + } else if (!isspacechar(curr) || atEOL) { + return false; + } + } + return false; +} + +bool IsPath(LexAccessor &styler, Sci_Position start) { + for (Sci_Position i = 0; i < 50; i++) { + char curr = styler.SafeGetCharAt(start+i, '\0'); + char next = styler.SafeGetCharAt(start+i+1, '\0'); + bool atEOL = (curr == '\r' && next != '\n') || (curr == '\n') || (curr == '\0'); + if (curr == '/') { + return true; + } else if (IsPathTerminator(curr) || curr == '$' || atEOL) { + return false; + } + } + return false; +} + +enum { + NixLineStateMaskInterpolation = 1, // string interpolation +}; + +// string interpolating state +struct InterpolatingState { + int state; + int braceCount; +}; + +// Options used for LexerNix +struct OptionsNix { + bool fold = false; +}; + +const char * const nixWordListDesc[] = { + "Keywords 1", + "Keywords 2", + "Keywords 3", + "Keywords 4", + nullptr +}; + +struct OptionSetNix : public OptionSet<OptionsNix> { + OptionSetNix() { + DefineProperty("fold", &OptionsNix::fold); + + DefineWordListSets(nixWordListDesc); + } +}; + + +LexicalClass lexicalClasses[] = { + // Lexer NIX SCLEX_NIX SCE_NIX_: + 0, "SCE_NIX_DEFAULT", "default", "White space", + 1, "SCE_NIX_COMMENTLINE", "comment line", "Comment: //", + 2, "SCE_NIX_COMMENTBLOCK", "comment", "Comment: /* */", + 3, "SCE_NIX_STRING", "literal string", "Double quoted string", + 4, "SCE_NIX_STRING_MULTILINE", "literal string multiline", "Single quoted multiline string", + 5, "SCE_NIX_ESCAPECHAR", "literal string escapesequence", "Escape sequence", + 6, "SCE_NIX_IDENTIFIER", "identifier", "Identifier", + 7, "SCE_NIX_OPERATOR", "operator", "Operator", + 8, "SCE_NIX_OPERATOR_STRING", "operator interpolated", "Braces following $ inside string", + 9, "SCE_NIX_NUMBER", "literal numeric", "Number", + 10, "SCE_NIX_KEY", "key", "Keys preceding '='", + 11, "SCE_NIX_PATH", "identifier", "Path literal", + 12, "SCE_NIX_KEYWORD1", "keyword", "Primary keywords", + 13, "SCE_NIX_KEYWORD2", "identifier", "Keywords 2", + 14, "SCE_NIX_KEYWORD3", "identifier", "Keywords 3", + 15, "SCE_NIX_KEYWORD4", "identifier", "Keywords 4", +}; + +class LexerNix : public DefaultLexer { + WordList keywordsPrimary; + WordList keywordsSecondary; + WordList keywordsTertiary; + WordList keywordsTypes; + OptionsNix options; + OptionSetNix osNix; +public: + LexerNix(const char *languageName_, int language_) : + DefaultLexer(languageName_, language_, lexicalClasses, std::size(lexicalClasses)) { + } + // Deleted so LexerNix objects can not be copied. + LexerNix(const LexerNix &) = delete; + LexerNix(LexerNix &&) = delete; + void operator=(const LexerNix &) = delete; + void operator=(LexerNix &&) = delete; + ~LexerNix() override = default; + + void SCI_METHOD Release() override { + delete this; + } + int SCI_METHOD Version() const override { + return lvRelease5; + } + const char *SCI_METHOD PropertyNames() override { + return osNix.PropertyNames(); + } + int SCI_METHOD PropertyType(const char *name) override { + return osNix.PropertyType(name); + } + const char *SCI_METHOD DescribeProperty(const char *name) override { + return osNix.DescribeProperty(name); + } + Sci_Position SCI_METHOD PropertySet(const char *key, const char *val) override; + const char *SCI_METHOD PropertyGet(const char *key) override { + return osNix.PropertyGet(key); + } + const char *SCI_METHOD DescribeWordListSets() override { + return osNix.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 nullptr; + } + + void BacktrackToStart(const LexAccessor &styler, int stateMask, Sci_PositionU &startPos, Sci_Position &lengthDoc, int &initStyle); + + static ILexer5 *LexerFactoryNix() { + return new LexerNix("nix", SCLEX_NIX); + } +}; + +Sci_Position SCI_METHOD LexerNix::PropertySet(const char *key, const char *val) { + if (osNix.PropertySet(&options, key, val)) { + return 0; + } + return -1; +} + +Sci_Position SCI_METHOD LexerNix::WordListSet(int n, const char *wl) { + WordList *wordListN = nullptr; + switch (n) { + case 0: + wordListN = &keywordsPrimary; + break; + case 1: + wordListN = &keywordsSecondary; + break; + case 2: + wordListN = &keywordsTertiary; + break; + case 3: + wordListN = &keywordsTypes; + break; + default: + break; + } + Sci_Position firstModification = -1; + if (wordListN && wordListN->Set(wl/*, false*/)) { + firstModification = 0; + } + return firstModification; +} + +void LexerNix::BacktrackToStart(const LexAccessor &styler, int stateMask, Sci_PositionU &startPos, Sci_Position &lengthDoc, int &initStyle) { + const Sci_Position currentLine = styler.GetLine(startPos); + if (currentLine != 0) { + Sci_Position line = currentLine - 1; + int lineState = styler.GetLineState(line); + while ((lineState & stateMask) != 0 && line != 0) { + --line; + lineState = styler.GetLineState(line); + } + if ((lineState & stateMask) == 0) { + ++line; + } + if (line != currentLine) { + const Sci_PositionU endPos = startPos + lengthDoc; + startPos = (line == 0) ? 0 : styler.LineStart(line); + lengthDoc = endPos - startPos; + initStyle = (startPos == 0) ? 0 : styler.StyleAt(startPos - 1); + } + } +} + +void LexerNix::Lex(Sci_PositionU startPos, Sci_Position lengthDoc, int initStyle, IDocument *pAccess) { + Accessor styler(pAccess, nullptr); + + std::vector<InterpolatingState> interpolatingStack; + + if (startPos != 0) { + // backtrack to the line where interpolation starts + BacktrackToStart(styler, NixLineStateMaskInterpolation, startPos, lengthDoc, initStyle); + } + + StyleContext sc(startPos, lengthDoc, initStyle, styler); + + while (sc.More()) { + switch (sc.state) { + case SCE_NIX_OPERATOR: + case SCE_NIX_OPERATOR_STRING: + sc.SetState(SCE_NIX_DEFAULT); + break; + + case SCE_NIX_NUMBER: + if (!IsDecimalNumber(sc.chPrev, sc.ch, sc.chNext)) { + sc.SetState(SCE_NIX_DEFAULT); + } + break; + + case SCE_NIX_IDENTIFIER: + if (sc.state == SCE_NIX_IDENTIFIER && !IsNixIdentifierChar(sc.ch)) { + char s[64]; + sc.GetCurrent(s, sizeof(s)); + if (IsKey(styler, sc.currentPos)) { + sc.ChangeState(SCE_NIX_KEY); + } else if (keywordsPrimary.InList(s)) { + sc.ChangeState(SCE_NIX_KEYWORD1); + } else if (keywordsSecondary.InList(s)) { + sc.ChangeState(SCE_NIX_KEYWORD2); + } else if (keywordsTertiary.InList(s)) { + sc.ChangeState(SCE_NIX_KEYWORD3); + } else if (keywordsTypes.InList(s)) { + sc.ChangeState(SCE_NIX_KEYWORD4); + } + + sc.SetState(SCE_NIX_DEFAULT); + } + break; + + case SCE_NIX_COMMENTLINE: + if (sc.atLineStart) { + sc.SetState(SCE_NIX_DEFAULT); + } + break; + + case SCE_NIX_COMMENTBLOCK: + if (sc.Match('*', '/')) { + sc.Forward(2); + sc.SetState(SCE_NIX_DEFAULT); + continue; + } + break; + + case SCE_NIX_STRING: + if (sc.atLineStart) { + sc.SetState(SCE_NIX_DEFAULT); + } else if (sc.ch == '\' && AnyOf(sc.chNext, '"', '\', 'n', 'r', 't', '$')) { + sc.SetState(SCE_NIX_STRING); + sc.ChangeState(SCE_NIX_ESCAPECHAR); + sc.Forward(2); + sc.SetState(SCE_NIX_STRING); + continue; + } else if (sc.ch == '"') { + sc.Forward(); + sc.SetState(SCE_NIX_DEFAULT); + continue; + } else if (sc.Match('$','$')) { + sc.Forward(); + continue; + } + break; + + case SCE_NIX_PATH: + if (sc.atLineStart) { + sc.SetState(SCE_NIX_DEFAULT); + } else if (sc.ch == '>') { + sc.Forward(); + sc.SetState(SCE_NIX_DEFAULT); + continue; + } else if (IsPathTerminator(sc.ch)) { + sc.SetState(SCE_NIX_DEFAULT); + } + break; + + case SCE_NIX_STRING_MULTILINE: + if (sc.ch == ''' && sc.chNext == ''') { + if (AnyOf(styler.SafeGetCharAt(sc.currentPos+2, '\0'), '$', ''', '\')) { + sc.SetState(SCE_NIX_ESCAPECHAR); + sc.Forward(2); + if (sc.ch == '$' || sc.ch == ''') { + sc.Forward(); + } else if (sc.ch == '\') { + sc.Forward(2); + } + sc.SetState(SCE_NIX_STRING_MULTILINE); + continue; + } else { + sc.Forward(2); + sc.SetState(SCE_NIX_DEFAULT); + continue; + } + } else if (sc.Match('$','$')) { + sc.Forward(); + continue; + } + break; + } + + if (sc.state == SCE_NIX_DEFAULT) + { + if (sc.ch == '/' && sc.chNext == '*') { + sc.SetState(SCE_NIX_COMMENTBLOCK); + sc.Forward(); + continue; + } else if (sc.ch == '#') { + sc.SetState(SCE_NIX_COMMENTLINE); + } else if (sc.ch == '"') { + sc.SetState(SCE_NIX_STRING); + } else if (sc.ch == ''' && sc.chNext == ''') { + sc.SetState(SCE_NIX_STRING_MULTILINE); + sc.Forward(); + continue; + } else if (IsNumberStart(sc.ch, sc.chNext)) { + sc.SetState(SCE_NIX_NUMBER); + } else if (sc.ch == '<') { + sc.SetState(SCE_NIX_PATH); + } else if ((IsNixIdentifierStart(sc.ch) || AnyOf(sc.ch, '~', '.', '/')) && + IsPath(styler, sc.currentPos)) { + sc.SetState(SCE_NIX_PATH); + } else if (IsNixIdentifierStart(sc.ch)) { + sc.SetState(SCE_NIX_IDENTIFIER); + } else if (IsAGraphic(sc.ch) && sc.ch != '$') { + sc.SetState(SCE_NIX_OPERATOR); + if (!interpolatingStack.empty() && AnyOf(sc.ch, '{', '}')) { + InterpolatingState ¤t = interpolatingStack.back(); + if (sc.ch == '{') { + current.braceCount += 1; + } else { + current.braceCount -= 1; + if (current.braceCount == 0) { + sc.ChangeState(SCE_NIX_OPERATOR_STRING); + sc.ForwardSetState(current.state); + interpolatingStack.pop_back(); + continue; + } + } + } + } + } + + // string interpolations + if (AnyOf(sc.state, SCE_NIX_DEFAULT, SCE_NIX_STRING, SCE_NIX_STRING_MULTILINE, SCE_NIX_PATH)) { + if (sc.Match('$','{')) { + interpolatingStack.push_back({sc.state, 1}); + sc.SetState(SCE_NIX_OPERATOR_STRING); + sc.Forward(); + } + } + + if (sc.atLineEnd) { + int lineState = 0; + if (!interpolatingStack.empty()) { + lineState |= NixLineStateMaskInterpolation; + } + styler.SetLineState(sc.currentLine, lineState); + } + + sc.Forward(); + } + + sc.Complete(); +} + +void LexerNix::Fold(Sci_PositionU startPos, Sci_Position lengthDoc, int initStyle, IDocument *pAccess) { + if (!options.fold) + return; + + Accessor styler(pAccess, nullptr); + const Sci_PositionU endPos = startPos + lengthDoc; + Sci_Position lineCurrent = styler.GetLine(startPos); + while (lineCurrent > 0) { + lineCurrent--; + startPos = styler.LineStart(lineCurrent); + initStyle = (startPos > 0) ? styler.StyleIndexAt(startPos) : 0; + if (!AnyOf(initStyle, SCE_NIX_COMMENTBLOCK, SCE_NIX_STRING_MULTILINE)) { + break; + } + } + int levelCurrent = SC_FOLDLEVELBASE; + if (lineCurrent > 0) { + levelCurrent = styler.LevelAt(lineCurrent - 1) >> 16; + } + + int levelNext = levelCurrent; + Sci_PositionU lineStartNext = styler.LineStart(lineCurrent + 1); + lineStartNext = std::min(lineStartNext, endPos); + + char chNext = styler[startPos]; + int styleNext = styler.StyleIndexAt(startPos); + int style = initStyle; + + while (startPos < endPos) { + const char ch = chNext; + const int stylePrev = style; + style = styleNext; + chNext = styler[++startPos]; + styleNext = styler.StyleIndexAt(startPos); + + switch (style) { + case SCE_NIX_COMMENTBLOCK: + if (style != stylePrev) { + levelNext++; + } + if (style != styleNext) { + levelNext--; + } + break; + + case SCE_NIX_STRING_MULTILINE: + if (style != stylePrev && !AnyOf(stylePrev, SCE_NIX_ESCAPECHAR, SCE_NIX_OPERATOR_STRING)) { + levelNext++; + } + if (style != styleNext && !AnyOf(styleNext, SCE_NIX_ESCAPECHAR, SCE_NIX_OPERATOR_STRING)) { + levelNext--; + } + break; + + case SCE_NIX_OPERATOR: + case SCE_NIX_OPERATOR_STRING: + if (ch == '{' || ch == '[' || ch == '(') { + levelNext++; + } else if (ch == '}' || ch == ']' || ch == ')') { + levelNext--; + } + break; + } + + if (startPos == lineStartNext) { + levelNext = std::max(levelNext, SC_FOLDLEVELBASE); + + const int levelUse = levelCurrent; + int lev = levelUse | (levelNext << 16); + if (levelUse < levelNext) { + lev |= SC_FOLDLEVELHEADERFLAG; + } + styler.SetLevel(lineCurrent, lev); + + lineCurrent++; + lineStartNext = styler.LineStart(lineCurrent + 1); + lineStartNext = std::min(lineStartNext, endPos); + levelCurrent = levelNext; + } + } +} + +} // unnamed namespace end + +extern const LexerModule lmNix(SCLEX_NIX, LexerNix::LexerFactoryNix, "nix", nixWordListDesc);
Modified: scintilla/lexilla/src/Lexilla.cxx 3 lines changed, 3 insertions(+), 0 deletions(-) =================================================================== @@ -108,6 +108,7 @@ extern LexerModule lmMSSQL; extern LexerModule lmMySQL; extern LexerModule lmNim; extern LexerModule lmNimrod; +extern LexerModule lmNix; extern LexerModule lmNncrontab; extern LexerModule lmNsis; extern LexerModule lmNull; @@ -204,6 +205,7 @@ static void AddGeanyLexers() &lmMake, &lmMarkdown, &lmNim, + &lmNix, &lmNsis, &lmNull, &lmOctave, @@ -324,6 +326,7 @@ void AddEachLexer() { &lmMySQL, &lmNim, &lmNimrod, + &lmNix, &lmNncrontab, &lmNsis, &lmNull,
Modified: scintilla/scintilla_changes.patch 3 lines changed, 2 insertions(+), 1 deletions(-) =================================================================== @@ -62,7 +62,7 @@ diff --git scintilla/lexilla/src/Lexilla.cxx scintilla/lexilla/src/Lexilla.cxx index cd4b23617..af4a73db4 100644 --- scintilla/lexilla/src/Lexilla.cxx +++ scintilla/lexilla/src/Lexilla.cxx -@@ -167,8 +167,74 @@ +@@ -167,8 +167,75 @@
CatalogueModules catalogueLexilla;
@@ -101,6 +101,7 @@ index cd4b23617..af4a73db4 100644 + &lmMake, + &lmMarkdown, + &lmNim, ++ &lmNix, + &lmNsis, + &lmNull, + &lmOctave,
Modified: src/editor.c 1 lines changed, 1 insertions(+), 0 deletions(-) =================================================================== @@ -1327,6 +1327,7 @@ static gboolean lexer_has_braces(ScintillaObject *sci) case SCLEX_PASCAL: /* for multiline comments? */ case SCLEX_BASH: case SCLEX_PERL: + case SCLEX_NIX: case SCLEX_TCL: case SCLEX_R: case SCLEX_RAKU:
Modified: src/filetypes.c 1 lines changed, 1 insertions(+), 0 deletions(-) =================================================================== @@ -214,6 +214,7 @@ static void init_builtin_filetypes(void) FT_INIT( NIM, NONE, "Nim", NULL ); FT_INIT( ZIG, NONE, "Zig", NULL ); FT_INIT( DART, NONE, "Dart", NULL ); + FT_INIT( NIX, NONE, "Nix", NULL ); }
Modified: src/filetypes.h 1 lines changed, 1 insertions(+), 0 deletions(-) =================================================================== @@ -115,6 +115,7 @@ typedef enum GEANY_FILETYPES_NIM, GEANY_FILETYPES_ZIG, GEANY_FILETYPES_DART, + GEANY_FILETYPES_NIX, /* ^ append items here */ GEANY_MAX_BUILT_IN_FILETYPES /* Don't use this, use filetypes_array->len instead */ }
Modified: src/highlighting.c 11 lines changed, 11 insertions(+), 0 deletions(-) =================================================================== @@ -1037,6 +1037,7 @@ void highlighting_init_styles(guint filetype_idx, GKeyFile *config, GKeyFile *co init_styleset_case(MATLAB); init_styleset_case(MARKDOWN); init_styleset_case(NIM); + init_styleset_case(NIX); init_styleset_case(NSIS); init_styleset_case(OBJECTIVEC); init_styleset_case(PASCAL); @@ -1135,6 +1136,7 @@ void highlighting_set_styles(ScintillaObject *sci, GeanyFiletype *ft) styleset_case(MARKDOWN); styleset_case(MATLAB); styleset_case(NIM); + styleset_case(NIX); styleset_case(NSIS); styleset_case(OBJECTIVEC); styleset_case(PASCAL); @@ -1705,6 +1707,11 @@ gboolean highlighting_is_string_style(gint lexer, gint style) style == SCE_DART_RAWSTRING_DQ || style == SCE_DART_TRIPLE_RAWSTRING_SQ || style == SCE_DART_TRIPLE_RAWSTRING_DQ); + + case SCLEX_NIX: + return (style == SCE_NIX_STRING || + style == SCE_NIX_STRING_MULTILINE || + style == SCE_NIX_ESCAPECHAR); } return FALSE; } @@ -1968,6 +1975,10 @@ gboolean highlighting_is_comment_style(gint lexer, gint style) style == SCE_DART_COMMENTLINEDOC || style == SCE_DART_COMMENTBLOCK || style == SCE_DART_COMMENTBLOCKDOC); + + case SCLEX_NIX: + return (style == SCE_NIX_COMMENTLINE || + style == SCE_NIX_COMMENTBLOCK); } return FALSE; }
Modified: src/highlightingmappings.h 31 lines changed, 31 insertions(+), 0 deletions(-) =================================================================== @@ -1233,6 +1233,37 @@ static const HLKeyword highlighting_keywords_NIM[] = #define highlighting_properties_NIM EMPTY_PROPERTIES
+/* NIX */ +#define highlighting_lexer_NIX SCLEX_NIX +static const HLStyle highlighting_styles_NIX[] = +{ + { SCE_NIX_DEFAULT, "default", FALSE }, + { SCE_NIX_COMMENTLINE, "commentline", FALSE }, + { SCE_NIX_COMMENTBLOCK, "commentblock", FALSE }, + { SCE_NIX_STRING, "string", FALSE }, + { SCE_NIX_STRING_MULTILINE, "stringmultiline", FALSE }, + { SCE_NIX_ESCAPECHAR, "escapechar", FALSE }, + { SCE_NIX_IDENTIFIER, "identifier", FALSE }, + { SCE_NIX_OPERATOR, "operator", FALSE }, + { SCE_NIX_OPERATOR_STRING, "operatorstring", FALSE }, + { SCE_NIX_NUMBER, "number", FALSE }, + { SCE_NIX_KEY, "key", FALSE }, + { SCE_NIX_PATH, "path", FALSE }, + { SCE_NIX_KEYWORD1, "keyword1", FALSE }, + { SCE_NIX_KEYWORD2, "keyword2", FALSE }, + { SCE_NIX_KEYWORD3, "keyword3", FALSE }, + { SCE_NIX_KEYWORD4, "keyword4", FALSE }, +}; +static const HLKeyword highlighting_keywords_NIX[] = +{ + { 0, "keywords1", FALSE }, + { 1, "keywords2", FALSE }, + { 2, "keywords3", FALSE }, + { 3, "keywords4", FALSE }, +}; +#define highlighting_properties_NIX EMPTY_PROPERTIES + + /* NSIS */ #define highlighting_lexer_NSIS SCLEX_NSIS static const HLStyle highlighting_styles_NSIS[] =
-------------- This E-Mail was brought to you by github_commit_mail.py (Source: https://github.com/geany/infrastructure).