... Or how to change $<sigil>.Str
value from token sigil { ... }
idependently from the matched text. Yes I'm asking how to cheat grammars above (i.e. calling) me.
I am trying to write a Slang for Raku without sigil.
So I want the nogil
token, matching anything <?>
to return NqpMatch that stringifies: $<sigil>.Str
to '$'.
Currently, my token sigil look like that
token sigil {
| <[$@%&]>
| <nogil> { say "Nogil returned: ", lk($/, 'nogil').Str; # Here It should print "$"
}
}
token nogil-proxy {
| '€'
| <?>
{log "No sigil:", get-stack; }
}
And the method with that should return a NQPMatch
with method Str
overwritten
method nogil {
my $cursor := self.nogil-proxy;
# .. This si where Nqp expertise would be nice
say "string is:", $cursor.Str; # here also it should print "$"
return $cursor;
}
Failed try:
$cursor.^cache_add('Str', sub { return '$'; } );
$cursor.^publish_method_cache;
for $cursor.^attributes { .name.say };
for $cursor.^methods { .name.say };
say $cursor.WHAT.Str;
nqp::setmethcacheauth($cursor, 0);
Currently, most of my tests work but I have problems in declarations without my (with no strict
) like my-var = 42;
because they are considered as method call.
@Arne-Sommer already made a post and an article. This is closely related. But this questions aims:
How can we customize the return value of a compile-time token and not how to declare it.
Str
into the match object, perhaps in asigil
action method. Though I suspect that'll only get you so far. Ultimately, the Raku grammar is formally ambiguous without sigils (that's why sigilless vars have to be introduced withmy \foo = ...
), so I suspect you'll run into endless problems trying to do this. – Ephemeronfoo
inmy foo...
to be a type; and this and other such predictive presumptions run deep. However, aiui, an actual raku grammar "SHOULD" never be formally ambiguous unless it involves "specified" scenarios declared to be ambiguous. Is that right afauk? – Costanziamixin
vs composition. AndCompose
method do not exists inNQPMatch
but mixin is working. Thank You! – Tewell:$foo
means:foo($foo)
, but:foo
means:foo(True)
, and you thus can't have a convenience form of the colonpair construct for passing a variable on without sigils - or you have to drop the one for passingTrue
. – Ephemeronfoo + bar
will parse asfoo
(listop) callingbar
and applying the prefix+
operator to it. Not an infix operator on two variables. – Ephemeronmy foo = 37; say MY::
->{$foo => 37}
. Sofoo
and$foo
is the same thing in declaration: I cansay "Seems cool $foo"
. But then I cannotfoo + $foo
because nofoo
inMY::
scope. So I'll have to cheat in many places. – Tewellfoo
in scope (<?>
) in<sigil>
. I have to check on routine call forfoo = 42
to be considered as a declaration. – Tewell