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/parenmatch.py

    r3031 r3064  
    4141       
    4242def Match_Parens(lex, matches):
     43        parens = lex.LParen | lex.RParen
     44        i = 0
     45        pscan = pablo.AdvanceThenScanTo(lex.LParen, parens)
     46        matches.closed[0] = pscan & lex.RParen
     47        all_closed = matches.closed[0]
     48        matches.error = pablo.atEOF(pscan)
     49        # Not matched, still pending.
     50        pending_LParen = pscan & lex.LParen
     51        RParen_unmatched = lex.RParen &~ matches.closed[0]
     52        inPlay = pending_LParen | RParen_unmatched
     53        while pending_LParen:
     54                i += 1
     55                pscan = pablo.AdvanceThenScanTo(pending_LParen, inPlay)
     56                matches.closed[i] = pscan & lex.RParen
     57                all_closed |= matches.closed[i]
     58                matches.error |= pablo.atEOF(pscan)
     59                pending_LParen = pscan & lex.LParen
     60                RParen_unmatched = lex.RParen &~ all_closed
     61                inPlay = pending_LParen | RParen_unmatched
     62        #
     63        # Any closing paren that was not actually used to close
     64        # an opener is in error.
     65        matches.error |= lex.RParen &~ all_closed
     66
     67
     68def Match_Parens0(lex, matches):
    4369        parens = lex.LParen | lex.RParen
    4470        Lscan = {}
Note: See TracChangeset for help on using the changeset viewer.