Changeset 21763

Show
Ignore:
Timestamp:
08/04/08 10:39:26 (4 months ago)
Author:
lwall
Message:

s/q:code/quasi/ plus various t/ buglets

Files:
9 modified

Legend:

Unmodified
Added
Removed
  • src/Pugs/Eval.hs

    r21673 r21763  
    899899        evalExp $ Syn "=" [Val lhs, App (_Var op) Nothing [Val val, rhsExp]] 
    900900 
    901 reduceSyn "q:code" [ body ] = expToEvalVal body 
     901reduceSyn "quasi" [ body ] = expToEvalVal body 
    902902 
    903903reduceSyn "CCallDyn" (Val (VStr quant):methExp:invExp:args) = do 
  • src/Pugs/Parser.hs

    r21673 r21763  
    984984            _ -> fail "no caller env to install pragma in" 
    985985 
    986 {-| Match a @q:code { ... }@ quotation -} 
     986{-| Match a @quasi { ... }@ quotation -} 
    987987ruleCodeQuotation :: RuleParser Exp 
    988988ruleCodeQuotation = rule "code quotation" $ do 
    989989    -- XXX - This is entirely kluge; it drops traits in the body too 
    990     symbol "q:code" >> optional (symbol "(:COMPILING)") 
     990    symbol "quasi" >> optional (symbol ":COMPILING") 
    991991    block <- ruleBlockBody 
    992     return (Syn "q:code" [bi_body block]) 
     992    return (Syn "quasi" [bi_body block]) 
    993993     
    994994-- | If we've executed code like @BEGIN { exit }@, we've to run all @\@*END@ 
  • src/perl6/Cursor.pmc

    r21743 r21763  
    202202        return { PATS => ['(?#::)'] };  # (but if we advanced just assume a :: here) 
    203203    } 
     204    $key = 'termish' if $key eq 'EXPR'; 
    204205    return $self->lexers->{$key} = $self->_AUTOLEXgen($key, $retree); 
    205206} 
  • src/perl6/STD.pm

    r21749 r21763  
    17571757} 
    17581758 
     1759token quasiquibble ($l) { 
     1760    :my $lang = $l; 
     1761    :my $start; 
     1762    :my $stop; 
     1763 
     1764    <.ws> 
     1765    [ <quotepair> <.ws> 
     1766        { 
     1767            my $kv = $<quotepair>[*-1]; 
     1768            $lang = $lang.tweak($kv.<k>, $kv.<v>) 
     1769                or self.panic("Unrecognized adverb :" ~ $kv.<k> ~ '(' ~ $kv.<v> ~ ')'); 
     1770        } 
     1771    ]* 
     1772 
     1773    { 
     1774        ($start,$stop) = $¢.peek_delimiters(); 
     1775        $lang = $start ne $stop ?? $lang.balanced($start,$stop) 
     1776                                !! $lang.unbalanced($stop); 
     1777    } 
     1778 
     1779    [ 
     1780    || <?{ $start eq '{' }> [ :lang($lang) <block> ] 
     1781    || $start [ :lang($lang) <statementlist> ] $stop 
     1782    ] 
     1783} 
     1784 
    17591785# note: polymorphic over many quote languages, we hope 
    17601786token nibbler { 
     
    18631889token quote:tr { 
    18641890    <sym> » <!before '('> <pat=tribble( $¢.cursor_fresh( ::STD::Q ).tweak(:q))> 
     1891} 
     1892 
     1893token quote:quasi { 
     1894    <sym> » <!before '('> <pat=quasiquibble($¢.cursor_fresh( ::STD::Quasi ))> 
    18651895} 
    18661896 
     
    22242254    } 
    22252255 
    2226     multi method tweak (:$code) { 
    2227         return ::RegexCode; 
    2228     } 
    2229  
    22302256    multi method tweak (*%x) { 
    22312257        my @k = keys(%x); 
     
    22352261 
    22362262 
     2263} # end grammar 
     2264 
     2265grammar Quasi is STD { 
     2266    token term:unquote { 
     2267        <starter><starter><starter> :: <statementlist> <stopper><stopper><stopper> 
     2268    } 
    22372269} # end grammar 
    22382270 
     
    23812413    [ 
    23822414        # Is it a longname declaration? 
    2383     || <?{ $<sigil> eq '&' }> <?ident> :: 
     2415    || <?{ $<sigil>.text eq '&' }> <?ident> :: 
    23842416        <ident=sublongname> 
    23852417 
    23862418    ||  # Is it a shaped array or hash declaration? 
    2387         <?{ $<sigil> eq '@' || $<sigil> eq '%' }> 
     2419        <?{ $<sigil>.text eq '@' || $<sigil>.text eq '%' }> 
    23882420        <ident>? 
    23892421        <.ws> 
     
    29052937    { <sym> } 
    29062938 
    2907 token term:sym<...> ( --> List_prefix) 
     2939token prefix:sym<...> ( --> List_prefix) 
    29082940{ 
    29092941    '...' 
    29102942} 
    29112943 
    2912 token term:sym<???> ( --> List_prefix) 
     2944token prefix:sym<???> ( --> List_prefix) 
    29132945{ 
    29142946    '???' 
    29152947} 
    29162948 
    2917 token term:sym<!!!> ( --> List_prefix) 
     2949token prefix:sym<!!!> ( --> List_prefix) 
    29182950{ 
    29192951    '!!!' 
     
    29292961#     { <typename> <?spacey> <arglist> { $<sym> = $<typename>.item; } } 
    29302962 
    2931 # unrecognized identifiers are assumed to be post-declared listops. 
     2963# force ident(), ident.(), etc. to be a function call always 
    29322964token term:ident ( --> Term ) 
    29332965{ 
    29342966    <ident> 
    29352967    [ 
    2936     | '.(' <in: ')', 'semilist', 'argument list'> {*}                               #= func args 
    2937     | '(' <in: ')', 'semilist', 'argument list'> {*}                                #= func args 
    2938     | <.unsp> '.'? '(' <in: ')', 'semilist', 'argument list'> {*}                   #= func args 
    2939     ] 
    2940 } 
    2941  
     2968    | '.(' <in: ')', 'semilist', 'argument list'> {*}             #= func args 
     2969    | '(' <in: ')', 'semilist', 'argument list'> {*}              #= func args 
     2970    | <.unsp> '.'? '(' <in: ')', 'semilist', 'argument list'> {*} #= func args 
     2971    ] 
     2972 
     2973    [ 
     2974    || ':' <?before \s> <arglist>    # either switch to listopiness 
     2975    || {{ $+prevop = $<O> = {}; }}   # or allow adverbs 
     2976    ] 
     2977} 
     2978 
     2979# names containing :: may or may not be function calls 
     2980# bare ident without parens also handled here if no other rule parses it 
    29422981token term:name ( --> Term) 
    29432982{ 
     
    29452984    [ 
    29462985    ||  <?{ 
    2947             $¢.is_type($<longname>.text) 
     2986            $¢.is_type($<longname>.text) or substr($<longname>.text,0,2) eq '::' 
    29482987        }> :: 
    29492988        # parametric type? 
     
    29552994        ]? 
    29562995        {*}                                                     #= typename 
     2996 
     2997    # unrecognized names are assumed to be post-declared listops. 
     2998    || <?before \s> <arglist> 
     2999        {*}                                                     #= listop args 
    29573000    || 
    29583001        [ 
    2959         | '.(' <in: ')', 'semilist', 'argument list'> {*}                               #= func args 
    2960         | '(' <in: ')', 'semilist', 'argument list'> {*}                                #= func args 
    2961         | <?before \s> <?{ substr($<longname>.text,0,2) ne '::' }> <arglist> {*}                            #= listop args 
    2962         | <.unsp> '.'? '(' <in: ')', 'semilist', 'argument list'> {*}                   #= func args 
    2963         | :: {*}                                                #= listop noarg 
     3002        | '.(' <in: ')', 'semilist', 'argument list'> 
     3003            {*}                                                 #= func args 
     3004 
     3005        | '(' <in: ')', 'semilist', 'argument list'> 
     3006            {*}                                                 #= func args 
     3007 
     3008        | <.unsp> '.'? '(' <in: ')', 'semilist', 'argument list'> 
     3009            {*}                                                 #= func args 
     3010 
     3011 
     3012        | ::  {*}                                               #= listop noarg 
     3013        ] 
     3014 
     3015        [ 
     3016        || ':' <?before \s> <arglist>    # either switch to listopiness 
     3017        || {{ $+prevop = $<O> = {}; }}   # or allow adverbs 
    29643018        ] 
    29653019    ] 
  • t/examples/99problems/problem91.t

    r20490 r21763  
    3636    } 
    3737     
    38     method toStr() { 
     38    method Str() { 
    3939        $.x ~ "/" ~ $.y; 
    4040    } 
    4141} 
    42  
    43 # Stringify a case 
    44 multi sub *prefix:<~> (Case $c) { $c.toStr } 
    4542 
    4643# All the moves a Knight can do 
     
    110107    } 
    111108    my Bool @chessboard[$n][$n]; 
    112     for ( 0..$n-1 ) -> $i { 
     109    for 0..$n-1 -> $i { 
    113110        @chessboard[$i] = [True xx $n]; 
    114111    } 
     
    120117my $n = 8; 
    121118my @result = searchFrom( Case.new(:x(0),:y(0)), $n ); 
    122 # @result.map:{.toStr}.join(", ").say; 
     119# @result.map:{.Str}.join(", ").say; 
    123120ok check_tour($n, @result), "This knight's tour is valid."; 
  • t/examples/all_parse.t

    r21719 r21763  
    4949# $! instead of this yucky workaround 
    5050for sort(@files) -> $ex { 
    51     my $out = `$*EXECUTABLE_NAME -c -Iblib6/lib $ex`; 
     51    my $out = qqx[$*EXECUTABLE_NAME -c -Iblib6/lib $ex]; 
    5252 
    5353    if $out ~~ m:P5/syntax OK\s*$/ { 
  • t/macros/caller.t

    r21719 r21763  
    1919 
    2020macro ast_compiling_current_line () { 
    21     return q:code(:COMPILING) { current_line() }; 
     21    return quasi :COMPILING { current_line() }; 
    2222} 
    2323 
    2424macro ast_current_line () { 
    25     return q:code { current_line() }; 
     25    return quasi { current_line() }; 
    2626} 
    2727 
  • t/macros/macro_code_test.t

    r21719 r21763  
    1919# is Eager 
    2020macro max ($x is CST, $y is CST) { 
    21     return q:code { ($x > $y) ?? $x !! $y }; 
     21    return quasi { ($x > $y) ?? $x !! $y }; 
    2222} 
    2323 
     
    3737=begin pod 
    3838 
    39 =head1 q:code & AST splicing options 
     39=head1 quasi & AST splicing options 
    4040 
    4141=head2 Splicing Problem 
    4242 
    43 The contents of q:code blocks need to be able to refer to values 
     43The contents of quasi blocks need to be able to refer to values 
    4444as any other closure does, but also define graft points for 
    4545other asts. 
     
    4747=head2 Solution Space 
    4848 
    49 First principle, adding q:code before a block doesn't change things 
     49First principle, adding quasi before a block doesn't change things 
    5050  - it's still a closure 
    5151  - if you mention $var it means the $var in the surrounding lexical scope 
    5252    (mentioning new vars may bind at the macro use) 
    5353  - subs continue to be bound to the local definitions 
    54   - macros continue to be expanded at parse time (q:code parse time) 
     54  - macros continue to be expanded at parse time (quasi parse time) 
    5555 
    5656Second principle, to do something special, say something special. 
     
    6262the point is to wrap or warp them into the returned AST|string. 
    6363We want an easy way to splice the input AST into the output AST 
    64 The output AST is usually a q:code block somehow using the macro arg asts: 
     64The output AST is usually a quasi block somehow using the macro arg asts: 
    6565 
    66   q:code { my $x; $x; $input_ast; $captured_var; $var_at_call } 
     66  quasi { my $x; $x; $input_ast; $captured_var; $var_at_call } 
    6767 
    6868=head2 Some Suggested Solutions 
     
    7272   literal($ast) macro to talk about an ast as a value 
    7373  
    74  * signature such as q:code ($ast) { $var; $ast } 
     74 * signature such as quasi ($ast) { $var; $ast } 
    7575   (idea--: duplicates macro's param list, violates sig -> application w/ args  
    7676    expectation with subs) 
     
    7979 
    8080 * escape meta-syntax (lisp's solution)   
    81     q:code { say "Exp (\qq[~$package]) = ", \qq[$package] } 
     81    quasi { say "Exp (\qq[~$package]) = ", \qq[$package] } 
    8282  
    83  * set of escape macros which only apply in q:code blocks glue($ast) 
     83 * set of escape macros which only apply in quasi blocks glue($ast) 
    8484 
    8585More complex restructuring of the input AST would require walking 
     
    9494=head2 Current Solution 
    9595 
    96 q:code { } is the quoter and {{{ }}} is the default antiquote 
     96quasi { } is the quoter and {{{ }}} is the default antiquote 
    9797(the rule is actually the delimiter repeated thrice). 
    98 The use of {{{ ... }}} in a q:code is just like an inline macro. 
    99 Pretending that the body of you program is within a q:code{ } 
     98The use of {{{ ... }}} in a quasi is just like an inline macro. 
     99Pretending that the body of you program is within a quasi{ } 
    100100then {{{ }}} can be used for inline macros, compile time 
    101101generation of ASTs which are spliced immediately. 
     
    138138$Larry "I don't see why not" 
    139139 
    140  q:code { sub x { ... }; macro y { ... }; use force; } 
     140 quasi { sub x { ... }; macro y { ... }; use force; } 
    141141 
    142142The AST needs to be rescanned anyway, so perform the appropriate 
  • t/macros/opaque_ast_macros.t

    r21719 r21763  
    66=head1 DESCRIPTION 
    77 
    8 Tests for macros which return q:code but do not do splicing 
     8Tests for macros which return quasi but do not do splicing 
    99 
    1010See L<S06/"Macros">. 
     
    1515 
    1616# L<S06/Macros> 
    17 macro four () { q:code { 2+2 } }  
     17macro four () { quasi { 2+2 } }  
    1818 
    19 is(four, 4, "macro returning q:code"); 
     19is(four, 4, "macro returning quasi"); 
    2020 
    21 macro hi () { q:code(:COMPILING) { "hello $s" } }  
     21macro hi () { quasi :COMPILING { "hello $s" } }  
    2222 
    2323macro hey () { ({ "hello $^s" }.body) }  
     
    3131 
    3232my $x; 
    33 macro noop ()  { $x = "Nothing happened"; q:code { } }  
     33macro noop ()  { $x = "Nothing happened"; quasi { } }  
    3434noop(); 
    3535#macro noop2 () { $x ~= ", twice"; return } # unspecced