Skip to content

Commit da74977

Browse files
committed
syntex: Copy unstable librustc_unicode fns into libsyntax
1 parent 3609333 commit da74977

File tree

5 files changed

+665
-5
lines changed

5 files changed

+665
-5
lines changed

src/libsyntax/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
#![feature(libc)]
3030
#![feature(rustc_private)]
3131
#![feature(staged_api)]
32-
#![feature(unicode)]
3332

3433
extern crate arena;
3534
extern crate fmt_macros;
@@ -93,6 +92,7 @@ pub mod std_inject;
9392
pub mod str;
9493
pub mod test;
9594
pub mod visit;
95+
pub mod unicode;
9696

9797
pub mod print {
9898
pub mod pp;

src/libsyntax/parse/lexer/mod.rs

+7-4
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ use ext::tt::transcribe::tt_next_token;
1616
use parse::token::str_to_ident;
1717
use parse::token;
1818
use str::{char_at, escape_default};
19+
use unicode::char::{is_xid_start, is_xid_continue};
1920

2021
use std::borrow::Cow;
2122
use std::char;
@@ -718,8 +719,10 @@ impl<'a> StringReader<'a> {
718719
// might be a float, but don't be greedy if this is actually an
719720
// integer literal followed by field/method access or a range pattern
720721
// (`0..2` and `12.foo()`)
721-
if self.curr_is('.') && !self.nextch_is('.') && !self.nextch().unwrap_or('\0')
722-
.is_xid_start() {
722+
if self.curr_is('.') &&
723+
!self.nextch_is('.') &&
724+
!is_xid_start(self.nextch().unwrap_or('\0'))
725+
{
723726
// might have stuff after the ., and if it does, it needs to start
724727
// with a number
725728
self.bump();
@@ -1487,7 +1490,7 @@ fn ident_start(c: Option<char>) -> bool {
14871490
(c >= 'a' && c <= 'z')
14881491
|| (c >= 'A' && c <= 'Z')
14891492
|| c == '_'
1490-
|| (c > '\x7f' && c.is_xid_start())
1493+
|| (c > '\x7f' && is_xid_start(c))
14911494
}
14921495

14931496
fn ident_continue(c: Option<char>) -> bool {
@@ -1497,7 +1500,7 @@ fn ident_continue(c: Option<char>) -> bool {
14971500
|| (c >= 'A' && c <= 'Z')
14981501
|| (c >= '0' && c <= '9')
14991502
|| c == '_'
1500-
|| (c > '\x7f' && c.is_xid_continue())
1503+
|| (c > '\x7f' && is_xid_continue(c))
15011504
}
15021505

15031506
#[cfg(test)]

src/libsyntax/unicode/char.rs

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
// Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
use super::tables::{derived_property, charwidth};
12+
13+
/// Returns whether the specified character satisfies the 'XID_Start'
14+
/// Unicode property.
15+
///
16+
/// 'XID_Start' is a Unicode Derived Property specified in
17+
/// [UAX #31](http://unicode.org/reports/tr31/#NFKC_Modifications),
18+
/// mostly similar to ID_Start but modified for closure under NFKx.
19+
#[unstable(feature = "unicode",
20+
reason = "mainly needed for compiler internals")]
21+
#[inline]
22+
pub fn is_xid_start(ch: char) -> bool { derived_property::XID_Start(ch) }
23+
24+
/// Returns whether the specified `char` satisfies the 'XID_Continue'
25+
/// Unicode property.
26+
///
27+
/// 'XID_Continue' is a Unicode Derived Property specified in
28+
/// [UAX #31](http://unicode.org/reports/tr31/#NFKC_Modifications),
29+
/// mostly similar to 'ID_Continue' but modified for closure under NFKx.
30+
#[unstable(feature = "unicode",
31+
reason = "mainly needed for compiler internals")]
32+
#[inline]
33+
pub fn is_xid_continue(ch: char) -> bool { derived_property::XID_Continue(ch) }
34+
35+
/// Returns this character's displayed width in columns, or `None` if it is a
36+
/// control character other than `'\x00'`.
37+
///
38+
/// `is_cjk` determines behavior for characters in the Ambiguous category:
39+
/// if `is_cjk` is `true`, these are 2 columns wide; otherwise, they are 1.
40+
/// In CJK contexts, `is_cjk` should be `true`, else it should be `false`.
41+
/// [Unicode Standard Annex #11](http://www.unicode.org/reports/tr11/)
42+
/// recommends that these characters be treated as 1 column (i.e.,
43+
/// `is_cjk` = `false`) if the context cannot be reliably determined.
44+
#[deprecated(reason = "use the crates.io `unicode-width` library instead",
45+
since = "1.0.0")]
46+
#[unstable(feature = "unicode",
47+
reason = "needs expert opinion. is_cjk flag stands out as ugly")]
48+
pub fn width(ch: char, is_cjk: bool) -> Option<usize> {
49+
charwidth::width(ch, is_cjk)
50+
}

src/libsyntax/unicode/mod.rs

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
pub mod char;
12+
mod tables;

0 commit comments

Comments
 (0)