Skip to content

Commit

Permalink
Add signature parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
Stefan O'Rear committed Jul 13, 2010
1 parent e22978c commit 60c9436
Show file tree
Hide file tree
Showing 2 changed files with 118 additions and 0 deletions.
83 changes: 83 additions & 0 deletions Niecza/Actions.pm
Expand Up @@ -6,6 +6,7 @@ use warnings;
use Op;
use Body;
use Unit;
use Sig;

our $AUTOLOAD;
my %carped;
Expand Down Expand Up @@ -324,6 +325,88 @@ sub variable { my ($cl, $M) = @_;
};
}

sub param_sep {}

# :: Sig::Target
sub param_var { my ($cl, $M) = @_;
if ($M->{signature}) {
$M->sorry('Sub-signatures NYI');
return;
}
if ($M->{twigil}[0] || ($M->{sigil}->Str ne '$')) {
$M->sorry('Non bare scalar targets NYI');
return;
}
$M->{_ast} = Sig::Target->new(slot =>
$M->{name}[0] ? ('$' . $M->{name}[0]->Str) : undef);
}

# :: Sig::Parameter
sub parameter { my ($cl, $M) = @_;
if (@{ $M->{type_constraint} } > 0) {
$M->sorry('Parameter type constraints NYI');
return;
}

if (@{ $M->{trait} } > 0) {
$M->sorry('Parameter traits NYI');
return;
}

if (@{ $M->{post_constraint} } > 0) {
$M->sorry('Parameter post constraints NYI');
return;
}

if ($M->{default_value}[0]) {
$M->sorry('Default values NYI');
return;
}

if ($M->{named_param}) {
$M->sorry('Named parameters NYI');
return;
}

if ($M->{quant} ne '' || $M->{kind} ne '!') {
$M->sorry('Exotic parameters NYI');
return;
}

$M->{_ast} = Sig::Parameter->new(target => $M->{param_var}{_ast});
}

# signatures exist in several syntactic contexts so just make an object for now
sub signature { my ($cl, $M) = @_;
if ($M->{type_constraint}[0]) {
$M->sorry("Return type constraints NYI");
return;
}

if ($M->{param_var}) {
$M->sorry('\| signatures NYI');
return;
}

for (@{ $M->{param_sep} }) {
if ($_->Str !~ /,/) {
$M->sorry('Parameter separator ' . $_->Str . ' NYI');
return;
}
}

$M->{_ast} = Sig->new(params =>
[map { $_->{_ast} } @{ $M->{parameter} }]);
}

sub multisig { my ($cl, $M) = @_;
if (@{ $M->{signature} } != 1) {
$M->sorry("Multiple signatures NYI");
return;
}
$M->{_ast} = $M->{signature}[0]{_ast};
}

sub voidmark { my ($cl, $M) = @_;
$M->{_ast} = 1;
}
Expand Down
35 changes: 35 additions & 0 deletions Sig.pm
@@ -0,0 +1,35 @@
use strict;
use warnings;
use 5.010;

{
package Sig::Target;
use Moose;

has slot => (is => 'ro', isa => 'Maybe[Str]', required => 1);

__PACKAGE__->meta->make_immutable;
no Moose;
}

{
package Sig::Parameter;
use Moose;

has target => (is => 'ro', isa => 'Sig::Target', required => 1);

__PACKAGE__->meta->make_immutable;
no Moose;
}

{
package Sig;
use Moose;

has params => (isa => 'ArrayRef[Sig::Parameter]', is => 'ro', required => 1);

__PACKAGE__->meta->make_immutable;
no Moose;
}

1;

0 comments on commit 60c9436

Please sign in to comment.