Ignore:
Timestamp:
Apr 22, 2013, 10:42:23 AM (6 years ago)
Author:
cameron
Message:

Simplify parenthesis matching; fix paren match with comments.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • proto/matchparens/pdfparenmatch.py

    r3030 r3064  
    4343def Match_Parens(lex, matches):
    4444        parens = lex.LParen | lex.RParen
    45         Lscan = pablo.AdvanceThenScanTo(lex.LParen, parens)
    46         Rscan = pablo.AdvanceThenScanTo(lex.RParen, parens)
    47         matches.instring = pablo.ExclusiveSpan(lex.LParen, Lscan)
    48         matches.closed = Lscan & lex.RParen
    49         matches.error = pablo.atEOF(Lscan)
    50         unclosed = Lscan & lex.LParen | Rscan & lex.RParen
    51         while unclosed:
    52                 unclosedLParen = unclosed & lex.LParen
    53                 unclosedRParen = unclosed & lex.RParen
    54                 Lscan = pablo.AdvanceThenScanTo(unclosedLParen, unclosed)
    55                 Rscan = pablo.AdvanceThenScanTo(unclosedRParen, unclosed)
    56                 matches.instring |= pablo.SpanUpTo(unclosedLParen, Lscan)
    57                 matches.closed |= Lscan & lex.RParen
    58                 matches.error |= pablo.atEOF(Lscan)
    59                 unclosed = Lscan & lex.LParen | Rscan & lex.RParen
     45        pscan = pablo.AdvanceThenScanTo(lex.LParen, parens)
     46        matches.closed = pscan & lex.RParen
     47        matches.instring = pablo.ExclusiveSpan(lex.LParen, pscan)
     48        matches.error = pablo.atEOF(pscan)
     49        # Not matched, still pending.
     50        pending_LParen = pscan & lex.LParen
     51        RParen_unmatched = lex.RParen &~ matches.closed
     52        inPlay = pending_LParen | RParen_unmatched
     53        while pending_LParen:
     54                pscan = pablo.AdvanceThenScanTo(pending_LParen, inPlay)
     55                matches.instring |= pablo.SpanUpTo(pending_LParen, pscan)
     56                matches.closed |= pscan & lex.RParen
     57                matches.error |= pablo.atEOF(pscan)
     58                pending_LParen = pscan & lex.LParen
     59                RParen_unmatched = lex.RParen &~ matches.closed
     60                inPlay = pending_LParen | RParen_unmatched
    6061        #
    6162        # Any closing paren that was not actually used to close
    6263        # an opener is in error.
    63         matches.error = matches.error | (lex.RParen &~ matches.closed)
    64 
     64        matches.error |= lex.RParen &~ matches.closed
    6565
    6666
Note: See TracChangeset for help on using the changeset viewer.