- Timestamp:
- 11/15/08 04:11:54 (8 weeks ago)
- Files:
-
- 1 modified
-
src/perl6/Cursor.pmc (modified) (12 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/perl6/Cursor.pmc
r23015 r23018 16 16 our $DEPTH = 0; 17 17 our %LEXERS; # per language, the cache of lexers, keyed by rule name 18 19 my %HIST; 18 our %FATECACHE; # fates we've already turned into linked lists 19 our %ANON; # knowledge about what can be borrowed from supergrammar 20 21 #my %HIST; 20 22 21 23 sub ::init_globals { … … 154 156 close FILE; 155 157 } 156 $class->new($text)->$rule(); 158 159 my $result; 160 if ($STORABLE) { 161 my $store = "lex/STD.pm.store"; 162 if (-f $store and -M $file > -M $store) { 163 *::LEXERS = retrieve($store); 164 } 165 $result = $class->new($text)->$rule(); 166 if (defined $result and $file eq 'STD.pm') { 167 store(\%::LEXERS, $store); 168 } 169 } 170 else { 171 $result = $class->new($text)->$rule(); 172 } 173 157 174 # for my $key (sort {$HIST{$a} <=> $HIST{$b}} keys(%HIST)) { 158 175 # warn "$HIST{$key}\t$key\n"; 159 176 # } 177 $result; 160 178 } 161 179 … … 256 274 } 257 275 258 our %FATECACHE;259 260 276 sub _AUTOLEXgen { my $self = shift; 261 277 my $key = shift; … … 263 279 264 280 my $lang = ref $self; 281 if ($lang =~ /^ANON/) { 282 my $anon = $ANON{$lang}; 283 my $super = $anon->{SUP}; 284 my $category = $anon->{CAT}; 285 print STDERR "AUTOLEXgen $key in $lang from $super without $category\n" if $DEBUG & DEBUG::mixins; 286 my $superlexer = $self->cursor_fresh($super)->_AUTOLEXpeek($key,$retree); 287 my $same = 1; 288 for my $pat (@{$superlexer->{PATS}}) { 289 if ($pat =~ / $category /) { 290 print STDERR "\tNope: $pat\n" if $DEBUG & DEBUG::mixins; 291 $same = 0; 292 last; 293 } 294 } 295 # no need to regen a sublexer that will turn out the same 296 return $superlexer if $same; 297 } 265 298 $self->deb("AUTOLEXgen $key in $lang") if $DEBUG & DEBUG::autolexer; 266 299 my $lexer = {}; … … 491 524 system "cp $dir/termish.store $dir/EXPR.store"; 492 525 } 493 return $lexer;494 526 } 495 527 … … 497 529 print $cache $name,"\n"; 498 530 print $cache join("\n",@pat),"\n\n" or die "Can't print: $!"; 499 print $cache Dump($T) if $T ;531 print $cache Dump($T) if $T and not $STORABLE; 500 532 close($cache) or die "Can't close: $!"; 501 533 $self->deb("regenerated $dir/$file") if $DEBUG & DEBUG::autolexer; … … 790 822 for (;;) { 791 823 if ($state->{'~~'}) { 792 if (not $state->{''}++) { 793 for (@{$state->{'~~'}}) { 794 next if /^\d/; 795 next unless $_; 796 next if ref $_ eq 'CODE'; 797 our %RXCACHE; 798 $_ = $RXCACHE{$_} //= eval "sub { \$::ORIG =~ /\\G$_/xsgc }"; 799 } 800 } 824 our %RXCACHE; 801 825 my @x = @{$state->{'~~'}}; 802 826 while (my ($final,$fnum) = splice(@x,0,2)) { … … 805 829 print STDERR $p," probing $fnum\n" if $DEBUG & DEBUG::autolexer; 806 830 pos($::ORIG) = $p; 807 next unless & $final;831 next unless &{$RXCACHE{$final} //= eval "sub { \$::ORIG =~ /\\G$final/xsgc }"}; 808 832 $pend = pos($::ORIG); 809 833 } … … 1057 1081 if ($name =~ s/^(\w+):(?=[«<({[])/$1:sym/) { 1058 1082 my ($sym) = $name =~ /:sym(.*)/; 1083 1084 # unfortunately p5 doesn't understand q«...» 1059 1085 if ($sym =~ s/^«(.*)»$/$1/) { 1060 1086 my $ok = "'"; … … 1067 1093 my $rule = "token $name { <sym> }"; 1068 1094 1095 # produce p5 method name 1069 1096 my $mangle = $name; 1070 1097 $mangle =~ s/^(\w*):(sym)?//; … … 1086 1113 $mangle = $category . '__S_' . sprintf("%03d",$GEN++) . $mangle; 1087 1114 1088 # XXX assuming no equiv 1115 # XXX assuming no equiv specified 1089 1116 my $coercion = 'Additive'; 1090 1117 if ($name =~ /^prefix:/) { … … 1144 1171 eval $e or die "Can't create $name: $@\n"; 1145 1172 $::PARSER = $lang->cursor_fresh($genpkg); 1173 my $oldlexer = $::LEXERS{$WHAT}; 1174 my $newlexer = $::LEXERS{$genpkg} //= {}; 1175 $ANON{$genpkg}{SUP} = $WHAT; 1176 $ANON{$genpkg}{CAT} = $category; 1177 print STDERR "=====================================\nADD $rule => $mangle\n" if $DEBUG & DEBUG::mixins;; 1178 for my $name (sort keys %{$oldlexer}) { 1179 print STDERR " $name:\n" if $DEBUG & DEBUG::mixins; 1180 my $same = 1; 1181 for my $pat (@{$oldlexer->{$name}->{PATS}}) { 1182 if ($pat =~ / $category /) { 1183 print STDERR "\t$pat\n" if $DEBUG & DEBUG::mixins; 1184 $same = 0; 1185 last; 1186 } 1187 } 1188 # no need to regen a sublexer that will turn out the same 1189 $newlexer->{$name} = $oldlexer->{$name} if $same; 1190 } 1146 1191 } 1147 1192 $lang;
