raku-mode icon indicating copy to clipboard operation
raku-mode copied to clipboard

heredoc indentation/highlighting

Open amba opened this issue 6 years ago • 8 comments

If I write the following (from Moritz Lentz's book)

        my $sth = self!db.prepare(qq:to/SELECT/);
        SELECT exitcode, timed_out, output
                                        FROM $table
                                        WHERE jobname = ?
                                        ORDER BY executed DESC
                                        LIMIT $count
                                        SELECT

perl6-mode does not recognize the here-doc and seams to indent and highlight its contents as perl6 code.

amba avatar Sep 17 '17 10:09 amba

see issue #4, basically same problem: improper indentation (and I wish I knew how to fix it!)

tbrowder avatar Sep 17 '17 15:09 tbrowder

This is really an irritating bug. I use heredocs a LOT and often find myself giving up and using vim to fix them!

tbrowder avatar Jan 05 '21 11:01 tbrowder

Reopened after accidentally closing the issue.

tbrowder avatar Jan 05 '21 11:01 tbrowder

I'm getting blurry vision. Sorry.

tbrowder avatar Jan 05 '21 11:01 tbrowder

A bit golfed down which works for me but with an error

Potential difficulties:
    Asked to remove 32 spaces, but the shortest indent is 0 spaces
    at /home/marcel/Languages/Raku/Projects/question-answer/x.raku:12
    ------>                                 SELECT⏏<EOL>
use v6;

my Str $table = 'my-table';
my Int $count = 10;

my Str $x = qq:to/SELECT/;
SELECT exitcode, timed_out, output
                                FROM $table
                                WHERE jobname = ?
                                ORDER BY executed DESC
                                LIMIT $count
                                SELECT

note $x;

MARTIMM avatar Nov 26 '21 18:11 MARTIMM

If there is a blank line before the SELECT (I can't see clearly), try removing it.

tbrowder avatar Nov 26 '21 23:11 tbrowder

There is no blank line before any of the two SELECTs. The error is thrown because the last SELECT is 32 characters indented while the leftmost word is at char column 0. To get it right, the last SELECT should also be at col 0.

MARTIMM avatar Nov 27 '21 10:11 MARTIMM

Any progress on this?

The issue seems to be that heredoc/qq quotes are effectively unsupported with any unmatched quotation or bracket (escaped or not) inside getting interpreted by raku-mode as raku code and not part of the quoted string.

I'm working on a raku script that autogenerates C code, and I've had to disable raku-mode entirely instead of fighting the auto-correction and incorrect highlighting. ie the following will throw off both the indentation and paren-matching:

my Str $rtv = qq:to/END/;
  \} else \{
       // do something
   \}
END

Digicrat avatar Mar 03 '22 04:03 Digicrat