Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
zufuliu opened this issue Apr 9, 2024 · 0 comments
Closed
Labels
committed Issue fixed in repository but not in release ruby Caused by the ruby lexer

Comments

@zufuliu
Copy link
Contributor

zufuliu commented Apr 9, 2024

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).

@nyamatongwe nyamatongwe added the ruby Caused by the ruby lexer label Apr 9, 2024
@nyamatongwe nyamatongwe added the committed Issue fixed in repository but not in release label Apr 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
committed Issue fixed in repository but not in release ruby Caused by the ruby lexer
Projects
None yet
Development

No branches or pull requests

2 participants