Changeset 22971 for src

Show
Ignore:
Timestamp:
11/11/08 01:51:06 (2 months ago)
Author:
lwall
Message:

[Cursor] isolate symbols in a NOTBEFORE to fix mncharity++'s last; problem
[Cursor] stub in a trie-engine as down payment on a real dfa

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • src/perl6/Cursor.pmc

    r22934 r22971  
    1313our $DEPTH = 0; 
    1414our %LEXERS;       # per language, the cache of lexers, keyed by rule name 
     15 
     16my %HIST; 
    1517 
    1618sub ::init_globals { 
     
    141143    } 
    142144    $class->new($text)->$rule(); 
     145#    for my $key (sort {$HIST{$a} <=> $HIST{$b}} keys(%HIST)) { 
     146#       warn "$HIST{$key}\t$key\n"; 
     147#    } 
    143148} 
    144149 
     
    591596    my $retree = shift; 
    592597    # $_[0] is now ref to a $trystate; 
     598#    $HIST{$name}++; 
    593599 
    594600    $self->deb("cursor_fate $pkg $name") if $DEBUG & DEBUG::cursors; 
     
    613619        return sub {}; 
    614620    } 
     621 
     622    # A rudimentary trie walker, unused so far.  It assumes a prebuilt trie; 
     623    # it will need some revisions to build it on the fly.  Also, it's currently 
     624    # written for clarity rather than speed, and that will also change later. 
     625    # There is an arbitrary cutoff between characters we look up by array 
     626    # vs characters we look up by hash. ->{T}[0] is the array, [1] is the hash. 
     627    # and [2] contains actual results generator closure.  At the moment we just 
     628    # drop through if we don't get a result, which is always. 
     629 
     630    if (my $state = $lexer->{T}) { 
     631        my $p = $P; 
     632        my $ch = $::ORIG[$p]; 
     633        my $next; 
     634        while ($next = $state->[0][$ch] // $state->[1]{chr $ch}) { 
     635            $ch = $::ORIG[++$p]; 
     636            $state = $next; 
     637        } 
     638        if ($state->[2]) { 
     639            return $state->[2]; 
     640        } 
     641    } 
     642 
    615643    pos($::ORIG) = $P; 
    616644    $::ORIG =~ m/\G(\[[\\<>«»]*..|[<>][<>]..|[$@%]?\w+|['"]|[ -~].|.)/smgc; 
     
    12421270 
    12431271    local $CTX = $self->callm if $DEBUG & DEBUG::trace_call; 
    1244     my @all = $block->($self); 
     1272    my @all = $block->($self->cursor_fresh); 
    12451273    return () if @all;  # XXX loses continuation 
    12461274    return $self->cursor($self->{_pos})->retm();