Changeset 21813 for src/perl6

Show
Ignore:
Timestamp:
08/06/08 20:21:22 (4 months ago)
Author:
lwall
Message:

[STD] factor out common prefix of all the *ibble routines
cleanup of type names

Location:
src/perl6
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • src/perl6/Cursor.pmc

    r21799 r21813  
    13301330 
    13311331sub _EXACT { my $self = shift; 
    1332     my $s = shift; 
     1332    my $s = shift() // ''; 
    13331333 
    13341334    local $CTX = $self->callm($s) if $DEBUG & DEBUG::trace_call; 
  • src/perl6/STD.pm

    r21799 r21813  
    7070 
    7171 
    72 #XXX shouldn't need this, it should all be in GLOBAL:: or the current package hash 
    73  
    74 my @typenames = (      # (need parens for gimme5 translator) 
    75     <Void Bit Int UInt Str Num Complex Bool True False Rat>, 
    76     <Exception Code Block List Seq Range Set Bag Junction Pair>, 
    77     <Mapping Signature Capture Blob Whatever Undef Failure>, 
    78     <StrPos StrLen Version P6opaque>, 
    79     <bit int int8 int16 int32 uint uint8 uint16 uint32 buf buf8 buf16 buf32 num complex bool rat>, 
    80     <Scalar Array Hash KeyHash KeySet KeyBag Buf IO Routine Sub Method>, 
    81     <Submethod Macro Regex Match Package Module Class Role Grammar Any Object>, 
    82     () 
    83 ); 
     72# XXX shouldn't need this, it should all be defined/imported by the prelude 
     73 
     74my @typenames = qw[ 
     75    Object Any Junction Whatever 
     76    Capture Match Signature 
     77    Package Module Class Role Grammar 
     78    Scalar Array Hash KeyHash KeySet KeyBag 
     79    Pair List Seq Range Set Bag Mapping 
     80    Void Undef Failure Exception 
     81    Code Block Routine Sub Macro 
     82    Method Submethod Regex 
     83 
     84    Str Blob 
     85    Char Byte Codepoint Grapheme StrPos StrLen Version 
     86 
     87    Num Complex 
     88    num complex 
     89 
     90    Int  int   int1  int2  int4 int8  int16  int32  int64 
     91    Rat  rat   rat1  rat2  rat4 rat8  rat16  rat32  rat64 
     92    Uint uint uint1 uint2 uint4 uint8 uint16 uint32 uint64 
     93    Buf  buf   buf1  buf2  buf4 buf8  buf16  buf32  buf64 
     94 
     95    Bit Bool True False 
     96    bit bool 
     97 
     98    Order Increasing Decreasing 
     99    Ordered Callable Positional Associatve 
     100    Ordering KeyExtractor Comparator OrderingPair 
     101 
     102    IO 
     103 
     104    KitchenSink 
     105]; 
     106 
    84107my %typenames; 
    85108%typenames{@typenames} = (1 xx @typenames); 
     
    16711694token escape:none { <!> } 
    16721695 
    1673 # XXX the front stuff needs to be factored out 
    1674 token quibble ($l) { 
     1696token babble ($l) { 
    16751697    :my $lang = $l; 
    16761698    :my $start; 
     
    16901712        $lang = $start ne $stop ?? $lang.balanced($start,$stop) 
    16911713                                !! $lang.unbalanced($stop); 
    1692     } 
     1714        $<B> = [$lang,$start,$stop]; 
     1715    } 
     1716} 
     1717 
     1718token quibble ($l) { 
     1719    :my ($lang, $start, $stop); 
     1720    <babble($l)> 
     1721    { my $B = $<babble><B>; ($lang,$start,$stop) = @$B; } 
    16931722 
    16941723    $start <nibble($lang)> $stop 
     
    17061735} 
    17071736 
    1708 method nibble ($lang) { 
    1709     my $outerlang = self.WHAT; 
    1710     my $LANG is context = $outerlang; 
    1711     self.cursor_fresh($lang).nibbler; 
    1712 } 
    1713  
    17141737token sibble ($l, $lang2) { 
    1715     :my $lang = $l; 
    1716     :my $start; 
    1717     :my $stop; 
    1718  
    1719     <.ws> 
    1720     [ <quotepair> <.ws> 
    1721         { 
    1722             my $kv = $<quotepair>[*-1]; 
    1723             $lang = $lang.tweak($kv.<k>, $kv.<v>) 
    1724                 or self.panic("Unrecognized adverb :" ~ $kv.<k> ~ '(' ~ $kv.<v> ~ ')'); 
    1725         } 
    1726     ]* 
    1727  
    1728     { ($start,$stop) = $¢.peek_delimiters(); } 
    1729  
     1738    :my ($lang, $start, $stop); 
     1739    <babble($l)> 
     1740    { my $B = $<babble><B>; ($lang,$start,$stop) = @$B; } 
     1741 
     1742    $start <left=nibble($lang)> $stop  
    17301743    [ <?{ $start ne $stop }> :: 
    1731         { $lang = $lang.balanced($start,$stop); } 
    1732         $start <left=nibble($lang)> $stop <.ws> '='<.ws> <right=EXPR(item %item_assignment)> 
    1733     || { $lang = $lang.unbalanced($stop); } 
    1734         $start <left=nibble($lang)> $stop 
     1744        <.ws> 
     1745        [ '=' || <.panic: "Missing '='"> ] 
     1746        <.ws> 
     1747        <right=EXPR(item %item_assignment)> 
     1748    ||  
    17351749        { $lang = $lang2.unbalanced($stop); } 
    17361750        <right=nibble($lang)> $stop 
     
    17391753 
    17401754token tribble ($l, $lang2 = $l) { 
    1741     :my $lang = $l; 
    1742     :my $start; 
    1743     :my $stop; 
    1744  
    1745     <.ws> 
    1746     [ <quotepair> <.ws> 
    1747         { 
    1748             my $kv = $<quotepair>[*-1]; 
    1749             $lang = $lang.tweak($kv.<k>, $kv.<v>) 
    1750                 or self.panic("Unrecognized adverb :" ~ $kv.<k> ~ '(' ~ $kv.<v> ~ ')'); 
    1751         } 
    1752     ]* 
    1753  
    1754     { 
    1755         ($start,$stop) = $¢.peek_delimiters(); 
    1756         $lang = $start ne $stop ?? $lang.balanced($start,$stop) 
    1757                                 !! $lang.unbalanced($stop); 
    1758     } 
    1759  
     1755    :my ($lang, $start, $stop); 
     1756    <babble($l)> 
     1757    { my $B = $<babble><B>; ($lang,$start,$stop) = @$B; } 
     1758 
     1759    $start <left=nibble($lang)> $stop  
    17601760    [ <?{ $start ne $stop }> :: 
    1761         { $lang = $lang.balanced($start,$stop); } 
    1762         $start <left=nibble($lang)> $stop <.ws> <quibble($lang2)> 
    1763     || { $lang = $lang.unbalanced($stop); } 
    1764         $start <left=nibble($lang)> $stop 
     1761        <.ws> <quibble($lang2)> 
     1762    ||  
    17651763        { $lang = $lang2.unbalanced($stop); } 
    17661764        <right=nibble($lang)> $stop 
     
    17691767 
    17701768token quasiquibble ($l) { 
    1771     :my $lang = $l; 
    1772     :my $start; 
    1773     :my $stop; 
    1774  
    1775     <.ws> 
    1776     [ <quotepair> <.ws> 
    1777         { 
    1778             my $kv = $<quotepair>[*-1]; 
    1779             $lang = $lang.tweak($kv.<k>, $kv.<v>) 
    1780                 or self.panic("Unrecognized adverb :" ~ $kv.<k> ~ '(' ~ $kv.<v> ~ ')'); 
    1781         } 
    1782     ]* 
    1783  
    1784     { 
    1785         ($start,$stop) = $¢.peek_delimiters(); 
    1786         $lang = $start ne $stop ?? $lang.balanced($start,$stop) 
    1787                                 !! $lang.unbalanced($stop); 
    1788     } 
     1769    :my ($lang, $start, $stop); 
     1770    <babble($l)> 
     1771    { my $B = $<babble><B>; ($lang,$start,$stop) = @$B; } 
    17891772 
    17901773    [ 
     
    18331816        $COMPILING::LAST_NIBBLE_MULTILINE = $¢ if $multiline; 
    18341817    } 
     1818} 
     1819 
     1820# and this is what makes nibbler polymorphic... 
     1821method nibble ($lang) { 
     1822    my $outerlang = self.WHAT; 
     1823    my $LANG is context = $outerlang; 
     1824    self.cursor_fresh($lang).nibbler; 
    18351825} 
    18361826