Branch: refs/heads/master Author: Jiří Techet techet@gmail.com Committer: GitHub noreply@github.com Date: Fri, 08 Nov 2024 15:25:57 UTC Commit: 2900a447e7ef288cb37247b663d42970b0b50f30 https://github.com/geany/geany/commit/2900a447e7ef288cb37247b663d42970b0b50f...
Log Message: ----------- Merge pull request #3974 from techee/zig
Add Zig support
Modified Paths: -------------- data/Makefile.am data/filedefs/filetypes.zig data/filetype_extensions.conf meson.build scintilla/Makefile.am scintilla/lexilla/include/SciLexer.h scintilla/lexilla/lexers/LexZig.cxx scintilla/lexilla/src/Lexilla.cxx scintilla/scintilla_changes.patch src/document.c src/editor.c src/filetypes.c src/filetypes.h src/highlighting.c src/highlightingmappings.h
Modified: data/Makefile.am 3 lines changed, 2 insertions(+), 1 deletions(-) =================================================================== @@ -84,7 +84,8 @@ filetypes_dist = \ filedefs/filetypes.vhdl \ filedefs/filetypes.xml \ filedefs/filetypes.yaml \ - filedefs/filetypes.zephir + filedefs/filetypes.zephir \ + filedefs/filetypes.zig
# generated filetypes filetypes_nodist = \
Modified: data/filedefs/filetypes.zig 74 lines changed, 74 insertions(+), 0 deletions(-) =================================================================== @@ -0,0 +1,74 @@ +# For complete documentation of this file, please see Geany's main documentation +[styling] +# Edit these in the colorscheme .conf file instead +default=default +comment_line=comment_line +comment_line_doc=comment_doc +comment_line_top=comment_doc +number=number_1 +operator=operator +character=character +string=string_1 +multistring=string_1 +escapechar=string_1 +identifier=identifier_1 +function=function +builtin_function=keyword_2 +kw_primary=keyword_1 +kw_secondary=keyword_2 +kw_tertiary=keyword_2 +kw_type=class +identifer_string=preprocessor + +[keywords] +# all items must be in one line +primary=addrspace align allowzero and anyframe anytype asm async await break callconv catch comptime const continue defer else enum errdefer error export extern fn for if inline linksection noalias noinline nosuspend opaque or orelse packed pub resume return struct suspend switch test threadlocal try union unreachable usingnamespace var volatile while true false null undefined +secondary=i8 u8 i16 u16 i32 u32 i64 u64 i128 u128 isize usize c_char c_short c_ushort c_int c_uint c_long c_ulong c_longlong c_ulonglong c_longdouble f16 f32 f64 f80 f128 bool anyopaque void noreturn type anyerror comptime_int comptime_float + +[lexer_properties] + +[settings] +# default extension used when saving files +extension=zig + +# MIME type +mime_type=text/x-zig + +# 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 + +[build-menu] +# %f will be replaced by the complete filename +# %e will be replaced by the filename without extension +FT_00_LB=_Build +FT_00_CM=zig build-exe %f +FT_00_WD= +FT_02_LB=Te_st +FT_02_CM=zig test %f +FT_02_WD= +EX_00_LB=_Run +EX_00_CM=zig run %f +EX_00_WD=
Modified: data/filetype_extensions.conf 1 lines changed, 1 insertions(+), 0 deletions(-) =================================================================== @@ -84,6 +84,7 @@ VHDL=*.vhd;*.vhdl; XML=*.xml;*.sgml;*.xsl;*.xslt;*.xsd;*.xhtml;*.xul;*.dtd;*.xtpl;*.mml;*.mathml; YAML=*.yaml;*.yml; Zephir=*.zep; +Zig=*.zig; None=*;
# Note: restarting is required after editing groups
Modified: meson.build 1 lines changed, 1 insertions(+), 0 deletions(-) =================================================================== @@ -293,6 +293,7 @@ lexilla = static_library('lexilla', 'scintilla/lexilla/lexers/LexVHDL.cxx', 'scintilla/lexilla/lexers/LexVisualProlog.cxx', 'scintilla/lexilla/lexers/LexYAML.cxx', + 'scintilla/lexilla/lexers/LexZig.cxx', 'scintilla/lexilla/lexlib/Accessor.cxx', 'scintilla/lexilla/lexlib/Accessor.h', 'scintilla/lexilla/lexlib/CatalogueModules.h',
Modified: scintilla/Makefile.am 3 lines changed, 2 insertions(+), 1 deletions(-) =================================================================== @@ -62,7 +62,8 @@ lexilla/lexers/LexTxt2tags.cxx \ lexilla/lexers/LexVHDL.cxx \ lexilla/lexers/LexVerilog.cxx \ lexilla/lexers/LexVisualProlog.cxx \ -lexilla/lexers/LexYAML.cxx +lexilla/lexers/LexYAML.cxx \ +lexilla/lexers/LexZig.cxx
LEXLIB_SRCS = \ lexilla/include/Lexilla.h \
Modified: scintilla/lexilla/include/SciLexer.h 92 lines changed, 92 insertions(+), 0 deletions(-) =================================================================== @@ -148,6 +148,10 @@ #define SCLEX_JULIA 133 #define SCLEX_ASCIIDOC 134 #define SCLEX_GDSCRIPT 135 +#define SCLEX_TOML 136 +#define SCLEX_TROFF 137 +#define SCLEX_DART 138 +#define SCLEX_ZIG 139 #define SCLEX_AUTOMATIC 1000 #define SCE_P_DEFAULT 0 #define SCE_P_COMMENTLINE 1 @@ -2058,6 +2062,94 @@ #define SCE_GD_WORD2 14 #define SCE_GD_ANNOTATION 15 #define SCE_GD_NODEPATH 16 +#define SCE_TOML_DEFAULT 0 +#define SCE_TOML_COMMENT 1 +#define SCE_TOML_IDENTIFIER 2 +#define SCE_TOML_KEYWORD 3 +#define SCE_TOML_NUMBER 4 +#define SCE_TOML_TABLE 5 +#define SCE_TOML_KEY 6 +#define SCE_TOML_ERROR 7 +#define SCE_TOML_OPERATOR 8 +#define SCE_TOML_STRING_SQ 9 +#define SCE_TOML_STRING_DQ 10 +#define SCE_TOML_TRIPLE_STRING_SQ 11 +#define SCE_TOML_TRIPLE_STRING_DQ 12 +#define SCE_TOML_ESCAPECHAR 13 +#define SCE_TOML_DATETIME 14 +#define SCE_TROFF_DEFAULT 0 +#define SCE_TROFF_REQUEST 1 +#define SCE_TROFF_COMMAND 2 +#define SCE_TROFF_NUMBER 3 +#define SCE_TROFF_OPERATOR 4 +#define SCE_TROFF_STRING 5 +#define SCE_TROFF_COMMENT 6 +#define SCE_TROFF_IGNORE 7 +#define SCE_TROFF_ESCAPE_STRING 8 +#define SCE_TROFF_ESCAPE_MACRO 9 +#define SCE_TROFF_ESCAPE_FONT 10 +#define SCE_TROFF_ESCAPE_NUMBER 11 +#define SCE_TROFF_ESCAPE_COLOUR 12 +#define SCE_TROFF_ESCAPE_GLYPH 13 +#define SCE_TROFF_ESCAPE_ENV 14 +#define SCE_TROFF_ESCAPE_SUPPRESSION 15 +#define SCE_TROFF_ESCAPE_SIZE 16 +#define SCE_TROFF_ESCAPE_TRANSPARENT 17 +#define SCE_TROFF_ESCAPE_ISVALID 18 +#define SCE_TROFF_ESCAPE_DRAW 19 +#define SCE_TROFF_ESCAPE_MOVE 20 +#define SCE_TROFF_ESCAPE_HEIGHT 21 +#define SCE_TROFF_ESCAPE_OVERSTRIKE 22 +#define SCE_TROFF_ESCAPE_SLANT 23 +#define SCE_TROFF_ESCAPE_WIDTH 24 +#define SCE_TROFF_ESCAPE_VSPACING 25 +#define SCE_TROFF_ESCAPE_DEVICE 26 +#define SCE_TROFF_ESCAPE_NOMOVE 27 +#define SCE_DART_DEFAULT 0 +#define SCE_DART_COMMENTLINE 1 +#define SCE_DART_COMMENTLINEDOC 2 +#define SCE_DART_COMMENTBLOCK 3 +#define SCE_DART_COMMENTBLOCKDOC 4 +#define SCE_DART_STRING_SQ 5 +#define SCE_DART_STRING_DQ 6 +#define SCE_DART_TRIPLE_STRING_SQ 7 +#define SCE_DART_TRIPLE_STRING_DQ 8 +#define SCE_DART_RAWSTRING_SQ 9 +#define SCE_DART_RAWSTRING_DQ 10 +#define SCE_DART_TRIPLE_RAWSTRING_SQ 11 +#define SCE_DART_TRIPLE_RAWSTRING_DQ 12 +#define SCE_DART_ESCAPECHAR 13 +#define SCE_DART_IDENTIFIER 14 +#define SCE_DART_IDENTIFIER_STRING 15 +#define SCE_DART_OPERATOR 16 +#define SCE_DART_OPERATOR_STRING 17 +#define SCE_DART_SYMBOL_IDENTIFIER 18 +#define SCE_DART_SYMBOL_OPERATOR 19 +#define SCE_DART_NUMBER 20 +#define SCE_DART_KEY 21 +#define SCE_DART_METADATA 22 +#define SCE_DART_KW_PRIMARY 23 +#define SCE_DART_KW_SECONDARY 24 +#define SCE_DART_KW_TERTIARY 25 +#define SCE_DART_KW_TYPE 26 +#define SCE_ZIG_DEFAULT 0 +#define SCE_ZIG_COMMENTLINE 1 +#define SCE_ZIG_COMMENTLINEDOC 2 +#define SCE_ZIG_COMMENTLINETOP 3 +#define SCE_ZIG_NUMBER 4 +#define SCE_ZIG_OPERATOR 5 +#define SCE_ZIG_CHARACTER 6 +#define SCE_ZIG_STRING 7 +#define SCE_ZIG_MULTISTRING 8 +#define SCE_ZIG_ESCAPECHAR 9 +#define SCE_ZIG_IDENTIFIER 10 +#define SCE_ZIG_FUNCTION 11 +#define SCE_ZIG_BUILTIN_FUNCTION 12 +#define SCE_ZIG_KW_PRIMARY 13 +#define SCE_ZIG_KW_SECONDARY 14 +#define SCE_ZIG_KW_TERTIARY 15 +#define SCE_ZIG_KW_TYPE 16 +#define SCE_ZIG_IDENTIFIER_STRING 17 /* --Autogenerated -- end of section automatically generated from Scintilla.iface */
#endif
Modified: scintilla/lexilla/lexers/LexZig.cxx 463 lines changed, 463 insertions(+), 0 deletions(-) =================================================================== @@ -0,0 +1,463 @@ +// Scintilla source code edit control +/** @file LexZig.cxx + ** Lexer for Zig language. + **/ +// Based on Zufu Liu's Notepad4 Zig lexer +// Modified for 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 IsIdentifierStart(int ch) noexcept { + return IsUpperOrLowerCase(ch) || ch == '_'; +} + +constexpr bool IsIdentifierStartEx(int ch) noexcept { + return IsIdentifierStart(ch) || ch >= 0x80; +} + +constexpr bool IsNumberStart(int ch, int chNext) noexcept { + return IsADigit(ch) || (ch == '.' && IsADigit(chNext)); +} + +constexpr bool IsIdentifierChar(int ch) noexcept { + return IsAlphaNumeric(ch) || ch == '_'; +} + +constexpr bool IsNumberContinue(int chPrev, int ch, int chNext) noexcept { + return ((ch == '+' || ch == '-') && (chPrev == 'e' || chPrev == 'E')) + || (ch == '.' && chNext != '.'); +} + +constexpr bool IsDecimalNumber(int chPrev, int ch, int chNext) noexcept { + return IsIdentifierChar(ch) || IsNumberContinue(chPrev, ch, chNext); +} + +constexpr bool IsIdentifierCharEx(int ch) noexcept { + return IsIdentifierChar(ch) || ch >= 0x80; +} + +// https://ziglang.org/documentation/master/#Escape-Sequences +struct EscapeSequence { + int outerState = SCE_ZIG_DEFAULT; + int digitsLeft = 0; + bool brace = false; + + // highlight any character as escape sequence. + void resetEscapeState(int state, int chNext) noexcept { + outerState = state; + digitsLeft = 1; + brace = false; + if (chNext == 'x') { + digitsLeft = 3; + } else if (chNext == 'u') { + digitsLeft = 5; + } + } + void resetEscapeState(int state) noexcept { + outerState = state; + digitsLeft = 1; + brace = false; + } + bool atEscapeEnd(int ch) noexcept { + --digitsLeft; + return digitsLeft <= 0 || !IsAHeXDigit(ch); + } +}; + +enum { + ZigLineStateMaskLineComment = 1, // line comment + ZigLineStateMaskMultilineString = 1 << 1, // multiline string +}; + +struct FoldLineState { + int lineComment; + int multilineString; + constexpr explicit FoldLineState(int lineState) noexcept: + lineComment(lineState & ZigLineStateMaskLineComment), + multilineString((lineState >> 1) & 1) { + } +}; + +enum class KeywordType { + None = SCE_ZIG_DEFAULT, + Function = SCE_ZIG_FUNCTION, +}; + +enum { + KeywordIndex_Primary = 0, + KeywordIndex_Secondary = 1, + KeywordIndex_Tertiary = 2, + KeywordIndex_Type = 3, +}; + +// Options used for LexerZig +struct OptionsZig { + bool fold = false; +}; + +const char *const zigWordListDesc[] = { + "Primary keywords", + "Secondary keywords", + "Tertiary keywords", + "Global type definitions", + nullptr +}; + +struct OptionSetZig : public OptionSet<OptionsZig> { + OptionSetZig() { + DefineProperty("fold", &OptionsZig::fold); + + DefineWordListSets(zigWordListDesc); + } +}; + +LexicalClass lexicalClasses[] = { + // Lexer ZIG SCLEX_ZIG SCE_ZIG_: + 0, "SCE_ZIG_DEFAULT", "default", "White space", + 1, "SCE_ZIG_COMMENTLINE", "comment line", "Comment: //", + 2, "SCE_ZIG_COMMENTLINEDOC", "comment line documentation", "Comment: ///", + 3, "SCE_ZIG_COMMENTLINETOP", "comment line documentation", "Comment: //!", + 4, "SCE_ZIG_NUMBER", "literal numeric", "Number", + 5, "SCE_ZIG_OPERATOR", "operator", "Operator", + 6, "SCE_ZIG_CHARACTER", "literal string character", "Single quoted string", + 7, "SCE_ZIG_STRING", "literal string", "Double quoted string", + 8, "SCE_ZIG_MULTISTRING", "literal string multiline", "Multiline string introduced by two backslashes", + 9, "SCE_ZIG_ESCAPECHAR", "literal string escapesequence", "Escape sequence", + 10, "SCE_ZIG_IDENTIFIER", "identifier", "Identifier", + 11, "SCE_ZIG_FUNCTION", "identifier", "Function definition", + 12, "SCE_ZIG_BUILTIN_FUNCTION", "identifier", "Builtin function", + 13, "SCE_ZIG_KW_PRIMARY", "keyword", "Primary keywords", + 14, "SCE_ZIG_KW_SECONDARY", "identifier", "Secondary keywords", + 15, "SCE_ZIG_KW_TERTIARY", "identifier", "Tertiary keywords", + 16, "SCE_ZIG_KW_TYPE", "identifier", "Global types", + 17, "SCE_ZIG_IDENTIFIER_STRING", "identifier", "Identifier using @"" syntax", +}; + +class LexerZig : public DefaultLexer { + WordList keywordsPrimary; + WordList keywordsSecondary; + WordList keywordsTertiary; + WordList keywordsTypes; + OptionsZig options; + OptionSetZig osZig; +public: + LexerZig(const char *languageName_, int language_) : + DefaultLexer(languageName_, language_, lexicalClasses, std::size(lexicalClasses)) { + } + // Deleted so LexerZig objects can not be copied. + LexerZig(const LexerZig &) = delete; + LexerZig(LexerZig &&) = delete; + void operator=(const LexerZig &) = delete; + void operator=(LexerZig &&) = delete; + ~LexerZig() override = default; + + void SCI_METHOD Release() override { + delete this; + } + int SCI_METHOD Version() const override { + return lvRelease5; + } + const char *SCI_METHOD PropertyNames() override { + return osZig.PropertyNames(); + } + int SCI_METHOD PropertyType(const char *name) override { + return osZig.PropertyType(name); + } + const char *SCI_METHOD DescribeProperty(const char *name) override { + return osZig.DescribeProperty(name); + } + Sci_Position SCI_METHOD PropertySet(const char *key, const char *val) override; + const char *SCI_METHOD PropertyGet(const char *key) override { + return osZig.PropertyGet(key); + } + const char *SCI_METHOD DescribeWordListSets() override { + return osZig.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); + Sci_PositionU LookbackNonWhite(LexAccessor &styler, Sci_PositionU startPos, int &chPrevNonWhite, int &stylePrevNonWhite); + + static ILexer5 *LexerFactoryZig() { + return new LexerZig("zig", SCLEX_ZIG); + } +}; + +Sci_Position SCI_METHOD LexerZig::PropertySet(const char *key, const char *val) { + if (osZig.PropertySet(&options, key, val)) { + return 0; + } + return -1; +} + +Sci_Position SCI_METHOD LexerZig::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)) { + firstModification = 0; + } + return firstModification; +} + +void LexerZig::Lex(Sci_PositionU startPos, Sci_Position lengthDoc, int initStyle, IDocument *pAccess) { + Accessor styler(pAccess, nullptr); + + KeywordType kwType = KeywordType::None; + int visibleChars = 0; + int lineState = 0; + EscapeSequence escSeq; + + StyleContext sc(startPos, lengthDoc, initStyle, styler); + + while (sc.More()) { + switch (sc.state) { + case SCE_ZIG_OPERATOR: + sc.SetState(SCE_ZIG_DEFAULT); + break; + + case SCE_ZIG_NUMBER: + if (!IsDecimalNumber(sc.chPrev, sc.ch, sc.chNext)) { + sc.SetState(SCE_ZIG_DEFAULT); + } + break; + + case SCE_ZIG_IDENTIFIER: + case SCE_ZIG_BUILTIN_FUNCTION: + if (!IsIdentifierCharEx(sc.ch)) { + if (sc.state == SCE_ZIG_IDENTIFIER) { + char s[64]; + sc.GetCurrent(s, sizeof(s)); + if (kwType != KeywordType::None) { + sc.ChangeState(static_cast<int>(kwType)); + } else if (keywordsPrimary.InList(s)) { + sc.ChangeState(SCE_ZIG_KW_PRIMARY); + kwType = KeywordType::None; + if (strcmp(s, "fn") == 0) { + kwType = KeywordType::Function; + } + } else if (keywordsSecondary.InList(s)) { + sc.ChangeState(SCE_ZIG_KW_SECONDARY); + } else if (keywordsTertiary.InList(s)) { + sc.ChangeState(SCE_ZIG_KW_TERTIARY); + } else if (keywordsTypes.InList(s)) { + sc.ChangeState(SCE_ZIG_KW_TYPE); + } + } + if (sc.state != SCE_ZIG_KW_PRIMARY) { + kwType = KeywordType::None; + } + sc.SetState(SCE_ZIG_DEFAULT); + } + break; + + case SCE_ZIG_CHARACTER: + case SCE_ZIG_STRING: + case SCE_ZIG_MULTISTRING: + case SCE_ZIG_IDENTIFIER_STRING: + if (sc.atLineStart) { + sc.SetState(SCE_ZIG_DEFAULT); + } else if (sc.ch == '\' && sc.state != SCE_ZIG_MULTISTRING) { + escSeq.resetEscapeState(sc.state, sc.chNext); + sc.SetState(SCE_ZIG_ESCAPECHAR); + sc.Forward(); + if (sc.Match('u', '{')) { + escSeq.brace = true; + escSeq.digitsLeft = 9; + sc.Forward(); + } + } else if ((sc.ch == ''' && sc.state == SCE_ZIG_CHARACTER) || + (sc.ch == '"' && (sc.state == SCE_ZIG_STRING || sc.state == SCE_ZIG_IDENTIFIER_STRING))) { + sc.ForwardSetState(SCE_ZIG_DEFAULT); + } + break; + + case SCE_ZIG_ESCAPECHAR: + if (escSeq.atEscapeEnd(sc.ch)) { + if (escSeq.brace && sc.ch == '}') { + sc.Forward(); + } + sc.SetState(escSeq.outerState); + continue; + } + break; + + case SCE_ZIG_COMMENTLINE: + case SCE_ZIG_COMMENTLINEDOC: + case SCE_ZIG_COMMENTLINETOP: + if (sc.atLineStart) { + sc.SetState(SCE_ZIG_DEFAULT); + } + break; + } + + if (sc.state == SCE_ZIG_DEFAULT) { + if (sc.Match('/', '/')) { + if (visibleChars == 0) { + lineState = ZigLineStateMaskLineComment; + } + sc.SetState(SCE_ZIG_COMMENTLINE); + sc.Forward(2); + if (sc.ch == '!') { + sc.ChangeState(SCE_ZIG_COMMENTLINETOP); + } else if (sc.ch == '/' && sc.chNext != '/') { + sc.ChangeState(SCE_ZIG_COMMENTLINEDOC); + } + } else if (sc.Match('\', '\')) { + lineState = ZigLineStateMaskMultilineString; + sc.SetState(SCE_ZIG_MULTISTRING); + } else if (sc.ch == '"') { + sc.SetState(SCE_ZIG_STRING); + } else if (sc.ch == ''') { + sc.SetState(SCE_ZIG_CHARACTER); + } else if (IsNumberStart(sc.ch, sc.chNext)) { + sc.SetState(SCE_ZIG_NUMBER); + } else if ((sc.ch == '@' && IsIdentifierStartEx(sc.chNext)) || IsIdentifierStartEx(sc.ch)) { + sc.SetState((sc.ch == '@') ? SCE_ZIG_BUILTIN_FUNCTION : SCE_ZIG_IDENTIFIER); + } else if (sc.ch == '@' && sc.chNext == '"') { + sc.SetState(SCE_ZIG_IDENTIFIER_STRING); + sc.Forward(); + } else if (IsAGraphic(sc.ch)) { + sc.SetState(SCE_ZIG_OPERATOR); + } + } + + if (visibleChars == 0 && !isspacechar(sc.ch)) { + visibleChars++; + } + if (sc.atLineEnd) { + styler.SetLineState(sc.currentLine, lineState); + lineState = 0; + kwType = KeywordType::None; + visibleChars = 0; + } + sc.Forward(); + } + + sc.Complete(); +} + +void LexerZig::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_ZIG_MULTISTRING, + SCE_ZIG_COMMENTLINE, SCE_ZIG_COMMENTLINEDOC, SCE_ZIG_COMMENTLINETOP)) { + break; + } + } + FoldLineState foldPrev(0); + int levelCurrent = SC_FOLDLEVELBASE; + if (lineCurrent > 0) { + levelCurrent = styler.LevelAt(lineCurrent - 1) >> 16; + foldPrev = FoldLineState(styler.GetLineState(lineCurrent - 1)); + } + + int levelNext = levelCurrent; + FoldLineState foldCurrent(styler.GetLineState(lineCurrent)); + Sci_PositionU lineStartNext = styler.LineStart(lineCurrent + 1); + lineStartNext = std::min(lineStartNext, endPos); + + while (startPos < endPos) { + initStyle = styler.StyleIndexAt(startPos); + + if (initStyle == SCE_ZIG_OPERATOR) { + const char ch = styler[startPos]; + if (ch == '{' || ch == '[' || ch == '(') { + levelNext++; + } else if (ch == '}' || ch == ']' || ch == ')') { + levelNext--; + } + } + + ++startPos; + if (startPos == lineStartNext) { + const FoldLineState foldNext(styler.GetLineState(lineCurrent + 1)); + levelNext = std::max(levelNext, SC_FOLDLEVELBASE); + if (foldCurrent.lineComment) { + levelNext += foldNext.lineComment - foldPrev.lineComment; + } else if (foldCurrent.multilineString) { + levelNext += foldNext.multilineString - foldPrev.multilineString; + } + + 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; + foldPrev = foldCurrent; + foldCurrent = foldNext; + } + } +} + +} // unnamed namespace end + +extern const LexerModule lmZig(SCLEX_ZIG, LexerZig::LexerFactoryZig, "zig", zigWordListDesc);
Modified: scintilla/lexilla/src/Lexilla.cxx 3 lines changed, 3 insertions(+), 0 deletions(-) =================================================================== @@ -160,6 +160,7 @@ extern LexerModule lmVisualProlog; extern LexerModule lmX12; extern LexerModule lmXML; extern LexerModule lmYAML; +extern LexerModule lmZig;
//--Autogenerated -- end of automatically generated section
@@ -224,6 +225,7 @@ static void AddGeanyLexers() &lmVisualProlog, &lmXML, &lmYAML, + &lmZig, }); }
@@ -372,6 +374,7 @@ void AddEachLexer() { &lmX12, &lmXML, &lmYAML, + &lmZig,
//--Autogenerated -- end of automatically generated section });
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,72 @@ +@@ -167,8 +167,73 @@
CatalogueModules catalogueLexilla;
@@ -123,6 +123,7 @@ index cd4b23617..af4a73db4 100644 + &lmVisualProlog, + &lmXML, + &lmYAML, ++ &lmZig, + }); +} +
Modified: src/document.c 1 lines changed, 1 insertions(+), 0 deletions(-) =================================================================== @@ -2722,6 +2722,7 @@ void document_highlight_tags(GeanyDocument *doc) case GEANY_FILETYPES_VALA: case GEANY_FILETYPES_RUST: case GEANY_FILETYPES_GO: + case GEANY_FILETYPES_ZIG: {
/* index of the keyword set in the Scintilla lexer, for
Modified: src/editor.c 2 lines changed, 2 insertions(+), 0 deletions(-) =================================================================== @@ -1330,6 +1330,7 @@ static gboolean lexer_has_braces(ScintillaObject *sci) case SCLEX_R: case SCLEX_RAKU: case SCLEX_RUST: + case SCLEX_ZIG: return TRUE; default: return FALSE; @@ -5146,6 +5147,7 @@ void editor_set_indentation_guides(GeanyEditor *editor) case SCLEX_D: case SCLEX_OCTAVE: case SCLEX_RUST: + case SCLEX_ZIG: mode = SC_IV_LOOKBOTH; break;
Modified: src/filetypes.c 1 lines changed, 1 insertions(+), 0 deletions(-) =================================================================== @@ -193,6 +193,7 @@ static void init_builtin_filetypes(void) FT_INIT( CIL, NONE, "CIL", NULL, SOURCE_FILE, COMPILED ); FT_INIT( PROLOG, NONE, "Prolog", NULL, SOURCE_FILE, COMPILED ); FT_INIT( NIM, NONE, "Nim", NULL, SOURCE_FILE, COMPILED ); + FT_INIT( ZIG, NONE, "Zig", NULL, SOURCE_FILE, COMPILED ); }
Modified: src/filetypes.h 1 lines changed, 1 insertions(+), 0 deletions(-) =================================================================== @@ -113,6 +113,7 @@ typedef enum GEANY_FILETYPES_CIL, GEANY_FILETYPES_PROLOG, GEANY_FILETYPES_NIM, + GEANY_FILETYPES_ZIG, /* ^ append items here */ GEANY_MAX_BUILT_IN_FILETYPES /* Don't use this, use filetypes_array->len instead */ }
Modified: src/highlighting.c 13 lines changed, 13 insertions(+), 0 deletions(-) =================================================================== @@ -1059,6 +1059,7 @@ void highlighting_init_styles(guint filetype_idx, GKeyFile *config, GKeyFile *co init_styleset_case(XML); init_styleset_case(YAML); init_styleset_case(ZEPHIR); + init_styleset_case(ZIG); default: if (ft->lexer_filetype) geany_debug("Filetype %s has a recursive lexer_filetype %s set!", @@ -1155,6 +1156,7 @@ void highlighting_set_styles(ScintillaObject *sci, GeanyFiletype *ft) styleset_case(XML); styleset_case(YAML); styleset_case(ZEPHIR); + styleset_case(ZIG); case GEANY_FILETYPES_NONE: default: styleset_default(sci, ft->id); @@ -1685,6 +1687,12 @@ gboolean highlighting_is_string_style(gint lexer, gint style) style == SCE_NIM_TRIPLE || style == SCE_NIM_TRIPLEDOUBLE || style == SCE_NIM_STRINGEOL); + + case SCLEX_ZIG: + return (style == SCE_ZIG_STRING || + style == SCE_ZIG_MULTISTRING || + style == SCE_ZIG_CHARACTER || + style == SCE_ZIG_ESCAPECHAR); } return FALSE; } @@ -1937,6 +1945,11 @@ gboolean highlighting_is_comment_style(gint lexer, gint style) style == SCE_NIM_COMMENTDOC || style == SCE_NIM_COMMENTLINE || style == SCE_NIM_COMMENTLINEDOC); + + case SCLEX_ZIG: + return (style == SCE_ZIG_COMMENTLINE || + style == SCE_ZIG_COMMENTLINEDOC || + style == SCE_ZIG_COMMENTLINETOP); } return FALSE; }
Modified: src/highlightingmappings.h 33 lines changed, 33 insertions(+), 0 deletions(-) =================================================================== @@ -1886,6 +1886,39 @@ static const HLKeyword highlighting_keywords_YAML[] = #define highlighting_properties_YAML EMPTY_PROPERTIES
+/* ZIG */ +#define highlighting_lexer_ZIG SCLEX_ZIG +static const HLStyle highlighting_styles_ZIG[] = +{ + { SCE_ZIG_DEFAULT, "default", FALSE }, + { SCE_ZIG_COMMENTLINE, "comment_line", FALSE }, + { SCE_ZIG_COMMENTLINEDOC, "comment_line_doc", FALSE }, + { SCE_ZIG_COMMENTLINETOP, "comment_line_top", FALSE }, + { SCE_ZIG_NUMBER, "number", FALSE }, + { SCE_ZIG_OPERATOR, "operator", FALSE }, + { SCE_ZIG_CHARACTER, "character", FALSE }, + { SCE_ZIG_STRING, "string", FALSE }, + { SCE_ZIG_MULTISTRING, "multistring", FALSE }, + { SCE_ZIG_ESCAPECHAR, "escapechar", FALSE }, + { SCE_ZIG_IDENTIFIER, "identifier", FALSE }, + { SCE_ZIG_FUNCTION, "function", FALSE }, + { SCE_ZIG_BUILTIN_FUNCTION, "builtin_function", FALSE }, + { SCE_ZIG_KW_PRIMARY, "kw_primary", FALSE }, + { SCE_ZIG_KW_SECONDARY, "kw_secondary", FALSE }, + { SCE_ZIG_KW_TERTIARY, "kw_tertiary", FALSE }, + { SCE_ZIG_KW_TYPE, "kw_type", FALSE }, + { SCE_ZIG_IDENTIFIER_STRING, "identifer_string", FALSE } +}; +static const HLKeyword highlighting_keywords_ZIG[] = +{ + { 0, "primary", FALSE }, + { 1, "secondary", FALSE }, + { 2, "tertiary", FALSE }, + { 3, "types", FALSE } +}; +#define highlighting_properties_ZIG EMPTY_PROPERTIES + + /* Zephir */ #define highlighting_lexer_ZEPHIR SCLEX_PHPSCRIPT #define highlighting_styles_ZEPHIR highlighting_styles_PHP
-------------- This E-Mail was brought to you by github_commit_mail.py (Source: https://github.com/geany/infrastructure).