source: proto/RE2PBS/prototype_template.py @ 1154

Last change on this file since 1154 was 1154, checked in by ksherdy, 8 years ago

Minor template fixes.

File size: 1.3 KB
Line 
1# -*- coding: utf-8 -*-
2#
3# prototype.py template
4#
5# Ken Herdy
6# April 20, 2010
7#
8#----------------------------------------------------------------------------
9#
10# (at)lex_strms - Lexical Item Streams.
11# (at)cc_code   - Character Class compiler equations.
12# (at)pbs_code  - Parallel bit stream equations.
13#
14#----------------------------------------------------------------------------
15
16import sys
17import bitutil
18
19u8data = ""
20lgth = 0
21
22class Basis_bits():
23        bit_0 = 0
24        bit_1 = 0
25        bit_2 = 0
26        bit_3 = 0 
27        bit_4 = 0
28        bit_5 = 0
29        bit_6 = 0
30        bit_7 = 0 
31 
32class Lex():
33@lex_strms
34
35def classify_bytes(basis_bits):
36        lex = Lex()
37
38@cc_code
39        return lex
40
41def demo(u8data, lex):
42        global lgth
43        lgth = len(u8data)
44       
45@pbs_code
46@pbs_debug
47
48        return
49
50if __name__ == "__main__":
51        import doctest
52        doctest.testmod()
53
54        if len(sys.argv) < 2:
55                sys.stderr.write("Usage: python " + __file__ + " <filename>" "\n")
56                sys.exit(2)
57
58        u8data = bitutil.readfile(sys.argv[1])
59        (bits, EOF_mask) = bitutil.transpose_streams(u8data)
60       
61        basis_bits = Basis_bits()
62        basis_bits.bit_0 = bits[0]
63        basis_bits.bit_1 = bits[1]
64        basis_bits.bit_2 = bits[2]
65        basis_bits.bit_3 = bits[3]
66        basis_bits.bit_4 = bits[4]
67        basis_bits.bit_5 = bits[5]
68        basis_bits.bit_6 = bits[6]
69        basis_bits.bit_7 = bits[7]
70       
71        lex = classify_bytes(basis_bits)
72        demo(u8data, lex)
Note: See TracBrowser for help on using the repository browser.