Changeset 2913 for proto/PDF/cb_pablo.py


Ignore:
Timestamp:
Feb 25, 2013, 10:15:51 AM (7 years ago)
Author:
cameron
Message:

escape processing optimization

File:
1 edited

Legend:

Unmodified
Added
Removed
  • proto/PDF/cb_pablo.py

    r2912 r2913  
    211211          even = parity.even
    212212
    213           start = lex.Backslash &~ pablo.Advance(lex.Backslash)
    214          
    215           even_start = start & even     
    216           even_final = pablo.ScanThru(even_start, lex.Backslash)
    217           escape = even_final & odd
    218           escape_char = even & pablo.SpanUpTo(even_start, even_final)
    219          
    220           odd_start = start & odd
    221           odd_final = pablo.ScanThru(odd_start, lex.Backslash)
    222           escape = escape | (odd_final & even)
    223           escape_char |= (odd & pablo.SpanUpTo(odd_start, odd_final))
    224 
    225           escape_Callouts.LParen = lex.LParen &~ escape
    226           escape_Callouts.RParen = lex.RParen &~ escape
    227           escape_Callouts.Nonoct = lex.Nonoct & escape 
    228           escape_Callouts.Oct1 = lex.Oct & escape
    229           escape_Callouts.Oct2 = escape_Callouts.Oct1 & pablo.Lookahead(lex.Oct)
    230           escape_Callouts.Oct1 &= ~escape_Callouts.Oct2
    231           escape_Callouts.Oct3 = escape_Callouts.Oct2 & pablo.Lookahead(lex.Oct, 2)
    232           escape_Callouts.Oct2 &= ~escape_Callouts.Oct3
    233           out_Callouts.delmask = escape_char
     213          escape_mark = lex.Backslash
     214          escaped = pablo.Advance(lex.Backslash)
     215          # Check for \\ and longer backslash runs; mark the 1st, 3rd, 5th ...
     216          # as escape_marks, the 2nd, 4th, 6th as escaped.
     217          start = escape_mark & escaped
     218          if start:
     219                  #
     220                  even_start = start & even     
     221                  even_final = pablo.ScanThru(even_start, lex.Backslash)
     222                  escaped = even_final & odd
     223                  escape_mark = even & pablo.SpanUpTo(even_start, even_final)
     224                 
     225                  odd_start = start & odd
     226                  odd_final = pablo.ScanThru(odd_start, lex.Backslash)
     227                  escaped = escaped | (odd_final & even)
     228                  escape_mark |= (odd & pablo.SpanUpTo(odd_start, odd_final))
     229
     230          escape_Callouts.LParen = lex.LParen &~ escaped
     231          escape_Callouts.RParen = lex.RParen &~ escaped
     232          escape_Callouts.Nonoct = lex.Nonoct & escaped
     233          escape_Callouts.Oct1 = lex.Oct & escaped
     234          if escape_Callouts.Oct1:
     235                  escape_Callouts.Oct2 = escape_Callouts.Oct1 & pablo.Lookahead(lex.Oct)
     236                  escape_Callouts.Oct1 &= ~escape_Callouts.Oct2
     237                  escape_Callouts.Oct3 = escape_Callouts.Oct2 & pablo.Lookahead(lex.Oct, 2)
     238                  escape_Callouts.Oct2 &= ~escape_Callouts.Oct3
     239          out_Callouts.delmask = escape_mark
    234240       
    235241def Parse_Comment(lex, escape_Callouts, marker, out_Callouts):
Note: See TracChangeset for help on using the changeset viewer.