From 4f3735881405bb463bbdd3c743701d1dfdc9dc39 Mon Sep 17 00:00:00 2001 From: Rainer Kottenhoff Date: Thu, 26 Sep 2019 21:34:07 +0200 Subject: [PATCH] + upd: Scintilla Perl Lexer --- scintilla/doc/ScintillaHistory.html | 9 ++++++++ scintilla/lexers/LexPerl.cxx | 33 +++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+) diff --git a/scintilla/doc/ScintillaHistory.html b/scintilla/doc/ScintillaHistory.html index b25f65b63..4a88a1715 100644 --- a/scintilla/doc/ScintillaHistory.html +++ b/scintilla/doc/ScintillaHistory.html @@ -545,6 +545,7 @@ Wil van Antwerpen Hodong Kim + SilverDirk

@@ -567,6 +568,14 @@ SciTE enables use of SCI_ commands in user.context.menu.

  • + Perl lexer supports indented here-docs. + Bug #2121. +
  • +
  • + Perl folder folds qw arrays. + Feature #1306. +
  • +
  • On Win32, stop the IME candidate window moving unnecessarily and position it better.
    Stop candidate window overlapping composition text and taskbar.
    Position candidate window closer to composition text.
    diff --git a/scintilla/lexers/LexPerl.cxx b/scintilla/lexers/LexPerl.cxx index 34f525586..834638f41 100644 --- a/scintilla/lexers/LexPerl.cxx +++ b/scintilla/lexers/LexPerl.cxx @@ -37,6 +37,8 @@ using namespace Scintilla; // Following a << you specify a string to terminate the quoted material, and // all lines following the current line down to the terminating string are // the value of the item. +// Prefixing the terminating string with a "~" specifies that you want to +// use "Indented Here-docs" (see below). // * The terminating string may be either an identifier (a word), or some // quoted text. // * If quoted, the type of quotes you use determines the treatment of the @@ -48,6 +50,18 @@ using namespace Scintilla; // (This is deprecated, -w warns of this syntax) // * The terminating string must appear by itself (unquoted and // with no surrounding whitespace) on the terminating line. +// +// Indented Here-docs +// ------------------ +// The here-doc modifier "~" allows you to indent your here-docs to +// make the code more readable. +// The delimiter is used to determine the exact whitespace to remove +// from the beginning of each line. All lines must have at least the +// same starting whitespace (except lines only containing a newline) +// or perl will croak. Tabs and spaces can be mixed, but are matched +// exactly. One tab will not be equal to 8 spaces! +// Additional beginning whitespace (beyond what preceded the +// delimiter) will be preserved. #define HERE_DELIM_MAX 256 // maximum length of HERE doc delimiter @@ -619,12 +633,14 @@ void SCI_METHOD LexerPerl::Lex(Sci_PositionU startPos, Sci_Position length, int // 2: here doc text (lines after the delimiter) int Quote; // the char after '<<' bool Quoted; // true if Quote in ('\'','"','`') + bool StripIndent; // true if '<<~' requested to strip leading whitespace int DelimiterLength; // strlen(Delimiter) char Delimiter[HERE_DELIM_MAX]; // the Delimiter HereDocCls() { State = 0; Quote = 0; Quoted = false; + StripIndent = false; DelimiterLength = 0; Delimiter[0] = '\0'; } @@ -896,8 +912,14 @@ void SCI_METHOD LexerPerl::Lex(Sci_PositionU startPos, Sci_Position length, int HereDoc.State = 1; // pre-init HERE doc class HereDoc.Quote = sc.chNext; HereDoc.Quoted = false; + HereDoc.StripIndent = false; HereDoc.DelimiterLength = 0; HereDoc.Delimiter[HereDoc.DelimiterLength] = '\0'; + if (delim_ch == '~') { // was actually '<<~' + sc.Forward(); + HereDoc.StripIndent = true; + HereDoc.Quote = delim_ch = sc.chNext; + } if (IsASpaceOrTab(delim_ch)) { // skip whitespace; legal only for quoted delimiters Sci_PositionU i = sc.currentPos + 1; @@ -964,6 +986,11 @@ void SCI_METHOD LexerPerl::Lex(Sci_PositionU startPos, Sci_Position length, int case SCE_PL_HERE_QX: // also implies HereDoc.State == 2 sc.Complete(); + if (HereDoc.StripIndent) { + // skip whitespace + while (IsASpaceOrTab(sc.ch) && !sc.atLineEnd) + sc.Forward(); + } if (HereDoc.DelimiterLength == 0 || sc.Match(HereDoc.Delimiter)) { int c = sc.GetRelative(HereDoc.DelimiterLength); if (c == '\r' || c == '\n') { // peek first, do not consume match @@ -1701,6 +1728,12 @@ void SCI_METHOD LexerPerl::Fold(Sci_PositionU startPos, Sci_Position length, int } else if (ch == ']') { levelCurrent--; } + } else if (style == SCE_PL_STRING_QW) { + // qw + if (stylePrevCh != style) + levelCurrent++; + else if (styleNext != style) + levelCurrent--; } // POD folding if (options.foldPOD && atLineStart) {