Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Experimentally change [+] to be a listop, using <args>
  • Loading branch information
sorear committed Jul 7, 2011
1 parent 4c894a7 commit 3708452
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 39 deletions.
1 change: 1 addition & 0 deletions TODO
Expand Up @@ -91,6 +91,7 @@ NASTY

Other stuff to do after:
- $_ handling: declare in *every* sub, empty/defouter according to returnable
TimToady thinks only Routines should have $/ and $!, maybe?.
- cnperl6 prototyping...
- CLR: KISS and then play with async I/O, possibly including soric
- pm's = hack
Expand Down
20 changes: 12 additions & 8 deletions src/NieczaActions.pm6
Expand Up @@ -1127,14 +1127,6 @@ method infix_circumfix_meta_operator:sym«<< >>» ($/) {
mkbool(substr($/,chars($/)-2,2) eq '>>'));
}

method prefix_circumfix_meta_operator:reduce ($/) {
my $assoc = $<s><op><O><assoc>;
my $op = $<s><op>.ast;
my $tr = substr($/,1,1) eq '\\';
make $op.meta_fun($/, '&reduceop', 1, mkbool($tr), mkbool($assoc eq 'list'),
mkbool($assoc eq 'right'), mkbool($assoc eq 'chain'));
}

method postfix_prefix_meta_operator:sym< » > ($/) { } #handled in POST
method prefix_postfix_meta_operator:sym< « > ($/) { } #handled in PRE

Expand Down Expand Up @@ -1587,6 +1579,18 @@ method term:colonpair ($/) {

method term:fatarrow ($/) { make $<fatarrow>.ast }

method term:reduce ($/) {
my $assoc = $<op><O><assoc>;
make Op::CallSub.new(|node($/),
invocant => mklex($/, '&reduceop'),
args => [
mkbool($<triangle> ne ''), mkbool($assoc eq 'list'),
mkbool($assoc eq 'right'), mkbool($assoc eq 'chain'),
$<op>.ast.as_function($/), @( $<args>.ast.[0] // [] )
]);
}


method do_variable_reference($M, $v) {
if $v<term> {
return $v<term>;
Expand Down
39 changes: 8 additions & 31 deletions src/STD.pm6
Expand Up @@ -266,9 +266,6 @@ proto token postfix_prefix_meta_operator is unary {*}
token category:prefix_postfix_meta_operator { <sym> }
proto token prefix_postfix_meta_operator is unary {*}

token category:prefix_circumfix_meta_operator { <sym> }
proto token prefix_circumfix_meta_operator is unary {*}

token category:terminator { <sym> }
proto token terminator {*}

Expand Down Expand Up @@ -1964,8 +1961,7 @@ grammar P6 is STD {
:my $*VAR;
:dba('prefix or term')
[
| <PRE> [ <!{ my $p = $<PRE>; my @p = @$p; @p[*-1]<O><term> and $<term> = pop @$p }> <PRE> ]*
[ <?{ $<term> }> || <term> || <.panic("Prefix requires an argument")> ]
| <PRE>+ [ <term> || <.panic("Prefix requires an argument")> ]
| <term>
]

Expand Down Expand Up @@ -3065,8 +3061,6 @@ grammar P6 is STD {
[
| <prefix>
$<O> = {$<prefix><O>} $<sym> = {$<prefix><sym>}
| <prefix_circumfix_meta_operator>
$<O> = {$<prefix_circumfix_meta_operator><O>} $<sym> = {$<prefix_circumfix_meta_operator>.Str}
]
# XXX assuming no precedence change

Expand Down Expand Up @@ -3166,38 +3160,21 @@ grammar P6 is STD {
self;
}

regex prefix_circumfix_meta_operator:reduce {
regex term:reduce {
:my $*IN_REDUCE = 1;
:my ($op, $term);
<?before '['\S+']'>
$<s> = (
'['
[
|| <op=.infixish('red')> <?before ']'>
|| \\<op=.infixish('tri')> <?before ']'>
|| <!>
]
']' ['«'|<?>]
)
{ $op = $<s><op>; }
'[' $<triangle>=['\\'?] <op=.infixish('red')> ']' {}

<.can_meta($op, "reduce with")>
<.can_meta($<op>, "reduce with")>

[
|| <!{ $op<O><diffy> }>
|| <?{ $op<O><assoc> eq 'chain' }>
|| <.sorry("Cannot reduce with " ~ $op<sym> ~ " because " ~ $op<O><dba> ~ " operators are diffy and not chaining")>
|| <!{ $<op><O><diffy> }>
|| <?{ $<op><O><assoc> eq 'chain' }>
|| <.sorry("Cannot reduce with " ~ $<op><sym> ~ " because " ~ $<op><O><dba> ~ " operators are diffy and not chaining")>
]

[
|| <?before '('>
|| <?before \s+ [ <?stdstopper> { $term = 1 } ]? >
|| { $term = 1 }
]

<O(|%($op<O>), |%list_prefix, assoc => 'unary', uassoc => 'left', term => $term)>
$<sym> = {$<s>.Str}

<args>
}

token prefix_postfix_meta_operator:sym< « > { <sym> | '<<' }
Expand Down

0 comments on commit 3708452

Please sign in to comment.