-
-
Notifications
You must be signed in to change notification settings - Fork 372
/
Spec.pm6
38 lines (37 loc) · 1.19 KB
/
Spec.pm6
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
class CompUnit::Repository::Spec {
has $.short-id;
has %.options;
has $.path;
has $.Str;
method from-string(Str:D $spec, :$default-short-id = 'file') {
return unless $spec.chars;
# something we understand
if $spec.contains('#') {
if $spec ~~ /^
<before .>
[
$<type>=[ <.ident>+ % '::' ]
$<options>=[ '#' $<option-name>=\w+
<[ < ( [ { ]> $<option-value>=<[\w-]>+? <[ > ) \] } ]>
]*
'#'
]?
$<path>=.*
$/ {
my $short-id := ~($<type> // $default-short-id);
my $path := $*SPEC.canonpath(~$<path>);
self.new(
:$short-id,
:options(%($<option-name>>>.Str Z=> $<option-value>>>.Str)),
:$path,
:Str($short-id ~ $<options> ~ '#' ~ $path)
);
}
}
else {
my $path := $*SPEC.canonpath($spec);
self.new(:short-id($default-short-id), :$path, :Str($default-short-id ~ '#' ~ $path))
}
}
}
# vim: expandtab shiftwidth=4