source: proto/parabix2/DTD_prescan.py @ 2022

Last change on this file since 2022 was 2002, checked in by cameron, 8 years ago

Fixes for DTD prescanning

File size: 1.9 KB
Line 
1#
2# DTD Prescanning
3#
4# Robert D. Cameron - April 8, 2012
5# Licensed under Open Software License 3.0
6#
7#
8# DTD prescanning quickly works through the internal DTD
9# subset to find the interiors of comments, PIs and quoted
10# strings, as well as the end of DTD.   Once this is
11# complete, all remaining opening angle brackets within the DTD
12# (i.e, ones that are not in an interior of comment, PI or string)
13# are declarations.  These can all be parsed in parallel.
14#               
15
16def preparse_internal_DTD(lex, int_subset_marker, prescan):
17        subset_prescan = lex.LAngle | lex.RBrak
18        decl_prescan = lex.RAngle | lex.SQuote | lex.DQuote
19        marker = pablo.ScanTo(int_subset_marker, subset_prescan)
20        decl_marker = marker &~ lex.RBrak
21        while decl_marker:
22                marker1 = pablo.Advance(decl_marker)
23                PI_marker = marker1 & lex.QMark
24                CtDecl_marker = marker1 & lex.Exclam
25                if PI_marker:
26                        prescan.start_interior |= PI_marker
27                        marker = pablo.ScanTo(marker, PI_closer)
28                        prescan.end_interior |= marker
29                if CtDecl_marker:
30                        marker2 = pablo.Advance(CtDecl_marker)
31                        Ct_marker = marker2 & lex.Hyphen
32                        Decl_marker = marker2 &~ lex.Hyphen
33                        if Ct_marker:
34                                prescan.start_interior |= Ct_marker
35                                marker = pablo.AdvancebyPos(Ct_marker, 3)
36                                marker = pablo.ScanTo(marker, DoubleHyphen)
37                                prescan.end_interior |= marker
38                        if Decl_marker:
39                                marker = pablo.ScanTo(Decl_marker, decl_prescan)
40                                quote_marker = marker &~ lex.RAngle
41                                while quote_marker:
42                                        dq = quote_marker & lex.DQuote
43                                        sq = quote_marker & lex.SQuote
44                                        prescan.start_interior |= quote_marker
45                                        quote_marker = pablo.ScanTo(dq, lex.DQuote &~ dq) | pablo.ScanTo(sq, lex.SQuote &~ sq)
46                                        prescan.end_interior |= quote_marker
47                                        marker = pablo.ScanTo(pablo.Advance(quote_marker), decl_prescan)
48                                        quote_marker = marker &~ lex.RAngle
49                marker = pablo.ScanTo(marker, subset_prescan)
50                decl_marker = marker &~ lex.RBrak
51        prescan.DTD_end = marker
52
53
54
55
56
57
58         
59
Note: See TracBrowser for help on using the repository browser.