-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathreprs.go.rl
105 lines (77 loc) · 3.27 KB
/
reprs.go.rl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
package main
var hexdigit []byte = []byte{'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'}
%%{
machine reprs_fsm;
alphtype byte;
need_escape = ('"' @ { out = append(out, '"') }
| "'" @ { out = append(out, '\'') }
| '\\'@ { out = append(out, '\\') }
| '\t' @ { out = append(out, 't') }
| '\n' @ { out = append(out, 'n') }
| '\r' @ { out = append(out, 'r') }
) > { out = append(out, '\\') };
normal = ((0x20 .. 0x7e) - need_escape) @ { out = append(out, fc); };
octet = normal | need_escape
| (any - normal - need_escape) @ {
out = append(out, "\\x"...)
out = append(out, hexdigit[fc / 16])
out = append(out, hexdigit[fc % 16])
};
main := octet*;
}%%
%% write data;
func Reprs(data []byte) []byte {
cs, p, pe := 0, 0, len(data)
out := make([]byte, 0, len(data) * 4)
%% write init;
%% write exec;
return out
}
var hexvalue []int32 = []int32{
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, -1, -1, -1, -1, -1, -1, -1, 10, 11, 12, 13, 14, 15, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, 10, 11, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
}
%%{
machine evals_fsm;
alphtype byte;
escape = 0x5c;
escape_sequence = escape escape @ { value = '\\' }
| escape 't' @ { value = '\t' }
| escape 'b' @ { value = '\b' }
| escape 'n' @ { value = '\n' }
| escape 'r' @ { value = '\r' }
| escape 'v' @ { value = '\v' }
| escape 'f' @ { value = '\f' }
| escape 'a' @ { value = '\a' }
| escape '"' @ { value = '"' }
| escape "'" @ { value = '\'' }
| escape 'x' @ { value = byte(0) } (xdigit @ {
value = byte(int32(value) * 16 + hexvalue[(uint32)(fc)])
}){2};
main := |*
any => { out = append(out, fc) };
escape_sequence => { out = append(out, value) };
*|;
}%%
%% write data;
func Evals(data []byte) []byte {
cs, p, pe, eof := 0, 0, len(data), len(data)
ts, te := 0, 0
_ = ts
act := 0
_ = act
var value byte
out := make([]byte, 0, len(data) * 4)
%% write init;
%% write exec;
return out
}