Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Initial implementation of CompUnitRepo.parse-spec
  • Loading branch information
lizmat committed Jun 17, 2014
1 parent 5007abc commit 0c069f5
Showing 1 changed file with 75 additions and 1 deletion.
76 changes: 75 additions & 1 deletion src/core/CompUnitRepo.pm
@@ -1,4 +1,5 @@
class CompUnitRepo::Local::File { ... }
class CompUnitRepo::Local::File { ... }
class CompUnitRepo::Local::Installation { ... }

class CompUnitRepo {
my Mu $p6ml := nqp::gethllsym('perl6', 'ModuleLoader');
Expand Down Expand Up @@ -50,4 +51,77 @@ class CompUnitRepo {
method resolve_repossession_conflicts(@conflicts) {
$p6ml.resolve_repossession_conflicts( nqp::findmethod(@conflicts, 'FLATTENABLE_LIST')(@conflicts) )
}

# prime the short-id -> type lookup
my %id2class = (
file => CompUnitRepo::Local::File,
inst => CompUnitRepo::Local::Installation,
);

method parse-spec ($specs) {
my @found;
my $class = %id2class<file>;

# for all possible specs
for $specs.split(/ \s* ',' \s* /) -> $spec {
my %options;

# something we understand
if $spec ~~ /^
[
$<type>=[ <.ident>+ % '::' ]
[ ':' $<n>=\w+
<[ < ( [ { ]> $<v>=<[\w-]>+ <[ > ) \] } ]>
{ %options{$<n>} = ~$<v> }
]*
':'
]?
$<path>=.+
$/ {

# a type (short-id or class name) was specified
if $<type> -> $this {
for %id2class{ $class = ~$this }:v -> $type {
$class = $type;
}
}

# still don't have a type object
if $class ~~ Str {
my $type = ::($class);

# alas, no a known class
if $type ~~ Failure {

# it's a short-id
if %id2class{$class}:exists {
$class = %id2class{$class}
}

# give up
else {
die $class ~~ m/\:/
?? "Must load class '$class' first"
!! "Unknown short-id '$class'";
}
}

# successfully converted string to type
else {
$class = $type;
%id2class{$class.short-id} //= $class;
}
}

# keep this one
@found.push: $($class, ~$<path>, %options);
}

# huh?
elsif $spec ~~ m/\w+/ {
die "Don't know what to do with '$spec'";
}
}
@found;
}
}

0 comments on commit 0c069f5

Please sign in to comment.