From 0434a1a9a2455ae09df76874daf1e57cb14d7656 Mon Sep 17 00:00:00 2001 From: Rainer Kottenhoff Date: Fri, 28 May 2021 09:51:39 +0200 Subject: [PATCH] +upd: Lexilla: improved Julia Lexer --- Versions/build.txt | 2 +- lexilla/doc/LexillaHistory.html | 4 + lexilla/lexers/LexJulia.cxx | 160 ++++++++++++++++++-------------- res/Notepad3.exe.manifest.conf | 4 +- src/VersionEx.h | 6 +- 5 files changed, 98 insertions(+), 78 deletions(-) diff --git a/Versions/build.txt b/Versions/build.txt index d00491fd7..0cfbf0888 100644 --- a/Versions/build.txt +++ b/Versions/build.txt @@ -1 +1 @@ -1 +2 diff --git a/lexilla/doc/LexillaHistory.html b/lexilla/doc/LexillaHistory.html index 9fce1314e..ae5cff908 100644 --- a/lexilla/doc/LexillaHistory.html +++ b/lexilla/doc/LexillaHistory.html @@ -610,6 +610,10 @@ On Win32 enable hardware-enforced stack protection. Feature #1405. +
  • + On 32-bit Win32 using g++, stop exported functions ending with @n causing failures with GetProcAddress. + Issue #10. +
  • Release 5.0.2 diff --git a/lexilla/lexers/LexJulia.cxx b/lexilla/lexers/LexJulia.cxx index a41b0e700..ba6c07644 100644 --- a/lexilla/lexers/LexJulia.cxx +++ b/lexilla/lexers/LexJulia.cxx @@ -49,15 +49,19 @@ struct OptionsJulia { bool foldComment; bool foldCompact; bool foldDocstring; + bool foldSyntaxBased; bool highlightTypeannotation; bool highlightLexerror; + bool stringInterpolation; OptionsJulia() { fold = true; foldComment = true; foldCompact = false; foldDocstring = true; + foldSyntaxBased = true; highlightTypeannotation = true; highlightLexerror = true; + stringInterpolation = true; } }; @@ -77,13 +81,20 @@ struct OptionSetJulia : public OptionSet { DefineProperty("fold.comment", &OptionsJulia::foldComment); - DefineProperty("fold.docstring", &OptionsJulia::foldDocstring); + DefineProperty("fold.julia.docstring", &OptionsJulia::foldDocstring, + "Fold multiline triple-doublequote strings, usually used to document a function or type above the definition."); - DefineProperty("highlight.typeannotation", &OptionsJulia::highlightTypeannotation, - "This option enables Julia highlighting of type after :: as type annotation instead of parsing from the keyword lists."); + DefineProperty("fold.julia.syntax.based", &OptionsJulia::foldSyntaxBased, + "Set this property to 0 to disable syntax based folding."); - DefineProperty("highlight.lexerror", &OptionsJulia::highlightLexerror, - "This option enables Julia highlighting of syntax error int character or number definition."); + DefineProperty("lexer.julia.highlight.typeannotation", &OptionsJulia::highlightTypeannotation, + "This option enables highlighting of type after :: as type annotation instead of parsing from the keyword lists."); + + DefineProperty("lexer.julia.highlight.lexerror", &OptionsJulia::highlightLexerror, + "This option enables highlighting of syntax error int character or number definition."); + + DefineProperty("lexer.julia.string.interpolation", &OptionsJulia::stringInterpolation, + "Set to 0 to not recognize string interpolation at all"); DefineWordListSets(juliaWordLists); } @@ -591,12 +602,13 @@ static void resumeCharacter(StyleContext &sc, bool lexerror) { if (lexerror) { if (sc.ch != '\'') { error = true; - while (sc.ch != '\'' && sc.ch != EOF && - sc.ch != '\r' && sc.ch != '\n') { + while (sc.ch != '\'' && + sc.ch != '\r' && + sc.ch != '\n') { sc.Forward(); } } - + if (error) { sc.ChangeState(SCE_JULIA_LEXERROR); sc.ForwardSetState(SCE_JULIA_DEFAULT); @@ -611,13 +623,14 @@ static void resumeCharacter(StyleContext &sc, bool lexerror) { if (sc.ch != '\'') { error = true; - while (sc.ch != '\'' && sc.ch != EOF && - sc.ch != '\r' && sc.ch != '\n') { + while (sc.ch != '\'' && + sc.ch != '\r' && + sc.ch != '\n') { sc.Forward(); } } } - + if (error) { sc.ChangeState(SCE_JULIA_LEXERROR); sc.ForwardSetState(SCE_JULIA_DEFAULT); @@ -640,10 +653,10 @@ static inline bool IsACharacter(StyleContext &sc) { static void ScanParenInterpolation(StyleContext &sc) { // TODO: no syntax highlighting inside a string interpolation - + // Level of nested parenthesis int interp_level = 0; - + // If true, it is inside a string and parenthesis are not counted. bool allow_paren_string = false; @@ -670,10 +683,10 @@ static void ScanParenInterpolation(StyleContext &sc) { } } -/* +/* * Resume parsing a String or Command, bounded by the `quote` character (\" or \`) * The `triple` argument specifies if it is a triple-quote String or Command. - * Interpolation is detected (with `$`), and parsed if `allow_interp` is true. + * Interpolation is detected (with `$`), and parsed if `allow_interp` is true. */ static void resumeStringLike(StyleContext &sc, int quote, bool triple, bool allow_interp, bool full_highlight) { int stylePrev = sc.state; @@ -694,9 +707,9 @@ static void resumeStringLike(StyleContext &sc, int quote, bool triple, bool allo } ScanParenInterpolation(sc); sc.ForwardSetState(stylePrev); - + checkcurrent = true; - + } else if (full_highlight && IsIdentifierFirstCharacter(sc.chNext)) { sc.SetState(SCE_JULIA_STRINGINTERP); sc.Forward(); @@ -710,13 +723,13 @@ static void resumeStringLike(StyleContext &sc, int quote, bool triple, bool allo checkcurrent = true; } - + if (checkcurrent) { // Check that the current character is not a special char, // otherwise it will be skipped resumeStringLike(sc, quote, triple, allow_interp, full_highlight); } - + } else if (sc.ch == quote) { if (triple) { if (sc.chNext == quote && sc.GetRelativeCharacter(2) == quote) { @@ -743,7 +756,7 @@ static void resumeString(StyleContext &sc, bool triple, bool allow_interp) { static void resumeNumber (StyleContext &sc, int base, bool &with_dot, bool lexerror) { if (IsNumberExpon(sc.ch, base)) { - if (isdigit(sc.chNext) || sc.chNext == '+' || sc.chNext == '-') { + if (IsADigit(sc.chNext) || sc.chNext == '+' || sc.chNext == '-') { sc.Forward(); // Capture all digits ScanDigits(sc, 10, false); @@ -760,7 +773,7 @@ static void resumeNumber (StyleContext &sc, int base, bool &with_dot, bool lexer ScanDigits(sc, base, true); } else if (IsADigit(sc.ch, base) || sc.ch == '_') { ScanDigits(sc, base, true); - } else if (isdigit(sc.ch) && !IsADigit(sc.ch, base)) { + } else if (IsADigit(sc.ch) && !IsADigit(sc.ch, base)) { if (lexerror) { sc.ChangeState(SCE_JULIA_LEXERROR); } @@ -772,7 +785,7 @@ static void resumeNumber (StyleContext &sc, int base, bool &with_dot, bool lexer } static void resumeOperator (StyleContext &sc) { - if (sc.chNext == ':' && (sc.ch == ':' || sc.ch == '<' || + if (sc.chNext == ':' && (sc.ch == ':' || sc.ch == '<' || (sc.ch == '>' && (sc.chPrev != '-' && sc.chPrev != '=')))) { // Case `:a=>:b` sc.Forward(); @@ -870,10 +883,10 @@ void SCI_METHOD LexerJulia::Lex(Sci_PositionU startPos, Sci_Position length, int } else { israwstring = false; } - + sc.ChangeState(SCE_JULIA_STRINGLITERAL); sc.SetState(SCE_JULIA_DEFAULT); - + } else if (sc.ch == '`') { sc.ChangeState(SCE_JULIA_COMMANDLITERAL); sc.SetState(SCE_JULIA_DEFAULT); @@ -882,13 +895,13 @@ void SCI_METHOD LexerJulia::Lex(Sci_PositionU startPos, Sci_Position length, int } else if (! IsIdentifierCharacter(sc.ch)) { char s[MAX_JULIA_IDENT_CHARS + 1]; sc.GetCurrent(s, sizeof(s)); - + // Treat the keywords differently if we are indexing or not if ( indexing_level > 0 && CheckBoundsIndexing(s)) { // Inside [], (), `begin` and `end` are numbers not block keywords sc.ChangeState(SCE_JULIA_NUMBER); transpose = false; - + } else { // Ignore the last index of NUM_JULIA_KEYWORD_LISTS that is // used for Raw string literals. @@ -915,22 +928,22 @@ void SCI_METHOD LexerJulia::Lex(Sci_PositionU startPos, Sci_Position length, int resumeCharacter(sc, options.highlightLexerror); break; case SCE_JULIA_DOCSTRING: - resumeString(sc, true, !israwstring); + resumeString(sc, true, options.stringInterpolation && !israwstring); if (sc.state == SCE_JULIA_DEFAULT && israwstring) { israwstring = false; } break; case SCE_JULIA_STRING: - resumeString(sc, false, !israwstring); + resumeString(sc, false, options.stringInterpolation && !israwstring); if (sc.state == SCE_JULIA_DEFAULT && israwstring) { israwstring = false; } break; case SCE_JULIA_COMMAND: - resumeCommand(sc, triple_backtick, true); + resumeCommand(sc, triple_backtick, options.stringInterpolation); break; case SCE_JULIA_MACRO: - if (isspace(sc.ch) || ! IsIdentifierCharacter(sc.ch)) { + if (IsASpace(sc.ch) || ! IsIdentifierCharacter(sc.ch)) { sc.SetState(SCE_JULIA_DEFAULT); } break; @@ -970,13 +983,14 @@ void SCI_METHOD LexerJulia::Lex(Sci_PositionU startPos, Sci_Position length, int // check start of a new state if (sc.state == SCE_JULIA_DEFAULT) { if (sc.ch == '#') { + sc.SetState(SCE_JULIA_COMMENT); // increment depth if we are a block comment if(sc.chNext == '=') { commentDepth ++; + sc.Forward(); } curLine = styler.GetLine(sc.currentPos); styler.SetLineState(curLine, commentDepth); - sc.SetState(SCE_JULIA_COMMENT); } else if (sc.ch == '!') { sc.SetState(SCE_JULIA_OPERATOR); } else if (sc.ch == '\'') { @@ -1007,7 +1021,7 @@ void SCI_METHOD LexerJulia::Lex(Sci_PositionU startPos, Sci_Position length, int sc.Forward(); } } - } else if (isdigit(sc.ch) || (sc.ch == '.' && isdigit(sc.chNext))) { + } else if (IsADigit(sc.ch) || (sc.ch == '.' && IsADigit(sc.chNext))) { base = 10; with_dot = false; transpose = true; @@ -1095,7 +1109,7 @@ void SCI_METHOD LexerJulia::Fold(Sci_PositionU startPos, Sci_Position length, in LexAccessor styler(pAccess); - // level of nested brackets + // level of nested brackets int indexing_level = 0; // level of nested parenthesis or brackets int list_comprehension = 0; @@ -1134,47 +1148,49 @@ void SCI_METHOD LexerJulia::Fold(Sci_PositionU startPos, Sci_Position length, in } } - // list comprehension allow `for`/`if` without `end` - if (style == SCE_JULIA_BRACKET) { - if (ch == '[') { - list_comprehension ++; - indexing_level ++; - levelNext ++; - } else if (ch == ']') { - list_comprehension --; - indexing_level --; - levelNext --; - } else if (ch == '(') { - list_comprehension ++; - levelNext ++; - } else if (ch == ')') { - list_comprehension --; - levelNext --; - } - // check non-negative - if (indexing_level < 0) { - indexing_level = 0; - } - if (list_comprehension < 0) { - list_comprehension = 0; - } - } - - // keyword - if (style == SCE_JULIA_KEYWORD1) { - word[wordlen++] = static_cast(ch); - if (wordlen == 100) { // prevent overflow - word[0] = '\0'; - wordlen = 1; - } - if (styleNext != SCE_JULIA_KEYWORD1) { - word[wordlen] = '\0'; - wordlen = 0; - if (list_comprehension <= 0 && indexing_level <= 0) { - levelNext += CheckKeywordFoldPoint(word); + // Syntax based folding, accounts for list comprehension + if (options.foldSyntaxBased) { + // list comprehension allow `for`, `if` and `begin` without `end` + if (style == SCE_JULIA_BRACKET) { + if (ch == '[') { + list_comprehension ++; + indexing_level ++; + levelNext ++; + } else if (ch == ']') { + list_comprehension --; + indexing_level --; + levelNext --; + } else if (ch == '(') { + list_comprehension ++; + levelNext ++; + } else if (ch == ')') { + list_comprehension --; + levelNext --; + } + // check non-negative + if (indexing_level < 0) { + indexing_level = 0; + } + if (list_comprehension < 0) { + list_comprehension = 0; + } + } + + // keyword + if (style == SCE_JULIA_KEYWORD1) { + word[wordlen++] = static_cast(ch); + if (wordlen == 100) { // prevent overflow + word[0] = '\0'; + wordlen = 1; + } + if (styleNext != SCE_JULIA_KEYWORD1) { + word[wordlen] = '\0'; + wordlen = 0; + if (list_comprehension <= 0 && indexing_level <= 0) { + levelNext += CheckKeywordFoldPoint(word); + } } } - } // Docstring diff --git a/res/Notepad3.exe.manifest.conf b/res/Notepad3.exe.manifest.conf index ca5eef776..bf80e9dbc 100644 --- a/res/Notepad3.exe.manifest.conf +++ b/res/Notepad3.exe.manifest.conf @@ -3,8 +3,8 @@ - Notepad3 beta + Notepad3 alpha diff --git a/src/VersionEx.h b/src/VersionEx.h index 0c24b5b0f..cff671976 100644 --- a/src/VersionEx.h +++ b/src/VersionEx.h @@ -9,12 +9,12 @@ #define VERSION_MAJOR 5 #define VERSION_MINOR 21 #define VERSION_REV 527 -#define VERSION_BUILD 1 +#define VERSION_BUILD 2 #define SCINTILLA_VER 502 #define LEXILLA_VER 502 #define ONIGURUMA_REGEX_VER 7.0.0 #define UCHARDET_VER 2018.09.27 #define TINYEXPR_VER 2018.05.11 #define UTHASH_VER 2.1.0 -#define VERSION_PATCH beta -#define VERSION_COMMIT_ID dkt1-amr +#define VERSION_PATCH alpha +#define VERSION_COMMIT_ID nebukadn