Skip to content

Commit cc2190a

Browse files
committed
Move codegen to its own crate
1 parent 5998839 commit cc2190a

File tree

4 files changed

+16
-14
lines changed

4 files changed

+16
-14
lines changed

codegen/Cargo.toml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[package]
2+
name = "codegen"
3+
version = "0.1.0"
4+
authors = ["Steven Fackler <sfackler@gmail.com>"]
5+
6+
[dependencies]
7+
regex = "0.2"

script/generate_rfc3454.rs renamed to codegen/src/main.rs

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,31 +2,26 @@ extern crate regex;
22

33
use regex::Regex;
44

5-
use std::env;
65
use std::fs::File;
76
use std::io::prelude::*;
8-
use std::io::{BufReader, BufWriter};
9-
use std::path::Path;
7+
use std::io::{BufRead, BufWriter};
108

119
// Generate character mapping tables directly from the specification.
1210
fn main() {
1311
// Input from the RFC.
14-
let in_file = File::open("rfc3454.txt").unwrap();
15-
let mut reader = BufReader::new(in_file);
12+
let reader = include_bytes!("rfc3454.txt");
1613

1714
// Output to a Rust source file.
18-
let out_dir = env::var("OUT_DIR").unwrap();
19-
let dest_path = Path::new(&out_dir).join("rfc3454.rs");
20-
let out_file = File::create(&dest_path).unwrap();
15+
let out_file = File::create("../src/rfc3454.rs").unwrap();
2116
let mut writer = BufWriter::new(out_file);
2217

2318
// Generate tables.
24-
include_table(&mut writer, &mut reader, "A.1");
25-
include_table(&mut writer, &mut reader, "B.2");
19+
include_table(&mut writer, &mut &reader[..], "A.1");
20+
include_table(&mut writer, &mut &reader[..], "B.2");
2621
}
2722

2823
// Generate code for the named mapping table.
29-
fn include_table<R: Read, W: Write>(writer: &mut BufWriter<W>, reader: &mut BufReader<R>, tablename: &str) {
24+
fn include_table<R: BufRead, W: Write>(writer: &mut W, reader: &mut R, tablename: &str) {
3025
// Scan to start of table.
3126
loop {
3227
let mut line = String::new();
@@ -37,7 +32,7 @@ fn include_table<R: Read, W: Write>(writer: &mut BufWriter<W>, reader: &mut BufR
3732
}
3833

3934
// Output table declaration.
40-
write!(writer, "pub const RFC3454_{}: &[(char, Option<char>, Option<&str>)] = &[\n", tablename.replace(".", "_")).unwrap();
35+
write!(writer, "pub const {}: &[(char, Option<char>, Option<&str>)] = &[\n", tablename.replace(".", "_")).unwrap();
4136

4237
// For each line:
4338
let target_re = Regex::new(r"([0-9A-F]+)(-([0-9A-F]+))?(; ([0-9A-F]+)( ([0-9A-F]+))?( ([0-9A-F]+))?( ([0-9A-F]+))?;)?").unwrap();
File renamed without changes.

src/rfc3454.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
// RFC 3454, Appendix A.1 Unassigned code points in Unicode 3.2 pub const A_1: &[(char, Option<char>, Option<&str>] = &[
21
pub const A_1: &[(char, Option<char>, Option<&str>)] = &[
2+
('\u{0221}', None, None),
33
('\u{0234}', Some('\u{024F}'), None),
44
('\u{02AE}', Some('\u{02AF}'), None),
55
('\u{02EF}', Some('\u{02FF}'), None),
@@ -397,7 +397,6 @@ pub const A_1: &[(char, Option<char>, Option<&str>)] = &[
397397
('\u{E0080}', Some('\u{EFFFD}'), None),
398398
];
399399

400-
// RFC 3454, Appendix B.2 Mapping for case-folding used with NFKC.
401400
pub const B_2: &[(char, Option<char>, Option<&str>)] = &[
402401
('\u{0041}', None, Some("\u{0061}")),
403402
('\u{0042}', None, Some("\u{0062}")),
@@ -1771,3 +1770,4 @@ pub const B_2: &[(char, Option<char>, Option<&str>)] = &[
17711770
('\u{1D7A8}', None, Some("\u{03C9}")),
17721771
('\u{1D7BB}', None, Some("\u{03C3}")),
17731772
];
1773+

0 commit comments

Comments
 (0)