I am trying to add «€» as an alias for the «$» scalar, and doing it with a Slang is the way to do it I think. But perl6.doc doesn't mention Slangs at all.
I have read the following:
- https://perlgeek.de/en/article/mutable-grammar-for-perl-6 (from 2008)
- https://mouq.github.io/slangs.html
And looked at the Slang::Roman and Slang::Tuxic modules.
The result is this file (ScalarEU.pm6):
use nqp;
unit module ScalarEU2;
sub EXPORT(|)
{
my role Euscalar
{
token sigil:sym<$> { '€' | '$' }
}
my Mu $MAIN-grammar := nqp::atkey(%*LANG, 'MAIN');
my $grammar := $MAIN-grammar.HOW.mixin($MAIN-grammar, Euscalar);
$*LANG.define_slang('MAIN', $grammar, $*LANG.actions);
{}
}
Then a program (called hello) using it:
use lib "lib";
use ScalarEU;
sub MAIN ($name)
{
say "Hello, €name!";
}
But it doesn't work, or rather, doesn't do what it should:
$ ./hello Tom
Hello, €name!
(I wrote the program this way so that it doesn't crash.)
I haven't added an action class, but the way the "token sigil" is set up shouldn't require that? But that assumption is based on an 11 year article, and may be wrong.
Also, https://github.com/rakudo/rakudo/issues/2404 says that $*LANG is obsolete, and to use $?LANG instead. REPL agrees:
> $*LANG
Dynamic variable $*LANG not found
> $?LANG
(low-level object `Perl6::Grammar`)
But programs can use both, without errors. (I have tried.)
007
which is being used to design how it should work. – Brad Gilbert$
s sprinkled throughout the Rakudo source code, outside its grammars and actions, that are part of what makes the$
sigil work. (Similarly for@
,%
, etc.) It would of course be technically possible to produce a revised Rakudo that lets you do what you're trying to do. It might even be possible to do it without impacting Rakudo performance. But it would be a lot of boring little edits (again, outside of the grammars/actions of a slang) and I suspect you'd have a seriously hard time persuading core devs to merge your changes back into the Rakudo master branch. – raiph$
s relate to internal variables so those won't matter. It looks like some of the rest also won't matter or won't matter much. For exampleissigil
. But code like%cont_info<sigil> eq '$'
or$sigil eq '$'
, to pick a couple random examples from a single source file, looks like it will. – raiph