Skip to content

Commit

Permalink
Allow infix:<.> if next thing is alphabetic
Browse files Browse the repository at this point in the history
As much as I mistrust "fluent" programming, we already have an infix:<.=>
operator, so it's not a big stretch to have infix:<.>.  We limit it
to actual method names so that we can detect (most) accidental use
of P5's use of . for concatenation.  Note that this is a term/infix
distinction now, so .meth where a term is expected still defaults to $_.
Community standards for method cascades will likely ask for whitespace
around infix:<.> to make a visual disinction from the term form, but we
don't enforce that, if for no other reason than to refrain from giving
the fluent programmers something to yammer on about.  Basically, I've
decided that the slight possibility for greater confusion is outweighed
by consistency with .= and utility of have a . that can also serve as
a precedence modifier.  (Since both .= and . parse leftward with
item assignment precedence, but rightward as a term.)
  • Loading branch information
TimToady committed Sep 27, 2015
1 parent 73836e1 commit cb25b2f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
15 changes: 15 additions & 0 deletions src/Perl6/Actions.nqp
Expand Up @@ -4004,6 +4004,10 @@ Compilation unit '$file' contained the following violations:
make $<dottyopish><term>.ast;
}

method initializer:sym<.>($/) {
make $<dottyopish><term>.ast;
}

method capterm($/) {
my $past := $<termish>
?? QAST::Op.new( $<termish>.ast )
Expand Down Expand Up @@ -5509,6 +5513,10 @@ Compilation unit '$file' contained the following violations:
make make_dot_equals($/[0].ast, $/[1].ast);
return 1;
}
if !$past && $sym eq '.' {
make make_dot($/[0].ast, $/[1].ast);
return 1;
}
elsif $past && nqp::eqat($past.name, '&METAOP_TEST_ASSIGN', 0) {
$past.push($/[0].ast);
$past.push(block_closure(make_thunk_ref($/[1].ast, $/)));
Expand Down Expand Up @@ -7653,6 +7661,13 @@ Compilation unit '$file' contained the following violations:
$call;
}

sub make_dot($target, $call) {
$*W.add_string_constant($call.name);
$call.unshift($target);
$call.op('callmethod');
$call;
}

# XXX This isn't quite right yet... need to evaluate these semantics
sub set_block_handler($/, $handler, $type) {
# Handler needs its own $/ and $!.
Expand Down
8 changes: 6 additions & 2 deletions src/Perl6/Grammar.nqp
Expand Up @@ -3621,6 +3621,7 @@ grammar Perl6::Grammar is HLL::Grammar does STD {
Perl6::Grammar.O(':prec<k=>, :assoc<list>, :dba<tight or>', '%tight_or');
Perl6::Grammar.O(':prec<j=>, :assoc<right>, :dba<conditional>, :fiddly<1>', '%conditional');
Perl6::Grammar.O(':prec<i=>, :assoc<right>, :dba<item assignment>', '%item_assignment');
Perl6::Grammar.O(':prec<i=>, :assoc<right>, :dba<item assignment>, :nextterm<dottyopish>, :sub<z=>', '%dottyinfix');
Perl6::Grammar.O(':prec<i=>, :assoc<right>, :dba<list assignment>, :sub<e=>, :fiddly<1>', '%list_assignment');
Perl6::Grammar.O(':prec<h=>, :assoc<unary>, :dba<loose unary>', '%loose_unary');
Perl6::Grammar.O(':prec<g=>, :assoc<list>, :dba<comma>, :nextterm<nulltermish>, :fiddly<1>', '%comma');
Expand Down Expand Up @@ -4036,7 +4037,10 @@ grammar Perl6::Grammar is HLL::Grammar does STD {
token infix:sym<xx> { <sym> >> <O('%replication')> }

token infix:sym<~> { <sym> <O('%concatenation')> }
token infix:sym<.> { <sym> <[\]\)\},:\s\$"']> <.obs('. to concatenate strings', '~')> }
token infix:sym<.> { <sym> <.ws>
[<-alpha> <.obs('. to concatenate strings', '~')>]?
<O('%dottyinfix')>
}

token infix:sym<&> { <sym> <O('%junctive_and, :iffy<1>')> }
token infix:sym<(&)> { <sym> <O('%junctive_and')> }
Expand Down Expand Up @@ -4176,7 +4180,7 @@ grammar Perl6::Grammar is HLL::Grammar does STD {
<sym> <O('%item_assignment')>
}

token infix:sym<.=> { <sym> <O('%item_assignment, :nextterm<dottyopish>')> }
token infix:sym<.=> { <sym> <O('%dottyinfix')> }

# Should probably have <!after '='> to agree w/spec, but after NYI.
# Modified infix != below instead to prevent misparse
Expand Down

0 comments on commit cb25b2f

Please sign in to comment.