Changeset 2514 for docs/Working/icXML


Ignore:
Timestamp:
Oct 20, 2012, 6:36:58 AM (7 years ago)
Author:
cameron
Message:

Add StringEnds?, transition marks, delmask

File:
1 edited

Legend:

Unmodified
Added
Removed
  • docs/Working/icXML/FigGen/genfig.py

    r2300 r2514  
    1313zero_ch = '_'
    1414
    15 class Tag_Callouts():
     15class Callouts():
    1616        ElemName_starts = 0
    1717        ElemName_ends = 0
     
    2020        AttVal_starts = 0
    2121        AttVal_ends = 0
    22         AttVal_spans = 0
     22        AttValSpan = 0
     23        AttEq_marks = 0
     24        AttCloseQuotes = 0
    2325        EmptyTag_marks = 0
    2426        EndTag_marks = 0
    25 
     27        Tag_closers = 0
     28        StartTag_closers = 0
     29        EmptyTag_closers = 0
     30        EndTag_closers = 0
     31        delmask=0
     32
     33def set_marks(source, filter_strm, ch):
     34        rslt = ''
     35        for i in range(len(source)):
     36                if filter_strm & 1: rslt += ch
     37                else: rslt += '_'
     38                filter_strm >>= 1
     39        return rslt
     40
     41def do_select(source, filter_strm):
     42        rslt = ''
     43        for i in range(len(source)):
     44                if filter_strm & 1: rslt += source[i]
     45                else: rslt += '_'
     46                filter_strm >>= 1
     47        return rslt
     48
     49def do_filter_strm(source, filter_strm):
     50        rslt = ''
     51        for i in range(len(source)):
     52                if filter_strm & 1: rslt += '_'
     53                else: rslt += source[i]
     54                filter_strm >>= 1
     55        return rslt
    2656
    2757def demo_stags(u8data):
     
    3161        m0 = lex.LAngle
    3262        m1 = bitutil.Advance(m0)
    33         tag_Callouts = Tag_Callouts()
     63        callouts = Callouts()
     64        callouts.AttEq_marks = 0
     65        callouts.AttCloseQuotes = 0
    3466       
    3567        # Delimiters for scans.
     
    4072        # Start the parallel parsing by inspecting the character
    4173        # after the opening "<" of a tag.
    42         tag_Callouts.ElemName_starts = m1 & ~lex.Slash
    43         tag_Callouts.EndTag_marks = m1 & lex.Slash
     74        callouts.ElemName_starts = m1 & ~lex.Slash
     75        callouts.EndTag_marks = m1 & lex.Slash
    4476       
    4577        # Start Tag/Empty Element Tag Parsing
    4678
    4779        # Advance all cursors by scanning through the tag name.
    48         tag_Callouts.ElemName_ends = pablo.ScanThru(tag_Callouts.ElemName_starts, lex.NameScan)
     80        callouts.ElemName_ends = pablo.ScanThru(callouts.ElemName_starts, lex.NameScan)
    4981        # Must have at least one name character for a legal start tag.
    5082        # Mark any occurrences of null names as errors.
    51         ParseError = tag_Callouts.ElemName_starts & tag_Callouts.ElemName_ends
     83        ParseError = callouts.ElemName_starts & callouts.ElemName_ends
    5284       
    5385        # Initialize the accumulators for attribute name and value positions.
    54         tag_Callouts.AttName_starts = 0 
    55         tag_Callouts.AttName_ends = 0
    56         tag_Callouts.AttVal_starts = 0
    57         tag_Callouts.AttVal_ends = 0
     86        callouts.AttName_starts = 0 
     87        callouts.AttName_ends = 0
     88        callouts.AttVal_starts = 0
     89        callouts.AttVal_ends = 0
    5890
    5991        # After the element name, there may or may not be an attlist.
    60         if tag_Callouts.ElemName_ends & lex.WS:
    61                 AfterWS = pablo.ScanThru(tag_Callouts.ElemName_ends, lex.WS)
     92        if callouts.ElemName_ends & lex.WS:
     93                AfterWS = pablo.ScanThru(callouts.ElemName_ends, lex.WS)
    6294                AttListEnd = AfterWS & AttListDelim
    6395                AttNameStart = AfterWS & ~AttListDelim
     
    69101                while AttNameStart:
    70102                        ParseError |= AttNameStart &~ lex.NameScan
    71                         tag_Callouts.AttName_starts |= AttNameStart
     103                        callouts.AttName_starts |= AttNameStart
    72104                        AttNameFollow = pablo.ScanThru(AttNameStart, lex.NameScan)
    73                         tag_Callouts.AttName_ends |= AttNameFollow
     105                        callouts.AttName_ends |= AttNameFollow
    74106                        # Scan through WS to the expected '=' delimiter.
    75107                        # EqExpected = pablo.ScanThru(AttNameFollow, lex.WS)
     
    78110                                EqExpected = pablo.ScanThru(AttNameFollow, lex.WS)
    79111                        else: EqExpected = AttNameFollow
     112                        callouts.AttEq_marks |= EqExpected
    80113                        ParseError |= EqExpected &~ lex.Equals
    81114                        AttValPos = pablo.AdvanceThenScanThru(EqExpected, lex.WS)
    82115#                       AttValPos = pablo.ScanThru(EqExpected, EqExpected | lex.WS)
    83                         tag_Callouts.AttVal_starts |= AttValPos
     116                        callouts.AttVal_starts |= AttValPos
    84117                        DQuoteAttVal = AttValPos & lex.DQuote
    85118                        SQuoteAttVal = AttValPos & lex.SQuote
     
    88121                        DQuoteAttEnd = pablo.AdvanceThenScanTo(DQuoteAttVal, DQuoteDelim)
    89122                        SQuoteAttEnd = pablo.AdvanceThenScanTo(SQuoteAttVal, SQuoteDelim)
     123                        callouts.AttCloseQuotes |= DQuoteAttEnd | SQuoteAttEnd
    90124                        AttValEnd = DQuoteAttEnd | SQuoteAttEnd
    91125                        ParseError |= (AttValPos | AttValEnd) &~ (lex.DQuote | lex.SQuote)
    92126                        AttValFollow = pablo.Advance(AttValEnd)
    93                         tag_Callouts.AttVal_ends |= AttValFollow
     127                        callouts.AttVal_ends |= AttValEnd
    94128                        #  AfterWS = pablo.ScanThru(AttValFollow, lex.WS)
    95129                        if AttValFollow & lex.WS:
     
    103137        else:
    104138                # No WS character after ElemName; must be at the end
    105                 AttListEnd = tag_Callouts.ElemName_ends & AttListDelim
    106                 ParseError |= tag_Callouts.ElemName_ends & ~AttListDelim
    107 
    108         STagEnds = AttListEnd & lex.RAngle
     139                AttListEnd = callouts.ElemName_ends & AttListDelim
     140                ParseError |= callouts.ElemName_ends & ~AttListDelim
     141
     142        callouts.StartTag_closers = AttListEnd & lex.RAngle
    109143        # Mark any "/" characters found as the ends of empty element tags.
    110         tag_Callouts.EmptyTag_marks = pablo.Advance(AttListEnd & lex.Slash)
    111        
    112         ParseError |= tag_Callouts.EmptyTag_marks & ~lex.RAngle
    113 
     144        callouts.EmptyTag_marks = pablo.Advance(AttListEnd & lex.Slash)
     145        callouts.EmptyTag_closers = pablo.Advance(callouts.EmptyTag_marks)
     146       
     147        ParseError |= callouts.EmptyTag_closers & ~lex.RAngle
     148        callouts.AttValSpan = callouts.AttVal_ends - pablo.Advance(callouts.AttVal_starts)
    114149        # End Tag Parsing
    115150
    116         EndTagEnds = pablo.AdvanceThenScanThru(tag_Callouts.EndTag_marks, lex.NameScan)
     151        EndTagEnds = pablo.AdvanceThenScanThru(callouts.EndTag_marks, lex.NameScan)
    117152        if EndTagEnds & lex.WS:
    118153                EndTagEnds = pablo.ScanThru(EndTagEnds, lex.WS)
    119154        ParseError |= EndTagEnds & ~lex.RAngle
     155        callouts.EndTag_closers = EndTagEnds
    120156        #pablo.assert_0(ParseError, "Tag parsing error found")
     157
     158        callouts.Tag_closers = callouts.StartTag_closers | callouts.EmptyTag_marks | callouts.EndTag_closers
     159
     160        callouts.TagSpan = (callouts.Tag_closers - lex.LAngle) | callouts.Tag_closers
     161
     162
    121163               
    122 
    123         print bitutil.latex_streams([('source data', u8data),
     164        transition_marks = callouts.AttEq_marks | callouts.StartTag_closers | callouts.EmptyTag_marks | callouts.EndTag_marks
     165        MarkupDelimiters = callouts.Tag_closers
     166        # Determine end positions of tagged strings
     167        StringEnds = callouts.AttCloseQuotes | lex.LAngle
     168        #
     169        # Mark the interiors of tags for deletion, excluding attribute
     170        # value strings, transition_mark positions and string ends.
     171        callouts.delmask = callouts.TagSpan &~ (callouts.AttValSpan | transition_marks | StringEnds)
     172        # Mark initial parts of CtCDPI for deletion.
     173        #callouts.delmask |= pablo.ExclusiveSpan(callouts.CtCDPI_marks, callouts.CtCDPI_content_starts)
     174
     175        # Mark the "!" of Comments or CDATA for deletion
     176        callouts.delmask |= pablo.Advance(lex.LAngle) & lex.Exclam
     177
     178        # Zero out all bits at deleted positions and string end positions (final null
     179        # character insertion).
     180        zeromask = callouts.delmask | StringEnds | transition_marks
     181       
     182
     183        print bitutil.latex_streams([('Source Data', u8data),
    124184                              ('Tag Openers', bitutil.bitstream2string(lex.LAngle, lgth, zero_ch)),
    125                               ('Start Tag Marks', bitutil.bitstream2string(tag_Callouts.ElemName_starts, lgth, zero_ch)),
    126                               ('End Tag Marks', bitutil.bitstream2string(tag_Callouts.EndTag_marks, lgth, zero_ch)),
    127                               ('Element Names', bitutil.bitstream2string(tag_Callouts.ElemName_ends - tag_Callouts.ElemName_starts, lgth, zero_ch)),
    128                               ('Att Names', bitutil.bitstream2string(tag_Callouts.AttName_ends - tag_Callouts.AttName_starts, lgth, zero_ch)),
    129                               ('Att Values', bitutil.bitstream2string(tag_Callouts.AttVal_ends - tag_Callouts.AttVal_starts, lgth, zero_ch))])
     185                              ('Start Tag Marks', bitutil.bitstream2string(callouts.ElemName_starts, lgth, zero_ch)),
     186                              ('End Tag Marks', bitutil.bitstream2string(callouts.EndTag_marks, lgth, zero_ch)),
     187                              ('Empty Tag Marks', bitutil.bitstream2string(callouts.EmptyTag_marks, lgth, zero_ch)),
     188                              ('Element Names', bitutil.bitstream2string(callouts.ElemName_ends - callouts.ElemName_starts, lgth, zero_ch)),
     189                              ('Att Names', bitutil.bitstream2string(callouts.AttName_ends - callouts.AttName_starts, lgth, zero_ch)),
     190                              ('Att Values', bitutil.bitstream2string(callouts.AttValSpan, lgth, zero_ch)),
     191                              ('String ends', bitutil.bitstream2string(StringEnds, lgth, zero_ch)),
     192                              ('String marks', set_marks(u8data,StringEnds, '0')),
     193                              ('Transition marks', bitutil.bitstream2string(transition_marks, lgth, zero_ch)),
     194                              ('Transition chars', do_select(u8data, transition_marks)),
     195                              ('Deletion mask', bitutil.bitstream2string(callouts.delmask, lgth, zero_ch)),
     196                              ('Undeleted', do_filter_strm(u8data, callouts.delmask|StringEnds))])
    130197
    131198
Note: See TracChangeset for help on using the changeset viewer.