Skip to content

Commit 05be072

Browse files
committed
---
yaml --- r: 144249 b: refs/heads/try2 c: 94a084a h: refs/heads/master i: 144247: cf333d9 v: v3
1 parent 44317c5 commit 05be072

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+768
-4199
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ refs/heads/snap-stage3: 78a7676898d9f80ab540c6df5d4c9ce35bb50463
55
refs/heads/try: 519addf6277dbafccbb4159db4b710c37eaa2ec5
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
8-
refs/heads/try2: 3f6f79b789e8000ce4903857a210318e92724da8
8+
refs/heads/try2: 94a084a4b45afe0bb8c1b1206184d4d0db4f4ec0
99
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/try2/src/etc/unicode.py

Lines changed: 33 additions & 150 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,11 @@ def fetch(f):
2626
def load_unicode_data(f):
2727
fetch(f)
2828
gencats = {}
29-
combines = []
3029
canon_decomp = {}
3130
compat_decomp = {}
3231
curr_cat = ""
33-
curr_combine = ""
3432
c_lo = 0
3533
c_hi = 0
36-
com_lo = 0
37-
com_hi = 0
3834
for line in fileinput.input(f):
3935
fields = line.split(";")
4036
if len(fields) != 15:
@@ -73,21 +69,7 @@ def load_unicode_data(f):
7369
c_lo = code
7470
c_hi = code
7571

76-
if curr_combine == "":
77-
curr_combine = combine
78-
com_lo = code
79-
com_hi = code
80-
81-
if curr_combine == combine:
82-
com_hi = code
83-
else:
84-
if curr_combine != "0":
85-
combines.append((com_lo, com_hi, curr_combine))
86-
curr_combine = combine
87-
com_lo = code
88-
com_hi = code
89-
90-
return (canon_decomp, compat_decomp, gencats, combines)
72+
return (canon_decomp, compat_decomp, gencats)
9173

9274

9375
def load_derived_core_properties(f):
@@ -196,149 +178,50 @@ def emit_property_module_old(f, mod, tbl):
196178
f.write(" }\n\n")
197179
f.write("}\n")
198180

199-
def format_table_content(f, content, indent):
200-
line = " "*indent
201-
first = True
202-
for chunk in content.split(","):
203-
if len(line) + len(chunk) < 98:
204-
if first:
205-
line += chunk
206-
else:
207-
line += ", " + chunk
208-
first = False
209-
else:
210-
f.write(line + ",\n")
211-
line = " "*indent + chunk
212-
f.write(line)
213-
214-
def emit_decomp_module(f, canon, compat, combine):
181+
def emit_decomp_module(f, canon, compat):
215182
canon_keys = canon.keys()
216183
canon_keys.sort()
217184

218185
compat_keys = compat.keys()
219186
compat_keys.sort()
220-
f.write("pub mod decompose {\n");
221-
f.write(" use option::Option;\n");
222-
f.write(" use option::{Some, None};\n");
223-
f.write(" use vec::ImmutableVector;\n");
224-
f.write("""
225-
fn bsearch_table(c: char, r: &'static [(char, &'static [char])]) -> Option<&'static [char]> {
226-
use cmp::{Equal, Less, Greater};
227-
match r.bsearch(|&(val, _)| {
228-
if c == val { Equal }
229-
else if val < c { Less }
230-
else { Greater }
231-
}) {
232-
Some(idx) => {
233-
let (_, result) = r[idx];
234-
Some(result)
235-
}
236-
None => None
237-
}
238-
}\n
239-
""")
187+
f.write("mod decompose {\n\n");
188+
f.write(" export canonical, compatibility;\n\n")
189+
f.write(" fn canonical(c: char, i: block(char)) "
190+
+ "{ d(c, i, false); }\n\n")
191+
f.write(" fn compatibility(c: char, i: block(char)) "
192+
+"{ d(c, i, true); }\n\n")
193+
f.write(" fn d(c: char, i: block(char), k: bool) {\n")
240194

