Skip to content

Commit 100c4e2

Browse files
committed
---
yaml --- r: 144188 b: refs/heads/try2 c: 83f4bee h: refs/heads/master v: v3
1 parent 5256b51 commit 100c4e2

File tree

12 files changed

+2467
-369
lines changed

12 files changed

+2467
-369
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: e66478193b1ad0582cdabb5ca769a85b26ea000c
8+
refs/heads/try2: 83f4bee44f077c8f45eb2bd314aee7f2af8ee0dc
99
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/try2/doc/rust.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -788,7 +788,7 @@ extern mod complicated_mod = "some-file/in/the-rust/path";
788788
##### Use declarations
789789

790790
~~~~~~~~ {.ebnf .gram}
791-
use_decl : "pub" ? "use" ident [ '=' path
791+
use_decl : "pub"? "use" ident [ '=' path
792792
| "::" path_glob ] ;
793793
794794
path_glob : ident [ "::" path_glob ] ?
@@ -1920,7 +1920,7 @@ it is automatically dereferenced to make the field access possible.
19201920
### Vector expressions
19211921

19221922
~~~~~~~~{.ebnf .gram}
1923-
vec_expr : '[' "mut" ? vec_elems? ']'
1923+
vec_expr : '[' "mut"? vec_elems? ']'
19241924
19251925
vec_elems : [expr [',' expr]*] | [expr ',' ".." expr]
19261926
~~~~~~~~

branches/try2/src/etc/extract_grammar.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -93,11 +93,7 @@
9393

9494
"//": "linecomment",
9595
"/*": "openblockcomment",
96-
"*/": "closeblockcomment",
97-
"macro_rules": "macro_rules",
98-
"=>" : "eg",
99-
".." : "dotdot",
100-
"," : "comma"
96+
"*/": "closeblockcomment"
10197
}
10298

10399
lines = []

branches/try2/src/etc/unicode.py

Lines changed: 99 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -178,50 +178,118 @@ def emit_property_module_old(f, mod, tbl):
178178
f.write(" }\n\n")
179179
f.write("}\n")
180180

181+
def format_table_content(f, content, indent):
182+
line = " "*indent
183+
first = True
184+
for chunk in content.split(","):
185+
if len(line) + len(chunk) < 98:
186+
if first:
187+
line += chunk
188+
else:
189+
line += ", " + chunk
190+
first = False
191+
else:
192+
f.write(line + ",\n")
193+
line = " "*indent + chunk
194+
f.write(line)
195+
181196
def emit_decomp_module(f, canon, compat):
182197
canon_keys = canon.keys()
183198
canon_keys.sort()
184199

185200
compat_keys = compat.keys()
186201
compat_keys.sort()
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)) "
202+
f.write("pub mod decompose {\n");
203+
f.write(" use option::Option;\n");
204+
f.write(" use option::{Some, None};\n");
205+
f.write(" use vec::ImmutableVector;\n");
206+
f.write("""
207+
fn bsearch_table(c: char, r: &'static [(char, &'static [char])]) -> Option<&'static [char]> {
208+
use cmp::{Equal, Less, Greater};
209+
match r.bsearch(|&(val, _)| {
210+
if c == val { Equal }
211+
else if val < c { Less }
212+
else { Greater }
213+
}) {
214+
Some(idx) => {
215+
let (_, result) = r[idx];
216+
Some(result)
217+
}
218+
None => None
219+
}
220+
}\n\n
221+
""")
222+
f.write(" // Canonical decompositions\n")
223+
f.write(" static canonical_table : &'static [(char, &'static [char])] = &[\n")
224+
data = ""
225+
first = True
226+
for char in canon_keys:
227+
if not first:
228+
data += ","
229+
first = False
230+
data += "(%s,&[" % escape_char(char)
231+
first2 = True
232+
for d in canon[char]:
233+
if not first2:
234+
data += ","
235+
first2 = False
236+
data += escape_char(d)
237+
data += "])"
238+
format_table_content(f, data, 8)
239+
f.write("\n ];\n\n")
240+
f.write(" // Compatibility decompositions\n")
241+
f.write(" static compatibility_table : &'static [(char, &'static [char])] = &[\n")
242+
data = ""
243+
first = True
244+
for char in compat_keys:
245+
if not first:
246+
data += ","
247+
first = False
248+
data += "(%s,&[" % escape_char(char)
249+
first2 = True
250+
for d in compat[char]:
251+
if not first2:
252+
data += ","
253+
first2 = False
254+
data += escape_char(d)
255+
data += "])"
256+
format_table_content(f, data, 8)
257+
f.write("\n ];\n\n")
258+
f.write(" pub fn canonical(c: char, i: &fn(char)) "
259+
+ "{ d(c, i, false); }\n\n")
260+
f.write(" pub fn compatibility(c: char, i: &fn(char)) "
192261
+"{ d(c, i, true); }\n\n")
193-
f.write(" fn d(c: char, i: block(char), k: bool) {\n")
262+
f.write(" fn d(c: char, i: &fn(char), k: bool) {\n")
263+
f.write(" use iterator::Iterator;\n");
194264

