Changeset 3030 for proto


Ignore:
Timestamp:
Apr 16, 2013, 12:07:24 PM (6 years ago)
Author:
cameron
Message:

Tighten up paren match prototypes

Location:
proto/matchparens
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • proto/matchparens/pdfparenmatch.pablo

    r3027 r3030  
    4040       
    4141def Match_Parens(lex, matches):
    42         unmatched = lex.RParen
    43         pscan = 0
    44         qscan = 0
    45         pscan = pablo.ScanTo(pablo.Advance(lex.LParen), lex.LParen | lex.RParen)
    46         qscan = pablo.ScanTo(pablo.Advance(lex.RParen), lex.LParen | lex.RParen)
    47         matches.instring = pablo.ExclusiveSpan(lex.LParen, pscan)
    48         matches.closed = pscan & lex.RParen
    49         unclosed = pscan & lex.LParen | qscan & lex.RParen
    50         matches.error = pablo.atEOF(pscan)
    51         all_closed = matches.closed
     42        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
    5249        while unclosed:
    53                 pscan = pablo.ScanTo(pablo.Advance(unclosed & lex.LParen), unclosed)
    54                 qscan = pablo.ScanTo(pablo.Advance(unclosed & lex.RParen), unclosed)
    55                 matches.instring = matches.instring | pablo.SpanUpTo(unclosed & lex.LParen, pscan)
    56                 matches.closed = pscan & lex.RParen
    57                 unclosed = pscan & lex.LParen | qscan & lex.RParen
    58                 all_closed |= matches.closed
    59                 matches.error |= pablo.atEOF(pscan)
     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
    6058        #
    6159        # Any closing paren that was not actually used to close
    6260        # an opener is in error.
    63         matches.error = matches.error | (lex.RParen &~ all_closed)
     61        matches.error = matches.error | (lex.RParen &~ matches.closed)
    6462
    6563
  • proto/matchparens/pdfparenmatch.py

    r2907 r3030  
    4242       
    4343def Match_Parens(lex, matches):
    44         unmatched = lex.RParen
    45         pscan = 0
    46         qscan = 0
    47         i = 0
    48         pscan = pablo.ScanTo(pablo.Advance(lex.LParen), lex.LParen | lex.RParen)
    49         qscan = pablo.ScanTo(pablo.Advance(lex.RParen), lex.LParen | lex.RParen)
    50         matches.instring = pablo.ExclusiveSpan(lex.LParen, pscan)
    51         matches.closed = pscan & lex.RParen
    52         unclosed = pscan & lex.LParen | qscan & lex.RParen
    53         matches.error = pscan &~ pablo.EOF_mask
    54         all_closed = matches.closed
     44        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
    5551        while unclosed:
    56                 i += 1
    57                 pscan = pablo.ScanTo(pablo.Advance(unclosed & lex.LParen), unclosed)
    58                 qscan = pablo.ScanTo(pablo.Advance(unclosed & lex.RParen), unclosed)
    59                 matches.instring |= pablo.SpanUpTo(unclosed & lex.LParen, pscan)
    60                 matches.closed = pscan & lex.RParen
    61                 unclosed = pscan & lex.LParen | qscan & lex.RParen
    62                 all_closed |= matches.closed
    63                 matches.error |= pscan &~ pablo.EOF_mask
     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
    6460        #
    6561        # Any closing paren that was not actually used to close
    6662        # an opener is in error.
    67         matches.error |= lex.RParen &~ all_closed
    68 
     63        matches.error = matches.error | (lex.RParen &~ matches.closed)
    6964
    7065
Note: See TracChangeset for help on using the changeset viewer.