Skip to content
Tcl Source Code Ticket Change Details
Login

Ticket Change Details

Overview

Artifact ID: 0ad9565c2a4b53f427a85179571d08750e6ada7b
Ticket: 2826551fffffffffffffffffffffffffffffffff
Line-sensitivity at -start, but also -all
User & Date: lars_h on 2009-07-24 12:53:45
Changes

  1. assignee changed to: "pvgoran"
  2. cmimetype changed to: "text/plain"
  3. comment changed to:
    I was going to use [regexp -all -inline] to split a unified diff into chunks, 
    but found that this would skip every second chunk. This seems to be 
    related to ^ not matching the beginning of line if the newline is before 
    the -start position.
    
    SMALL EXAMPLE:
    
    set data {
    @1
     2
    +3
    @4
    -5
    +6
     7
    @8
     9
    }
    regexp -all -inline {(?n)^@.*\n(?:[^@].*\n?)*} $data
    
    RETURNS
    
    {@1
     2
    +3
    } {@8
     9
    }
    
    RATHER THAN
    
    {@1
     2
    +3
    } {@4
    -5
    +6
     7
    } {@8
     9
    }
    
    EXPLANATION: A diff chunk consists of one header line beginning with @, followed by a body 
    consisting of lines not beginning with @ (but rather space, plus, or minus). The header line
    is thus in line-sensitive mode matched by ^@.* and a body line is matched by ^[^@].*, so 
    a sensible combined regexp is (?n)^@.*\n(?:[^@].*\n?)*  Each chunk is indeed matched by
    this, but when -all is used, only every second chunk is found.
    
    In this case, dropping the ^ from the regexp allows all chunks to be found:
    
    % regexp -all -inline {(?n)@.*\n(?:[^@].*\n?)*} $data
    {@1
     2
    +3
    } {@4
    -5
    +6
     7
    } {@8
     9
    }
    
    This suggests the problem may be that ^ fails to match when at the -start position, as one obvious 
    way to implement [regexp -all] is as the equivalent of a loop around [regexp -start]. Indeed,
    
    % regexp -start 1 -indices {(?n)^a} "\nab" match
    0
    % regexp -start 0 -indices {(?n)^a} "\nab" match
    1
    % set match
    1 1
    
    
    
  4. foundin changed to: "obsolete: 8.6b1"
  5. is_private changed to: "0"
  6. priority changed to: "5 Medium"
  7. resolution changed to: "None"
  8. status changed to: "Open"
  9. submitter changed to: "lars_h"
  10. subsystem changed to: "43. Regexp"
  11. title changed to: "Line-sensitivity at -start, but also -all"
  12. type changed to: "Bug"