1 | |
---|
2 | |
---|
3 | struct Basis_bits{ |
---|
4 | stream bit_0; |
---|
5 | stream bit_1; |
---|
6 | stream bit_2; |
---|
7 | stream bit_3; |
---|
8 | stream bit_4; |
---|
9 | stream bit_5; |
---|
10 | stream bit_6; |
---|
11 | stream bit_7; |
---|
12 | }; |
---|
13 | |
---|
14 | struct Lex{ |
---|
15 | stream a; |
---|
16 | stream p; |
---|
17 | stream l; |
---|
18 | stream e; |
---|
19 | stream LF; |
---|
20 | }; |
---|
21 | |
---|
22 | struct Output{ |
---|
23 | stream match_follows; |
---|
24 | stream lines; |
---|
25 | stream line_starts; |
---|
26 | stream line_ends; |
---|
27 | }; |
---|
28 | |
---|
29 | function ClassifyBytes(struct Basis_bits basis_bits, struct Lex lex) { |
---|
30 | stream temp1 = (basis_bits.bit_1 & (~ basis_bits.bit_0)); |
---|
31 | stream temp2 = (basis_bits.bit_2 & (~ basis_bits.bit_3)); |
---|
32 | stream temp3 = (temp1 & temp2); |
---|
33 | stream temp4 = (basis_bits.bit_4 | basis_bits.bit_5); |
---|
34 | stream temp5 = (basis_bits.bit_7 & (~ basis_bits.bit_6)); |
---|
35 | stream temp6 = (temp5 & (~ temp4)); |
---|
36 | lex.a = (temp3 & temp6); |
---|
37 | stream temp7 = (basis_bits.bit_2 & basis_bits.bit_3); |
---|
38 | stream temp8 = (temp1 & temp7); |
---|
39 | stream temp9 = (basis_bits.bit_6 | basis_bits.bit_7); |
---|
40 | stream temp10 = (temp4 | temp9); |
---|
41 | lex.p = (temp8 & (~ temp10)); |
---|
42 | stream temp11 = (basis_bits.bit_4 & basis_bits.bit_5); |
---|
43 | stream temp12 = (temp11 & (~ temp9)); |
---|
44 | lex.l = (temp3 & temp12); |
---|
45 | stream temp13 = (basis_bits.bit_5 & (~ basis_bits.bit_4)); |
---|
46 | stream temp14 = (temp13 & temp5); |
---|
47 | lex.e = (temp3 & temp14); |
---|
48 | stream temp15 = (basis_bits.bit_0 | basis_bits.bit_1); |
---|
49 | stream temp16 = (basis_bits.bit_2 | basis_bits.bit_3); |
---|
50 | stream temp17 = (temp15 | temp16); |
---|
51 | stream temp18 = (basis_bits.bit_4 & (~ basis_bits.bit_5)); |
---|
52 | stream temp19 = (basis_bits.bit_6 & (~ basis_bits.bit_7)); |
---|
53 | stream temp20 = (temp18 & temp19); |
---|
54 | lex.LF = (temp20 & (~ temp17)); |
---|
55 | } |
---|
56 | |
---|
57 | function Match(struct Lex lex, struct Output output) { |
---|
58 | stream cursor = pablo.Advance(lex.a); |
---|
59 | cursor = pablo.Advance((cursor & lex.p)); |
---|
60 | cursor = pablo.Advance((cursor & lex.p)); |
---|
61 | cursor = pablo.Advance((cursor & lex.l)); |
---|
62 | cursor = pablo.Advance((cursor & lex.e)); |
---|
63 | output.match_follows = cursor; |
---|
64 | } |
---|
65 | |
---|
66 | function MatchLines(struct Lex lex, struct Output output) { |
---|
67 | stream all_line_starts = (pablo.ScanToFirst((~ lex.LF)) | (pablo.Advance(lex.LF) & (~ lex.LF))); |
---|
68 | stream all_line_ends = lex.LF; |
---|
69 | stream last_line_start = pablo.ScanToFirst(all_line_starts); |
---|
70 | stream cursor = last_line_start; |
---|
71 | while (pablo.inFile(cursor)) { |
---|
72 | if ((cursor & all_line_starts)) { |
---|
73 | last_line_start = cursor; |
---|
74 | } |
---|
75 | if ((cursor & output.match_follows)) { |
---|
76 | cursor = pablo.ScanTo(cursor, lex.LF); |
---|
77 | output.lines |= pablo.InclusiveSpan(last_line_start, cursor); |
---|
78 | } |
---|
79 | cursor = pablo.AdvanceThenScanTo(cursor, (all_line_starts | output.match_follows)); |
---|
80 | } |
---|
81 | output.line_starts = (output.lines & all_line_starts); |
---|
82 | output.line_ends = pablo.ScanTo(output.line_starts, (output.lines & all_line_ends)); |
---|
83 | } |
---|
84 | |
---|
85 | /* |
---|
86 | function Main(struct Basis_bits basis_bits, struct Lex lex, struct Output output) { |
---|
87 | Transpose(byte_data, basis_bits); |
---|
88 | ClassifyBytes(basis_bits, lex); |
---|
89 | Match(lex, output); |
---|
90 | MatchLines(lex, output); |
---|
91 | } |
---|
92 | */ |
---|