Legend:
- Unmodified
- Added
- Removed
-
src/perl6/Cursor.pmc
r22827 r22836 169 169 our %lexers; # per language, the cache of lexers, keyed by rule name 170 170 171 sub from { $_[0]->{_from} } 172 sub to { $_[0]->{_to} } 173 sub chars { $_[0]->{_to} - $_[0]->{_from} } 174 sub text { substr($::ORIG, $_[0]->{_from}, $_[0]->{_to} - $_[0]->{_from}) } 171 sub from { $_[0]->{_from} // $_[0]->{_pos} } 172 sub to { $_[0]->{_pos} } 175 173 sub pos { $_[0]->{_pos} } 174 sub chars { $_[0]->{_pos} - ($_[0]->{_from} // $_[0]->{_pos}) } 175 sub text { exists $_[0]->{_from} ? substr($::ORIG, $_[0]->{_from}, $_[0]->{_pos} - $_[0]->{_from}) : '' } 176 176 sub peek { $_[0]->{_peek} } 177 177 sub orig { \$::ORIG } … … 711 711 my $lang = @_ && $_[0] ? shift() : ref $self; 712 712 $self->deb("cursor_fresh lang $lang") if $DEBUG & DEBUG::cursors; 713 $r{_to} = $r{_from} = $r{_pos} = $self->{_pos}; 713 # $r{_from} = 714 $r{_pos} = $self->{_pos}; 714 715 $r{_fate} = $self->{_fate}; 715 716 $r{_herelang} = $self->{_herelang} if $self->{_herelang}; … … 798 799 delete $copy{_fate}; 799 800 my $text = STD::Dump(\%copy); 800 $text =~ s/^\s*_(?:pos|orig):.*\n//mg;801 801 $text; 802 802 } … … 819 819 } 820 820 } 821 $r{_pos} = $r{_to} = $submatch->{_to}; 821 $submatch->{_from} = $r{_from} = $r{_pos}; 822 $r{_pos} = $submatch->{_pos}; 822 823 delete $r{_fate}; 823 824 CORE::bless \%r, ref $self; # return new match cursor for parent … … 871 872 $self->deb("cursor_all from $fpos to $tpos") if $DEBUG & DEBUG::cursors; 872 873 my %r = %$self; 873 $r{_from} = $fpos; 874 $r{_to} = $tpos; 874 # $r{_from} = $fpos; 875 875 $r{_pos} = $tpos; 876 876 … … 887 887 $self->deb("cursor to $tpos --------->$GREEN$peek$CLEAR"); 888 888 } 889 $self->{_to} = $tpos;890 889 $self->{_pos} = $tpos; 891 890 … … 903 902 } 904 903 my %r = %$self; 905 $r{_from} = $self->{_pos} // 0; 906 $r{_to} = $tpos; 904 # $r{_from} = $self->{_pos} // 0; 907 905 $r{_pos} = $tpos; 908 906 … … 921 919 my %r = %$self; 922 920 $r{_pos} = $fpos; 923 $r{_from} = $fpos; 924 $r{_to} = $self->{_from}; 921 # $r{_from} = $self->{_from}; 925 922 926 923 CORE::bless \%r, ref $self; … … 1012 1009 1013 1010 my \$C = \$self; 1011 my \$S = \$self->{_pos}; 1014 1012 \$C->{'sym'} = \$sym; 1015 1013 1016 \$self->_MATCHIFY( '$mangle', Cursor::lazymap sub { STD::$coercion->coerce(\$_[0]) },1014 \$self->_MATCHIFY(\$S, '$mangle', Cursor::lazymap sub { STD::$coercion->coerce(\$_[0]) }, 1017 1015 \$C->_SYM(\$sym, 0) 1018 1016 ); … … 1078 1076 warn "Returning non-Cursor: $self\n" unless exists $self->{_pos}; 1079 1077 my ($package, $file, $line, $subname, $hasargs) = caller(1); 1080 $self->deb($subname, " returning @{[$self->{_ from}]}..@{[$self->{_to}]}");1078 $self->deb($subname, " returning @{[$self->{_pos}]}"); 1081 1079 $self; 1082 1080 } 1083 1081 1084 1082 sub _MATCHIFY { my $self = shift; 1083 my $S = shift; 1085 1084 my $name = shift; 1086 1085 return () unless @_; 1087 my @result = lazymap( sub { my $x = shift; $x-> {_from} = $self->{_from}; $x->_REDUCE($name)->retm() }, @_);1086 my @result = lazymap( sub { my $x = shift; $x->_REDUCE($S, $name)->retm() }, @_); 1088 1087 if (wantarray) { 1089 1088 @result; … … 1095 1094 1096 1095 sub _MATCHIFYr { my $self = shift; 1096 my $S = shift; 1097 1097 my $name = shift; 1098 1098 return () unless @_; 1099 1099 my $var = shift; 1100 $var->{_from} = $self->{_from};1101 $var->_REDUCE($ name)->retm();1100 # $var->{_from} = $self->{_from}; 1101 $var->_REDUCE($S, $name)->retm(); 1102 1102 } 1103 1103 … … 1146 1146 1147 1147 local $CTX = $self->callm if $DEBUG & DEBUG::trace_call; 1148 my $ to= $self;1149 my $prev_ to = $to->{_to} // 0;1148 my $pos = $self; 1149 my $prev_pos = $pos->{_pos} // 0; 1150 1150 my @all; 1151 1151 my $eos = length(${\$::ORIG}); 1152 1152 for (;;) { 1153 last if $ to->{_pos} == $eos;1154 my @matches = $block->($ to); # XXX shouldn't read whole list1153 last if $pos->{_pos} == $eos; 1154 my @matches = $block->($pos); # XXX shouldn't read whole list 1155 1155 # say @matches.perl; 1156 1156 last unless @matches; 1157 1157 my $first = $matches[0]; # no backtracking into block on ratchet 1158 last if $first->{_ to} == $prev_to;1159 $prev_ to = $first->{_to};1158 last if $first->{_pos} == $prev_pos; 1159 $prev_pos = $first->{_pos}; 1160 1160 push @all, $first; 1161 $ to= $first;1162 } 1163 $self->cursor_tweak($ to->{_pos})->retm();1161 $pos = $first; 1162 } 1163 $self->cursor_tweak($pos->{_pos})->retm(); 1164 1164 } 1165 1165 … … 1177 1177 lazymap( 1178 1178 sub { 1179 $self->cursor($_[0]->{_ to})->retm()1179 $self->cursor($_[0]->{_pos})->retm() 1180 1180 }, $x, LazyMap->new(sub { $x->_PLUSf($_[0]) }, $block) 1181 1181 ); … … 1226 1226 for my $x ($block->($self)) { 1227 1227 for my $s ($sep->($x)) { 1228 push @result, lazymap(sub { $self->cursor($_[0]->{_ to}) }, $x, $s->_REPSEPf($sep,$block));1228 push @result, lazymap(sub { $self->cursor($_[0]->{_pos}) }, $x, $s->_REPSEPf($sep,$block)); 1229 1229 } 1230 1230 } … … 1354 1354 local $CTX = $self->callm if $DEBUG & DEBUG::trace_call; 1355 1355 my $end = $self->cursor($self->{_pos}); 1356 my @all = $block->($end); # Make sure $_->{_from} == $_->{_ to}1356 my @all = $block->($end); # Make sure $_->{_from} == $_->{_pos} 1357 1357 if (@all and $all[0]) { 1358 1358 return $all[0]->cursor_all(($self->{_pos}) x 2)->retm(); … … 1376 1376 1377 1377 my $C = $self; 1378 my $ startpos= $C->pos;1379 $::MEMOS[$ startpos]{ws} = undef; # exists means we know, undef means no ws before here1380 1381 $self->_MATCHIFY( 'ws',1378 my $S = $C->pos; 1379 $::MEMOS[$S]{ws} = undef; # exists means we know, undef means no ws before here 1380 1381 $self->_MATCHIFY($S, 'ws', 1382 1382 $C->_BRACKET( sub { my $C=shift; 1383 1383 do { my @gather; … … 1400 1400 push @gather, (map { my $C=$_; 1401 1401 (map { my $C=$_; 1402 scalar(do { $::MEMOS[$C->{_pos}]{ws} = $ startpos unless $C->{_pos} == $startpos}, $C)1402 scalar(do { $::MEMOS[$C->{_pos}]{ws} = $S unless $C->{_pos} == $S }, $C) 1403 1403 } $C->_STARr(sub { my $C=shift; 1404 1404 $C->_SPACE() … … 1531 1531 local $CTX = $self->callm if $DEBUG & DEBUG::trace_call; 1532 1532 my $len = length($s); 1533 my $from = $self->{_ from} - $len;1533 my $from = $self->{_pos} - $len; 1534 1534 if ($from >= 0 and substr($::ORIG, $from, $len) eq $s) { 1535 1535 my $r = $self->cursor_rev($from); … … 1564 1564 for my $s (@array) { 1565 1565 my $len = length($s); 1566 my $from = $self->{_ from} = $len;1566 my $from = $self->{_pos} = $len; 1567 1567 if (substr($::ORIG, $from, $len) eq $s) { 1568 1568 $self->deb("ARRAY_rev elem $s matched @{[substr($::ORIG,$from,$len)]} at $from $len") if $DEBUG & DEBUG::matchers; … … 1590 1590 sub _DIGIT_rev { my $self = shift; 1591 1591 local $CTX = $self->callm if $DEBUG & DEBUG::trace_call; 1592 my $from = $self->{_ from} - 1;1592 my $from = $self->{_pos} - 1; 1593 1593 if ($from < 0) { 1594 1594 # say "DIGIT_rev didn't match $char at $from"; … … 1622 1622 sub _ALNUM_rev { my $self = shift; 1623 1623 local $CTX = $self->callm if $DEBUG & DEBUG::trace_call; 1624 my $from = $self->{_ from} - 1;1624 my $from = $self->{_pos} - 1; 1625 1625 if ($from < 0) { 1626 1626 # say "ALNUM_rev didn't match $char at $from"; … … 1654 1654 sub alpha_rev { my $self = shift; 1655 1655 local $CTX = $self->callm if $DEBUG & DEBUG::trace_call; 1656 my $from = $self->{_ from} - 1;1656 my $from = $self->{_pos} - 1; 1657 1657 if ($from < 0) { 1658 1658 return (); … … 1684 1684 sub _SPACE_rev { my $self = shift; 1685 1685 local $CTX = $self->callm if $DEBUG & DEBUG::trace_call; 1686 my $from = $self->{_ from} - 1;1686 my $from = $self->{_pos} - 1; 1687 1687 if ($from < 0) { 1688 1688 # say "SPACE_rev didn't match $char at $from"; … … 1716 1716 sub _HSPACE_rev { my $self = shift; 1717 1717 local $CTX = $self->callm if $DEBUG & DEBUG::trace_call; 1718 my $from = $self->{_ from} - 1;1718 my $from = $self->{_pos} - 1; 1719 1719 if ($from < 0) { 1720 1720 # say "HSPACE_rev didn't match $char at $from"; … … 1748 1748 sub _VSPACE_rev { my $self = shift; 1749 1749 local $CTX = $self->callm if $DEBUG & DEBUG::trace_call; 1750 my $from = $self->{_ from} - 1;1750 my $from = $self->{_pos} - 1; 1751 1751 if ($from < 0) { 1752 1752 # say "VSPACE_rev didn't match $char at $from"; … … 1784 1784 1785 1785 local $CTX = $self->callm if $DEBUG & DEBUG::trace_call; 1786 my $from = $self->{_ from} - 1;1786 my $from = $self->{_pos} - 1; 1787 1787 if ($from < 0) { 1788 1788 # say "CCLASS didn't match $char at $from"; … … 1814 1814 sub _ANY_rev { my $self = shift; 1815 1815 local $CTX = $self->callm if $DEBUG & DEBUG::trace_call; 1816 my $from = $self->{_ from} - 1;1816 my $from = $self->{_pos} - 1; 1817 1817 if ($from < 0) { 1818 1818 return (); … … 1909 1909 1910 1910 sub _REDUCE { my $self = shift; 1911 my $S = shift; 1911 1912 my $tag = shift; 1912 1913 1913 1914 $self->{_reduced} = $tag; 1915 $self->{_from} = $S; 1914 1916 if ($::ACTIONS) { 1915 1917 eval { $::ACTIONS->$tag($self) }; 1916 1918 warn $@ if $@ and not $@ =~ /locate/; 1917 1919 } 1918 $self->deb("REDUCE $tag from " . $ self->{_from}. " to " . $self->{_pos}) if $DEBUG & DEBUG::matchers;1920 $self->deb("REDUCE $tag from " . $S . " to " . $self->{_pos}) if $DEBUG & DEBUG::matchers; 1919 1921 $self; 1920 1922 } … … 1924 1926 local $CTX = $self->callm if $DEBUG & DEBUG::trace_call; 1925 1927 my $P = $self->{_pos}; 1926 my $F = $self->{_from};1927 $self->{FIRST} = substr($::ORIG, $F, $P - $F);1928 1928 $self->deb("Commit branch to $P") if $DEBUG & DEBUG::matchers; 1929 1929 $self, LazyMap->new(sub { $self->deb("ABORTBRANCH") if $DEBUG & DEBUG::trace_call; die "ABORTBRANCH" }, $self); -
src/perl6/Makefile
r22694 r22836 7 7 STD.pmc: STD.pm gimme5 8 8 ./gimme5 $< >STD.pm5 9 perl -p -e 'next if /^---/../\A\w+\Z/;' -e 's/\A \s+//;' STD.pm5 >$@9 perl -p -e 'next if /^---/../\A\w+\Z/;' -e 's/\A[ \t]+//;' STD.pm5 >$@ 10 10 rm -rf lex 11 11 -
src/perl6/STD.pm
r22832 r22836 3406 3406 3407 3407 my $here = self; 3408 self.deb("In EXPR, at ", $here.pos) if $*DEBUG +& DEBUG::EXPR; 3408 my $S = $here.pos; 3409 self.deb("In EXPR, at $S") if $*DEBUG +& DEBUG::EXPR; 3409 3410 3410 3411 my &reduce := -> { … … 3425 3426 push @chain, pop(@termstack).cleanup; 3426 3427 @chain = reverse @chain if @chain > 1; 3428 my $startpos = @chain[0].pos; 3427 3429 my $nop = $op.cursor_fresh(); 3428 3430 $nop<chain> = [@chain]; 3429 3431 $nop<_arity> = 'CHAIN'; 3430 push @termstack, $nop._REDUCE( 'EXPR');3432 push @termstack, $nop._REDUCE($startpos, 'EXPR'); 3431 3433 } 3432 3434 when 'list' { … … 3453 3455 } 3454 3456 @list = reverse @list if @list > 1; 3457 my $startpos = @list[0].pos; 3455 3458 @delims = reverse @delims if @delims > 1; 3456 3459 my $nop = $op.cursor_fresh(); … … 3460 3463 $nop<delims> = [@delims]; 3461 3464 $nop<_arity> = 'LIST'; 3462 push @termstack, $nop._REDUCE( 'EXPR');3465 push @termstack, $nop._REDUCE($startpos, 'EXPR'); 3463 3466 } 3464 3467 when 'unary' { … … 3472 3475 $op<_from> = $op<arg><_from>; 3473 3476 } 3474 if ($op<arg><_ to> > $op<_to>) {3475 $op<_ to> = $op<arg><_to>;3477 if ($op<arg><_pos> > $op<_pos>) { 3478 $op<_pos> = $op<arg><_pos>; 3476 3479 } 3477 3480 $op<_arity> = 'UNARY'; 3478 push @termstack, $op._REDUCE( 'EXPR');3481 push @termstack, $op._REDUCE($op<_from>, 'EXPR'); 3479 3482 } 3480 3483 default { … … 3483 3486 self.deb("Termstack size: ", +@termstack) if $*DEBUG +& DEBUG::EXPR; 3484 3487 3485 self.deb($op.dump) if $*DEBUG +& DEBUG::EXPR;3486 3488 $op<right> = (pop @termstack).cleanup; 3487 3489 $op<left> = (pop @termstack).cleanup; 3488 3490 $op<_from> = $op<left><_from>; 3489 $op<_ to> = $op<right><_to>;3491 $op<_pos> = $op<right><_pos>; 3490 3492 $op<_arity> = 'BINARY'; 3491 push @termstack, $op._REDUCE('EXPR'); 3493 self.deb($op.dump) if $*DEBUG +& DEBUG::EXPR; 3494 push @termstack, $op._REDUCE($op<_from>, 'EXPR'); 3492 3495 } 3493 3496 } … … 3599 3602 +@termstack == 1 or $here.panic("Internal operator parser error, termstack == " ~ (+@termstack)); 3600 3603 @termstack[0]<_from> = self.pos; 3601 @termstack[0]<_ to> = $here.pos;3602 } 3603 self._MATCHIFYr( "EXPR", @termstack);3604 @termstack[0]<_pos> = $here.pos; 3605 } 3606 self._MATCHIFYr($S, "EXPR", @termstack); 3604 3607 } 3605 3608 -
src/perl6/gimme5
r22824 r22836 327 327 328 328 my \$C = \$self; 329 \$C->{_to} = \$C->{_from}= \$C->{_pos};329 my \$S = \$C->{_pos}; 330 330 331 331 my \@result = eval { … … 356 356 push \@gather, \$C->\$try(\@_); 357 357 } 358 \$self->_MATCHIFY( "$name", \@gather);358 \$self->_MATCHIFY(\$S, "$name", \@gather); 359 359 }; 360 360 if (\$@) { … … 597 597 598 598 my $C = $self; 599 $C->{_to} = $C->{_from}= $C->{_pos};599 my $S = $C->{_pos}; 600 600 END 601 601 … … 630 630 $body .= <<"END"; 631 631 632 \$self->_MATCHIFY$ratchet( "$NAME", $coercion632 \$self->_MATCHIFY$ratchet(\$S, "$NAME", $coercion 633 633 <<MEAT>> 634 634 ); … … 1218 1218 ws(); 1219 1219 $key =~ s/(['\\])/\\$1/g; 1220 return bless { name => '_REDUCE', args => " '$key'", min => 0, max => 0},1220 return bless { name => '_REDUCE', args => "\$S, '$key'", min => 0, max => 0}, 1221 1221 "RE_method_internal"; 1222 1222 }
