Changeset 3031


Ignore:
Timestamp:
Apr 16, 2013, 2:48:59 PM (6 years ago)
Author:
cameron
Message:

More tightening of paren match prototypes

Location:
proto/matchparens
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • proto/matchparens/pablo.py

    r2454 r3031  
    151151
    152152def AdvanceThenScanTo(marker, scanclass):
    153         return ScanTo(marker, scanclass &~ marker)
     153        #return ScanTo(Advance(marker), scanclass)
     154        charclass = ~scanclass & EOF_mask
     155        return (marker + (charclass | marker)) &~ charclass
    154156
    155157#
  • proto/matchparens/parenmatch.py

    r2904 r3031  
    4141       
    4242def Match_Parens(lex, matches):
    43         unmatched = lex.RParen
    44         pscan = {}
    45         qscan = {}
     43        parens = lex.LParen | lex.RParen
     44        Lscan = {}
     45        Rscan = {}
    4646        i = 0
    47         pscan[0] = pablo.ScanTo(pablo.Advance(lex.LParen), lex.LParen | lex.RParen)
    48         qscan[0] = pablo.ScanTo(pablo.Advance(lex.RParen), lex.LParen | lex.RParen)
    49         matches.closed[i] = pscan[i] & lex.RParen
    50         unclosed = pscan[i] & lex.LParen | qscan[i] & lex.RParen
    51         matches.error = pscan[i] &~ pablo.EOF_mask
     47        Lscan[0] = pablo.AdvanceThenScanTo(lex.LParen, parens)
     48        Rscan[0] = pablo.AdvanceThenScanTo(lex.RParen, parens)
     49        matches.closed[0] = Lscan[0] & lex.RParen
     50        matches.error = pablo.atEOF(Lscan[0])
     51        unclosed = Lscan[i] & lex.LParen | Rscan[i] & lex.RParen
    5252        all_closed = matches.closed[i]
    5353        while unclosed:
    5454                i += 1
    55                 pscan[i] = pablo.ScanTo(pablo.Advance(unclosed & lex.LParen), unclosed)
    56                 qscan[i] = pablo.ScanTo(pablo.Advance(unclosed & lex.RParen), unclosed)
    57                 matches.closed[i] = pscan[i] & lex.RParen
    58                 unclosed = pscan[i] & lex.LParen | qscan[i] & lex.RParen
     55                unclosedLParen = unclosed & lex.LParen
     56                unclosedRParen = unclosed & lex.RParen
     57                Lscan[i] = pablo.AdvanceThenScanTo(unclosedLParen, unclosed)
     58                Rscan[i] = pablo.AdvanceThenScanTo(unclosedRParen, unclosed)
     59                matches.closed[i] = Lscan[i] & lex.RParen
     60                matches.error |= pablo.atEOF(Lscan[i])
     61                unclosed = Lscan[i] & lex.LParen | Rscan[i] & lex.RParen
    5962                all_closed |= matches.closed[i]
    60                 matches.error |= pscan[i] &~ pablo.EOF_mask
    6163        #
    6264        # Any closing paren that was not actually used to close
    6365        # an opener is in error.
    6466        matches.error |= lex.RParen &~ all_closed
    65 
    6667
    6768
  • proto/matchparens/parenmatch2.py

    r2904 r3031  
    4141       
    4242def Match_Parens(lex, matches):
    43         unmatched = lex.RParen
    44         pscan = 0
    45         qscan = 0
    46         i = 0
    47         pscan = pablo.ScanTo(pablo.Advance(lex.LParen), lex.LParen | lex.RParen)
    48         qscan = pablo.ScanTo(pablo.Advance(lex.RParen), lex.LParen | lex.RParen)
    49         matches.closed = pscan & lex.RParen
    50         unclosed = pscan & lex.LParen | qscan & lex.RParen
    51         matches.error = pscan &~ pablo.EOF_mask
    52         all_closed = matches.closed
     43        parens = lex.LParen | lex.RParen
     44        Lscan = pablo.AdvanceThenScanTo(lex.LParen, parens)
     45        Rscan = pablo.AdvanceThenScanTo(lex.RParen, parens)
     46        matches.closed = Lscan & lex.RParen
     47        matches.error = pablo.atEOF(Lscan)
     48        unclosed = Lscan & lex.LParen | Rscan & lex.RParen
    5349        while unclosed:
    54                 i += 1
    55                 pscan = pablo.ScanTo(pablo.Advance(unclosed & lex.LParen), unclosed)
    56                 qscan = pablo.ScanTo(pablo.Advance(unclosed & lex.RParen), unclosed)
    57                 matches.closed = pscan & lex.RParen
    58                 unclosed = pscan & lex.LParen | qscan & lex.RParen
    59                 all_closed |= matches.closed
    60                 matches.error |= pscan &~ pablo.EOF_mask
     50                unclosedLParen = unclosed & lex.LParen
     51                unclosedRParen = unclosed & lex.RParen
     52                Lscan = pablo.AdvanceThenScanTo(unclosedLParen, unclosed)
     53                Rscan = pablo.AdvanceThenScanTo(unclosedRParen, unclosed)
     54                matches.closed |= Lscan & lex.RParen
     55                matches.error |= pablo.atEOF(Lscan)
     56                unclosed = Lscan & lex.LParen | Rscan & lex.RParen
    6157        #
    6258        # Any closing paren that was not actually used to close
    6359        # an opener is in error.
    64         matches.error |= lex.RParen &~ all_closed
    65 
    66 
     60        matches.error |= lex.RParen &~ matches.closed
    6761
    6862
Note: See TracChangeset for help on using the changeset viewer.