Changeset 3736 for proto/RE/demo/grep.py


Ignore:
Timestamp:
Mar 20, 2014, 2:21:12 AM (6 years ago)
Author:
ksherdy
Message:

Added compilable grep demo. Single segment. Basis for follow/leader s2k iterator.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • proto/RE/demo/grep.py

    r3735 r3736  
    7878        matches                 = 0
    7979        lines                   = 0
    80         line_starts             = 0
    81         line_follows            = 0
     80        line_starts     = 0
     81        line_ends               = 0
    8282        byte_data               = 0
    8383
     
    117117        output.matches = m4
    118118
    119 # Spans
    120 #
    121 # compilable - w.t.e. line splicing - (i) break at an arbitrary point with fixed lookahead
    122119def MatchLines(lex, output):
    123         crt_line_start      = 0
    124         crt_line_follows    = 0
    125         crt_line_start      = pablo.Advance(~crt_line_start) ^ ~crt_line_start # line_start = pablo.First()
    126         LF_or_match         = lex.LF | output.matches
    127         cursor              = pablo.ScanToFirst(LF_or_match)
     120
     121        line_start      = pablo.Advance(~0) ^ ~0 # pablo.First()
     122        cursor                  = line_start
    128123
    129124        while(pablo.inFile(cursor)):
     125                cursor = pablo.ScanTo(cursor, (lex.LF | output.matches))
    130126                if(cursor & lex.LF):
    131                         crt_line_start = pablo.Advance(cursor)
     127                        line_start = pablo.Advance(cursor)
     128                        cursor = line_start
    132129                if(cursor & output.matches):
    133                         cursor = pablo.AdvanceThenScanTo(cursor, lex.LF)
    134                         crt_line_follows = cursor
     130                        output.line_starts  |= line_start
     131                        output.line_ends    |= pablo.AdvanceThenScanTo(cursor, lex.LF)
     132                        output.lines |= pablo.InclusiveSpan(output.line_starts, output.line_ends) # LF
     133                        cursor = pablo.Advance(cursor)
    135134
    136                         output.line_starts  |= crt_line_start
    137                         output.line_follows |= crt_line_follows # pablo.Advance(cursor)
    138 
    139                         output.lines |= pablo.SpanUpTo(line_start, crt_line_follows)
    140                        
    141                         # output.lines |= pablo.InclusiveSpan(line_start, cursor) | cursor # a line has a LF
    142                         # cursor = next_end
    143                 cursor = pablo.AdvanceThenScanTo(cursor, LF_or_match)
    144135###
    145136### <-- Demo only for now.
Note: See TracChangeset for help on using the changeset viewer.