195-
f.write(" if c <= '\\x7f' { i(c); ret; }\n")
265+
f.write(" if c <= '\\x7f' { i(c); return; }\n")
196266

197267
# First check the canonical decompositions
198-
f.write(" // Canonical decomposition\n")
199-
f.write(" alt c {\n")
200-
for char in canon_keys:
201-
f.write(" %s {\n" % escape_char(char))
202-
for d in canon[char]:
203-
f.write(" d(%s, i, k);\n"
204-
% escape_char(d))
205-
f.write(" }\n")
206-
207-
f.write(" _ { }\n")
208-
f.write(" }\n\n")
268+
f.write("""
269+
match bsearch_table(c, canonical_table) {
270+
Some(canon) => {
271+
for x in canon.iter() {
272+
d(*x, |b| i(b), k);
273+
}
274+
return;
275+
}
276+
None => ()
277+
}\n\n""")
209278

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

213282
# Then check the compatibility decompositions
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")
283+
f.write("""
284+
match bsearch_table(c, compatibility_table) {
285+
Some(compat) => {
286+
for x in compat.iter() {
287+
d(*x, |b| i(b), k);
288+
}
289+
return;
290+
}
291+
None => ()
292+
}\n\n""")
225293

226294
# Finally bottom out.
227295
f.write(" i(c);\n")
@@ -256,7 +324,7 @@ def emit_decomp_module(f, canon, compat):
256324

257325
emit_property_module(rf, "general_category", gencats)
258326

259-
#emit_decomp_module(rf, canon_decomp, compat_decomp)
327+
emit_decomp_module(rf, canon_decomp, compat_decomp)
260328

261329
derived = load_derived_core_properties("DerivedCoreProperties.txt")
262330
emit_property_module(rf, "derived_property", derived)

branches/try2/src/libstd/char.rs

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
use option::{None, Option, Some};
1414
use int;
1515
use str::StrSlice;
16-
use unicode::{derived_property, general_category};
16+
use unicode::{derived_property, general_category, decompose};
1717

1818
#[cfg(test)] use str::OwnedStr;
1919

@@ -202,6 +202,51 @@ pub fn from_digit(num: uint, radix: uint) -> Option<char> {
202202
}
203203
}
204204

205+
// Constants from Unicode 6.2.0 Section 3.12 Conjoining Jamo Behavior
206+
static S_BASE: uint = 0xAC00;
207+
static L_BASE: uint = 0x1100;
208+
static V_BASE: uint = 0x1161;
209+
static T_BASE: uint = 0x11A7;
210+
static L_COUNT: uint = 19;
211+
static V_COUNT: uint = 21;
212+
static T_COUNT: uint = 28;
213+
static N_COUNT: uint = (V_COUNT * T_COUNT);
214+
static S_COUNT: uint = (L_COUNT * N_COUNT);
215+
216+
// Decompose a precomposed Hangul syllable
217+
fn decompose_hangul(s: char, f: &fn(char)) {
218+
let si = s as uint - S_BASE;
219+
220+
let li = si / N_COUNT;
221+
f((L_BASE + li) as char);
222+
223+
let vi = (si % N_COUNT) / T_COUNT;
224+
f((V_BASE + vi) as char);
225+
226+
let ti = si % T_COUNT;
227+
if ti > 0 {
228+
f((T_BASE + ti) as char);
229+
}
230+
}
231+
232+
/// Returns the canonical decompostion of a character
233+
pub fn decompose_canonical(c: char, f: &fn(char)) {
234+
if (c as uint) < S_BASE || (c as uint) >= (S_BASE + S_COUNT) {
235+
decompose::canonical(c, f);
236+
} else {
237+
decompose_hangul(c, f);
238+
}
239+
}
240+
241+
/// Returns the compatibility decompostion of a character
242+
pub fn decompose_compatible(c: char, f: &fn(char)) {
243+
if (c as uint) < S_BASE || (c as uint) >= (S_BASE + S_COUNT) {
244+
decompose::compatibility(c, f);
245+
} else {
246+
decompose_hangul(c, f);
247+
}
248+
}
249+
205250
///
206251
/// Return the hexadecimal unicode escape of a char.
207252
///

