source: proto/xmlschema/parabix2_symtab_pbs.py @ 3027

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

project checkin

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