7

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.

codesections
  • 8,900
  • 16
  • 50
Richard Hainsworth
  • 1,585
  • 7
  • 9

2 Answers2

5

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.

Elizabeth Mattijsen
  • 25,654
  • 3
  • 75
  • 105
1

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

jjmerelo
  • 22,578
  • 8
  • 40
  • 86