Changeset 22586 for misc

Show
Ignore:
Timestamp:
10/12/08 05:22:44 (3 months ago)
Author:
putter
Message:

[elfish/STD_blue] Improved guessing of rule names. And --format=p5a quoting of same. Kludge to cope with STD graph cycles.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • misc/elfish/STD_blue/STD_blue_run

    r22234 r22586  
    126126} 
    127127 
    128  
    129 # for to_dump0, see ../../STD_red/match.rb, bottom 
     128# Notes 
     129# For to_dump0, see ../../STD_red/match.rb, bottom. 
     130# The STD graph seems generally cyclic. :/ 
    130131use autobox; 
    131132{ package STD; 
    132   our $type = 'comp_unit'; 
     133  sub condition_sym { 
     134    my($o,$sym)=@_; 
     135    if ($sym !~ /^sym/) { $sym } 
     136    elsif ($sym =~ /\Asym<\s*(.+?)\s*>\z/) { $1 } 
     137    elsif ($sym =~ /\Asym«\s*(.+?)\s*»\z/) { $1 } 
     138    elsif ($sym =~ /\Asym\['(.+?)']\z/) { $1 } 
     139    else { die "bogus sym: $sym\n" } 
     140  } 
     141  our $category = 'comp_unit'; 
     142  our %seen; 
     143  our $max_repetition = 3; 
    133144  sub to_dump0 { 
    134145    my($o)=@_; 
     146    if($seen{$o}++ > $max_repetition) { return "LOOP:$o"->to_dump0 } 
    135147    my $f = $o->{_from}; 
    136148    my $t = $o->{_to}; 
    137     my $str = ${$o->{_orig}}; 
    138     my $s = substr($str,$f,$t-$f); 
    139     $s =~ s/(\\')/\\$1/g; 
     149    my $whole_file = ${$o->{_orig}}; 
     150    my $str = substr($whole_file,$f,$t-$f); 
     151    my $s = $str->to_dump0; 
    140152    my $h = join("",map{ 
    141       if(/^_/) { "" } else { 
     153      if(!/^[a-zA-Z]/) { "" } 
     154      elsif(/\A(O)\z/) { "" } 
     155      else { 
    142156        my $v = $o->{$_}; 
    143         local $type = $_; 
     157        local $category = $_; 
    144158        my $vs = $v->to_dump0; 
    145159        "\n $_ => $vs," 
    146160      } 
    147161    }keys(%$o)); 
    148     "match('$type','$s',$f,$t,{$h})" 
     162    my $rule = $category; 
     163    my $sym = $o->{sym}; 
     164    if($sym) { 
     165      my $normalized = $o->condition_sym($sym); 
     166      $rule .= ":".$normalized if $sym ne $rule; 
     167    } 
     168    my $rule_str = $rule->to_dump0; 
     169    "match($rule_str,$s,$f,$t,{$h})" 
    149170  } 
    150171}