Changeset 1263 for proto/parabix2


Ignore:
Timestamp:
Aug 3, 2011, 11:22:57 AM (8 years ago)
Author:
cameron
Message:

Elim Scope1 class, add Marker class

File:
1 edited

Legend:

Unmodified
Added
Removed
  • proto/parabix2/parabix2_pablo.py

    r1251 r1263  
    7575        WS = 0
    7676
    77 class Scope1 ():
    78         RefStart = 0
    79         LAngle = 0
    80         Hyphen = 0
    81         QMark = 0
    82         RBracket = 0
     77class Marker ():
     78        LAngle_scope = 0
     79        Ref_opener = 0
     80        CD_closer = 0
    8381
    8482class CtCDPI_Callouts():
    85         CD_end = 0
    8683        Ct_starts = 0
    8784        Ct_ends = 0
     
    9289        PI_name_ends = 0
    9390        PI_ends = 0
    94         CtCDPI_mask = 0
    9591
    9692class Ref_Callouts():
     
    315311                       
    316312       
    317 def Add_scope_streams(lex, scope1):
    318         #scope1.LAngle = bitutil.Advance(lex.LAngle)
    319         #scope1.Hyphen = bitutil.Advance(lex.Hyphen)
    320         #scope1.QMark = bitutil.Advance(lex.QMark)
    321         v = lex.LAngle | lex.Hyphen
    322         w = lex.Hyphen | lex.QMark
    323         v1 = bitutil.Advance(v)
    324         w1 = bitutil.Advance(w)
    325         scope1.LAngle = v1 &~ w1
    326         scope1.Hyphen = v1 & w1
    327         scope1.QMark = w1 &~ v1
    328         scope1.RefStart = 0 # default
    329 
    330 def Parse_CtCDPI(ctCDPI_Callouts, lex, scope1, check_streams):
    331         ctCDPI_Callouts.CD_end = 0
     313def Parse_CtCDPI(lex, marker, ctCDPI_Callouts, check_streams):
    332314        ctCDPI_Callouts.Ct_starts = 0
    333315        ctCDPI_Callouts.Ct_ends = 0
     
    338320        ctCDPI_Callouts.PI_name_ends = 0
    339321        ctCDPI_Callouts.PI_ends = 0
    340         ctCDPI_Callouts.CtCDPI_mask = 0
    341322        ctCDPI_error = 0
    342323        CtCDPI_starts = 0
    343324        Ct_errors = 0
    344 
     325        ctCDPI_mask = 0
     326
     327        v = lex.LAngle | lex.Hyphen
     328        w = lex.Hyphen | lex.QMark
     329        v1 = bitutil.Advance(v)
     330        w1 = bitutil.Advance(w)
     331       
     332        LAngle_scope = v1 &~ w1  #bitutil.Advance(lex.LAngle)
     333        PI_opener = LAngle_scope & lex.QMark
     334        CtCD_opener= LAngle_scope & lex.Exclam
     335        CtCDPI_opener = PI_opener | CtCD_opener
     336
     337        #DoubleHyphen = 0
     338        CD_closer = 0
     339        #PI_closer = 0
     340       
     341        #if lex.Hyphen: DoubleHyphen = bitutil.Advance(lex.Hyphen) & lex.Hyphen
     342        DoubleHyphen = v1 & w1 & lex.Hyphen
    345343        if lex.RBracket:
    346                 scope1.RBracket = bitutil.Advance(lex.RBracket)
    347                 ctCDPI_Callouts.CD_end = bitutil.Advance(scope1.RBracket & lex.RBracket) & lex.RAngle
    348         PI_start = scope1.LAngle & lex.QMark
    349         CtCD_start = scope1.LAngle & lex.Exclam
    350         CtCDPI_start = PI_start | CtCD_start
    351 
    352         DoubleHyphen = scope1.Hyphen & lex.Hyphen
    353         PI_end = scope1.QMark & lex.RAngle
    354 
     344                DoubleRBracket = bitutil.Advance(lex.RBracket) & lex.RBracket
     345                CD_closer = bitutil.Advance(DoubleRBracket) & lex.RAngle
     346        #if lex.QMark: PI_closer = bitutil.Advance(lex.QMark) & lex.RAngle
     347        PI_closer = w1 & ~v1 & lex.RAngle
    355348
    356349        #
    357350        # Initiate the scan
    358         CtCDPI_Cursor = bitutil.ScanToFirst(CtCDPI_start)
     351        CtCDPI_Cursor = bitutil.ScanToFirst(CtCDPI_opener)
    359352        while CtCDPI_Cursor:
    360353                CtCDPI_starts |= CtCDPI_Cursor
    361                 PI_Cursor = CtCDPI_Cursor & PI_start
     354                PI_Cursor = CtCDPI_Cursor & PI_opener
    362355                CD_Ct_Cursor = bitutil.Advance(CtCDPI_Cursor & ~PI_Cursor)
    363356                CD_Cursor = CD_Ct_Cursor & lex.LBracket
     
    375368                PI_name_end = bitutil.ScanThru(PI_Cursor, lex.NameScan)
    376369                ctCDPI_Callouts.PI_name_ends |= PI_name_end
    377                 PI_Cursor = bitutil.ScanTo(PI_name_end, PI_end)
    378                 CD_Cursor = bitutil.ScanTo(CD_Cursor, ctCDPI_Callouts.CD_end)
     370                PI_Cursor = bitutil.ScanTo(PI_name_end, PI_closer)
     371                CD_Cursor = bitutil.ScanTo(CD_Cursor, CD_closer)
    379372                Ct_Cursor = bitutil.Advance(bitutil.ScanTo(Ct_Cursor, DoubleHyphen))
    380373                ctCDPI_Callouts.PI_ends |= PI_Cursor
     
    382375                ctCDPI_Callouts.Ct_ends |= Ct_Cursor
    383376                CtCDPI_Cursor = PI_Cursor | CD_Cursor | Ct_Cursor
    384                 CtCDPI_Cursor = bitutil.ScanTo(CtCDPI_Cursor, CtCDPI_start)
    385        
    386                 ctCDPI_Callouts.CtCDPI_mask = bitutil.Advance(ctCDPI_Callouts.CD_ends | ctCDPI_Callouts.Ct_ends | ctCDPI_Callouts.PI_ends) - CtCDPI_starts             
     377                CtCDPI_Cursor = bitutil.ScanTo(CtCDPI_Cursor, CtCDPI_opener)
     378       
     379                ctCDPI_mask = bitutil.Advance(ctCDPI_Callouts.CD_ends | ctCDPI_Callouts.Ct_ends | ctCDPI_Callouts.PI_ends) - CtCDPI_starts             
    387380                #ctCDPI_Callouts.error = Ct_ends & ~lex.RAngle | Ct_starts & ~ lex.Hyphen
    388381                ctCDPI_error = Ct_errors | ctCDPI_Callouts.Ct_ends & ~lex.RAngle
    389                 ctCDPI_error |= bitutil.Advance(ctCDPI_Callouts.PI_name_ends & ~ lex.WS) & ~ PI_end
     382                ctCDPI_error |= bitutil.Advance(ctCDPI_Callouts.PI_name_ends & ~ lex.WS) & ~ PI_closer
    390383                ctCDPI_error |= ctCDPI_Callouts.PI_name_starts & ctCDPI_Callouts.PI_name_ends
    391384                # If any of the Comment, CDATA or PI markups are unterminated, it is an error.
    392                 ctCDPI_error |= ctCDPI_Callouts.CtCDPI_mask &~ EOF_mask
     385                ctCDPI_error |= ctCDPI_mask &~ EOF_mask
    393386       
    394387        if ctCDPI_error:
     
    397390        check_streams.misc_mask = (lex.WS | lex.LAngle | (bitutil.Advance(ctCDPI_Callouts.Ct_ends | ctCDPI_Callouts.PI_ends) - (ctCDPI_Callouts.Ct_starts | ctCDPI_Callouts.PI_starts)) | CtCDPI_starts) & EOF_mask
    398391
    399 def Parse_tags(lex, scope1, ctCDPI_Callouts, tag_Callouts):
    400 
     392
     393        # Identify the remaining significant markers for XML processing.
     394        marker.LAngle_scope = LAngle_scope &~ ctCDPI_mask
     395        marker.Ref_opener = lex.RefStart &~ ctCDPI_mask
     396        marker.CD_closer = CD_closer &~ ctCDPI_mask
     397
     398def Parse_tags(lex, marker, tag_Callouts):
    401399       
    402400        # Delimiters for scans.
     
    407405        # Start the parallel parsing by inspecting the character
    408406        # after the opening "<" of a tag.
    409         LAngleFollow = scope1.LAngle &~ ctCDPI_Callouts.CtCDPI_mask
    410         tag_Callouts.ElemName_starts = LAngleFollow & ~lex.Slash
    411         tag_Callouts.EndTag_marks = LAngleFollow & lex.Slash
     407        tag_Callouts.ElemName_starts = marker.LAngle_scope & ~lex.Slash
     408        tag_Callouts.EndTag_marks = marker.LAngle_scope & lex.Slash
    412409       
    413410        # Start Tag/Empty Element Tag Parsing
     
    489486        # Attribute value spans
    490487        tag_Callouts.AttVal_spans = tag_Callouts.AttVal_ends - tag_Callouts.AttVal_starts
    491                        
    492 def Parse_refs(lex, scope1, ctCDPI_Callouts, ref_Callouts):
     488
     489def Parse_refs(lex, marker, ref_Callouts):
    493490        ref_Callouts.GenRef_starts = 0
    494491        ref_Callouts.GenRef_ends = 0
     
    499496        ref_error = 0
    500497
    501         Ref1 = lex.RefStart &~ ctCDPI_Callouts.CtCDPI_mask
    502498        # All remaining "&" must be reference start characters; parse them.
    503         if Ref1:
    504                 scope1.RefStart = bitutil.Advance(Ref1)
    505                 NumRef2 = scope1.RefStart & lex.Hash
    506                 ref_Callouts.GenRef_starts = scope1.RefStart &~ lex.Hash
     499        if marker.Ref_opener:
     500                Ref_scope = bitutil.Advance(marker.Ref_opener)
     501                NumRef2 = Ref_scope & lex.Hash
     502                ref_Callouts.GenRef_starts = Ref_scope &~ lex.Hash
    507503                NumRef3 = bitutil.Advance(NumRef2)
    508504                HexRef3 = NumRef3 & lex.x
     
    549545        check_streams.non_ascii_names = (name_stream &~ name_start) & ~lex.ASCII_name_char & ~u8.suffix
    550546   
    551 def Do_check_streams(ctCDPI_Callouts, tag_Callouts, lex, u8, scope1, ref_Callouts, xml_names, check_streams):
    552     # Ensure that no occurrence of ]]> occurs outside of markup.
    553     CD_end_error = ctCDPI_Callouts.CD_end & ~(ctCDPI_Callouts.CtCDPI_mask | tag_Callouts.AttVal_spans)
    554            
    555     # Consolidate and check for errors
    556     if CD_end_error:
     547def Do_check_streams(ctCDPI_Callouts, tag_Callouts, lex, u8, marker, ref_Callouts, xml_names, check_streams):
     548        CD_end_error = marker.CD_closer & ~tag_Callouts.AttVal_spans
     549        if CD_end_error:
    557550                error_tracker.NoteError("Error: ]]> in text", CD_end_error)
    558                
    559 
    560     check_streams.tag_marks = tag_Callouts.EmptyTag_marks | tag_Callouts.ElemName_starts | tag_Callouts.EndTag_marks | tag_Callouts.AttName_starts
    561     check_streams.name_follows = tag_Callouts.ElemName_ends | tag_Callouts.AttName_ends
    562     check_streams.att_refs = tag_Callouts.AttVal_spans & scope1.RefStart
    563    
     551        check_streams.tag_marks = tag_Callouts.EmptyTag_marks | tag_Callouts.ElemName_starts | tag_Callouts.EndTag_marks | tag_Callouts.AttName_starts
     552        check_streams.name_follows = tag_Callouts.ElemName_ends | tag_Callouts.AttName_ends
     553        check_streams.att_refs = tag_Callouts.AttVal_spans & marker.Ref_opener
     554     
    564555   
    565556def Main(basis_bits, lex, u8, xml_char, scope1, ctCDPI_Callouts, ref_Callouts, tag_Callouts, masks, xml_names, check_streams): 
     
    574565        Classify_bytes_Validate_utf8(basis_bits, lex, u8)
    575566
    576         Add_scope_streams(lex, scope1)
     567        #Add_scope_streams(lex, scope1)
    577568   
    578569        # Parse all comments, CDATA sections and processing instructions.
    579         Parse_CtCDPI(ctCDPI_Callouts, lex, scope1, check_streams)
     570        Parse_CtCDPI(lex, marker, ctCDPI_Callouts, check_streams)
    580571               
    581572        # All remaining '<' must be tag start characters; parse tags.
    582         Parse_tags(lex, scope1, ctCDPI_Callouts, tag_Callouts)
     573        Parse_tags(lex, marker, tag_Callouts)
    583574
    584575        # All remaining '&' must be reference start characters; parse them.
    585         Parse_refs(lex, scope1, ctCDPI_Callouts, ref_Callouts)
     576        Parse_refs(lex, marker, ref_Callouts)
    586577       
    587578        # Validate XML namespaces and generate bit streams to post validate non-ascii range XML names
     
    589580   
    590581   
    591         Do_check_streams(ctCDPI_Callouts, tag_Callouts, lex, u8, scope1, ref_Callouts, xml_names, check_streams)
    592 
    593 
     582        Do_check_streams(ctCDPI_Callouts, tag_Callouts, lex, u8, marker, ref_Callouts, xml_names, check_streams)
     583
     584
Note: See TracChangeset for help on using the changeset viewer.