source: proto/xmlschema/parabix2_validation.py @ 3218

Last change on this file since 3218 was 2219, checked in by shiyangy, 7 years ago

project checkin

File size: 24.8 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 = 0
113        ElemName_ends_4 = 0
114        ElemName_ends_5 = 0
115        ElemName_ends_6 = 0
116        ElemName_ends_7 = 0
117        ElemName_ends_8 = 0
118        ElemName_ends_9 = 0
119        ElemName_ends_10 = 0
120        ElemName_ends_11 = 0
121        ElemName_ends_12 = 0
122        ElemName_ends_13 = 0
123        ElemName_ends_14 = 0
124        ElemName_ends_15 = 0
125        ElemName_ends_16 = 0
126        ElemName_ends_17_and_longer = 0
127        AttName_starts = 0
128        AttName_ends = 0
129        AttVal_starts = 0
130        AttVal_ends = 0
131        AttVal_spans = 0
132        EmptyTag_marks = 0
133        EndTag_marks = 0
134       
135        Tag_closing = 0
136
137class Basis_bits():
138        bit_0 = 0
139        bit_1 = 0
140        bit_2 = 0
141        bit_3 = 0
142        bit_4 = 0
143        bit_5 = 0
144        bit_6 = 0
145        bit_7 = 0
146
147class Check_streams():
148        misc_mask = 0
149        non_ascii_name_starts = 0
150        non_ascii_names = 0
151        tag_marks = 0
152        name_follows = 0
153        att_refs = 0
154
155class Xml_names():
156        namespace_error = 0
157       
158class elem():
159        purchaseOrder = 0
160        shipTo =0
161        name =0
162        street =0
163        city =0
164        state =0
165        zip =0
166        billTo =0
167        comment =0
168        items =0
169        item =0
170        productName =0
171        quantity =0
172        USPrice =0
173        shipDate =0
174
175def Classify_bytes_Validate_utf8(basis_bits, lex, u8):
176        temp1 = (basis_bits.bit_0 | basis_bits.bit_1);
177        temp2 = (basis_bits.bit_2 &~ basis_bits.bit_3);
178        temp3 = (temp2 &~ temp1);
179        temp4 = (basis_bits.bit_5 &~ basis_bits.bit_4);
180        temp5 = (basis_bits.bit_6 &~ basis_bits.bit_7);
181        temp6 = (temp4 & temp5);
182        lex.RefStart = (temp3 & temp6);
183        temp7 = (basis_bits.bit_2 & basis_bits.bit_3);
184        temp8 = (temp7 &~ temp1);
185        temp9 = (basis_bits.bit_4 &~ basis_bits.bit_5);
186        temp10 = (basis_bits.bit_6 & basis_bits.bit_7);
187        temp11 = (temp9 & temp10);
188        lex.Semicolon = (temp8 & temp11);
189        temp12 = (basis_bits.bit_4 & basis_bits.bit_5);
190        temp13 = (basis_bits.bit_6 | basis_bits.bit_7);
191        temp14 = (temp12 &~ temp13);
192        lex.LAngle = (temp8 & temp14);
193        temp15 = (temp12 & temp5);
194        lex.RAngle = (temp8 & temp15);
195        temp16 = (basis_bits.bit_1 &~ basis_bits.bit_0);
196        temp17 = (basis_bits.bit_3 &~ basis_bits.bit_2);
197        temp18 = (temp16 & temp17);
198        lex.LBracket = (temp18 & temp11);
199        temp19 = (basis_bits.bit_7 &~ basis_bits.bit_6);
200        temp20 = (temp12 & temp19);
201        lex.RBracket = (temp18 & temp20);
202        temp21 = (basis_bits.bit_4 | basis_bits.bit_5);
203        temp22 = (temp19 &~ temp21);
204        lex.Exclam = (temp3 & temp22);
205        temp23 = (temp12 & temp10);
206        lex.QMark = (temp8 & temp23);
207        lex.Hyphen = (temp3 & temp20);
208        lex.Equals = (temp8 & temp20);
209        temp24 = (temp4 & temp10);
210        lex.SQuote = (temp3 & temp24);
211        temp25 = (temp5 &~ temp21);
212        lex.DQuote = (temp3 & temp25);
213        lex.Slash = (temp3 & temp23);
214        temp26 = (temp10 &~ temp21);
215        lex.Hash = (temp3 & temp26);
216        temp27 = (temp16 & temp7);
217        temp28 = (temp9 &~ temp13);
218        lex.x = (temp27 & temp28);
219        temp29 = (temp9 & temp5);
220        lex.Colon = (temp8 & temp29);
221        temp30 = (temp18 & temp23);
222        temp31 = (temp30 | lex.Colon);
223        temp32 = (temp16 &~ basis_bits.bit_2);
224        temp33 = (basis_bits.bit_5 | temp10);
225        temp34 = (basis_bits.bit_4 & temp33);
226        temp35 = (~temp34);
227        temp36 = (temp21 | temp13);
228        temp37 = ((basis_bits.bit_3 & temp35)|(~(basis_bits.bit_3) & temp36));
229        temp38 = (temp32 & temp37);
230        temp39 = (temp31 | temp38);
231        temp40 = (temp16 & basis_bits.bit_2);
232        temp41 = (temp40 & temp37);
233        lex.ASCII_name_start = (temp39 | temp41);
234        temp42 = (temp30 | lex.Hyphen);
235        temp43 = (temp3 & temp15);
236        temp44 = (temp42 | temp43);
237        temp45 = (temp8 &~ temp34);
238        temp46 = (temp44 | temp45);
239        temp47 = (temp46 | temp38);
240        lex.ASCII_name_char = (temp47 | temp41);
241        lex.NameScan = (lex.ASCII_name_char | basis_bits.bit_0);
242        temp48 = (temp1 | basis_bits.bit_2);
243        x00_x1F = (~temp48);
244        temp49 = (basis_bits.bit_2 | basis_bits.bit_3);
245        temp50 = (temp1 | temp49);
246        lex.CR = (temp20 &~ temp50);
247        lex.LF = (temp29 &~ temp50);
248        temp51 = (temp9 & temp19);
249        lex.HT = (temp51 &~ temp50);
250        lex.SP = (temp3 &~ temp36);
251        temp52 = (temp20 | temp29);
252        temp53 = (temp52 | temp51);
253        temp54 = (temp53 &~ temp50);
254        lex.WS = (temp54 | lex.SP);
255        temp55 = (basis_bits.bit_5 | basis_bits.bit_6);
256        temp56 = (basis_bits.bit_4 & temp55);
257        lex.Digit = (temp8 &~ temp56);
258        temp57 = (temp16 &~ temp49);
259        temp58 = (temp57 &~ basis_bits.bit_4);
260        temp59 = (~temp10);
261        temp60 = ((basis_bits.bit_5 & temp59)|(~(basis_bits.bit_5) & temp13));
262        temp61 = (temp58 & temp60);
263        temp62 = (lex.Digit | temp61);
264        temp63 = (temp16 & temp2);
265        temp64 = (temp63 &~ basis_bits.bit_4);
266        temp65 = (temp64 & temp60);
267        lex.Hex = (temp62 | temp65);
268        lex_error = x00_x1F &~ lex.WS
269        if lex_error & EOF_mask:
270                error_tracker.NoteError("Error: illegal character", lex_error)
271
272
273        ### Validate_utf8(basis_bits, u8):
274        u8.unibyte = (~basis_bits.bit_0);
275        u8.suffix = 0
276        u8_error = 0
277        u8_FFFE_FFFF = 0
278        u8anyscope = 0 #local
279        if basis_bits.bit_0:
280                u8.prefix = (basis_bits.bit_0 & basis_bits.bit_1);
281                u8.prefix2 = (u8.prefix &~ basis_bits.bit_2);
282                u8.prefix3 = (u8.prefix & temp2);
283                u8.prefix4 = (u8.prefix & temp7);
284                u8.suffix = (basis_bits.bit_0 &~ basis_bits.bit_1);
285                temp66 = (u8.prefix &~ temp49);
286                temp67 = (temp21 | basis_bits.bit_6);
287                temp68 = (temp66 &~ temp67);
288                temp69 = (basis_bits.bit_5 & temp13);
289                temp70 = (basis_bits.bit_4 | temp69);
290                temp71 = (u8.prefix4 & temp70);
291                u8.badprefix = (temp68 | temp71);
292                u8_error = u8.badprefix
293                u8.scope22 = pablo.Advance(u8.prefix2)
294                u8anyscope = u8.scope22
295                if u8.prefix3 | u8.prefix4:
296                        xE0 = (u8.prefix3 &~ temp36);
297                        xED = (u8.prefix3 & temp20);
298                        xF0 = (u8.prefix4 &~ temp36);
299                        temp72 = (temp4 &~ temp13);
300                        xF4 = (u8.prefix4 & temp72);
301                        u8.xA0_xBF = (u8.suffix & basis_bits.bit_2);
302                        u8.x80_x9F = (u8.suffix &~ basis_bits.bit_2);
303                        u8.x90_xBF = (u8.suffix & temp49);
304                        u8.x80_x8F = (u8.suffix &~ temp49);
305                        xEF = (u8.prefix3 & temp23);
306                        temp73 = (u8.suffix & temp7);
307                        u8.xBF = (temp73 & temp23);
308                        u8.xBE = (temp73 & temp15);
309                        u8.xE0_scope = pablo.Advance(xE0);
310                        u8.xED_scope = pablo.Advance(xED);
311                        u8.xF0_scope = pablo.Advance(xF0);
312                        u8.xF4_scope = pablo.Advance(xF4);
313                        u8.xEF_scope = pablo.Advance(xEF);
314                        u8.scope32 = pablo.Advance(u8.prefix3)
315                        u8.scope33 = pablo.Advance(u8.scope32)
316                        u8.scope42 = pablo.Advance(u8.prefix4)
317                        u8.scope43 = pablo.Advance(u8.scope42)
318                        u8.scope44 = pablo.Advance(u8.scope43)
319
320                        u8lastscope = u8.scope22 | u8.scope33 | u8.scope44
321                        u8anyscope = u8lastscope | u8.scope32 | u8.scope42 | u8.scope43
322
323                        u8error1 = u8.xE0_scope & u8.x80_x9F
324                        u8error2 = u8.xED_scope & u8.xA0_xBF
325                        u8error3 = u8.xF0_scope & u8.x80_x8F
326                        u8error4 = u8.xF4_scope & u8.x90_xBF
327
328                        u8_error |= u8error1 | u8error2 | u8error3 | u8error4
329
330                        EF_BF_pending = pablo.Advance(u8.xEF_scope & u8.xBF)
331
332                        u8_FFFE_FFFF = (EF_BF_pending & (u8.xBE | u8.xBF))
333                u8mismatch = u8anyscope ^ u8.suffix
334                u8_error |= u8mismatch | u8_FFFE_FFFF
335                if u8_error:
336                        error_tracker.NoteError("UTF-8 error found", (u8_error))
337
338
339def Add_scope_streams(lex, scope1):
340        #scope1.LAngle = pablo.Advance(lex.LAngle)
341        #scope1.Hyphen = pablo.Advance(lex.Hyphen)
342        #scope1.QMark = pablo.Advance(lex.QMark)
343        v = lex.LAngle | lex.Hyphen
344        w = lex.Hyphen | lex.QMark
345        v1 = pablo.Advance(v)
346        w1 = pablo.Advance(w)
347        scope1.LAngle = v1 &~ w1
348        scope1.Hyphen = v1 & w1
349        scope1.QMark = w1 &~ v1
350        scope1.RefStart = 0 # default
351
352def Parse_CtCDPI(ctCDPI_Callouts, lex, scope1, check_streams):
353        ctCDPI_Callouts.CD_end = 0
354        ctCDPI_Callouts.Ct_starts = 0
355        ctCDPI_Callouts.Ct_ends = 0
356        ctCDPI_Callouts.CD_starts = 0
357        ctCDPI_Callouts.CD_ends = 0
358        ctCDPI_Callouts.PI_starts = 0
359        ctCDPI_Callouts.PI_name_starts = 0
360        ctCDPI_Callouts.PI_name_ends = 0
361        ctCDPI_Callouts.PI_ends = 0
362        ctCDPI_Callouts.CtCDPI_mask = 0
363        ctCDPI_error = 0
364        CtCDPI_starts = 0
365        Ct_errors = 0
366
367        if lex.RBracket:
368                scope1.RBracket = pablo.Advance(lex.RBracket)
369                ctCDPI_Callouts.CD_end = pablo.Advance(scope1.RBracket & lex.RBracket) & lex.RAngle
370        PI_start = scope1.LAngle & lex.QMark
371        CtCD_start = scope1.LAngle & lex.Exclam
372        CtCDPI_start = PI_start | CtCD_start
373
374        DoubleHyphen = scope1.Hyphen & lex.Hyphen
375        PI_end = scope1.QMark & lex.RAngle
376
377
378        #
379        # Initiate the scan
380        CtCDPI_Cursor = pablo.ScanToFirst(CtCDPI_start)
381        while CtCDPI_Cursor:
382                CtCDPI_starts |= CtCDPI_Cursor
383                PI_Cursor = CtCDPI_Cursor & PI_start
384                CD_Ct_Cursor = pablo.Advance(CtCDPI_Cursor & ~PI_Cursor)
385                CD_Cursor = CD_Ct_Cursor & lex.LBracket
386                Ct_Cursor = CD_Ct_Cursor & lex.Hyphen
387                ctCDPI_Callouts.PI_starts |= PI_Cursor
388                ctCDPI_Callouts.CD_starts |= CD_Cursor
389                ctCDPI_Callouts.Ct_starts |= Ct_Cursor
390                Ct_Cursor = pablo.Advance(Ct_Cursor)
391                Ct_errors |= Ct_Cursor & ~ lex.Hyphen
392                # Advance twice past <!--, so that we don't treat <!---
393                # as being a terminated comment.
394                Ct_Cursor = pablo.Advance(pablo.Advance(Ct_Cursor))
395                PI_Cursor = pablo.Advance(PI_Cursor)
396                ctCDPI_Callouts.PI_name_starts |= PI_Cursor
397                PI_name_end = pablo.ScanThru(PI_Cursor, lex.NameScan)
398                ctCDPI_Callouts.PI_name_ends |= PI_name_end
399                PI_Cursor = pablo.ScanTo(PI_name_end, PI_end)
400                CD_Cursor = pablo.ScanTo(CD_Cursor, ctCDPI_Callouts.CD_end)
401                Ct_Cursor = pablo.Advance(pablo.ScanTo(Ct_Cursor, DoubleHyphen))
402                ctCDPI_Callouts.PI_ends |= PI_Cursor
403                ctCDPI_Callouts.CD_ends |= CD_Cursor
404                ctCDPI_Callouts.Ct_ends |= Ct_Cursor
405                CtCDPI_Cursor = PI_Cursor | CD_Cursor | Ct_Cursor
406                CtCDPI_Cursor = pablo.ScanTo(CtCDPI_Cursor, CtCDPI_start)
407
408                ctCDPI_Callouts.CtCDPI_mask = pablo.Advance(ctCDPI_Callouts.CD_ends | ctCDPI_Callouts.Ct_ends | ctCDPI_Callouts.PI_ends) - CtCDPI_starts
409                #ctCDPI_Callouts.error = Ct_ends & ~lex.RAngle | Ct_starts & ~ lex.Hyphen
410                ctCDPI_error = Ct_errors | ctCDPI_Callouts.Ct_ends & ~lex.RAngle
411                ctCDPI_error |= pablo.Advance(ctCDPI_Callouts.PI_name_ends & ~ lex.WS) & ~ PI_end
412                ctCDPI_error |= ctCDPI_Callouts.PI_name_starts & ctCDPI_Callouts.PI_name_ends
413                # If any of the Comment, CDATA or PI markups are unterminated, it is an error.
414                ctCDPI_error |= ctCDPI_Callouts.CtCDPI_mask &~ EOF_mask
415
416        if ctCDPI_error:
417                error_tracker.NoteError("Error in comment, CDATA or processing instruction syntax", ctCDPI_error)
418
419        check_streams.misc_mask = (lex.WS | lex.LAngle | (pablo.Advance(ctCDPI_Callouts.Ct_ends | ctCDPI_Callouts.PI_ends) - (ctCDPI_Callouts.Ct_starts | ctCDPI_Callouts.PI_starts)) | CtCDPI_starts) & EOF_mask
420
421def Parse_tags(lex, scope1, ctCDPI_Callouts, tag_Callouts):
422
423
424        # Delimiters for scans.
425        DQuoteDelim = lex.DQuote | lex.LAngle
426        SQuoteDelim = lex.SQuote | lex.LAngle
427        AttListDelim = lex.Slash | lex.RAngle
428
429        # Start the parallel parsing by inspecting the character
430        # after the opening "<" of a tag.
431        LAngleFollow = scope1.LAngle &~ ctCDPI_Callouts.CtCDPI_mask
432        tag_Callouts.ElemName_starts = LAngleFollow & ~lex.Slash
433        tag_Callouts.EndTag_marks = LAngleFollow & lex.Slash
434
435        # Start Tag/Empty Element Tag Parsing
436
437        # Advance all cursors by scanning through the tag name.
438        tag_Callouts.ElemName_ends = pablo.ScanThru(tag_Callouts.ElemName_starts, lex.NameScan)
439        # Must have at least one name character for a legal start tag.
440        # Mark any occurrences of null names as errors.
441        ParseError = tag_Callouts.ElemName_starts & tag_Callouts.ElemName_ends
442
443        # Initialize the accumulators for attribute name and value positions.
444        tag_Callouts.AttName_starts = 0
445        tag_Callouts.AttName_ends = 0
446        EqToCheck = 0
447        tag_Callouts.AttVal_starts = 0
448        AttValEnds = 0
449        tag_Callouts.AttVal_ends = 0
450
451        # After the element name, there may or may not be an attlist.
452        AfterWS = pablo.ScanThru(tag_Callouts.ElemName_ends, lex.WS)
453        AttListEnd = AfterWS & AttListDelim
454        AttNameStart = AfterWS & ~AttListDelim
455        # At least one WS character is required between ElemNames and AttNames.
456        ParseError |= tag_Callouts.ElemName_ends & AttNameStart
457
458        #
459        # The following loop iterates through attributes within a start tag.
460        # Because all start tags are processed in parallel, the number of
461        # iterations is the maximum number of attributes found in any one
462        # start tag, plus one.
463        while AttNameStart:
464                tag_Callouts.AttName_starts |= AttNameStart
465                AttNameFollow = pablo.ScanThru(AttNameStart, lex.NameScan)
466                tag_Callouts.AttName_ends |= AttNameFollow
467                # Scan through WS to the expected '=' delimiter.
468                # EqExpected = pablo.ScanThru(AttNameFollow, lex.WS)
469                # But use if test to optimize.
470                if AttNameFollow & lex.WS:
471                        EqExpected = pablo.ScanThru(AttNameFollow, lex.WS)
472                else: EqExpected = AttNameFollow
473                EqToCheck |= EqExpected
474                AttValPos = pablo.ScanThru(EqExpected, EqExpected | lex.WS)
475                tag_Callouts.AttVal_starts |= AttValPos
476                DQuoteAttVal = AttValPos & lex.DQuote
477                SQuoteAttVal = AttValPos & lex.SQuote
478                DQuoteAttEnd = pablo.ScanTo(DQuoteAttVal, DQuoteDelim &~ DQuoteAttVal)
479                SQuoteAttEnd = pablo.ScanTo(SQuoteAttVal, SQuoteDelim &~ SQuoteAttVal)
480                AttValEnd = DQuoteAttEnd | SQuoteAttEnd
481                AttValEnds |= AttValEnd
482                AttValFollow = pablo.Advance(AttValEnd)
483                tag_Callouts.AttVal_ends |= AttValFollow
484                #  AfterWS = pablo.ScanThru(AttValFollow, lex.WS)
485                if AttValFollow & lex.WS:
486                        AfterWS = pablo.ScanThru(AttValFollow, lex.WS)
487                else: AfterWS = AttValFollow
488                AfterWS = pablo.ScanThru(AttValFollow, lex.WS)
489                AttListEnd |= AfterWS & AttListDelim
490                AttNameStart = AfterWS & ~AttListDelim
491
492        # No more attribute values to process when AttNameStart == 0.
493        STagEnds = AttListEnd & lex.RAngle
494        # Mark any "/" characters found as the ends of empty element tags.
495        tag_Callouts.EmptyTag_marks = pablo.Advance(AttListEnd & lex.Slash)
496       
497        tag_Callouts.Tag_closing = tag_Callouts.EmptyTag_marks | tag_Callouts.EndTag_marks
498
499        # Check for errors.
500        ParseError |= tag_Callouts.AttVal_ends & tag_Callouts.AttName_starts # No intervening WS.
501        ParseError |= tag_Callouts.AttName_starts & tag_Callouts.AttName_ends # Null AttName
502        ParseError |= EqToCheck & ~lex.Equals # = not found where expected.
503        ParseError |= tag_Callouts.AttVal_starts & ~ (lex.DQuote | lex.SQuote)
504        ParseError |= AttValEnds & ~ (lex.DQuote | lex.SQuote)
505        ParseError |= tag_Callouts.EmptyTag_marks & ~lex.RAngle
506
507        # End Tag Parsing
508
509        EndTagEnds = pablo.ScanThru(tag_Callouts.EndTag_marks, tag_Callouts.EndTag_marks | lex.NameScan)
510        if EndTagEnds & lex.WS:
511                EndTagEnds = pablo.ScanThru(EndTagEnds, lex.WS)
512        ParseError |= EndTagEnds & ~lex.RAngle
513        if ParseError:
514                error_tracker.NoteError("Tag parsing error found", (ParseError))
515
516
517        # Attribute value spans
518        tag_Callouts.AttVal_spans = tag_Callouts.AttVal_ends - tag_Callouts.AttVal_starts
519
520def Parse_refs(lex, scope1, ctCDPI_Callouts, ref_Callouts):
521        ref_Callouts.GenRef_starts = 0
522        ref_Callouts.GenRef_ends = 0
523        ref_Callouts.DecRef_starts = 0
524        ref_Callouts.DecRef_ends = 0
525        ref_Callouts.HexRef_starts = 0
526        ref_Callouts.HexRef_ends = 0
527        ref_error = 0
528
529        Ref1 = lex.RefStart &~ ctCDPI_Callouts.CtCDPI_mask
530        # All remaining "&" must be reference start characters; parse them.
531        if Ref1:
532                scope1.RefStart = pablo.Advance(Ref1)
533                NumRef2 = scope1.RefStart & lex.Hash
534                ref_Callouts.GenRef_starts = scope1.RefStart &~ lex.Hash
535                NumRef3 = pablo.Advance(NumRef2)
536                HexRef3 = NumRef3 & lex.x
537                ref_Callouts.DecRef_starts = NumRef3 &~ lex.x
538                ref_Callouts.HexRef_starts = pablo.Advance(HexRef3)
539                ref_Callouts.GenRef_ends = pablo.ScanThru(ref_Callouts.GenRef_starts, lex.NameScan)
540                ref_Callouts.DecRef_ends = pablo.ScanThru(ref_Callouts.DecRef_starts, lex.Digit)
541                ref_Callouts.HexRef_ends = pablo.ScanThru(ref_Callouts.HexRef_starts, lex.Hex)
542                # Error checks
543                # At least one digit required for DecRef, one hex digit for HexRef.
544                ref_error1 = ref_Callouts.DecRef_starts &~ lex.Digit
545                ref_error2 = ref_Callouts.HexRef_starts &~ lex.Hex
546                # Semicolon terminator required (also covers unterminated at EOF).
547                ref_ends = ref_Callouts.GenRef_ends | ref_Callouts.DecRef_ends | ref_Callouts.HexRef_ends
548                ref_error3 = ref_ends &~ lex.Semicolon
549                ref_error = ref_error1 | ref_error2 | ref_error3
550                if ref_error:
551                        error_tracker.NoteError("Reference error found", (ref_error))
552
553
554
555def Validate_xml_names(ctCDPI_Callouts, ref_Callouts, tag_Callouts, lex, u8, xml_names, check_streams):
556        PI_names = ctCDPI_Callouts.PI_name_ends - ctCDPI_Callouts.PI_name_starts
557        GenRefs = ref_Callouts.GenRef_ends - ref_Callouts.GenRef_starts
558        ElemNames = tag_Callouts.ElemName_ends - tag_Callouts.ElemName_starts
559        AttNames = tag_Callouts.AttName_ends - tag_Callouts.AttName_starts
560        qname_stream =  ElemNames | AttNames
561        ncname_stream = PI_names | GenRefs
562        name_stream = qname_stream | ncname_stream
563        name_start = name_stream &~ pablo.Advance(name_stream)
564        name_cursor = name_stream & ~pablo.Advance(name_stream)
565        void_prefix_err = name_cursor & lex.Colon
566        namespace_sep = pablo.ScanThru(name_cursor, lex.NameScan &~ lex.Colon) & lex.Colon
567        local_part_start = pablo.Advance(namespace_sep)
568        local_part_err = local_part_start &~ lex.NameScan
569        colon2_err = pablo.ScanThru(local_part_start, lex.NameScan &~ lex.Colon) & lex.Colon
570        ncname_err = ncname_stream & lex.Colon
571        namespace_error = void_prefix_err | local_part_err | colon2_err | ncname_err
572        if namespace_error:
573                error_tracker.NoteError("error found", namespace_error)
574
575
576        check_streams.non_ascii_name_starts = name_start &~lex.ASCII_name_start
577        check_streams.non_ascii_names = (name_stream &~ name_start) & ~lex.ASCII_name_char & ~u8.suffix
578
579def Do_check_streams(ctCDPI_Callouts, tag_Callouts, lex, u8, scope1, ref_Callouts, xml_names, check_streams):
580    # Ensure that no occurrence of ]]> occurs outside of markup.
581    CD_end_error = ctCDPI_Callouts.CD_end & ~(ctCDPI_Callouts.CtCDPI_mask | tag_Callouts.AttVal_spans)
582
583    # Consolidate and check for errors
584    if CD_end_error:
585                error_tracker.NoteError("Error: ]]> in text", CD_end_error)
586
587
588    check_streams.tag_marks = tag_Callouts.EmptyTag_marks | tag_Callouts.ElemName_starts | tag_Callouts.EndTag_marks | tag_Callouts.AttName_starts
589    check_streams.name_follows = tag_Callouts.ElemName_ends | tag_Callouts.AttName_ends
590    check_streams.att_refs = tag_Callouts.AttVal_spans & scope1.RefStart
591
592
593def Form_Length_Group_Bitstreams(tag_Callouts):
594
595    remaining_starts = tag_Callouts.ElemName_starts
596    remaining_ends = tag_Callouts.ElemName_ends
597    temp = tag_Callouts.ElemName_starts
598
599    # Group symbols of length 1
600    temp = pablo.Advance(temp)
601    tag_Callouts.ElemName_ends_1 = temp & remaining_ends
602    remaining_ends = remaining_ends & ~tag_Callouts.ElemName_ends_1
603
604    # Group symbols of length 2
605    temp = pablo.Advance(temp)
606    tag_Callouts.ElemName_ends_2 = temp & remaining_ends
607    remaining_ends = remaining_ends & ~tag_Callouts.ElemName_ends_2
608
609    # Group symbols of length 3
610    temp = pablo.Advance(temp)
611    tag_Callouts.ElemName_ends_3 = temp & remaining_ends
612    remaining_ends = remaining_ends & ~tag_Callouts.ElemName_ends_3
613
614    # Group symbols of length 4
615    temp = pablo.Advance(temp)
616    tag_Callouts.ElemName_ends_4 = temp & remaining_ends
617    remaining_ends = remaining_ends & ~tag_Callouts.ElemName_ends_4
618
619    # Group symbols of length 5
620    temp = pablo.Advance(temp)
621    tag_Callouts.ElemName_ends_5 = temp & remaining_ends
622    remaining_ends = remaining_ends & ~tag_Callouts.ElemName_ends_5
623
624    # Group symbols of length 6
625    temp = pablo.Advance(temp)
626    tag_Callouts.ElemName_ends_6 = temp & remaining_ends
627    remaining_ends = remaining_ends & ~tag_Callouts.ElemName_ends_6
628
629    # Group symbols of length 7
630    temp = pablo.Advance(temp)
631    tag_Callouts.ElemName_ends_7 = temp & remaining_ends
632    remaining_ends = remaining_ends & ~tag_Callouts.ElemName_ends_7
633
634    # Group symbols of length 8
635    temp = pablo.Advance(temp)
636    tag_Callouts.ElemName_ends_8 = temp & remaining_ends
637    remaining_ends = remaining_ends & ~tag_Callouts.ElemName_ends_8
638
639    # Group symbols of length 9
640    temp = pablo.Advance(temp)
641    tag_Callouts.ElemName_ends_9 = temp & remaining_ends
642    remaining_ends = remaining_ends & ~tag_Callouts.ElemName_ends_9
643
644    # Group symbols of length 10
645    temp = pablo.Advance(temp)
646    tag_Callouts.ElemName_ends_10 = temp & remaining_ends
647    remaining_ends = remaining_ends & ~tag_Callouts.ElemName_ends_10
648
649    # Group symbols of length 11
650    temp = pablo.Advance(temp)
651    tag_Callouts.ElemName_ends_11 = temp & remaining_ends
652    remaining_ends = remaining_ends & ~tag_Callouts.ElemName_ends_11
653
654    # Group symbols of length 12
655    temp = pablo.Advance(temp)
656    tag_Callouts.ElemName_ends_12 = temp & remaining_ends
657    remaining_ends = remaining_ends & ~tag_Callouts.ElemName_ends_12
658
659    # Group symbols of length 13
660    temp = pablo.Advance(temp)
661    tag_Callouts.ElemName_ends_13 = temp & remaining_ends
662    remaining_ends = remaining_ends & ~tag_Callouts.ElemName_ends_13
663
664    # Group symbols of length 14
665    temp = pablo.Advance(temp)
666    tag_Callouts.ElemName_ends_14 = temp & remaining_ends
667    remaining_ends = remaining_ends & ~tag_Callouts.ElemName_ends_14
668
669    # Group symbols of length 15
670    temp = pablo.Advance(temp)
671    tag_Callouts.ElemName_ends_15 = temp & remaining_ends
672    remaining_ends = remaining_ends & ~tag_Callouts.ElemName_ends_15
673
674    # Group symbols of length 16
675    temp = pablo.Advance(temp)
676    tag_Callouts.ElemName_ends_16 = temp & remaining_ends
677    remaining_ends = remaining_ends & ~tag_Callouts.ElemName_ends_16
678
679    # Group symbols of length 17 and longer
680    tag_Callouts.ElemName_ends_17_and_longer = remaining_ends
681
682
683def Compute_Hash_Value_Bitstream(hash_data, basis_bits):
684    hash_data.Hash_value = basis_bits.bit_2 ^ basis_bits.bit_4 ^ basis_bits.bit_6
685    #hash_data.Hash_value = basis_bits.bit_3 ^ basis_bits.bit_5 ^ basis_bits.bit_7
686   
687def Validate_Elem_Vec(elem,basis_bits):
688        temp1 = (basis_bits.bit_0 | basis_bits.bit_1)
689        temp2 = (basis_bits.bit_2 | basis_bits.bit_3)
690        temp3 = (temp1 | temp2)
691        temp4 = (basis_bits.bit_4 | basis_bits.bit_5)
692        temp5 = (basis_bits.bit_7 &~ basis_bits.bit_6)
693        temp6 = (temp5 &~ temp4)
694        elem.purchaseOrder = (temp6 &~ temp3)
695        temp7 = (basis_bits.bit_6 &~ basis_bits.bit_7)
696        temp8 = (temp7 &~ temp4)
697        elem.shipTo = (temp8 &~ temp3)
698        temp9 = (basis_bits.bit_6 & basis_bits.bit_7)
699        temp10 = (temp9 &~ temp4)
700        elem.name = (temp10 &~ temp3)
701        temp11 = (basis_bits.bit_5 &~ basis_bits.bit_4)
702        temp12 = (basis_bits.bit_6 | basis_bits.bit_7)
703        temp13 = (temp11 &~ temp12)
704        elem.street = (temp13 &~ temp3)
705        temp14 = (temp11 & temp5)
706        elem.city = (temp14 &~ temp3)
707        temp15 = (temp11 & temp7)
708        elem.state = (temp15 &~ temp3)
709        temp16 = (temp11 & temp9)
710        elem.zip = (temp16 &~ temp3)
711        temp17 = (basis_bits.bit_4 &~ basis_bits.bit_5)
712        temp18 = (temp17 &~ temp12)
713        elem.billTo = (temp18 &~ temp3)
714        temp19 = (temp17 & temp5)
715        elem.comment = (temp19 &~ temp3)
716        temp20 = (temp17 & temp7)
717        elem.items = (temp20 &~ temp3)
718        temp21 = (temp17 & temp9)
719        elem.item = (temp21 &~ temp3)
720        temp22 = (basis_bits.bit_4 & basis_bits.bit_5)
721        temp23 = (temp22 &~ temp12)
722        elem.productName = (temp23 &~ temp3)
723        temp24 = (temp22 & temp5)
724        elem.quantity = (temp24 &~ temp3)
725        temp25 = (temp22 & temp7)
726        elem.USPrice = (temp25 &~ temp3)
727        temp26 = (temp22 & temp9)
728        elem.shipDate = (temp26 &~ temp3)
729
730
731def Main(basis_bits, lex, u8, xml_char, scope1, ctCDPI_Callouts, ref_Callouts, tag_Callouts, masks, xml_names, check_streams, hash_data):
732       
733        # Classify bytes for UTF-8 processing, whitespace and control
734        # processing and XML lexical analysis.
735        # Classify_bytes(basis_bits, lex)
736
737        # Validate UTF-8 multibyte sequences and determine the UTF-8 scope streams
738        # Validate_utf8(basis_bits, u8)
739                               
740        Classify_bytes_Validate_utf8(basis_bits, lex, u8)
741
742        Add_scope_streams(lex, scope1)
743   
744        # Parse all comments, CDATA sections and processing instructions.
745        Parse_CtCDPI(ctCDPI_Callouts, lex, scope1, check_streams)
746               
747        # All remaining '<' must be tag start characters; parse tags.
748        Parse_tags(lex, scope1, ctCDPI_Callouts, tag_Callouts) 
749
750        # All remaining '&' must be reference start characters; parse them.
751        Parse_refs(lex, scope1, ctCDPI_Callouts, ref_Callouts)
752       
753        # Validate XML namespaces and generate bit streams to post validate non-ascii range XML names
754        Validate_xml_names(ctCDPI_Callouts, ref_Callouts, tag_Callouts, lex, u8, xml_names, check_streams)
755   
756   
757        Do_check_streams(ctCDPI_Callouts, tag_Callouts, lex, u8, scope1, ref_Callouts, xml_names, check_streams)
758
759        # These methods are needed to do Paralel Bitstream Based Length Sorting
760        Form_Length_Group_Bitstreams(tag_Callouts)
761
762        Compute_Hash_Value_Bitstream(hash_data, basis_bits);
763       
764               
Note: See TracBrowser for help on using the repository browser.