branches/try2/src/libstd/iterator.rs

Lines changed: 10 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ implementing the `Iterator` trait.
1818
*/
1919

2020
use cmp;
21-
use num::{Zero, One, Integer, CheckedAdd, Saturating};
21+
use num::{Zero, One, Integer, Saturating};
2222
use option::{Option, Some, None};
2323
use ops::{Add, Mul, Sub};
2424
use cmp::Ord;
@@ -838,7 +838,7 @@ impl<A, T: Iterator<A>, U: Iterator<A>> Iterator<A> for Chain<T, U> {
838838
let lower = a_lower.saturating_add(b_lower);
839839

840840
let upper = match (a_upper, b_upper) {
841-
(Some(x), Some(y)) => x.checked_add(&y),
841+
(Some(x), Some(y)) => Some(x.saturating_add(y)),
842842
_ => None
843843
};
844844

@@ -1115,34 +1115,22 @@ impl<A, T: Iterator<A>> Iterator<A> for Peekable<A, T> {
11151115
if self.peeked.is_some() { self.peeked.take() }
11161116
else { self.iter.next() }
11171117
}
1118-
1119-
#[inline]
1120-
fn size_hint(&self) -> (uint, Option<uint>) {
1121-
let (lo, hi) = self.iter.size_hint();
1122-
if self.peeked.is_some() {
1123-
let lo = lo.saturating_add(1);
1124-
let hi = match hi {
1125-
Some(x) => x.checked_add(&1),
1126-
None => None
1127-
};
1128-
(lo, hi)
1129-
} else {
1130-
(lo, hi)
1131-
}
1132-
}
11331118
}
11341119

11351120
impl<'self, A, T: Iterator<A>> Peekable<A, T> {
11361121
/// Return a reference to the next element of the iterator with out advancing it,
11371122
/// or None if the iterator is exhausted.
11381123
#[inline]
11391124
pub fn peek(&'self mut self) -> Option<&'self A> {
1140-
if self.peeked.is_none() {
1141-
self.peeked = self.iter.next();
1142-
}
11431125
match self.peeked {
11441126
Some(ref value) => Some(value),
1145-
None => None,
1127+
None => {
1128+
self.peeked = self.iter.next();
1129+
match self.peeked {
1130+
Some(ref value) => Some(value),
1131+
None => None,
1132+
}
1133+
},
11461134
}
11471135
}
11481136
}
@@ -1388,7 +1376,7 @@ impl<'self, A, T: Iterator<A>, B, U: Iterator<B>> Iterator<B> for
13881376
let (blo, bhi) = self.backiter.map_default((0, Some(0)), |it| it.size_hint());
13891377
let lo = flo.saturating_add(blo);
13901378
match (self.iter.size_hint(), fhi, bhi) {
1391-
((0, Some(0)), Some(a), Some(b)) => (lo, a.checked_add(&b)),
1379+
((0, Some(0)), Some(a), Some(b)) => (lo, Some(a.saturating_add(b))),
13921380
_ => (lo, None)
13931381
}
13941382
}
@@ -1494,12 +1482,6 @@ impl<'self, A, St> Iterator<A> for Unfoldr<'self, A, St> {
14941482
fn next(&mut self) -> Option<A> {
14951483
(self.f)(&mut self.state)
14961484
}
1497-
1498-
#[inline]
1499-
fn size_hint(&self) -> (uint, Option<uint>) {
1500-
// no possible known bounds at this point
1501-
(0, None)
1502-
}
15031485
}
15041486

15051487
/// An infinite iterator starting at `start` and advancing by `step` with each
@@ -1543,9 +1525,6 @@ impl<A: Add<A, A> + Ord + Clone> Iterator<A> for Range<A> {
15431525
None
15441526
}
15451527
}
1546-
1547-
// FIXME: #8606 Implement size_hint() on Range
1548-
// Blocked on #8605 Need numeric trait for converting to `Option<uint>`
15491528
}
15501529

15511530
impl<A: Sub<A, A> + Integer + Ord + Clone> DoubleEndedIterator<A> for Range<A> {

0 commit comments

Comments
 (0)