241-
f.write("""
242-
fn bsearch_range_value_table(c: char, r: &'static [(char, char, u8)]) -> u8 {
243-
use cmp::{Equal, Less, Greater};
244-
match r.bsearch(|&(lo, hi, _)| {
245-
if lo <= c && c <= hi { Equal }
246-
else if hi < c { Less }
247-
else { Greater }
248-
}) {
249-
Some(idx) => {
250-
let (_, _, result) = r[idx];
251-
result
252-
}
253-
None => 0
254-
}
255-
}\n\n
256-
""")
195+
f.write(" if c <= '\\x7f' { i(c); ret; }\n")
257196

258-
f.write(" // Canonical decompositions\n")
259-
f.write(" static canonical_table : &'static [(char, &'static [char])] = &[\n")
260-
data = ""
261-
first = True
197+
# First check the canonical decompositions
198+
f.write(" // Canonical decomposition\n")
199+
f.write(" alt c {\n")
262200
for char in canon_keys:
263-
if not first:
264-
data += ","
265-
first = False
266-
data += "(%s,&[" % escape_char(char)
267-
first2 = True
201+
f.write(" %s {\n" % escape_char(char))
268202
for d in canon[char]:
269-
if not first2:
270-
data += ","
271-
first2 = False
272-
data += escape_char(d)
273-
data += "])"
274-
format_table_content(f, data, 8)
275-
f.write("\n ];\n\n")
276-
277-
f.write(" // Compatibility decompositions\n")
278-
f.write(" static compatibility_table : &'static [(char, &'static [char])] = &[\n")
279-
data = ""
280-
first = True
281-
for char in compat_keys:
282-
if not first:
283-
data += ","
284-
first = False
285-
data += "(%s,&[" % escape_char(char)
286-
first2 = True
287-
for d in compat[char]:
288-
if not first2:
289-
data += ","
290-
first2 = False
291-
data += escape_char(d)
292-
data += "])"
293-
format_table_content(f, data, 8)
294-
f.write("\n ];\n\n")
295-
296-
f.write(" static combining_class_table : &'static [(char, char, u8)] = &[\n")
297-
ix = 0
298-
for pair in combine:
299-
f.write(ch_prefix(ix))
300-
f.write("(%s, %s, %s)" % (escape_char(pair[0]), escape_char(pair[1]), pair[2]))
301-
ix += 1
302-
f.write("\n ];\n")
303-
304-
f.write(" pub fn canonical(c: char, i: &fn(char)) "
305-
+ "{ d(c, i, false); }\n\n")
306-
f.write(" pub fn compatibility(c: char, i: &fn(char)) "
307-
+"{ d(c, i, true); }\n\n")
308-
f.write(" pub fn canonical_combining_class(c: char) -> u8 {\n"
309-
+ " bsearch_range_value_table(c, combining_class_table)\n"
310-
+ " }\n\n")
311-
f.write(" fn d(c: char, i: &fn(char), k: bool) {\n")
312-
f.write(" use iterator::Iterator;\n");
203+
f.write(" d(%s, i, k);\n"
204+
% escape_char(d))
205+
f.write(" }\n")
313206

314-
f.write(" if c <= '\\x7f' { i(c); return; }\n")
315-
316-
# First check the canonical decompositions
317-
f.write("""
318-
match bsearch_table(c, canonical_table) {
319-
Some(canon) => {
320-
for x in canon.iter() {
321-
d(*x, |b| i(b), k);
322-
}
323-
return;
324-
}
325-
None => ()
326-
}\n\n""")
207+
f.write(" _ { }\n")
208+
f.write(" }\n\n")
327209

328210
# Bottom out if we're not doing compat.
329-
f.write(" if !k { i(c); return; }\n")
211+
f.write(" if !k { i(c); ret; }\n\n ")
330212

331213
# Then check the compatibility decompositions
332-
f.write("""
333-
match bsearch_table(c, compatibility_table) {
334-
Some(compat) => {
335-
for x in compat.iter() {
336-
d(*x, |b| i(b), k);
337-
}
338-
return;
339-
}
340-
None => ()
341-
}\n\n""")
214+
f.write(" // Compatibility decomposition\n")
215+
f.write(" alt c {\n")
216+
for char in compat_keys:
217+
f.write(" %s {\n" % escape_char(char))
218+
for d in compat[char]:
219+
f.write(" d(%s, i, k);\n"
220+
% escape_char(d))
221+
f.write(" }\n")
222+
223+
f.write(" _ { }\n")
224+
f.write(" }\n\n")
342225

