ScintillaOrg / lexilla

A library of language lexers for use with Scintilla
https://www.scintilla.org/Lexilla.html
Other
163 stars 59 forks source link

[Ruby] Allow modifier if, unless, while and until after heredoc delimiter #236

Closed zufuliu closed 2 months ago

zufuliu commented 2 months ago

https://docs.ruby-lang.org/en/master/syntax/control_expressions_rdoc.html#label-Modifier+if+and+unless https://docs.ruby-lang.org/en/master/syntax/control_expressions_rdoc.html#label-Modifier+while+and+until

Patch ruby-heredoc-0409.patch

diff --git a/lexers/LexRuby.cxx b/lexers/LexRuby.cxx
index f5e1aec3..fda7450e 100644
--- a/lexers/LexRuby.cxx
+++ b/lexers/LexRuby.cxx
@@ -645,7 +645,7 @@ bool sureThisIsNotHeredoc(Sci_Position lt2StartPos, Accessor &styler) {
                 return definitely_not_a_here_doc;
             } else {
                 const char ch = styler[j];
-                if (ch == '#' || isEOLChar(ch) || ch == '.' || ch == ',') {
+                if (ch == '#' || isEOLChar(ch) || ch == '.' || ch == ',' || IsLowerCase(ch)) {
                     // This is OK, so break and continue;
                     break;
                 } else {
diff --git a/test/examples/ruby/Issue67.rb b/test/examples/ruby/Issue67.rb
index dcdb8c06..406ae308 100644
--- a/test/examples/ruby/Issue67.rb
+++ b/test/examples/ruby/Issue67.rb
@@ -11,3 +11,22 @@ ONE
 $stdout.puts <<~EOT.chomp
    squiggly heredoc
 EOT
+
+# modifier if, unless, while and until
+alias error puts
+
+error <<EOF if true
+heredoc if true
+EOF
+
+error <<EOF unless false
+heredoc unless false
+EOF
+
+error <<EOF while false
+heredoc while false
+EOF
+
+error <<EOF until true
+heredoc until true
+EOF

IsLowerCase(ch) is simple fix to check these keywords as <<indentifier1 indentifier2 is invalid when << is an operator (shift or append).