hankache / rakuguide

The Raku Guide

Home Page:https://raku.guide

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Use of string concatenation rather than variable interpolation?

con-mo8 opened this issue · comments

One of the core advantages of Perl 6 over Perl 5 for me is how advanced variable interpolation is in quoting. For some reason most of perl6intro prefers "" ~ value ~ "" which I find kind of messy. Is there a strong preference for this? Or am I ok to go through and change these where appropriate? For example say "The capital of France is: %capitals<France>" works perfectly well. More complex expressions I'd prefer "{ expression }" to "" ~ expression ~ "". I'd reserve ~ for something more like $str1 ~ $str2 where there is no default quote construct to be included.

@con-mo8 No specific preference.
In absolute, interpolation is better than string concatenation. So I prefer this: say "The zoo contains {@animals.elems} animals"; over this: say "The zoo contains " ~ @animals.elems ~ " animals";
Unfortunately the syntax highlighter (pygments) doesn't highlight correctly when interpolating code inside a string; the code inside {} will appear as raw text (font and color).
This is mainly why I used string concatenation. I want the readers to be able to grep visually the text part (string) and the code part.

Though I definitely understand the concern for proper highlighting, I also wanted to add that technically in the example you gave @hankache you don't even need curlies as a simple () would inform the compiler that the prior word was a method call e.g., "The zoo contains @animals.elems() animals".

That being said, even my perl6fe language highlighter doesn't catch this style of interpolation (though it is planned).

@hankache not sure it helps but the latest vim highlighter does fully support string interpolation amongst other more Perl 6 specific syntax.

@con-mo8 Unfortunately, asciidoctor supports only pygments and highlight.js. In addition pygments is the only one that does support Perl 6 highlighting.
@MadcapJake Were you considering adding Perl 6 support to highlight.js?

@hankache unfortunately highlight.js doesn't support heredocs but otherwise I'm almost finished with Perl 6 support for it. I've been looking at SyntaxHighlighter which utilizes XRegexp and that has the ability to do named captures (for supporting heredocs) so I will probably do a plugin for that next.

Another option is GitHub's Highlights as that way you could directly utilize my language-perl6fe grammar, but I don't know how easy that would be to integrate into asciidoctor, I did a cursory look and I don't think anyone's tried it before.

A final option would be to beef up Pygments' Perl 6 lexer! I'll take a look and see what can be done there too as I've written a Pygments lexer before.

@MadcapJake Please do tell me if you manage to do one of the above, so I can test them on perl6intro.

@samcv is doing a great job on https://github.com/perl6/atom-language-perl6
Does anyone have any idea if we can let asciidoctor use https://github.com/atom/highlights ?

@hankache you probably know I converted the docs site to use highlights, so it may be possible.
I don't know too much about asciidoc, what do we currently use for highlighting?