source: proto/SymbolTable/parabix2_symtab_pbs_log.py @ 1232

Last change on this file since 1232 was 1232, checked in by vla24, 8 years ago

Updated symbol table implementation.

File size: 21.7 KB
Line 
1# -*- coding: utf-8 -*-
2#
3# parabix2_compilable.py
4#
5# Parallel XML Parsing with Bitstream Addition
6#
7# - Complete prototype for all bitstream computations in Parabix2
8# - Optimized for compilation
9# - Separate compilation
10
11# Robert D. Cameron
12# July 29, 2010
13#
14
15#import bitutil
16
17class u8 ():
18  unibyte = 0
19  prefix = 0
20  prefix2 = 0
21  prefix3 = 0
22  prefix4 = 0
23  suffix = 0
24  badprefix = 0
25  xE0 = 0
26  xED = 0
27  xF0 = 0
28  xF4 = 0
29  xA0_xBF = 0
30  x80_x9F = 0
31  x90_xBF = 0
32  x80_x8F = 0
33  xEF = 0
34  xBF = 0
35  xBE = 0
36  scope22 = 0
37  scope32 = 0
38  scope33 = 0
39  scope42 = 0
40  scope43 = 0
41  scope44 = 0
42  xE0_scope = 0
43  xED_scope = 0
44  xF0_scope = 0
45  xF4_scope = 0
46  xEF_scope = 0
47
48class Lex ():
49        CR = 0
50        LF = 0
51        HT = 0
52        SP = 0
53        CRLF = 0
54        RefStart = 0
55        Semicolon = 0
56        Colon = 0
57        LAngle = 0
58        RAngle = 0
59        LBracket = 0
60        RBracket = 0
61        Exclam = 0
62        QMark = 0
63        Hyphen = 0
64        Equals = 0
65        SQuote = 0
66        DQuote = 0
67        Slash = 0
68        Hash = 0
69        x = 0
70        ASCII_name_start = 0
71        ASCII_name_char = 0
72        NameScan = 0
73        Digit = 0
74        Hex = 0
75        WS = 0
76
77class Scope1 ():
78        RefStart = 0
79        LAngle = 0
80        Hyphen = 0
81        QMark = 0
82        RBracket = 0
83
84class CtCDPI_Callouts():
85        CD_end = 0
86        Ct_starts = 0
87        Ct_ends = 0
88        CD_starts = 0
89        CD_ends = 0
90        PI_starts = 0
91        PI_name_starts = 0
92        PI_name_ends = 0
93        PI_ends = 0
94        CtCDPI_mask = 0
95
96class Ref_Callouts():
97        GenRef_starts = 0
98        GenRef_ends = 0
99        DecRef_starts = 0
100        DecRef_ends = 0
101        HexRef_starts = 0
102        HexRef_ends = 0
103
104class Hash_data():
105        Hash_value = 0
106
107class Tag_Callouts():
108        ElemName_starts = 0
109        ElemName_ends = 0
110        ElemName_ends_1 = 0
111        ElemName_ends_2 = 0
112        ElemName_ends_3_to_4 = 0
113        ElemName_ends_5_to_8 = 0
114        ElemName_ends_9_to_16 = 0
115        ElemName_ends_17_and_longer = 0
116        AttName_starts = 0
117        AttName_ends = 0
118        AttVal_starts = 0
119        AttVal_ends = 0
120        AttVal_spans = 0
121        EmptyTag_marks = 0
122        EndTag_marks = 0
123
124class Basis_bits():
125        bit_0 = 0
126        bit_1 = 0
127        bit_2 = 0
128        bit_3 = 0
129        bit_4 = 0
130        bit_5 = 0
131        bit_6 = 0
132        bit_7 = 0
133
134class Check_streams():
135        misc_mask = 0
136        non_ascii_name_starts = 0
137        non_ascii_names = 0
138        tag_marks = 0
139        name_follows = 0
140        att_refs = 0
141
142class Xml_names():
143        namespace_error = 0
144
145def Classify_bytes_Validate_utf8(basis_bits, lex, u8):
146        temp1 = (basis_bits.bit_0 | basis_bits.bit_1);
147        temp2 = (basis_bits.bit_2 &~ basis_bits.bit_3);
148        temp3 = (temp2 &~ temp1);
149        temp4 = (basis_bits.bit_5 &~ basis_bits.bit_4);
150        temp5 = (basis_bits.bit_6 &~ basis_bits.bit_7);
151        temp6 = (temp4 & temp5);
152        lex.RefStart = (temp3 & temp6);
153        temp7 = (basis_bits.bit_2 & basis_bits.bit_3);
154        temp8 = (temp7 &~ temp1);
155        temp9 = (basis_bits.bit_4 &~ basis_bits.bit_5);
156        temp10 = (basis_bits.bit_6 & basis_bits.bit_7);
157        temp11 = (temp9 & temp10);
158        lex.Semicolon = (temp8 & temp11);
159        temp12 = (basis_bits.bit_4 & basis_bits.bit_5);
160        temp13 = (basis_bits.bit_6 | basis_bits.bit_7);
161        temp14 = (temp12 &~ temp13);
162        lex.LAngle = (temp8 & temp14);
163        temp15 = (temp12 & temp5);
164        lex.RAngle = (temp8 & temp15);
165        temp16 = (basis_bits.bit_1 &~ basis_bits.bit_0);
166        temp17 = (basis_bits.bit_3 &~ basis_bits.bit_2);
167        temp18 = (temp16 & temp17);
168        lex.LBracket = (temp18 & temp11);
169        temp19 = (basis_bits.bit_7 &~ basis_bits.bit_6);
170        temp20 = (temp12 & temp19);
171        lex.RBracket = (temp18 & temp20);
172        temp21 = (basis_bits.bit_4 | basis_bits.bit_5);
173        temp22 = (temp19 &~ temp21);
174        lex.Exclam = (temp3 & temp22);
175        temp23 = (temp12 & temp10);
176        lex.QMark = (temp8 & temp23);
177        lex.Hyphen = (temp3 & temp20);
178        lex.Equals = (temp8 & temp20);
179        temp24 = (temp4 & temp10);
180        lex.SQuote = (temp3 & temp24);
181        temp25 = (temp5 &~ temp21);
182        lex.DQuote = (temp3 & temp25);
183        lex.Slash = (temp3 & temp23);
184        temp26 = (temp10 &~ temp21);
185        lex.Hash = (temp3 & temp26);
186        temp27 = (temp16 & temp7);
187        temp28 = (temp9 &~ temp13);
188        lex.x = (temp27 & temp28);
189        temp29 = (temp9 & temp5);
190        lex.Colon = (temp8 & temp29);
191        temp30 = (temp18 & temp23);
192        temp31 = (temp30 | lex.Colon);
193        temp32 = (temp16 &~ basis_bits.bit_2);
194        temp33 = (basis_bits.bit_5 | temp10);
195        temp34 = (basis_bits.bit_4 & temp33);
196        temp35 = (~temp34);
197        temp36 = (temp21 | temp13);
198        temp37 = ((basis_bits.bit_3 & temp35)|(~(basis_bits.bit_3) & temp36));
199        temp38 = (temp32 & temp37);
200        temp39 = (temp31 | temp38);
201        temp40 = (temp16 & basis_bits.bit_2);
202        temp41 = (temp40 & temp37);
203        lex.ASCII_name_start = (temp39 | temp41);
204        temp42 = (temp30 | lex.Hyphen);
205        temp43 = (temp3 & temp15);
206        temp44 = (temp42 | temp43);
207        temp45 = (temp8 &~ temp34);
208        temp46 = (temp44 | temp45);
209        temp47 = (temp46 | temp38);
210        lex.ASCII_name_char = (temp47 | temp41);
211        lex.NameScan = (lex.ASCII_name_char | basis_bits.bit_0);
212        temp48 = (temp1 | basis_bits.bit_2);
213        x00_x1F = (~temp48);
214        temp49 = (basis_bits.bit_2 | basis_bits.bit_3);
215        temp50 = (temp1 | temp49);
216        lex.CR = (temp20 &~ temp50);
217        lex.LF = (temp29 &~ temp50);
218        temp51 = (temp9 & temp19);
219        lex.HT = (temp51 &~ temp50);
220        lex.SP = (temp3 &~ temp36);
221        temp52 = (temp20 | temp29);
222        temp53 = (temp52 | temp51);
223        temp54 = (temp53 &~ temp50);
224        lex.WS = (temp54 | lex.SP);
225        temp55 = (basis_bits.bit_5 | basis_bits.bit_6);
226        temp56 = (basis_bits.bit_4 & temp55);
227        lex.Digit = (temp8 &~ temp56);
228        temp57 = (temp16 &~ temp49);
229        temp58 = (temp57 &~ basis_bits.bit_4);
230        temp59 = (~temp10);
231        temp60 = ((basis_bits.bit_5 & temp59)|(~(basis_bits.bit_5) & temp13));
232        temp61 = (temp58 & temp60);
233        temp62 = (lex.Digit | temp61);
234        temp63 = (temp16 & temp2);
235        temp64 = (temp63 &~ basis_bits.bit_4);
236        temp65 = (temp64 & temp60);
237        lex.Hex = (temp62 | temp65);
238        lex_error = x00_x1F &~ lex.WS
239        if lex_error & EOF_mask:
240                error_tracker.NoteError("Error: illegal character", lex_error)
241
242
243        ### Validate_utf8(basis_bits, u8):
244        u8.unibyte = (~basis_bits.bit_0);
245        u8.suffix = 0
246        u8_error = 0
247        u8_FFFE_FFFF = 0
248        u8anyscope = 0 #local
249        if basis_bits.bit_0:
250                u8.prefix = (basis_bits.bit_0 & basis_bits.bit_1);
251                u8.prefix2 = (u8.prefix &~ basis_bits.bit_2);
252                u8.prefix3 = (u8.prefix & temp2);
253                u8.prefix4 = (u8.prefix & temp7);
254                u8.suffix = (basis_bits.bit_0 &~ basis_bits.bit_1);
255                temp66 = (u8.prefix &~ temp49);
256                temp67 = (temp21 | basis_bits.bit_6);
257                temp68 = (temp66 &~ temp67);
258                temp69 = (basis_bits.bit_5 & temp13);
259                temp70 = (basis_bits.bit_4 | temp69);
260                temp71 = (u8.prefix4 & temp70);
261                u8.badprefix = (temp68 | temp71);
262                u8_error = u8.badprefix
263                u8.scope22 = bitutil.Advance(u8.prefix2)
264                u8anyscope = u8.scope22
265                if u8.prefix3 | u8.prefix4:
266                        xE0 = (u8.prefix3 &~ temp36);
267                        xED = (u8.prefix3 & temp20);
268                        xF0 = (u8.prefix4 &~ temp36);
269                        temp72 = (temp4 &~ temp13);
270                        xF4 = (u8.prefix4 & temp72);
271                        u8.xA0_xBF = (u8.suffix & basis_bits.bit_2);
272                        u8.x80_x9F = (u8.suffix &~ basis_bits.bit_2);
273                        u8.x90_xBF = (u8.suffix & temp49);
274                        u8.x80_x8F = (u8.suffix &~ temp49);
275                        xEF = (u8.prefix3 & temp23);
276                        temp73 = (u8.suffix & temp7);
277                        u8.xBF = (temp73 & temp23);
278                        u8.xBE = (temp73 & temp15);
279                        u8.xE0_scope = bitutil.Advance(xE0);
280                        u8.xED_scope = bitutil.Advance(xED);
281                        u8.xF0_scope = bitutil.Advance(xF0);
282                        u8.xF4_scope = bitutil.Advance(xF4);
283                        u8.xEF_scope = bitutil.Advance(xEF);
284                        u8.scope32 = bitutil.Advance(u8.prefix3)
285                        u8.scope33 = bitutil.Advance(u8.scope32)
286                        u8.scope42 = bitutil.Advance(u8.prefix4)
287                        u8.scope43 = bitutil.Advance(u8.scope42)
288                        u8.scope44 = bitutil.Advance(u8.scope43)
289
290                        u8lastscope = u8.scope22 | u8.scope33 | u8.scope44
291                        u8anyscope = u8lastscope | u8.scope32 | u8.scope42 | u8.scope43
292
293                        u8error1 = u8.xE0_scope & u8.x80_x9F
294                        u8error2 = u8.xED_scope & u8.xA0_xBF
295                        u8error3 = u8.xF0_scope & u8.x80_x8F
296                        u8error4 = u8.xF4_scope & u8.x90_xBF
297
298                        u8_error |= u8error1 | u8error2 | u8error3 | u8error4
299
300                        EF_BF_pending = bitutil.Advance(u8.xEF_scope & u8.xBF)
301
302                        u8_FFFE_FFFF = (EF_BF_pending & (u8.xBE | u8.xBF))
303                u8mismatch = u8anyscope ^ u8.suffix
304                u8_error |= u8mismatch | u8_FFFE_FFFF
305                if u8_error:
306                        error_tracker.NoteError("UTF-8 error found", (u8_error))
307
308
309def Add_scope_streams(lex, scope1):
310        #scope1.LAngle = bitutil.Advance(lex.LAngle)
311        #scope1.Hyphen = bitutil.Advance(lex.Hyphen)
312        #scope1.QMark = bitutil.Advance(lex.QMark)
313        v = lex.LAngle | lex.Hyphen
314        w = lex.Hyphen | lex.QMark
315        v1 = bitutil.Advance(v)
316        w1 = bitutil.Advance(w)
317        scope1.LAngle = v1 &~ w1
318        scope1.Hyphen = v1 & w1
319        scope1.QMark = w1 &~ v1
320        scope1.RefStart = 0 # default
321
322def Parse_CtCDPI(ctCDPI_Callouts, lex, scope1, check_streams):
323        ctCDPI_Callouts.CD_end = 0
324        ctCDPI_Callouts.Ct_starts = 0
325        ctCDPI_Callouts.Ct_ends = 0
326        ctCDPI_Callouts.CD_starts = 0
327        ctCDPI_Callouts.CD_ends = 0
328        ctCDPI_Callouts.PI_starts = 0
329        ctCDPI_Callouts.PI_name_starts = 0
330        ctCDPI_Callouts.PI_name_ends = 0
331        ctCDPI_Callouts.PI_ends = 0
332        ctCDPI_Callouts.CtCDPI_mask = 0
333        ctCDPI_error = 0
334        CtCDPI_starts = 0
335        Ct_errors = 0
336
337        if lex.RBracket:
338                scope1.RBracket = bitutil.Advance(lex.RBracket)
339                ctCDPI_Callouts.CD_end = bitutil.Advance(scope1.RBracket & lex.RBracket) & lex.RAngle
340        PI_start = scope1.LAngle & lex.QMark
341        CtCD_start = scope1.LAngle & lex.Exclam
342        CtCDPI_start = PI_start | CtCD_start
343
344        DoubleHyphen = scope1.Hyphen & lex.Hyphen
345        PI_end = scope1.QMark & lex.RAngle
346
347
348        #
349        # Initiate the scan
350        CtCDPI_Cursor = bitutil.ScanToFirst(CtCDPI_start)
351        while CtCDPI_Cursor:
352                CtCDPI_starts |= CtCDPI_Cursor
353                PI_Cursor = CtCDPI_Cursor & PI_start
354                CD_Ct_Cursor = bitutil.Advance(CtCDPI_Cursor & ~PI_Cursor)
355                CD_Cursor = CD_Ct_Cursor & lex.LBracket
356                Ct_Cursor = CD_Ct_Cursor & lex.Hyphen
357                ctCDPI_Callouts.PI_starts |= PI_Cursor
358                ctCDPI_Callouts.CD_starts |= CD_Cursor
359                ctCDPI_Callouts.Ct_starts |= Ct_Cursor
360                Ct_Cursor = bitutil.Advance(Ct_Cursor)
361                Ct_errors |= Ct_Cursor & ~ lex.Hyphen
362                # Advance twice past <!--, so that we don't treat <!---
363                # as being a terminated comment.
364                Ct_Cursor = bitutil.Advance(bitutil.Advance(Ct_Cursor))
365                PI_Cursor = bitutil.Advance(PI_Cursor)
366                ctCDPI_Callouts.PI_name_starts |= PI_Cursor
367                PI_name_end = bitutil.ScanThru(PI_Cursor, lex.NameScan)
368                ctCDPI_Callouts.PI_name_ends |= PI_name_end
369                PI_Cursor = bitutil.ScanTo(PI_name_end, PI_end)
370                CD_Cursor = bitutil.ScanTo(CD_Cursor, ctCDPI_Callouts.CD_end)
371                Ct_Cursor = bitutil.Advance(bitutil.ScanTo(Ct_Cursor, DoubleHyphen))
372                ctCDPI_Callouts.PI_ends |= PI_Cursor
373                ctCDPI_Callouts.CD_ends |= CD_Cursor
374                ctCDPI_Callouts.Ct_ends |= Ct_Cursor
375                CtCDPI_Cursor = PI_Cursor | CD_Cursor | Ct_Cursor
376                CtCDPI_Cursor = bitutil.ScanTo(CtCDPI_Cursor, CtCDPI_start)
377
378                ctCDPI_Callouts.CtCDPI_mask = bitutil.Advance(ctCDPI_Callouts.CD_ends | ctCDPI_Callouts.Ct_ends | ctCDPI_Callouts.PI_ends) - CtCDPI_starts
379                #ctCDPI_Callouts.error = Ct_ends & ~lex.RAngle | Ct_starts & ~ lex.Hyphen
380                ctCDPI_error = Ct_errors | ctCDPI_Callouts.Ct_ends & ~lex.RAngle
381                ctCDPI_error |= bitutil.Advance(ctCDPI_Callouts.PI_name_ends & ~ lex.WS) & ~ PI_end
382                ctCDPI_error |= ctCDPI_Callouts.PI_name_starts & ctCDPI_Callouts.PI_name_ends
383                # If any of the Comment, CDATA or PI markups are unterminated, it is an error.
384                ctCDPI_error |= ctCDPI_Callouts.CtCDPI_mask &~ EOF_mask
385
386        if ctCDPI_error:
387                error_tracker.NoteError("Error in comment, CDATA or processing instruction syntax", ctCDPI_error)
388
389        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
390
391def Parse_tags(lex, scope1, ctCDPI_Callouts, tag_Callouts):
392
393
394        # Delimiters for scans.
395        DQuoteDelim = lex.DQuote | lex.LAngle
396        SQuoteDelim = lex.SQuote | lex.LAngle
397        AttListDelim = lex.Slash | lex.RAngle
398
399        # Start the parallel parsing by inspecting the character
400        # after the opening "<" of a tag.
401        LAngleFollow = scope1.LAngle &~ ctCDPI_Callouts.CtCDPI_mask
402        tag_Callouts.ElemName_starts = LAngleFollow & ~lex.Slash
403        tag_Callouts.EndTag_marks = LAngleFollow & lex.Slash
404
405        # Start Tag/Empty Element Tag Parsing
406
407        # Advance all cursors by scanning through the tag name.
408        tag_Callouts.ElemName_ends = bitutil.ScanThru(tag_Callouts.ElemName_starts, lex.NameScan)
409        # Must have at least one name character for a legal start tag.
410        # Mark any occurrences of null names as errors.
411        ParseError = tag_Callouts.ElemName_starts & tag_Callouts.ElemName_ends
412
413        # Initialize the accumulators for attribute name and value positions.
414        tag_Callouts.AttName_starts = 0
415        tag_Callouts.AttName_ends = 0
416        EqToCheck = 0
417        tag_Callouts.AttVal_starts = 0
418        AttValEnds = 0
419        tag_Callouts.AttVal_ends = 0
420
421        # After the element name, there may or may not be an attlist.
422        AfterWS = bitutil.ScanThru(tag_Callouts.ElemName_ends, lex.WS)
423        AttListEnd = AfterWS & AttListDelim
424        AttNameStart = AfterWS & ~AttListDelim
425        # At least one WS character is required between ElemNames and AttNames.
426        ParseError |= tag_Callouts.ElemName_ends & AttNameStart
427
428        #
429        # The following loop iterates through attributes within a start tag.
430        # Because all start tags are processed in parallel, the number of
431        # iterations is the maximum number of attributes found in any one
432        # start tag, plus one.
433        while AttNameStart:
434                tag_Callouts.AttName_starts |= AttNameStart
435                AttNameFollow = bitutil.ScanThru(AttNameStart, lex.NameScan)
436                tag_Callouts.AttName_ends |= AttNameFollow
437                # Scan through WS to the expected '=' delimiter.
438                # EqExpected = bitutil.ScanThru(AttNameFollow, lex.WS)
439                # But use if test to optimize.
440                if AttNameFollow & lex.WS:
441                        EqExpected = bitutil.ScanThru(AttNameFollow, lex.WS)
442                else: EqExpected = AttNameFollow
443                EqToCheck |= EqExpected
444                AttValPos = bitutil.ScanThru(EqExpected, EqExpected | lex.WS)
445                tag_Callouts.AttVal_starts |= AttValPos
446                DQuoteAttVal = AttValPos & lex.DQuote
447                SQuoteAttVal = AttValPos & lex.SQuote
448                DQuoteAttEnd = bitutil.ScanTo(DQuoteAttVal, DQuoteDelim &~ DQuoteAttVal)
449                SQuoteAttEnd = bitutil.ScanTo(SQuoteAttVal, SQuoteDelim &~ SQuoteAttVal)
450                AttValEnd = DQuoteAttEnd | SQuoteAttEnd
451                AttValEnds |= AttValEnd
452                AttValFollow = bitutil.Advance(AttValEnd)
453                tag_Callouts.AttVal_ends |= AttValFollow
454                #  AfterWS = bitutil.ScanThru(AttValFollow, lex.WS)
455                if AttValFollow & lex.WS:
456                        AfterWS = bitutil.ScanThru(AttValFollow, lex.WS)
457                else: AfterWS = AttValFollow
458                AfterWS = bitutil.ScanThru(AttValFollow, lex.WS)
459                AttListEnd |= AfterWS & AttListDelim
460                AttNameStart = AfterWS & ~AttListDelim
461
462        # No more attribute values to process when AttNameStart == 0.
463        STagEnds = AttListEnd & lex.RAngle
464        # Mark any "/" characters found as the ends of empty element tags.
465        tag_Callouts.EmptyTag_marks = bitutil.Advance(AttListEnd & lex.Slash)
466
467        # Check for errors.
468        ParseError |= tag_Callouts.AttVal_ends & tag_Callouts.AttName_starts # No intervening WS.
469        ParseError |= tag_Callouts.AttName_starts & tag_Callouts.AttName_ends # Null AttName
470        ParseError |= EqToCheck & ~lex.Equals # = not found where expected.
471        ParseError |= tag_Callouts.AttVal_starts & ~ (lex.DQuote | lex.SQuote)
472        ParseError |= AttValEnds & ~ (lex.DQuote | lex.SQuote)
473        ParseError |= tag_Callouts.EmptyTag_marks & ~lex.RAngle
474
475        # End Tag Parsing
476
477        EndTagEnds = bitutil.ScanThru(tag_Callouts.EndTag_marks, tag_Callouts.EndTag_marks | lex.NameScan)
478        if EndTagEnds & lex.WS:
479                EndTagEnds = bitutil.ScanThru(EndTagEnds, lex.WS)
480        ParseError |= EndTagEnds & ~lex.RAngle
481        if ParseError:
482                error_tracker.NoteError("Tag parsing error found", (ParseError))
483
484
485        # Attribute value spans
486        tag_Callouts.AttVal_spans = tag_Callouts.AttVal_ends - tag_Callouts.AttVal_starts
487
488def Parse_refs(lex, scope1, ctCDPI_Callouts, ref_Callouts):
489        ref_Callouts.GenRef_starts = 0
490        ref_Callouts.GenRef_ends = 0
491        ref_Callouts.DecRef_starts = 0
492        ref_Callouts.DecRef_ends = 0
493        ref_Callouts.HexRef_starts = 0
494        ref_Callouts.HexRef_ends = 0
495        ref_error = 0
496
497        Ref1 = lex.RefStart &~ ctCDPI_Callouts.CtCDPI_mask
498        # All remaining "&" must be reference start characters; parse them.
499        if Ref1:
500                scope1.RefStart = bitutil.Advance(Ref1)
501                NumRef2 = scope1.RefStart & lex.Hash
502                ref_Callouts.GenRef_starts = scope1.RefStart &~ lex.Hash
503                NumRef3 = bitutil.Advance(NumRef2)
504                HexRef3 = NumRef3 & lex.x
505                ref_Callouts.DecRef_starts = NumRef3 &~ lex.x
506                ref_Callouts.HexRef_starts = bitutil.Advance(HexRef3)
507                ref_Callouts.GenRef_ends = bitutil.ScanThru(ref_Callouts.GenRef_starts, lex.NameScan)
508                ref_Callouts.DecRef_ends = bitutil.ScanThru(ref_Callouts.DecRef_starts, lex.Digit)
509                ref_Callouts.HexRef_ends = bitutil.ScanThru(ref_Callouts.HexRef_starts, lex.Hex)
510                # Error checks
511                # At least one digit required for DecRef, one hex digit for HexRef.
512                ref_error1 = ref_Callouts.DecRef_starts &~ lex.Digit
513                ref_error2 = ref_Callouts.HexRef_starts &~ lex.Hex
514                # Semicolon terminator required (also covers unterminated at EOF).
515                ref_ends = ref_Callouts.GenRef_ends | ref_Callouts.DecRef_ends | ref_Callouts.HexRef_ends
516                ref_error3 = ref_ends &~ lex.Semicolon
517                ref_error = ref_error1 | ref_error2 | ref_error3
518                if ref_error:
519                        error_tracker.NoteError("Reference error found", (ref_error))
520
521
522
523def Validate_xml_names(ctCDPI_Callouts, ref_Callouts, tag_Callouts, lex, u8, xml_names, check_streams):
524        PI_names = ctCDPI_Callouts.PI_name_ends - ctCDPI_Callouts.PI_name_starts
525        GenRefs = ref_Callouts.GenRef_ends - ref_Callouts.GenRef_starts
526        ElemNames = tag_Callouts.ElemName_ends - tag_Callouts.ElemName_starts
527        AttNames = tag_Callouts.AttName_ends - tag_Callouts.AttName_starts
528        qname_stream =  ElemNames | AttNames
529        ncname_stream = PI_names | GenRefs
530        name_stream = qname_stream | ncname_stream
531        name_start = name_stream &~ bitutil.Advance(name_stream)
532        name_cursor = name_stream & ~bitutil.Advance(name_stream)
533        void_prefix_err = name_cursor & lex.Colon
534        namespace_sep = bitutil.ScanThru(name_cursor, lex.NameScan &~ lex.Colon) & lex.Colon
535        local_part_start = bitutil.Advance(namespace_sep)
536        local_part_err = local_part_start &~ lex.NameScan
537        colon2_err = bitutil.ScanThru(local_part_start, lex.NameScan &~ lex.Colon) & lex.Colon
538        ncname_err = ncname_stream & lex.Colon
539        namespace_error = void_prefix_err | local_part_err | colon2_err | ncname_err
540        if namespace_error:
541                error_tracker.NoteError("error found", namespace_error)
542
543
544        check_streams.non_ascii_name_starts = name_start &~lex.ASCII_name_start
545        check_streams.non_ascii_names = (name_stream &~ name_start) & ~lex.ASCII_name_char & ~u8.suffix
546
547def Do_check_streams(ctCDPI_Callouts, tag_Callouts, lex, u8, scope1, ref_Callouts, xml_names, check_streams):
548    # Ensure that no occurrence of ]]> occurs outside of markup.
549    CD_end_error = ctCDPI_Callouts.CD_end & ~(ctCDPI_Callouts.CtCDPI_mask | tag_Callouts.AttVal_spans)
550
551    # Consolidate and check for errors
552    if CD_end_error:
553                error_tracker.NoteError("Error: ]]> in text", CD_end_error)
554
555
556    check_streams.tag_marks = tag_Callouts.EmptyTag_marks | tag_Callouts.ElemName_starts | tag_Callouts.EndTag_marks | tag_Callouts.AttName_starts
557    check_streams.name_follows = tag_Callouts.ElemName_ends | tag_Callouts.AttName_ends
558    check_streams.att_refs = tag_Callouts.AttVal_spans & scope1.RefStart
559
560def Form_Length_Group_Bitstreams(tag_Callouts):
561
562    starts = tag_Callouts.ElemName_starts
563    remaining_ends = tag_Callouts.ElemName_ends
564
565    # Group symbols of length 1
566    starts_1 = bitutil.Advance(starts)
567    tag_Callouts.ElemName_ends_1 = starts_1 & remaining_ends
568    remaining_ends = remaining_ends & ~tag_Callouts.ElemName_ends_1
569
570    # Group symbols of length 2
571    starts_2 = bitutil.Advance(starts_1)
572    tag_Callouts.ElemName_ends_2 = starts_2 & remaining_ends
573    remaining_ends = remaining_ends & ~tag_Callouts.ElemName_ends_2
574
575    # Group symbols of length 3_to_4
576    temp = starts_1 | starts_2
577    temp32 = bitutil.Advance32(temp)
578    #starts_3_to_4 = bitutil.Advance(bitutil.Advance(temp))
579    starts_3_to_4 = interpose32 (temp, temp32, 2)
580    tag_Callouts.ElemName_ends_3_to_4 = starts_3_to_4 & remaining_ends
581    remaining_ends = remaining_ends & ~tag_Callouts.ElemName_ends_3_to_4
582
583    # Group symbols of length 5_to_8
584    temp = temp | starts_3_to_4
585    temp32 = bitutil.Advance32(temp)
586    #starts_5_to_8 = bitutil.Advance(bitutil.Advance(bitutil.Advance(bitutil.Advance(temp))))
587    starts_5_to_8 = interpose32 (temp, temp32, 4)
588    tag_Callouts.ElemName_ends_5_to_8 = starts_5_to_8 & remaining_ends
589    remaining_ends = remaining_ends & ~tag_Callouts.ElemName_ends_5_to_8
590
591    # Group symbols of length 9_to_16
592    temp = temp | starts_5_to_8
593    temp32 = bitutil.Advance32 (temp)
594    #starts_9_to_16 = bitutil.Advance(bitutil.Advance(bitutil.Advance(bitutil.Advance(bitutil.Advance(bitutil.Advance(bitutil.Advance(bitutil.Advance(temp))))))))
595    starts_9_to_16 = interpose32 (temp, temp32, 8)
596    tag_Callouts.ElemName_ends_9_to_16 = starts_9_to_16 & remaining_ends
597    remaining_ends = remaining_ends & ~tag_Callouts.ElemName_ends_9_to_16
598
599    # Group symbols of length 17 and longer
600    tag_Callouts.ElemName_ends_17_and_longer = remaining_ends
601
602
603def Compute_Hash_Value_Bitstream(hash_data, basis_bits):
604    hash_data.Hash_value = basis_bits.bit_2 ^ basis_bits.bit_4 ^ basis_bits.bit_6
605    #hash_data.Hash_value = basis_bits.bit_3 ^ basis_bits.bit_5 ^ basis_bits.bit_7
606
607#def main(basis_bits, lex, u8, scope1, ctCDPI_Callouts, masks, check_streams, tag_Callouts, ref_Callouts, xml_names):
608def Main(basis_bits, lex, u8, xml_char, scope1, ctCDPI_Callouts, ref_Callouts, tag_Callouts, masks, xml_names, check_streams, hash_data):
609       
610        # Classify bytes for UTF-8 processing, whitespace and control
611        # processing and XML lexical analysis.
612        # Classify_bytes(basis_bits, lex)
613
614        # Validate UTF-8 multibyte sequences and determine the UTF-8 scope streams
615        # Validate_utf8(basis_bits, u8)
616                               
617        Classify_bytes_Validate_utf8(basis_bits, lex, u8)
618
619        Add_scope_streams(lex, scope1)
620   
621        # Parse all comments, CDATA sections and processing instructions.
622        Parse_CtCDPI(ctCDPI_Callouts, lex, scope1, check_streams)
623               
624        # All remaining '<' must be tag start characters; parse tags.
625        Parse_tags(lex, scope1, ctCDPI_Callouts, tag_Callouts) 
626
627        # All remaining '&' must be reference start characters; parse them.
628        Parse_refs(lex, scope1, ctCDPI_Callouts, ref_Callouts)
629       
630        # Validate XML namespaces and generate bit streams to post validate non-ascii range XML names
631        Validate_xml_names(ctCDPI_Callouts, ref_Callouts, tag_Callouts, lex, u8, xml_names, check_streams)
632   
633   
634        Do_check_streams(ctCDPI_Callouts, tag_Callouts, lex, u8, scope1, ref_Callouts, xml_names, check_streams)
635
636        # These methods are needed to do Paralel Bitstream Based Length Sorting
637        Form_Length_Group_Bitstreams(tag_Callouts)
638
639        Compute_Hash_Value_Bitstream(hash_data, basis_bits);
640               
Note: See TracBrowser for help on using the repository browser.