1 use crate::output::Output;
2 use crate::parse::Properties;
3 use crate::CHUNK;
4
5 const HEAD: &str = "\
6 // \x40generated by ../generate. To regenerate, run the following in the repo root:
7 //
8 // $ curl -LO https://www.unicode.org/Public/zipped/15.0.0/UCD.zip
9 // $ unzip UCD.zip -d UCD
10 // $ cargo run --manifest-path generate/Cargo.toml
11
12 const T: bool = true;
13 const F: bool = false;
14
15 #[repr(C, align(8))]
16 pub(crate) struct Align8<T>(pub(crate) T);
17 #[repr(C, align(64))]
18 pub(crate) struct Align64<T>(pub(crate) T);
19 ";
20
output( properties: &Properties, index_start: &[u8], index_continue: &[u8], halfdense: &[u8], ) -> Output21 pub fn output(
22 properties: &Properties,
23 index_start: &[u8],
24 index_continue: &[u8],
25 halfdense: &[u8],
26 ) -> Output {
27 let mut out = Output::new();
28 writeln!(out, "{}", HEAD);
29
30 writeln!(
31 out,
32 "pub(crate) static ASCII_START: Align64<[bool; 128]> = Align64([",
33 );
34 for i in 0u8..4 {
35 write!(out, " ");
36 for j in 0..32 {
37 let ch = (i * 32 + j) as char;
38 let is_xid_start = properties.is_xid_start(ch);
39 write!(out, " {},", if is_xid_start { 'T' } else { 'F' });
40 }
41 writeln!(out);
42 }
43 writeln!(out, "]);");
44 writeln!(out);
45
46 writeln!(
47 out,
48 "pub(crate) static ASCII_CONTINUE: Align64<[bool; 128]> = Align64([",
49 );
50 for i in 0u8..4 {
51 write!(out, " ");
52 for j in 0..32 {
53 let ch = (i * 32 + j) as char;
54 let is_xid_continue = properties.is_xid_continue(ch);
55 write!(out, " {},", if is_xid_continue { 'T' } else { 'F' });
56 }
57 writeln!(out);
58 }
59 writeln!(out, "]);");
60 writeln!(out);
61
62 writeln!(out, "pub(crate) const CHUNK: usize = {};", CHUNK);
63 writeln!(out);
64
65 writeln!(
66 out,
67 "pub(crate) static TRIE_START: Align8<[u8; {}]> = Align8([",
68 index_start.len(),
69 );
70 for line in index_start.chunks(16) {
71 write!(out, " ");
72 for byte in line {
73 write!(out, " 0x{:02X},", byte);
74 }
75 writeln!(out);
76 }
77 writeln!(out, "]);");
78 writeln!(out);
79
80 writeln!(
81 out,
82 "pub(crate) static TRIE_CONTINUE: Align8<[u8; {}]> = Align8([",
83 index_continue.len(),
84 );
85 for line in index_continue.chunks(16) {
86 write!(out, " ");
87 for byte in line {
88 write!(out, " 0x{:02X},", byte);
89 }
90 writeln!(out);
91 }
92 writeln!(out, "]);");
93 writeln!(out);
94
95 writeln!(
96 out,
97 "pub(crate) static LEAF: Align64<[u8; {}]> = Align64([",
98 halfdense.len(),
99 );
100 for line in halfdense.chunks(16) {
101 write!(out, " ");
102 for byte in line {
103 write!(out, " 0x{:02X},", byte);
104 }
105 writeln!(out);
106 }
107 writeln!(out, "]);");
108
109 out
110 }
111