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 | |
---|
15 | struct Lex{ |
---|
16 | stream a; |
---|
17 | stream p; |
---|
18 | stream l; |
---|
19 | stream e; |
---|
20 | stream LF; |
---|
21 | }; |
---|
22 | |
---|
23 | struct Output{ |
---|
24 | stream match_follows; |
---|
25 | stream lines; |
---|
26 | stream line_starts; |
---|
27 | stream line_ends; |
---|
28 | }; |
---|
29 | |
---|
30 | filter ClassifyBytes(struct Basis_bits basis_bits, struct Lex lex) { |
---|
31 | stream temp1 = (basis_bits.bit_1 & (~ basis_bits.bit_0)); |
---|
32 | stream temp2 = (basis_bits.bit_2 & (~ basis_bits.bit_3)); |
---|
33 | stream temp3 = (temp1 & temp2); |
---|
34 | stream temp4 = (basis_bits.bit_4 | basis_bits.bit_5); |
---|
35 | stream temp5 = (basis_bits.bit_7 & (~ basis_bits.bit_6)); |
---|
36 | stream temp6 = (temp5 & (~ temp4)); |
---|
37 | lex.a = (temp3 & temp6); |
---|
38 | stream temp7 = (basis_bits.bit_2 & basis_bits.bit_3); |
---|
39 | stream temp8 = (temp1 & temp7); |
---|
40 | stream temp9 = (basis_bits.bit_6 | basis_bits.bit_7); |
---|
41 | stream temp10 = (temp4 | temp9); |
---|
42 | lex.p = (temp8 & (~ temp10)); |
---|
43 | stream temp11 = (basis_bits.bit_4 & basis_bits.bit_5); |
---|
44 | stream temp12 = (temp11 & (~ temp9)); |
---|
45 | lex.l = (temp3 & temp12); |
---|
46 | stream temp13 = (basis_bits.bit_5 & (~ basis_bits.bit_4)); |
---|
47 | stream temp14 = (temp13 & temp5); |
---|
48 | lex.e = (temp3 & temp14); |
---|
49 | stream temp15 = (basis_bits.bit_0 | basis_bits.bit_1); |
---|
50 | stream temp16 = (basis_bits.bit_2 | basis_bits.bit_3); |
---|
51 | stream temp17 = (temp15 | temp16); |
---|
52 | stream temp18 = (basis_bits.bit_4 & (~ basis_bits.bit_5)); |
---|
53 | stream temp19 = (basis_bits.bit_6 & (~ basis_bits.bit_7)); |
---|
54 | stream temp20 = (temp18 & temp19); |
---|
55 | lex.LF = (temp20 & (~ temp17)); |
---|
56 | } |
---|
57 | |
---|
58 | filter Match(struct Lex lex, struct Output output) { |
---|
59 | stream cursor = pablo.Advance(lex.a); |
---|
60 | cursor = pablo.Advance((cursor & lex.p)); |
---|
61 | cursor = pablo.Advance((cursor & lex.p)); |
---|
62 | cursor = pablo.Advance((cursor & lex.l)); |
---|
63 | cursor = pablo.Advance((cursor & lex.e)); |
---|
64 | output.match_follows = cursor; |
---|
65 | } |
---|
66 | |
---|
67 | filter MatchLines(struct Lex lex, struct Output output) { |
---|
68 | stream all_line_starts = (pablo.ScanToFirst((~ lex.LF)) | (pablo.Advance(lex.LF) & (~ lex.LF))); |
---|
69 | stream all_line_ends = lex.LF; |
---|
70 | stream last_line_start = pablo.ScanToFirst(all_line_starts); |
---|
71 | stream cursor = last_line_start; |
---|
72 | while (pablo.inFile(cursor)) { |
---|
73 | if ((cursor & all_line_starts)) { |
---|
74 | last_line_start = cursor; |
---|
75 | } |
---|
76 | if ((cursor & output.match_follows)) { |
---|
77 | cursor = pablo.ScanTo(cursor, lex.LF); |
---|
78 | output.lines |= pablo.InclusiveSpan(last_line_start, cursor); |
---|
79 | } |
---|
80 | cursor = pablo.AdvanceThenScanTo(cursor, (all_line_starts | output.match_follows)); |
---|
81 | } |
---|
82 | output.line_starts = (output.lines & all_line_starts); |
---|
83 | output.line_ends = pablo.ScanTo(output.line_starts, (output.lines & all_line_ends)); |
---|
84 | } |
---|
85 | |
---|
86 | |
---|
87 | graph Main() { |
---|
88 | |
---|
89 | struct Byte_data byte_data; |
---|
90 | struct Basis_bits basis_bits; |
---|
91 | struct Lex lex; |
---|
92 | struct Output output; |
---|
93 | struct MatchLines matchLines; |
---|
94 | |
---|
95 | filter Transpose transpose; |
---|
96 | filter ClassifyBytes classifyBytes; |
---|
97 | filter Match match; |
---|
98 | filter MatchLines matchLines; |
---|
99 | |
---|
100 | transpose(byte_data, basis_bits); |
---|
101 | classifyBytes(basis_bits, lex); |
---|
102 | match(lex, output); |
---|
103 | matchLines(lex, output); |
---|
104 | |
---|
105 | } |
---|