Changeset 3735


Ignore:
Timestamp:
Mar 18, 2014, 3:07:56 PM (4 years ago)
Author:
ksherdy
Message:

Updated to match lines without LFs. GNU grep does this.

File:
1 edited

Legend:

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

    r3728 r3735  
    7979        lines                   = 0
    8080        line_starts             = 0
    81         line_ends               = 0
     81        line_follows            = 0
    8282        byte_data               = 0
    8383
     
    121121# compilable - w.t.e. line splicing - (i) break at an arbitrary point with fixed lookahead
    122122def MatchLines(lex, output):
    123         line_start      = 0
    124         line_start      = pablo.Advance(~line_start) ^ ~line_start # line_start = pablo.First()
    125         LF_or_match     = lex.LF | output.matches
    126         cursor          = pablo.ScanToFirst(LF_or_match)
     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)
    127128
    128129        while(pablo.inFile(cursor)):
    129130                if(cursor & lex.LF):
    130                         line_start = pablo.Advance(cursor)
     131                        crt_line_start = pablo.Advance(cursor)
    131132                if(cursor & output.matches):
    132133                        cursor = pablo.AdvanceThenScanTo(cursor, lex.LF)
    133                
    134                         # output.line_starts  |= line_start
    135                         # output.line_follows |= pablo.Advance(cursor)
     134                        crt_line_follows = cursor
    136135
    137                         output.lines |= pablo.SpanUpTo(line_start, cursor)
     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)
    138140                       
    139141                        # output.lines |= pablo.InclusiveSpan(line_start, cursor) | cursor # a line has a LF
Note: See TracChangeset for help on using the changeset viewer.