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.pablo

    r3030 r3064  
    4141def Match_Parens(lex, matches):
    4242        parens = lex.LParen | lex.RParen
    43         Lscan = pablo.AdvanceThenScanTo(lex.LParen, parens)
    44         Rscan = pablo.AdvanceThenScanTo(lex.RParen, parens)
    45         matches.instring = pablo.ExclusiveSpan(lex.LParen, Lscan)
    46         matches.closed = Lscan & lex.RParen
    47         matches.error = pablo.atEOF(Lscan)
    48         unclosed = Lscan & lex.LParen | Rscan & lex.RParen
    49         while unclosed:
    50                 unclosedLParen = unclosed & lex.LParen
    51                 unclosedRParen = unclosed & lex.RParen
    52                 Lscan = pablo.AdvanceThenScanTo(unclosedLParen, unclosed)
    53                 Rscan = pablo.AdvanceThenScanTo(unclosedRParen, unclosed)
    54                 matches.instring |= pablo.SpanUpTo(unclosedLParen, Lscan)
    55                 matches.closed |= Lscan & lex.RParen
    56                 matches.error |= pablo.atEOF(Lscan)
    57                 unclosed = Lscan & lex.LParen | Rscan & lex.RParen
     43        pscan = pablo.AdvanceThenScanTo(lex.LParen, parens)
     44        matches.closed = pscan & lex.RParen
     45        matches.instring = pablo.ExclusiveSpan(lex.LParen, pscan)
     46        matches.error = pablo.atEOF(pscan)
     47        # Not matched, still pending.
     48        pending_LParen = pscan & lex.LParen
     49        RParen_unmatched = lex.RParen &~ matches.closed
     50        inPlay = pending_LParen | RParen_unmatched
     51        while pending_LParen:
     52                pscan = pablo.AdvanceThenScanTo(pending_LParen, inPlay)
     53                matches.instring |= pablo.SpanUpTo(pending_LParen, pscan)
     54                matches.closed |= pscan & lex.RParen
     55                matches.error |= pablo.atEOF(pscan)
     56                pending_LParen = pscan & lex.LParen
     57                RParen_unmatched = lex.RParen &~ matches.closed
     58                inPlay = pending_LParen | RParen_unmatched
    5859        #
    5960        # Any closing paren that was not actually used to close
    6061        # an opener is in error.
    61         matches.error = matches.error | (lex.RParen &~ matches.closed)
    62 
     62        matches.error |= lex.RParen &~ matches.closed
    6363
    6464def Main(basis_bits, lex, matches):
Note: See TracChangeset for help on using the changeset viewer.