Changeset 3065 for proto


Ignore:
Timestamp:
Apr 22, 2013, 11:09:52 AM (6 years ago)
Author:
cameron
Message:

Fully parallel comment/string matching - initial version

File:
1 edited

Legend:

Unmodified
Added
Removed
  • proto/PDF/cb_pablo.py

    r2951 r3065  
    301301        marker.error |= escape_Callouts.RParen &~ all_closed       
    302302       
     303
     304#
     305# Modified version with comment processing
     306#
     307# Let pending_LParen be left parentheses for which we have a pending
     308#   obligation to find the corresponding right parentheses.
     309#
     310# Let pending_Pct be Percent marks that have not yet been
     311#   ruled out as comment opening delimiters
     312#
     313#
     314def Match_Parens_With_Comments(lex, escape_Callouts, marker, out_Callouts):
     315        instring = 0
     316        closed_RParen = 0
     317        marker.error = 0
     318        line_starts = ~pablo.Advance(~lex.EOL)
     319        line_ends1 = pablo.ScanTo(line_starts, lex.EOL | lex.Percent)
     320        pending_Pct = line_ends1 & lex.Percent
     321        known_outside_Ct = pablo.SpanUpTo(line_starts, line_ends1)
     322        pending_LParen = known_outside_Ct & escape_Callouts.LParen
     323        unmatched_RParen = escape_Callouts.RParen
     324
     325        inPlay = pending_LParen | unmatched_RParen | pending_Pct
     326
     327        while pending_LParen:
     328
     329                # Scan from pending ( marks to next [()%].   Everything we find
     330                # must be within a string.
     331                pscan = pablo.AdvanceThenScanTo(pending_LParen, inPlay)
     332                instring |= pablo.ExclusiveSpan(pending_LParen, pscan) | pscan &~ escape_Callouts.RParen
     333                closed_RParen |= pscan & escape_Callouts.RParen
     334                marker.error |= pablo.atEOF(pscan)
     335                pending_LParen = pscan & escape_Callouts.LParen
     336                # Did we scan into a pending comment region?
     337                pct_found = pscan & pending_Pct
     338               
     339                if pct_found:
     340                        # The scan from the "(" was terminated prematurely by the "%" mark.
     341                        # We include this position in pending_LParen so that the scan can
     342                        # continue next time around.
     343                        pending_LParen |= pct_found
     344                        # Clear this % position as a line terminator, and find the next.
     345                        # Determine the region that was previously identified as potentially
     346                        # inside a comment and mark it as outside.
     347                        line_ends1 &= ~pct_found
     348                        line_ends1 |= pablo.AdvanceThenScanTo(pct_found, lex.EOL | lex.Percent)
     349                        # Add any new potential comment delimiter to the pending ones.
     350                        pending_Pct |= line_ends1 & lex.Percent
     351                        newly_outside = pablo.SpanUpTo(pct_found, line_ends1)
     352                        known_outside_Ct |= newly_outside
     353                        # If any LParens have been revealed, add scan obligations for them
     354                        pending_LParen |= newly_outside & escape_Callouts.LParen
     355               
     356                unmatched_RParen = escape_Callouts.RParen &~ closed_RParen                             
     357                inPlay = pending_LParen | unmatched_RParen | pending_Pct
     358        #
     359        # No more scans to do.  Any pending pct marks are now known
     360        # as definite comment delimiters.
     361        comment_start = line_ends1 & lex.Percent
     362        out_Callouts.mask = pablo.InclusiveSpan(comment_start, pablo.ScanTo(comment_start, lex.EOL))
     363        #
     364        # Any closing paren that was not actually used to close
     365        # an opener is in error.
     366        marker.starts = pablo.Advance(~instring) & instring
     367        marker.ends = pablo.ScanThru(marker.starts, instring)
     368        marker.error |= escape_Callouts.RParen &~ closed_RParen &~ pablo.SpanUpTo(matches.comment_start, matches.comment_end)
     369
     370
    303371         
    304372def Parse_HexStrings(lex, marker, out_Callouts) :
     
    505573
    506574        Parse_Escaped(lex, parity, escape_Callouts, out_Callouts)
     575
     576        Match_Parens_With_Comments(lex, escape_Callouts, marker, out_Callouts)
    507577       
    508578        Parse_HexStrings(lex, marker, out_Callouts)
Note: See TracChangeset for help on using the changeset viewer.