How best is it to extract a hash from the config portion of a RakuAST::Doc::Block ? Here is the program:
use v6.d;
use experimental :rakuast;
my $ast = Q:to/CONF/.AST;
=for rakudoc :category("Language") :kind<sub> :subkind<operator>
Stuff
CONF
my $block = $ast.rakudoc[0];
my %config = $block.config.pairs.map( { .key => .value.DEPARSE } );
say %config.raku
Here is the result.
{:category("(\"Language\")"), :kind("<sub>"), :subkind("<operator>")}
But .DEPARSE is producing the quotation markers, viz, ("...") and <...>. How can I just extract the string?
The.DEPARSEmethod attempts to re-create the original Raku code. For strings this means quotes are included.If you want to get to the actual values, you can call the
.literalizemethod on any RakuAST object. This will either returnNilif it cannot be literalized, or the actual value if it can.UPDATE: It was a while when I worked last on this. While the above will work, there is actually already a method that will DWIM:
.resolved-config. So:will produce:
Note the use of
:=instead of=. While the=will also work, the:=will be much more efficient as it wouldn't need to copy anything.