Changeset 5591

Show
Ignore:
Timestamp:
07/14/05 15:24:51 (3 years ago)
Author:
iblech
svk:copy_cache_prev:
7591
Message:

examples/eval.p6:
* fail_s are catched now
* Switched to P5-regex, as PGE is currently borked.
* Made D/Z work and updated the banner message.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • examples/eval.p6

    r5580 r5591  
    33 
    44# Todo list: 
    5 # - ^Z should exit. 
    65# - There must be a cleaner way of presenting .perl without a leading \. 
    76# - Need to implement :{e,E,d,D,h,r,l}. 
     
    1211} 
    1312 
    14 say "^Z doesn't work, please use :q for now."; 
     13# We'd like to not pollute the eval's environment with our vars ($line, etc.). 
     14sub clean_eval ($___str) { eval $___str } 
    1515 
    16 my $EOF = chr(26); 
     16say "Welcome to Pugs -- $?PUGS_VERSION"; 
     17say "Type :h for help."; 
    1718 
    1819loop (;;) { 
     
    2122    print "pugs> "; 
    2223    my $line = =$*IN; 
    23     chomp($line); 
     24 
     25    # Quit and EOF. 
     26    quit() unless defined $line; 
     27    $line .= chomp; 
     28    # Skip empty lines. 
     29    next   if $line eq ""; 
    2430     
    2531    given ($line) { 
    26         when ""         { } # XXX should simply move to the next iteration of the outer loop 
    27         when $EOF       { quit(); } 
    28         when /^\: (.) \s+/ { 
     32        when rx:P5/^\:(.)/ { 
    2933            given ($0) { 
    3034                when "e" { 
     
    5559        } 
    5660        default { 
    57             my $ret = eval $_; 
    58             if ($!) { 
    59                 say $!; 
    60             } else { 
    61                 #say $ret.perl; 
    62                 say $ret.perl.substr(1, $ret.perl.chars - 1); # XXX NASTY HACK 
    63             } 
     61            # We need to .perl the result right here to make prettyprinting of 
     62            # junctions work. 
     63            my $ret = clean_eval $line; 
     64            say chomp $! and next if $!; 
     65 
     66            # We've to .perl in a second pass (and in a try {...} block) to 
     67            # catch "fail_"s. 
     68            $ret    = try { $ret.perl }; 
     69            say chomp $! and next if $!; 
     70            say substr($ret, 0, 1) eq "\\" ?? substr($ret, 1) :: $ret;   # XXX NASTY HACK 
     71            #" #--vim 
    6472        } 
    6573    } 
     
    7684This simplistic program will keep reading from standard input and evaluating whatever is 
    7785typed. 
    78  
    79 =end