Changeset 21973
Legend:
- Unmodified
- Added
- Removed
-
src/perl6/Cursor.pmc
r21905 r21973 1091 1091 } 1092 1092 1093 sub _MATCHIFYr { my $self = shift; 1094 return () unless @_; 1095 my $var = shift; 1096 $var->{_from} = $self->{_from}; 1097 $var->retm(); 1098 } 1099 1093 1100 sub _SCANf { my $self = shift; 1094 1101 … … 1291 1298 lazymap(sub { bless($_[0],ref($self))->retm() }, 1292 1299 $block->($self)); 1300 } 1301 1302 sub _BRACKETr { my $self = shift; 1303 my $block = shift; 1304 1305 local $CTX = $self->callm if $DEBUG & DEBUG::trace_call; 1306 my ($val) = $block->($self) or return (); 1307 bless($val,ref($self))->retm(); 1293 1308 } 1294 1309 … … 1419 1434 lazymap(sub { $self->cursor_bind($names, $_[0])->retm() }, 1420 1435 $block->($self)); 1436 } 1437 1438 sub _SUBSUMEr { my $self = shift; 1439 my $names = shift; 1440 my $block = shift; 1441 1442 local $CTX = $self->callm($names ? "@$names" : "") if $DEBUG & DEBUG::trace_call; 1443 my ($var) = $block->($self) or return (); 1444 $self->cursor_bind($names, $var)->retm(); 1421 1445 } 1422 1446 … … 2219 2243 { package RE_noop; our @ISA = 'RE_base'; 2220 2244 sub longest { my $self = shift; my ($C) = @_; 2221 return ;2245 return $IMP; 2222 2246 } 2223 2247 } -
src/perl6/STD.pm
r21955 r21973 422 422 423 423 token vws { 424 \v ::424 \v 425 425 { $COMPILING::LINE++ } # XXX wrong several ways, use self.lineof($¢.pos) 426 426 [ '#DEBUG -1' { say "DEBUG"; $STD::DEBUG = $*DEBUG = -1; } ]? … … 441 441 [ <!after ^^ . > || <.panic: "Can't use embedded comments in column 1"> ] 442 442 <.quibble($¢.cursor_fresh( ::STD::Q ))> {*} #= embedded 443 | ::\N* {*} #= end443 | {} \N* {*} #= end 444 444 ] 445 445 } … … 773 773 ] 774 774 # XXX assuming no precedence change 775 ::775 776 776 <prefix_postfix_meta_operator>* {*} #= prepost 777 777 { $+prevop = $<O> } … … 793 793 token termish { 794 794 [ 795 | <pre>+ ::<noun>795 | <pre>+ <noun> 796 796 | <noun> 797 797 ] 798 ::799 798 800 799 # also queue up any postfixes, since adverbs could change things … … 839 838 840 839 token fatarrow { 841 <key=identifier> \h* '=>' ::<.ws> <val=EXPR(item %item_assignment)>840 <key=identifier> \h* '=>' <.ws> <val=EXPR(item %item_assignment)> 842 841 } 843 842 … … 862 861 { $key = ""; $value = $<postcircumfix>; } 863 862 {*} #= structural 864 | $<var> = (<sigil> ::<twigil>? <desigilname>)863 | $<var> = (<sigil> {} <twigil>? <desigilname>) 865 864 { $key = $<var><desigilname>.text; $value = $<var>; } 866 865 {*} #= varname … … 1088 1087 <.unsp>? 1089 1088 [ 1090 | '(' ::<in: ')', 'signature'>1091 | '[' ::<in: ']', 'semilist', 'shape definition'>1092 | '{' ::<in: '}', 'semilist', 'shape definition'>1089 | '(' <in: ')', 'signature'> 1090 | '[' <in: ']', 'semilist', 'shape definition'> 1091 | '{' <in: '}', 'semilist', 'shape definition'> 1093 1092 | <?before '<'> <postcircumfix> 1094 1093 ]* … … 1188 1187 }} 1189 1188 {*} #= block 1190 || <?{ $+begin_compunit }> ::<?before ';'>1189 || <?{ $+begin_compunit }> {} <?before ';'> 1191 1190 { 1192 1191 $longname orelse $¢.panic("Compilation unit cannot be anonymous"); … … 1500 1499 1501 1500 token variable { 1502 <?before <sigil> > ::1501 <?before <sigil> > {} 1503 1502 [ 1504 1503 || '&' <twigil>? <sublongname> {*} #= subnoun … … 1561 1560 [ 1562 1561 | <identifier> 1563 | '(' ::<in: ')', 'EXPR', 'indirect name'>1562 | '(' <in: ')', 'EXPR', 'indirect name'> 1564 1563 ] 1565 1564 } … … 1665 1664 token rad_number { 1666 1665 ':' $<radix> = [\d+] <.unsp>? # XXX optional dot here? 1667 ::# don't recurse in lexer1666 {} # don't recurse in lexer 1668 1667 [ 1669 1668 || '<' … … 1771 1770 1772 1771 $start <left=nibble($lang)> $stop 1773 [ <?{ $start ne $stop }> ::1772 [ <?{ $start ne $stop }> 1774 1773 <.ws> 1775 1774 [ '=' || <.panic: "Missing '='"> ] … … 1788 1787 1789 1788 $start <left=nibble($lang)> $stop 1790 [ <?{ $start ne $stop }> ::1789 [ <?{ $start ne $stop }> 1791 1790 <.ws> <quibble($lang2)> 1792 1791 || … … 2153 2152 2154 2153 token codepoint { 2155 '[' ::( [<!before ']'> .]*? ) ']'2154 '[' {} ( [<!before ']'> .]*? ) ']' 2156 2155 } 2157 2156 … … 2174 2173 | <codepoint> 2175 2174 | \d+ 2176 | ::[ <[ ?.._ ]> || <.panic: "Unrecognized \\c character"> ]2175 | [ <[ ?.._ ]> || <.panic: "Unrecognized \\c character"> ] 2177 2176 ] 2178 2177 } … … 2271 2270 2272 2271 # in single quotes, keep backslash on random character by default 2273 token backslash:misc { ::(.) { $<text> = "\\" ~ $0; } }2272 token backslash:misc { {} (.) { $<text> = "\\" ~ $0; } } 2274 2273 2275 2274 # begin tweaks (DO NOT ERASE) … … 2283 2282 token stopper { \" } 2284 2283 # in double quotes, omit backslash on random \W backslash by default 2285 token backslash:misc { ::[ (\W) { $<text> = $0.text; } | $<x>=(\w) <.panic("Unrecognized backslash sequence: '\\" ~ $<x>.text ~ "'")> ] }2284 token backslash:misc { {} [ (\W) { $<text> = $0.text; } | $<x>=(\w) <.panic("Unrecognized backslash sequence: '\\" ~ $<x>.text ~ "'")> ] } 2286 2285 2287 2286 # begin tweaks (DO NOT ERASE) … … 2342 2341 grammar Quasi is STD { 2343 2342 token term:unquote { 2344 <starter><starter><starter> ::<statementlist> <stopper><stopper><stopper>2343 <starter><starter><starter> <statementlist> <stopper><stopper><stopper> 2345 2344 } 2346 2345 … … 2387 2386 | <sigil> '.' 2388 2387 [ 2389 | '(' ::<in: ')', 'signature'>2390 | '[' ::<in: ']', 'signature'>2391 | '{' ::<in: '}', 'signature'>2388 | '(' <in: ')', 'signature'> 2389 | '[' <in: ']', 'signature'> 2390 | '{' <in: '}', 'signature'> 2392 2391 | <?before '<'> <postcircumfix> 2393 2392 ] … … 2512 2511 [ 2513 2512 # Is it a longname declaration? 2514 || <?{ $<sigil>.text eq '&' }> <?ident ifier> ::2513 || <?{ $<sigil>.text eq '&' }> <?ident> {} 2515 2514 <identifier=sublongname> 2516 2515 … … 3089 3088 | '(' <in: ')', 'semilist', 'argument list'> {*} #= func args 3090 3089 | <.unsp> '.'? '(' <in: ')', 'semilist', 'argument list'> {*} #= func args 3091 | ::[<?before \s> <!{ $istype }> <.ws> <!infixstopper> <arglist>]? { $listopy = 1 }3090 | {} [<?before \s> <!{ $istype }> <.ws> <!infixstopper> <arglist>]? { $listopy = 1 } 3092 3091 ] 3093 3092 … … 3103 3102 token term:name ( --> Term) 3104 3103 { 3105 <longname> ::3104 <longname> 3106 3105 [ 3107 3106 || <?{ 3108 3107 $¢.is_type($<longname>.text) or substr($<longname>.text,0,2) eq '::' 3109 }> ::3108 }> 3110 3109 # parametric type? 3111 3110 <.unsp>? [ <?before '['> <postcircumfix> ]? … … 3522 3521 [ 3523 3522 | \w 3524 | <metachar> 3525 | ::<.panic: "Unrecognized regex metacharacter">3523 | <metachar> :: 3524 | <.panic: "Unrecognized regex metacharacter"> 3526 3525 ] 3527 3526 } … … 3545 3544 3546 3545 token metachar:sym<{ }> { 3546 <?before '{'> 3547 3547 <codeblock> 3548 3548 {{ $/<sym> := <{ }> }} … … 3567 3567 3568 3568 token metachar:sym<[ ]> { 3569 '[' ::[:lang(self.unbalanced(']')) <nibbler>]3569 '[' {} [:lang(self.unbalanced(']')) <nibbler>] 3570 3570 [ ']' || <.panic: "Unable to parse regex; couldn't find right bracket"> ] 3571 3571 { $/<sym> := <[ ]> } … … 3573 3573 3574 3574 token metachar:sym<( )> { 3575 '(' ::[:lang(self.unbalanced(')')) <nibbler>]3575 '(' {} [:lang(self.unbalanced(')')) <nibbler>] 3576 3576 [ ')' || <.panic: "Unable to parse regex; couldn't find right parenthesis"> ] 3577 3577 { $/<sym> := <( )> } … … 3592 3592 3593 3593 token metachar:sym«< >» { 3594 '<' <unsp>? ::<assertion>3594 '<' <unsp>? {} <assertion> 3595 3595 [ '>' || <.panic: "regex assertion not terminated by angle bracket"> ] 3596 3596 } … … 3638 3638 | <codepoint> 3639 3639 | \d+ 3640 | ::[ <[ ?.._ ]> || <.panic: "Unrecognized \\c character"> ]3640 | [ <[ ?.._ ]> || <.panic: "Unrecognized \\c character"> ] 3641 3641 ] 3642 3642 } … … 3654 3654 token backslash:x { :i <sym> [ <hexint> | '[' [<.ws><hexint><.ws> ] ** ',' ']' ] } 3655 3655 token backslash:misc { $<litchar>=(\W) } 3656 token backslash:oops { ::<.panic: "Unrecognized regex backslash sequence"> }3656 token backslash:oops { <.panic: "Unrecognized regex backslash sequence"> } 3657 3657 3658 3658 token assertion:sym<...> { <sym> } … … 3684 3684 | ':' <.ws> 3685 3685 [ :lang($¢.cursor_fresh($+LANG).unbalanced('>')) <arglist> ] 3686 | '(' ::3686 | '(' {} 3687 3687 [ :lang($¢.cursor_fresh($+LANG)) <arglist> ] 3688 3688 [ ')' || <.panic: "Assertion call missing right parenthesis"> ] … … 3698 3698 | ':' <.ws> 3699 3699 [ :lang($¢.cursor_fresh($+LANG).unbalanced('>')) <arglist> ] 3700 | '(' ::3700 | '(' {} 3701 3701 [ :lang($¢.cursor_fresh($+LANG)) <arglist> ] 3702 3702 [ ')' || <.panic: "Assertion call missing right parenthesis"> ] -
src/perl6/gimme5
r21951 r21973 463 463 } 464 464 465 my $pkg; 465 466 if ($args =~ s/ *--> *(\w*) *$//) { 466 my $pkg = $pkg_really{$1} || "${PKG}::$1"; 467 $coercion = " Cursor::lazymap sub { $pkg->coerce(\$_[0]) }, "; 467 $pkg = $pkg_really{$1} || "${PKG}::$1"; 468 468 } 469 469 $args .= ', '; … … 605 605 } 606 606 else { 607 if ($pkg) { 608 if ($MAYBACKTRACK) { 609 $coercion = " Cursor::lazymap sub { $pkg->coerce(\$_[0]) }, "; 610 } 611 else { 612 $coercion = " map { $pkg->coerce(\$_) } "; 613 } 614 } 615 my $ratchet = $MAYBACKTRACK ? '' : 'r'; 607 616 $body .= <<"END"; 608 617 609 \$self->_MATCHIFY ($coercion618 \$self->_MATCHIFY$ratchet($coercion 610 619 <<MEAT>> 611 620 ); … … 1492 1501 my $re = shift; 1493 1502 return $re unless @BINDINGS; 1494 $re = "\$C->_SUBSUME([" . 1503 my $ratchet = $MAYBACKTRACK ? '' : 'r'; 1504 $re = "\$C->_SUBSUME$ratchet([" . 1495 1505 join(',', map {"'$_'"} @BINDINGS) . 1496 1506 "], sub {\n" . ::indent("my \$C = shift()->cursor_fresh;\n" . $re) . "\n})"; … … 1638 1648 $re = ::indent($$self{re}->walk(@_)); 1639 1649 } 1640 $re = "\$C->_BRACKET$REV( sub { my \$C=shift;\n" . ::indent($re) . "\n})"; 1650 my $ratchet = $MAYBACKTRACK ? '' : 'r'; 1651 $re = "\$C->_BRACKET$ratchet( sub { my \$C=shift;\n" . ::indent($re) . "\n})"; 1641 1652 $self->bind($re); 1642 1653 }