343226
# Finally bottom out.
344227
f.write(" i(c);\n")
@@ -351,7 +234,7 @@ def emit_decomp_module(f, canon, compat, combine):
351234
os.remove(i);
352235
rf = open(r, "w")
353236

354-
(canon_decomp, compat_decomp, gencats, combines) = load_unicode_data("UnicodeData.txt")
237+
(canon_decomp, compat_decomp, gencats) = load_unicode_data("UnicodeData.txt")
355238

356239
# Preamble
357240
rf.write('''// Copyright 2012-2013 The Rust Project Developers. See the COPYRIGHT
@@ -373,7 +256,7 @@ def emit_decomp_module(f, canon, compat, combine):
373256

374257
emit_property_module(rf, "general_category", gencats)
375258

376-
emit_decomp_module(rf, canon_decomp, compat_decomp, combines)
259+
#emit_decomp_module(rf, canon_decomp, compat_decomp)
377260

378261
derived = load_derived_core_properties("DerivedCoreProperties.txt")
379262
emit_property_module(rf, "derived_property", derived)

branches/try2/src/libextra/fileinput.rs

Lines changed: 20 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ reset once it has been finished, so attempting to iterate on `[None,
2727
None]` will only take input once unless `io::stdin().seek(0, SeekSet)`
2828
is called between.
2929
30-
The `make_path_option_vec` function handles converting a list of file paths as
30+
The `pathify` function handles converting a list of file paths as
3131
strings to the appropriate format, including the (optional) conversion
3232
of `"-"` to `stdin`.
3333
@@ -42,7 +42,7 @@ to handle any `FileInput` structs. E.g. a simple `cat` program
4242
4343
or a program that numbers lines after concatenating two files
4444
45-
for input_vec_state(make_path_option_vec([~"a.txt", ~"b.txt"])) |line, state| {
45+
for input_vec_state(pathify([~"a.txt", ~"b.txt"])) |line, state| {
4646
io::println(fmt!("%u: %s", state.line_num,
4747
line));
4848
}
@@ -145,14 +145,8 @@ struct FileInput_ {
145145
previous_was_newline: bool
146146
}
147147

148-
149-
// FIXME #5723: remove this when Reader has &mut self.
150-
// Removing it would mean giving read_byte in the Reader impl for
151-
// FileInput &mut self, which in turn means giving most of the
152-
// io::Reader trait methods &mut self. That can't be done right now
153-
// because of io::with_bytes_reader and #5723.
154-
// Should be removable via
155-
// "self.fi" -> "self." and renaming FileInput_. Documentation above
148+
// XXX: remove this when Reader has &mut self. Should be removable via
149+
// "self.fi." -> "self." and renaming FileInput_. Documentation above
156150
// will likely have to be updated to use `let mut in = ...`.
157151
pub struct FileInput {
158152
fi: @mut FileInput_
@@ -200,7 +194,7 @@ impl FileInput {
200194
*/
201195
pub fn from_args() -> FileInput {
202196
let args = os::args();
203-
let pathed = make_path_option_vec(args.tail(), true);
197+
let pathed = pathify(args.tail(), true);
204198
FileInput::from_vec(pathed)
205199
}
206200

@@ -357,7 +351,8 @@ Convert a list of strings to an appropriate form for a `FileInput`
357351
instance. `stdin_hyphen` controls whether `-` represents `stdin` or
358352
a literal `-`.
359353
*/
360-
pub fn make_path_option_vec(vec: &[~str], stdin_hyphen : bool) -> ~[Option<Path>] {
354+
// XXX: stupid, unclear name
355+
pub fn pathify(vec: &[~str], stdin_hyphen : bool) -> ~[Option<Path>] {
361356
vec.iter().map(|str| {
362357
if stdin_hyphen && "-" == *str {
363358
None
@@ -415,7 +410,7 @@ pub fn input_vec_state(files: ~[Option<Path>],
415410
#[cfg(test)]
416411
mod test {
417412

418-
use super::{FileInput, make_path_option_vec, input_vec, input_vec_state};
413+
use super::{FileInput, pathify, input_vec, input_vec_state};
419414

420415
use std::io;
421416
use std::uint;
@@ -431,22 +426,22 @@ mod test {
431426
}
432427

433428
#[test]
434-
fn test_make_path_option_vec() {
429+
fn test_pathify() {
435430
let strs = [~"some/path",
436431
~"some/other/path"];
437432
let paths = ~[Some(Path("some/path")),
438433
Some(Path("some/other/path"))];
439434

440-
assert_eq!(make_path_option_vec(strs, true), paths.clone());
441-
assert_eq!(make_path_option_vec(strs, false), paths);
435+
assert_eq!(pathify(strs, true), paths.clone());
436+
assert_eq!(pathify(strs, false), paths);
442437

443-
assert_eq!(make_path_option_vec([~"-"], true), ~[None]);
444-
assert_eq!(make_path_option_vec([~"-"], false), ~[Some(Path("-"))]);
438+
assert_eq!(pathify([~"-"], true), ~[None]);
439+
assert_eq!(pathify([~"-"], false), ~[Some(Path("-"))]);
445440
}
446441
447442
#[test]
448443
fn test_fileinput_read_byte() {
449-
let filenames = make_path_option_vec(vec::from_fn(
444+
let filenames = pathify(vec::from_fn(
450445
3,
451446
|i| fmt!("tmp/lib-fileinput-test-fileinput-read-byte-%u.tmp", i)), true);
452447
@@ -476,7 +471,7 @@ mod test {
476471
477472
#[test]
478473
fn test_fileinput_read() {
479-
let filenames = make_path_option_vec(vec::from_fn(
474+
let filenames = pathify(vec::from_fn(
480475
3,
481476
|i| fmt!("tmp/lib-fileinput-test-fileinput-read-%u.tmp", i)), true);
482477
@@ -497,7 +492,7 @@ mod test {
497492
#[test]
498493
fn test_input_vec() {
499494
let mut all_lines = ~[];
500-
let filenames = make_path_option_vec(vec::from_fn(
495+
let filenames = pathify(vec::from_fn(
501496
3,
502497
|i| fmt!("tmp/lib-fileinput-test-input-vec-%u.tmp", i)), true);
503498

@@ -519,7 +514,7 @@ mod test {
519514

520515
#[test]
521516
fn test_input_vec_state() {
522-
let filenames = make_path_option_vec(vec::from_fn(
517+
let filenames = pathify(vec::from_fn(
523518
3,
524519
|i| fmt!("tmp/lib-fileinput-test-input-vec-state-%u.tmp", i)),true);
525520

@@ -541,7 +536,7 @@ mod test {
541536

542537
#[test]
543538
fn test_empty_files() {
544-
let filenames = make_path_option_vec(vec::from_fn(
539+
let filenames = pathify(vec::from_fn(
545540
3,
546541
|i| fmt!("tmp/lib-fileinput-test-empty-files-%u.tmp", i)),true);
547542

@@ -588,7 +583,7 @@ mod test {
588583
589584
#[test]
590585
fn test_next_file() {
591-
let filenames = make_path_option_vec(vec::from_fn(
586+
let filenames = pathify(vec::from_fn(
592587
3,
593588
|i| fmt!("tmp/lib-fileinput-test-next-file-%u.tmp", i)),true);
594589
@@ -619,7 +614,7 @@ mod test {
619614
#[test]
620615
#[should_fail]
621616
fn test_input_vec_missing_file() {
622-
do input_vec(make_path_option_vec([~"this/file/doesnt/exist"], true)) |line| {
617+
do input_vec(pathify([~"this/file/doesnt/exist"], true)) |line| {
623618
println(line);
624619
true
625620
};

0 commit comments

Comments
 (0)