source: proto/parabix2/DTD_prescan.py @ 1999

Last change on this file since 1999 was 1999, checked in by cameron, 7 years ago

DTD prescanner - initial checkin.

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