Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to parse a Module name canonically

I have a regex that parses a string that should be a fully qualified module name for Raku (see below). Since only the auth, ver, and api versions seem to be used in the Precomp modules, I only test for those.

I need to separate out the name of the module from the identifiers.

My regex is:

my $rx := /
                       ^
                       $<name> = ( [ \w | '::' ] + )
                       [ ':' $<part> = ( [ 'ver' | 'auth' | 'api' ] )
                        \< ~ \> $<val> = ( .*? ) ]*
                       $
                      /;

Question is whether there is a standard way to match to a Raku module, or a sub so that this regex does not become an error in the future.

like image 371
Richard Hainsworth Avatar asked Jul 23 '20 13:07

Richard Hainsworth


2 Answers

Looking at the grammar of Raku, it looks like it is just first eating all adverbs in a package definition, and then checks each one of them if it's either ver, auth or api, to die if it is not one of these.

So, I would say: No, currently there is no standard way to match a Raku module name.

like image 100
Elizabeth Mattijsen Avatar answered Oct 19 '22 19:10

Elizabeth Mattijsen


It's probably the best if you use Zef::Identity

use Zef::Identity;

say Zef::Identity.new( "WithApi:ver<0.0.2>:api<1>" ).hash;
# {api => 1, auth => , from => Perl6, name => WithApi, ver => 0.0.2}

It's probably already installed in your system, since it's part of zef

like image 34
jjmerelo Avatar answered Oct 19 '22 21:10

jjmerelo