Skip to content

Commit

Permalink
Start to get our trait parsing more in line with STD.pm. We now call …
Browse files Browse the repository at this point in the history
…it trait_mod in the grammar and have got just one rule now, but it's very much a surface change at the moment.
  • Loading branch information
jnthn committed Jun 29, 2009
1 parent 11d479e commit e069931
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 24 deletions.
31 changes: 16 additions & 15 deletions src/parser/actions.pm
Expand Up @@ -901,20 +901,21 @@ method method_def($/) {

method trait($/) {
my $past;
if $<trait_auxiliary> {
$past := $<trait_auxiliary>.ast;
if $<trait_mod> {
$past := $<trait_mod>.ast;
}
elsif $<trait_verb> {
$past := $<trait_verb>.ast;
elsif $<colonpair> {
$/.panic('traits specified as colon pairs not yet understood');
}
make $past;
}


method trait_auxiliary($/) {
method trait_mod($/) {
my $sym := ~$<sym>;
my $trait := PAST::Op.new( :name('infix:,'), 'trait_auxiliary:' ~ $sym);
my $trait := PAST::Op.new( :name('infix:,'));
if $sym eq 'is' {
$trait.push( 'trait_auxiliary:' ~ $sym );
$trait.push( ~$<name> );
if $<postcircumfix> {
my $arg := $<postcircumfix>[0].ast;
Expand All @@ -923,6 +924,7 @@ method trait_auxiliary($/) {
}
}
elsif $sym eq 'does' {
$trait.push( 'trait_auxiliary:' ~ $sym );
$trait.push( ~$<name> );
if $<EXPR> {
for @(build_call($<EXPR>[0].ast)) {
Expand All @@ -936,19 +938,18 @@ method trait_auxiliary($/) {
}
}
}
elsif $sym eq 'handles' {
$trait.push( 'trait_verb:' ~ $sym );
$trait.push( $<noun>.ast );
}
else {
$trait.push( 'trait_verb:' ~ $sym );
$trait.push( $<fulltypename>.ast );
}
make $trait;
}


method trait_verb($/) {
my $sym := ~$<sym>;
my $value;
if $sym eq 'handles' { $value := $<noun>.ast; }
else { $value := $<fulltypename>.ast; }
make PAST::Op.new( :name('infix:,'), 'trait_verb:' ~ $sym, $value );
}


method signature($/, $key) {
our @?BLOCK;
if $key eq 'open' {
Expand Down
12 changes: 3 additions & 9 deletions src/parser/grammar.pg
Expand Up @@ -437,23 +437,17 @@ rule method_def {

rule trait {
[
| <trait_auxiliary>
| <trait_verb>
| <trait_mod>
| <colonpair>
]
{*}
}

rule trait_auxiliary {
rule trait_mod {
[
| $<sym>=[is] <name><postcircumfix>?
| $<sym>=[does] <name>['['<EXPR>?']']?
| $<sym>=[will] <identifier> <block>
]
{*}
}

rule trait_verb {
[
| $<sym>=[of|returns] <fulltypename>
| $<sym>=[handles] <noun>
]
Expand Down

0 comments on commit e069931

Please sign in to comment.