source: proto/PDF/cb_pablo.py @ 3066

Last change on this file since 3066 was 3066, checked in by lindanl, 6 years ago

New comment and string parsing

File size: 22.3 KB
Line 
1# cb_pdf.py
2#
3# (c) 2012 Robert D. Cameron, Ken Herdy, Ben Hull, Dan Lin
4# All rights reserved.
5#
6import sys
7import pablo
8
9class Basis_bits():     
10        bit_0 = 0
11        bit_1 = 0
12        bit_2 = 0
13        bit_3 = 0
14        bit_4 = 0
15        bit_5 = 0
16        bit_6 = 0
17        bit_7 = 0
18
19class Parity():
20        odd = 0
21        even = 0
22
23class Lex ():
24        pdf_mod_bit_1 = 0
25        pdf_mod_bit_2 = 0
26        pdf_mod_bit_3 = 0
27        pdf_mod_bit_4 = 0
28        pdf_mod_bit_5 = 0
29        pdf_mod_bit_6 = 0
30        pdf_mod_bit_7 = 0
31        LParen = 0
32        RParen = 0
33        Backslash = 0
34        Special = 0
35        Percent = 0
36        Period = 0
37        LAngle = 0
38        RAngle = 0
39        LBracket = 0
40        RBracket = 0
41        Slash = 0
42        EOL = 0
43        WS = 0
44        Digit = 0
45        Sign = 0
46        Hex = 0
47        Hash = 0
48        CR = 0
49        LF = 0
50        Oct = 0
51        Nonoct = 0
52        Regular = 0
53       
54class Escape_Callouts():
55    LParen = 0
56    RParen = 0
57    Oct1 = 0
58    Oct2 = 0
59    Oct3 = 0
60    Nonoct = 0
61
62
63class Out_Callouts():
64    mask = 0
65    hex_opener = 0
66    zeromask = 0
67    delmask = 0
68    hexString_mask = 0
69    names_escapes = 0
70    bit_0 = 0
71    bit_1 = 0
72    bit_2 = 0
73    bit_3 = 0
74    bit_4 = 0
75    bit_5 = 0
76    bit_6 = 0
77    bit_7 = 0
78   
79class marker():
80    starts = 0
81    ends = 0
82    error = 0
83   
84   
85
86def Classify_bytes(basis_bits, lex):
87        temp1 = (basis_bits.bit_1 &~ basis_bits.bit_0)
88        temp2 = (basis_bits.bit_2 &~ basis_bits.bit_3)
89        temp3 = (temp1 & temp2)
90        temp4 = (basis_bits.bit_6 &~ basis_bits.bit_7)
91        temp5 = (basis_bits.bit_4 | basis_bits.bit_5)
92        temp6 = (basis_bits.bit_5 &~ basis_bits.bit_4)
93        temp7 = (temp5 &~ temp6)
94        temp8 = (basis_bits.bit_4 & basis_bits.bit_5)
95        temp9 = (temp7 &~ temp8)
96        temp10 = (temp4 &~ temp9)
97        temp11 = (temp3 & temp10)
98        temp12 = (basis_bits.bit_2 & basis_bits.bit_3)
99        temp13 = (temp1 & temp12)
100        temp14 = (temp4 &~ temp5)
101        temp15 = (temp13 & temp14)
102        temp16 = (temp11 | temp15)
103        temp17 = (basis_bits.bit_6 | basis_bits.bit_7)
104        temp18 = (temp6 &~ temp17)
105        temp19 = (temp13 & temp18)
106        lex.pdf_mod_bit_1 = (temp16 | temp19)
107        lex.pdf_mod_bit_2 = (temp16 | temp19)
108        temp20 = (temp14 | temp18)
109        lex.pdf_mod_bit_3 = (temp13 & temp20)
110        temp21 = (temp4 &~ temp7)
111        temp22 = (temp3 & temp21)
112        temp23 = (temp22 | temp15)
113        lex.pdf_mod_bit_4 = (temp23 | temp19)
114        temp24 = (temp8 & temp4)
115        temp25 = (temp3 & temp24)
116        temp26 = (temp25 | temp15)
117        lex.pdf_mod_bit_5 = (temp26 | temp19)
118        lex.pdf_mod_bit_6 = (temp22 | temp15)
119        lex.pdf_mod_bit_7 = (temp13 & temp20)
120        temp27 = (basis_bits.bit_0 | basis_bits.bit_1)
121        temp28 = (temp2 &~ temp27)
122        temp29 = (basis_bits.bit_4 &~ basis_bits.bit_5)
123        temp30 = (temp29 &~ temp17)
124        lex.LParen = (temp28 & temp30)
125        temp31 = (basis_bits.bit_7 &~ basis_bits.bit_6)
126        temp32 = (temp29 & temp31)
127        lex.RParen = (temp28 & temp32)
128        temp33 = (basis_bits.bit_3 &~ basis_bits.bit_2)
129        temp34 = (temp1 & temp33)
130        temp35 = (temp8 &~ temp17)
131        lex.Backslash = (temp34 & temp35)
132        temp36 = (temp17 &~ temp31)
133        temp37 = (temp29 &~ temp36)
134        temp38 = (temp28 & temp37)
135        temp39 = (temp12 &~ temp27)
136        temp40 = (temp39 & temp35)
137        temp41 = (temp38 | temp40)
138        temp42 = (temp39 & temp24)
139        temp43 = (temp41 | temp42)
140        temp44 = (basis_bits.bit_6 & basis_bits.bit_7)
141        temp45 = (temp29 & temp44)
142        temp46 = (temp34 & temp45)
143        temp47 = (temp43 | temp46)
144        temp48 = (temp8 & temp31)
145        temp49 = (temp34 & temp48)
146        temp50 = (temp47 | temp49)
147        temp51 = (temp13 & temp45)
148        temp52 = (temp50 | temp51)
149        temp53 = (temp13 & temp48)
150        temp54 = (temp52 | temp53)
151        temp55 = (temp6 & temp31)
152        temp56 = (temp28 & temp55)
153        temp57 = (temp54 | temp56)
154        temp58 = (temp8 & temp44)
155        temp59 = (temp28 & temp58)
156        lex.Special = (temp57 | temp59)
157        lex.Percent = (temp28 & temp55)
158        lex.Period = (temp28 & temp24)
159        lex.LAngle = (temp39 & temp35)
160        lex.RAngle = (temp39 & temp24)
161        lex.LBracket = (temp34 & temp45)
162        lex.RBracket = (temp34 & temp48)
163        lex.Slash = (temp28 & temp58)
164        temp60 = (basis_bits.bit_2 | basis_bits.bit_3)
165        temp61 = (temp27 | temp60)
166        temp62 = (temp29 & temp4)
167        temp63 = (temp48 | temp62)
168        lex.EOL = (temp63 &~ temp61)
169        temp64 = (temp5 | temp17)
170        temp65 = (temp61 | temp64)
171        temp66 = (temp35 &~ temp61)
172        temp67 = (temp65 &~ temp66)
173        temp68 = (temp48 &~ temp61)
174        temp69 = (temp67 &~ temp68)
175        temp70 = (temp62 &~ temp61)
176        temp71 = (temp69 &~ temp70)
177        temp72 = (temp32 &~ temp61)
178        temp73 = (temp71 &~ temp72)
179        temp74 = (temp28 &~ temp64)
180        temp75 = (temp73 &~ temp74)
181        lex.WS = (~temp75)
182        temp76 = (basis_bits.bit_5 | basis_bits.bit_6)
183        temp77 = (basis_bits.bit_4 & temp76)
184        lex.Digit = (temp39 &~ temp77)
185        temp78 = (temp48 | temp45)
186        lex.Sign = (temp28 & temp78)
187        temp79 = (temp1 &~ temp60)
188        temp80 = (temp79 &~ basis_bits.bit_4)
189        temp81 = (~temp44)
190        temp82 = ((basis_bits.bit_5 & temp81)|(~(basis_bits.bit_5) & temp17))
191        temp83 = (temp80 & temp82)
192        temp84 = (lex.Digit | temp83)
193        temp85 = (temp3 &~ basis_bits.bit_4)
194        temp86 = (temp85 & temp82)
195        lex.Hex = (temp84 | temp86)
196        temp87 = (temp44 &~ temp5)
197        lex.Hash = (temp28 & temp87)
198        lex.CR = (temp48 &~ temp61)
199        lex.LF = (temp62 &~ temp61)
200        lex.Oct = (temp39 &~ basis_bits.bit_4)
201        lex.Nonoct = (temp16 | temp19)
202        lex.Regular = ~ (lex.Special | lex.WS)
203
204       
205def Parse_Escaped(lex, parity, escape_Callouts, out_Callouts):
206 
207        escape_Callouts.LParen = lex.LParen
208        escape_Callouts.RParen = lex.RParen
209        escape_Callouts.Nonoct = 0
210        escape_Callouts.Oct1 = 0
211        escape_Callouts.Oct2 = 0
212        escape_Callouts.Oct3 = 0
213        out_Callouts.delmask = 0
214 
215        if lex.Backslash:
216
217          odd = parity.odd
218          even = parity.even
219
220          escape_mark = lex.Backslash
221          escaped = pablo.Advance(lex.Backslash)
222          # Check for \\ and longer backslash runs; mark the 1st, 3rd, 5th ...
223          # as escape_marks, the 2nd, 4th, 6th as escaped.
224          start = escape_mark & escaped
225          if start:
226                  #
227                  even_start = start & even     
228                  even_final = pablo.ScanThru(even_start, lex.Backslash) 
229                  escaped = even_final & odd
230                  escape_mark = even & pablo.SpanUpTo(even_start, even_final)
231                 
232                  odd_start = start & odd
233                  odd_final = pablo.ScanThru(odd_start, lex.Backslash)
234                  escaped = escaped | (odd_final & even)
235                  escape_mark |= (odd & pablo.SpanUpTo(odd_start, odd_final))
236
237          escape_Callouts.LParen = lex.LParen &~ escaped
238          escape_Callouts.RParen = lex.RParen &~ escaped
239          escape_Callouts.Nonoct = lex.Nonoct & escaped
240          escape_Callouts.Oct1 = lex.Oct & escaped
241          if escape_Callouts.Oct1:
242                  escape_Callouts.Oct2 = escape_Callouts.Oct1 & pablo.Lookahead(lex.Oct)
243                  escape_Callouts.Oct1 &= ~escape_Callouts.Oct2
244                  escape_Callouts.Oct3 = escape_Callouts.Oct2 & pablo.Lookahead(lex.Oct, 2)
245                  escape_Callouts.Oct2 &= ~escape_Callouts.Oct3
246          out_Callouts.delmask = escape_mark
247       
248def Parse_Comment(lex, escape_Callouts, marker, out_Callouts):
249  out_Callouts.mask = 0
250  if lex.Percent:
251        knownParen = 0
252        CtCand = lex.Percent
253        line_start = ~pablo.Advance(~lex.EOL)
254        knownNonCtReg = pablo.SpanUpTo(line_start, pablo.ScanTo(line_start, lex.EOL | CtCand))
255        newParen = knownNonCtReg & (escape_Callouts.LParen | escape_Callouts.RParen)
256        while newParen &~ knownParen:
257          knownParen |= newParen
258          pscan = pablo.AdvanceThenScanTo(newParen & escape_Callouts.LParen, escape_Callouts.LParen | escape_Callouts.RParen)
259          pscanReg = pablo.SpanUpTo(newParen & escape_Callouts.LParen, pscan)
260          CtCand = CtCand &~ pscanReg
261          knownNonCtReg = pablo.SpanUpTo(line_start, pablo.ScanTo(line_start, lex.EOL | CtCand))
262          closed = pscan & escape_Callouts.RParen
263          opener = pscan & escape_Callouts.LParen
264          while pablo.inFile(opener):
265            pscan = pablo.AdvanceThenScanTo(opener, escape_Callouts.RParen &~ closed)
266            pscanReg = pablo.SpanUpTo(opener, pscan)
267            CtCand = CtCand &~ pscanReg
268            closed = pscan & escape_Callouts.RParen
269            opener = pscan & escape_Callouts.LParen
270            knownNonCtReg |= pscanReg
271          newParen = knownNonCtReg & (escape_Callouts.LParen | escape_Callouts.RParen)
272        comment = CtCand &~ knownNonCtReg
273        out_Callouts.mask = pablo.InclusiveSpan(comment, pablo.ScanTo(comment, lex.EOL))
274
275def Parse_String(escape_Callouts, marker, out_Callouts):
276        unmatched = escape_Callouts.RParen
277        marker.error = 0
278        pscan = 0
279        qscan = 0
280        pscan = pablo.ScanTo(pablo.Advance(escape_Callouts.LParen), escape_Callouts.LParen | escape_Callouts.RParen)
281        qscan = pablo.ScanTo(pablo.Advance(escape_Callouts.RParen), escape_Callouts.LParen | escape_Callouts.RParen)
282        instring = pablo.ExclusiveSpan(escape_Callouts.LParen, pscan) 
283        closed = pscan & escape_Callouts.RParen
284        unclosed = pscan & escape_Callouts.LParen | qscan & escape_Callouts.RParen
285        marker.error = pablo.atEOF(pscan)
286        all_closed = closed
287        while unclosed:
288                pscan = pablo.ScanTo(pablo.Advance(unclosed & escape_Callouts.LParen), unclosed)
289                qscan = pablo.ScanTo(pablo.Advance(unclosed & escape_Callouts.RParen), unclosed)
290                instring |= pablo.SpanUpTo(unclosed & escape_Callouts.LParen, pscan)
291                closed = pscan & escape_Callouts.RParen
292                unclosed = pscan & escape_Callouts.LParen | qscan & escape_Callouts.RParen
293                all_closed |= closed
294                marker.error |= pablo.atEOF(pscan)
295        #
296        # Any closing paren that was not actually used to close
297        # an opener is in error.
298        out_Callouts.mask |= instring
299        marker.starts = pablo.Advance(~instring)&instring
300        marker.ends = pablo.ScanThru(marker.starts, instring)
301        marker.error |= escape_Callouts.RParen &~ all_closed       
302       
303
304#
305# Modified version with comment processing
306#
307# Let pending_LParen be left parentheses for which we have a pending
308#   obligation to find the corresponding right parentheses.
309#
310# Let pending_Pct be Percent marks that have not yet been
311#   ruled out as comment opening delimiters
312#
313#
314def Match_Parens_With_Comments(lex, escape_Callouts, marker, out_Callouts):
315        instring = 0
316        closed_RParen = 0
317        marker.error = 0
318        line_starts = ~pablo.Advance(~lex.EOL)
319        line_ends1 = pablo.ScanTo(line_starts, lex.EOL | lex.Percent)
320        pending_Pct = line_ends1 & lex.Percent
321        known_outside_Ct = pablo.SpanUpTo(line_starts, line_ends1)
322        pending_LParen = known_outside_Ct & escape_Callouts.LParen
323        unmatched_RParen = escape_Callouts.RParen
324
325        inPlay = pending_LParen | unmatched_RParen | pending_Pct
326
327        while pending_LParen:
328
329                # Scan from pending ( marks to next [()%].   Everything we find
330                # must be within a string.
331                pscan = pablo.AdvanceThenScanTo(pending_LParen, inPlay)
332                instring |= pablo.ExclusiveSpan(pending_LParen, pscan) | pscan &~ escape_Callouts.RParen
333                closed_RParen |= pscan & escape_Callouts.RParen
334                marker.error |= pablo.atEOF(pscan)
335                pending_LParen = pscan & escape_Callouts.LParen
336                # Did we scan into a pending comment region?
337                pct_found = pscan & pending_Pct
338               
339                if pct_found:
340                        # The scan from the "(" was terminated prematurely by the "%" mark.
341                        # We include this position in pending_LParen so that the scan can
342                        # continue next time around.
343                        pending_LParen |= pct_found
344                        # Clear this % position as a line terminator, and find the next.
345                        # Determine the region that was previously identified as potentially
346                        # inside a comment and mark it as outside.
347                        line_ends1 &= ~pct_found
348                        line_ends1 |= pablo.AdvanceThenScanTo(pct_found, lex.EOL | lex.Percent)
349                        # Add any new potential comment delimiter to the pending ones.
350                        pending_Pct |= line_ends1 & lex.Percent
351                        newly_outside = pablo.SpanUpTo(pct_found, line_ends1)
352                        known_outside_Ct |= newly_outside
353                        # If any LParens have been revealed, add scan obligations for them
354                        pending_LParen |= newly_outside & escape_Callouts.LParen
355               
356                unmatched_RParen = escape_Callouts.RParen &~ closed_RParen                             
357                inPlay = pending_LParen | unmatched_RParen | pending_Pct
358        #
359        # No more scans to do.  Any pending pct marks are now known
360        # as definite comment delimiters.
361        comment_start = line_ends1 & lex.Percent
362        comment_end = pablo.ScanTo(comment_start, lex.EOL)
363        out_Callouts.mask = pablo.InclusiveSpan(comment_start, comment_end)
364        out_Callouts.mask |= instring
365        #
366        # Any closing paren that was not actually used to close
367        # an opener is in error.
368        marker.starts = pablo.Advance(~instring) & instring
369        marker.ends = pablo.ScanThru(marker.starts, instring)
370        marker.error |= escape_Callouts.RParen &~ closed_RParen &~ pablo.SpanUpTo(comment_start, comment_end)
371
372
373         
374def Parse_HexStrings(lex, marker, out_Callouts) :
375        hexString_starts = lex.LAngle &~ out_Callouts.mask
376        out_Callouts.hex_opener = hexString_starts
377        out_Callouts.hexString_mask = 0 
378        if hexString_starts:
379                hexString_ends = pablo.ScanThru(pablo.Advance(hexString_starts),lex.Hex|lex.WS)
380                marker.error |= hexString_ends &~ lex.RAngle
381                out_Callouts.hexString_mask = pablo.InclusiveSpan(hexString_starts,hexString_ends)
382                out_Callouts.mask |= out_Callouts.hexString_mask
383                marker.starts |= hexString_starts
384                marker.ends |= hexString_ends
385
386
387def Parse_Names(lex, marker, out_Callouts) :
388        name_starts =lex.Slash &~ out_Callouts.mask
389        names_follows = pablo.ScanThru(pablo.Advance(name_starts), lex.Regular)
390        out_Callouts.names_escapes = lex.Hash & pablo.Lookahead(lex.Hex) & pablo.Lookahead(lex.Hex,2)   
391        out_Callouts.mask |= pablo.InclusiveSpan(name_starts,names_follows)
392        marker.starts |= name_starts
393        marker.ends |= names_follows
394       
395def Parse_Numeric(lex, marker, out_Callouts) :
396        numeric_characters = (lex.Digit | lex.Period | lex.Sign)
397        numeric_starts = (numeric_characters &~ pablo.Advance(lex.Regular)) &~ out_Callouts.mask
398        numeric_follows = pablo.ScanThru(numeric_starts, lex.Regular)
399        marker.starts |= numeric_starts
400        marker.ends |= numeric_follows
401
402       
403def Parse_Keywords(lex, marker, out_Callouts) :
404        keywords_starts = (lex.Regular &~ pablo.Advance(lex.Regular)) &~ out_Callouts.mask
405        keywords_follows = pablo.ScanThru(keywords_starts, lex.Regular)
406        marker.starts |= keywords_starts       
407        marker.ends |= keywords_follows
408       
409       
410def Prepare_content_buffer(basis_bits, lex, marker, parity, escape_Callouts, out_Callouts):
411
412    out_Callouts.bit_0 = basis_bits.bit_0
413    out_Callouts.bit_1 = basis_bits.bit_1
414    out_Callouts.bit_2 = basis_bits.bit_2
415    out_Callouts.bit_3 = basis_bits.bit_3
416    out_Callouts.bit_4 = basis_bits.bit_4
417    out_Callouts.bit_5 = basis_bits.bit_5
418    out_Callouts.bit_6 = basis_bits.bit_6
419    out_Callouts.bit_7 = basis_bits.bit_7
420   
421    names_escapes_scope1 = pablo.Advance(out_Callouts.names_escapes)
422    names_escapes_scope2 = pablo.Advance(names_escapes_scope1)
423    hexstring_nameescape_mask = out_Callouts.hexString_mask | names_escapes_scope1 | names_escapes_scope2
424   
425    if hexstring_nameescape_mask:
426     
427        out_Callouts.delmask |= out_Callouts.hexString_mask & lex.WS
428       
429        NondigitHexString = lex.Hex &~ lex.Digit
430        out_Callouts.bit_0 &= ~hexstring_nameescape_mask
431        out_Callouts.bit_1 &= ~hexstring_nameescape_mask
432        out_Callouts.bit_2 &= ~hexstring_nameescape_mask
433        out_Callouts.bit_3 &= ~hexstring_nameescape_mask
434        out_Callouts.bit_4 |= (hexstring_nameescape_mask & NondigitHexString)
435        carry7 = out_Callouts.bit_7 & NondigitHexString & hexstring_nameescape_mask
436        out_Callouts.bit_7 ^= NondigitHexString & hexstring_nameescape_mask
437        carry6 = out_Callouts.bit_6 & carry7
438        out_Callouts.bit_6 ^= carry7
439        out_Callouts.bit_5 ^= carry6
440       
441    if out_Callouts.hexString_mask:
442        hexsting_partial_start = out_Callouts.hex_opener
443        hexsting_partial_odd_start = hexsting_partial_start & parity.odd
444        hexsting_partial_even_start = hexsting_partial_start & parity.even
445        hexsting_partial_odd_end = pablo.ScanThru(pablo.Advance(hexsting_partial_odd_start),lex.Hex)
446        hexsting_partial_even_end = pablo.ScanThru(pablo.Advance(hexsting_partial_even_start),lex.Hex)
447        hexsting_partial_odd_mask = pablo.ExclusiveSpan(hexsting_partial_odd_start,hexsting_partial_odd_end) | (hexsting_partial_odd_end & parity.odd)       
448        hexsting_partial_even_mask = pablo.ExclusiveSpan(hexsting_partial_even_start,hexsting_partial_even_end) | (hexsting_partial_even_end & parity.even)
449       
450        del_position = (hexsting_partial_odd_mask & parity.even) | (hexsting_partial_even_mask & parity.odd)
451        kept_position = (hexsting_partial_odd_mask & parity.odd) | (hexsting_partial_even_mask & parity.even)
452       
453         
454        hexsting_partial_end = hexsting_partial_odd_end | hexsting_partial_even_end
455        hexsting_partial_ends = hexsting_partial_end
456        kept_positions = kept_position
457        del_positions = del_position
458        del_pre_ends = 0
459        while hexsting_partial_end & lex.WS:
460          del_pre_end = del_position & pablo.Lookahead(lex.WS) 
461          kept_pre_end = kept_position & pablo.Lookahead(lex.WS) 
462         
463          del_even_start = pablo.ScanThru(pablo.Advance(del_pre_end),lex.WS) & parity.even
464          del_odd_start = pablo.ScanThru(pablo.Advance(del_pre_end),lex.WS) & parity.odd
465          kept_even_start = pablo.ScanThru(pablo.Advance(kept_pre_end),lex.WS) & parity.even
466          kept_odd_start = pablo.ScanThru(pablo.Advance(kept_pre_end),lex.WS) & parity.odd
467           
468          del_even_end = pablo.ScanThru(del_even_start,lex.Hex)
469          del_odd_end = pablo.ScanThru(del_odd_start,lex.Hex)
470          kept_even_end = pablo.ScanThru(kept_even_start,lex.Hex)
471          kept_odd_end = pablo.ScanThru(kept_odd_start,lex.Hex)
472         
473          hexsting_partial_odd_mask = pablo.InclusiveSpan(del_even_start,del_even_end) | pablo.InclusiveSpan(kept_odd_start,kept_odd_end) 
474          hexsting_partial_even_mask = pablo.InclusiveSpan(del_odd_start,del_odd_end) | pablo.InclusiveSpan(kept_even_start,kept_even_end)   
475         
476          hexsting_partial_end = del_even_end | del_odd_end | kept_even_end | kept_odd_end
477         
478          kept_position = (hexsting_partial_odd_mask & parity.even) | (hexsting_partial_even_mask & parity.odd)
479          del_position = (hexsting_partial_odd_mask & parity.odd) | (hexsting_partial_even_mask & parity.even)
480          del_position = del_position &~ hexsting_partial_end
481         
482          hexsting_partial_ends |= hexsting_partial_end
483          kept_positions |= kept_position
484          del_positions |= del_position
485          del_pre_ends |= del_pre_end
486         
487     
488        out_Callouts.bit_4 &= ~hexsting_partial_ends
489        out_Callouts.bit_5 &= ~hexsting_partial_ends
490        out_Callouts.bit_6 &= ~hexsting_partial_ends
491        out_Callouts.bit_7 &= ~hexsting_partial_ends
492     
493        out_Callouts.bit_0 = pablo.Advance(del_positions & out_Callouts.bit_4) | (out_Callouts.bit_0 & ~kept_positions) | pablo.ScanThru(pablo.Advance((out_Callouts.bit_4 & del_pre_ends)), lex.WS)
494        out_Callouts.bit_1 = pablo.Advance(del_positions & out_Callouts.bit_5) | (out_Callouts.bit_1 & ~kept_positions) | pablo.ScanThru(pablo.Advance((out_Callouts.bit_5 & del_pre_ends)), lex.WS)
495        out_Callouts.bit_2 = pablo.Advance(del_positions & out_Callouts.bit_6) | (out_Callouts.bit_2 & ~kept_positions) | pablo.ScanThru(pablo.Advance((out_Callouts.bit_6 & del_pre_ends)), lex.WS) 
496        out_Callouts.bit_3 = pablo.Advance(del_positions & out_Callouts.bit_7) | (out_Callouts.bit_3 & ~kept_positions) | pablo.ScanThru(pablo.Advance((out_Callouts.bit_7 & del_pre_ends)), lex.WS) 
497       
498        out_Callouts.delmask |= del_positions
499           
500       
501
502    if escape_Callouts.Nonoct:       
503        out_Callouts.bit_1 ^= ( lex.pdf_mod_bit_1 & escape_Callouts.Nonoct)
504        out_Callouts.bit_2 ^= ( lex.pdf_mod_bit_2 & escape_Callouts.Nonoct)
505        out_Callouts.bit_3 ^= ( lex.pdf_mod_bit_3 & escape_Callouts.Nonoct)
506        out_Callouts.bit_4 ^= ( lex.pdf_mod_bit_4 & escape_Callouts.Nonoct)
507        out_Callouts.bit_5 ^= ( lex.pdf_mod_bit_5 & escape_Callouts.Nonoct)
508        out_Callouts.bit_6 ^= ( lex.pdf_mod_bit_6 & escape_Callouts.Nonoct)
509        out_Callouts.bit_7 ^= ( lex.pdf_mod_bit_7 & escape_Callouts.Nonoct)
510       
511    if out_Callouts.names_escapes:
512        out_Callouts.delmask |= out_Callouts.names_escapes | names_escapes_scope1
513        out_Callouts.bit_0 = (out_Callouts.bit_0 &~ names_escapes_scope2) 
514        out_Callouts.bit_1 = (out_Callouts.bit_1 &~ names_escapes_scope2)
515        out_Callouts.bit_2 = (out_Callouts.bit_2 &~ names_escapes_scope2) 
516        out_Callouts.bit_3 = (out_Callouts.bit_3 &~ names_escapes_scope2) 
517        out_Callouts.bit_0 |= pablo.Advance(out_Callouts.bit_4 & names_escapes_scope1)
518        out_Callouts.bit_1 |= pablo.Advance(out_Callouts.bit_5 & names_escapes_scope1)
519        out_Callouts.bit_2 |= pablo.Advance(out_Callouts.bit_6 & names_escapes_scope1)
520        out_Callouts.bit_3 |= pablo.Advance(out_Callouts.bit_7 & names_escapes_scope1) 
521       
522    if escape_Callouts.Oct1:
523        out_Callouts.bit_0 = (out_Callouts.bit_0 &~ escape_Callouts.Oct1) 
524        out_Callouts.bit_1 = (out_Callouts.bit_1 &~ escape_Callouts.Oct1)
525        out_Callouts.bit_2 = (out_Callouts.bit_2 &~ escape_Callouts.Oct1) 
526        out_Callouts.bit_3 = (out_Callouts.bit_3 &~ escape_Callouts.Oct1) 
527     
528    if escape_Callouts.Oct2:
529        out_Callouts.delmask |= escape_Callouts.Oct2
530        Oct2_scope1 = pablo.Advance(escape_Callouts.Oct2)
531        out_Callouts.bit_2 = (out_Callouts.bit_2 &~ Oct2_scope1) | pablo.Advance(out_Callouts.bit_5 & escape_Callouts.Oct2)
532        out_Callouts.bit_3 = (out_Callouts.bit_3 &~ Oct2_scope1) | pablo.Advance(out_Callouts.bit_6 & escape_Callouts.Oct2)
533        out_Callouts.bit_4 = (out_Callouts.bit_4 &~ Oct2_scope1) | pablo.Advance(out_Callouts.bit_7 & escape_Callouts.Oct2)
534       
535    if escape_Callouts.Oct3:
536        Oct3_scope1 = pablo.Advance(escape_Callouts.Oct3)
537        Oct3_scope2 = pablo.Advance(Oct3_scope1)
538        out_Callouts.delmask |= escape_Callouts.Oct3 | Oct3_scope1
539        temp0 = pablo.Advance(out_Callouts.bit_6 & escape_Callouts.Oct3)
540        temp1 = pablo.Advance(out_Callouts.bit_7 & escape_Callouts.Oct3)
541        out_Callouts.bit_0 = (out_Callouts.bit_0 &~ Oct3_scope2) | pablo.Advance(temp0)
542        out_Callouts.bit_1 = (out_Callouts.bit_1 &~ Oct3_scope2) | pablo.Advance(temp1)
543        out_Callouts.bit_2 = (out_Callouts.bit_2 &~ Oct3_scope2) | pablo.Advance(out_Callouts.bit_5 & Oct3_scope1)
544        out_Callouts.bit_3 = (out_Callouts.bit_3 &~ Oct3_scope2) | pablo.Advance(out_Callouts.bit_6 & Oct3_scope1)
545        out_Callouts.bit_4 = (out_Callouts.bit_4 &~ Oct3_scope2) | pablo.Advance(out_Callouts.bit_7 & Oct3_scope1)       
546     
547 
548    out_Callouts.zeromask = out_Callouts.delmask 
549    out_Callouts.bit_0 = out_Callouts.bit_0 &~ out_Callouts.zeromask   
550    out_Callouts.bit_1 = out_Callouts.bit_1 &~ out_Callouts.zeromask
551    out_Callouts.bit_2 = out_Callouts.bit_2 &~ out_Callouts.zeromask
552    out_Callouts.bit_3 = out_Callouts.bit_3 &~ out_Callouts.zeromask
553    out_Callouts.bit_4 = out_Callouts.bit_4 &~ out_Callouts.zeromask
554    out_Callouts.bit_5 = out_Callouts.bit_5 &~ out_Callouts.zeromask
555    out_Callouts.bit_6 = out_Callouts.bit_6 &~ out_Callouts.zeromask
556    out_Callouts.bit_7 = out_Callouts.bit_7 &~ out_Callouts.zeromask
557   
558#
559# Make sure all three forms of linebreak (CR, CRLF, LF) are translated to a
560# single LF.
561#
562def Normalize_WS(lex, out_Callouts):
563        if lex.CR:
564                # Modify CR (#x0D) to LF (#x0A)
565                out_Callouts.bit_5 ^= lex.CR
566                out_Callouts.bit_6 ^= lex.CR
567                out_Callouts.bit_7 ^= lex.CR
568                CRLF = pablo.Advance(lex.CR) & lex.LF
569                out_Callouts.delmask |= CRLF
570
571
572def Main(basis_bits, lex, escape_Callouts, out_Callouts):
573  pass
574
575
576
577
Note: See TracBrowser for help on using the repository browser.