aboutsummaryrefslogtreecommitdiffhomepage
path: root/lexers/LexPerl.cxx
diff options
context:
space:
mode:
authorSilverDirk <unknown>2019-09-26 15:55:18 +1000
committerSilverDirk <unknown>2019-09-26 15:55:18 +1000
commit657e4799c353d42b3e3fcc5f01d4d35536700a86 (patch)
tree28bec4be32fcc764bf7d61da8d1a70f7c8ea2ae4 /lexers/LexPerl.cxx
parentd3f8e9aaa4612971f830fb0fa260a88a7b1bd422 (diff)
downloadscintilla-mirror-657e4799c353d42b3e3fcc5f01d4d35536700a86.tar.gz
Backport: Bug [#2121]. Support indented here-docs.
Backport of changeset 7689:f32c4f7293a7.
Diffstat (limited to 'lexers/LexPerl.cxx')
-rw-r--r--lexers/LexPerl.cxx27
1 files changed, 27 insertions, 0 deletions
diff --git a/lexers/LexPerl.cxx b/lexers/LexPerl.cxx
index 9b1dc761a..a9c81ce51 100644
--- a/lexers/LexPerl.cxx
+++ b/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