Skip to content

Commit f8d0c14

Browse files
committed
---
yaml --- r: 152050 b: refs/heads/try2 c: 5811d2b h: refs/heads/master v: v3
1 parent b6d1234 commit f8d0c14

File tree

32 files changed

+1237
-425
lines changed

32 files changed

+1237
-425
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: 49a65815f17d9d3ee1a8ea323aaaf96e1beb265a
8+
refs/heads/try2: 5811d2bd966716cea1d7653fa7a7cec64171a532
99
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/try2/src/doc/rustdoc.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,31 @@ pub fn recalibrate() {
4141
# }
4242
~~~
4343

44+
Documentation can also be controlled via the `doc` attribute on items. This is
45+
implicitly done by the compiler when using the above form of doc comments
46+
(converting the slash-based comments to `#[doc]` attributes).
47+
48+
~~~
49+
#[doc = "
50+
Calculates the factorial of a number.
51+
52+
Given the input integer `n`, this function will calculate `n!` and return it.
53+
"]
54+
pub fn factorial(n: int) -> int { if n < 2 {1} else {n * factorial(n)} }
55+
# fn main() {}
56+
~~~
57+
58+
The `doc` attribute can also be used to control how rustdoc emits documentation
59+
in some cases.
60+
61+
```
62+
// Rustdoc will inline documentation of a `pub use` into this crate when the
63+
// `pub use` reaches across crates, but this behavior can also be disabled.
64+
#[doc(no_inline)]
65+
pub use std::option::Option;
66+
# fn main() {}
67+
```
68+
4469
Doc comments are markdown, and are currently parsed with the
4570
[sundown][sundown] library. rustdoc does not yet do any fanciness such as
4671
referencing other items inline, like javadoc's `@see`. One exception to this

branches/try2/src/doc/tutorial.md

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,24 @@ they don't contain references to names that aren't actually defined.
5757
5858
# Getting started
5959

60-
> *Warning:* The tarball and installer links are for the most recent
61-
> release, not master. To use master, you **must** build from [git].
60+
There are two ways to install the Rust compiler: by building from source or
61+
by downloading prebuilt binaries or installers for your platform. The
62+
[install page][rust-install] contains links to download binaries for both
63+
the nightly build and the most current Rust major release. For Windows and
64+
OS X, the install page provides links to native installers.
6265

63-
The Rust compiler currently must be built from a [tarball] or [git], unless
64-
you are on Windows, in which case using the [installer][win-exe] is
65-
recommended. There is a list of community-maintained nightly builds and
66-
packages [on the wiki][wiki-packages].
66+
> *Note:* Windows users should read the detailed
67+
> [Getting started][wiki-start] notes on the wiki. Even when using
68+
> the binary installer, the Windows build requires a MinGW installation,
69+
> the precise details of which are not discussed here.
70+
71+
For Linux and OS X, the install page provides links to binary tarballs.
72+
To install the Rust compiler from the from a binary tarball, download
73+
the binary package, extract it, and execute the `install.sh` script in
74+
the root directory of the package.
75+
76+
To build the Rust compiler from source, you will need to obtain the source through
77+
[Git][git] or by downloading the source package from the [install page][rust-install].
6778

6879
Since the Rust compiler is written in Rust, it must be built by
6980
a precompiled "snapshot" version of itself (made in an earlier state
@@ -79,13 +90,9 @@ Snapshot binaries are currently built and tested on several platforms:
7990
You may find that other platforms work, but these are our "tier 1"
8091
supported build environments that are most likely to work.
8192

82-
> *Note:* Windows users should read the detailed
83-
> [Getting started][wiki-start] notes on the wiki. Even when using
84-
> the binary installer, the Windows build requires a MinGW installation,
85-
> the precise details of which are not discussed here.
86-
8793
[wiki-start]: https://github.com/mozilla/rust/wiki/Note-getting-started-developing-Rust
8894
[git]: https://github.com/mozilla/rust.git
95+
[rust-install]: http://www.rust-lang.org/install.html
8996

9097
To build from source you will also need the following prerequisite
9198
packages:
@@ -1099,7 +1106,7 @@ let ys = xs;
10991106
11001107
xs = Nil;
11011108
1102-
// `xs` can be used again
1109+
// `xs` can't be used again
11031110
~~~
11041111

11051112
A destructor call will only occur for a variable that has not been moved from,

branches/try2/src/libcore/tuple.rs

Lines changed: 50 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,55 @@
99
// except according to those terms.
1010

1111
//! Operations on tuples
12-
13-
#![allow(missing_doc)]
12+
//!
13+
//! To access a single element of a tuple one can use the following
14+
//! methods:
15+
//!
16+
//! * `valN` - returns a value of _N_-th element
17+
//! * `refN` - returns a reference to _N_-th element
18+
//! * `mutN` - returns a mutable reference to _N_-th element
19+
//!
20+
//! Indexing starts from zero, so `val0` returns first value, `val1`
21+
//! returns second value, and so on. In general, a tuple with _S_
22+
//! elements provides aforementioned methods suffixed with numbers
23+
//! from `0` to `S-1`. Traits which contain these methods are
24+
//! implemented for tuples with up to 12 elements.
25+
//!
26+
//! If every type inside a tuple implements one of the following
27+
//! traits, then a tuple itself also implements it.
28+
//!
29+
//! * `Clone`
30+
//! * `Eq`
31+
//! * `TotalEq`
32+
//! * `Ord`
33+
//! * `TotalOrd`
34+
//! * `Default`
35+
//!
36+
//! # Examples
37+
//!
38+
//! Using methods:
39+
//!
40+
//! ```
41+
//! let pair = ("pi", 3.14);
42+
//! assert_eq!(pair.val0(), "pi");
43+
//! assert_eq!(pair.val1(), 3.14);
44+
//! ```
45+
//!
46+
//! Using traits implemented for tuples:
47+
//!
48+
//! ```
49+
//! use std::default::Default;
50+
//!
51+
//! let a = (1, 2);
52+
//! let b = (3, 4);
53+
//! assert!(a != b);
54+
//!
55+
//! let c = b.clone();
56+
//! assert!(b == c);
57+
//!
58+
//! let d : (u32, f32) = Default::default();
59+
//! assert_eq!(d, (0u32, 0.0f32));
60+
//! ```
1461
1562
use clone::Clone;
1663
#[cfg(not(test))] use cmp::*;
@@ -26,6 +73,7 @@ macro_rules! tuple_impls {
2673
}
2774
)+) => {
2875
$(
76+
#[allow(missing_doc)]
2977
pub trait $Tuple<$($T),+> {
3078
$(fn $valN(self) -> $T;)+
3179
$(fn $refN<'a>(&'a self) -> &'a $T;)+

branches/try2/src/libregex/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,7 @@ pub mod native {
401401
// undesirable consequences (such as requiring a dependency on
402402
// `libsyntax`).
403403
//
404-
// Secondly, the code generated generated by `regex!` must *also* be able
404+
// Secondly, the code generated by `regex!` must *also* be able
405405
// to access various functions in this crate to reduce code duplication
406406
// and to provide a value with precisely the same `Regex` type in this
407407
// crate. This, AFAIK, is impossible to mitigate.

branches/try2/src/libregex/re.rs

Lines changed: 83 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -100,38 +100,45 @@ pub fn is_match(regex: &str, text: &str) -> Result<bool, parse::Error> {
100100
/// documentation.
101101
#[deriving(Clone)]
102102
#[allow(visible_private_types)]
103-
pub struct Regex {
104-
/// The representation of `Regex` is exported to support the `regex!`
105-
/// syntax extension. Do not rely on it.
106-
///
107-
/// See the comments for the `program` module in `lib.rs` for a more
108-
/// detailed explanation for what `regex!` requires.
103+
pub enum Regex {
104+
// The representation of `Regex` is exported to support the `regex!`
105+
// syntax extension. Do not rely on it.
106+
//
107+
// See the comments for the `program` module in `lib.rs` for a more
108+
// detailed explanation for what `regex!` requires.
109109
#[doc(hidden)]
110-
pub original: String,
110+
Dynamic(Dynamic),
111111
#[doc(hidden)]
112-
pub names: Vec<Option<String>>,
112+
Native(Native),
113+
}
114+
115+
#[deriving(Clone)]
116+
#[doc(hidden)]
117+
pub struct Dynamic {
118+
original: String,
119+
names: Vec<Option<String>>,
113120
#[doc(hidden)]
114-
pub p: MaybeNative,
121+
pub prog: Program
115122
}
116123

117-
impl fmt::Show for Regex {
118-
/// Shows the original regular expression.
119-
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
120-
write!(f, "{}", self.original)
121-
}
124+
#[doc(hidden)]
125+
pub struct Native {
126+
#[doc(hidden)]
127+
pub original: &'static str,
128+
#[doc(hidden)]
129+
pub names: &'static [Option<&'static str>],
130+
#[doc(hidden)]
131+
pub prog: fn(MatchKind, &str, uint, uint) -> Vec<Option<uint>>
122132
}
123133

124-
pub enum MaybeNative {
125-
Dynamic(Program),
126-
Native(fn(MatchKind, &str, uint, uint) -> Vec<Option<uint>>),
134+
impl Clone for Native {
135+
fn clone(&self) -> Native { *self }
127136
}
128137

129-
impl Clone for MaybeNative {
130-
fn clone(&self) -> MaybeNative {
131-
match *self {
132-
Dynamic(ref p) => Dynamic(p.clone()),
133-
Native(fp) => Native(fp),
134-
}
138+
impl fmt::Show for Regex {
139+
/// Shows the original regular expression.
140+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
141+
write!(f, "{}", self.as_str())
135142
}
136143
}
137144

@@ -146,10 +153,11 @@ impl Regex {
146153
pub fn new(re: &str) -> Result<Regex, parse::Error> {
147154
let ast = try!(parse::parse(re));
148155
let (prog, names) = Program::new(ast);
149-
Ok(Regex {
156+
Ok(Dynamic(Dynamic {
150157
original: re.to_strbuf(),
151-
names: names, p: Dynamic(prog),
152-
})
158+
names: names,
159+
prog: prog,
160+
}))
153161
}
154162

155163
/// Returns true if and only if the regex matches the string given.
@@ -495,6 +503,46 @@ impl Regex {
495503
}
496504
new.append(text.slice(last_match, text.len()))
497505
}
506+
507+
/// Returns the original string of this regex.
508+
pub fn as_str<'a>(&'a self) -> &'a str {
509+
match *self {
510+
Dynamic(Dynamic { ref original, .. }) => original.as_slice(),
511+
Native(Native { ref original, .. }) => original.as_slice(),
512+
}
513+
}
514+
515+
#[doc(hidden)]
516+
#[allow(visible_private_types)]
517+
#[experimental]
518+
pub fn names_iter<'a>(&'a self) -> NamesIter<'a> {
519+
match *self {
520+
Native(ref n) => NamesIterNative(n.names.iter()),
521+
Dynamic(ref d) => NamesIterDynamic(d.names.iter())
522+
}
523+
}
524+
525+
fn names_len(&self) -> uint {
526+
match *self {
527+
Native(ref n) => n.names.len(),
528+
Dynamic(ref d) => d.names.len()
529+
}
530+
}
531+
532+
}
533+
534+
enum NamesIter<'a> {
535+
NamesIterNative(::std::slice::Items<'a, Option<&'static str>>),
536+
NamesIterDynamic(::std::slice::Items<'a, Option<String>>)
537+
}
538+
539+
impl<'a> Iterator<Option<String>> for NamesIter<'a> {
540+
fn next(&mut self) -> Option<Option<String>> {
541+
match *self {
542+
NamesIterNative(ref mut i) => i.next().map(|x| x.map(|s| s.to_strbuf())),
543+
NamesIterDynamic(ref mut i) => i.next().map(|x| x.as_ref().map(|s| s.to_strbuf())),
544+
}
545+
}
498546
}
499547

500548
/// NoExpand indicates literal string replacement.
@@ -612,22 +660,23 @@ pub struct Captures<'t> {
612660
}
613661

614662
impl<'t> Captures<'t> {
663+
#[allow(experimental)]
615664
fn new(re: &Regex, search: &'t str, locs: CaptureLocs)
616665
-> Option<Captures<'t>> {
617666
if !has_match(&locs) {
618667
return None
619668
}
620669

621670
let named =
622-
if re.names.len() == 0 {
671+
if re.names_len() == 0 {
623672
None
624673
} else {
625674
let mut named = HashMap::new();
626-
for (i, name) in re.names.iter().enumerate() {
675+
for (i, name) in re.names_iter().enumerate() {
627676
match name {
628-
&None => {},
629-
&Some(ref name) => {
630-
named.insert(name.to_strbuf(), i);
677+
None => {},
678+
Some(name) => {
679+
named.insert(name, i);
631680
}
632681
}
633682
}
@@ -862,9 +911,9 @@ fn exec(re: &Regex, which: MatchKind, input: &str) -> CaptureLocs {
862911

863912
fn exec_slice(re: &Regex, which: MatchKind,
864913
input: &str, s: uint, e: uint) -> CaptureLocs {
865-
match re.p {
866-
Dynamic(ref prog) => vm::run(which, prog, input, s, e),
867-
Native(exec) => exec(which, input, s, e),
914+
match *re {
915+
Dynamic(Dynamic { ref prog, .. }) => vm::run(which, prog, input, s, e),
916+
Native(Native { prog, .. }) => prog(which, input, s, e),
868917
}
869918
}
870919

branches/try2/src/libregex/test/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ mod native_bench;
2020
#[path = "tests.rs"]
2121
mod native_tests;
2222

23+
#[cfg(not(stage1))]
24+
mod native_static;
25+
2326
// Due to macro scoping rules, this definition only applies for the modules
2427
// defined below. Effectively, it allows us to use the same tests for both
2528
// native and dynamic regexes.
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// Copyright 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 regex::Regex;
12+
static RE: Regex = regex!(r"\d+");
13+
14+
#[test]
15+
fn static_splitn() {
16+
let text = "cauchy123plato456tyler789binx";
17+
let subs: Vec<&str> = RE.splitn(text, 2).collect();
18+
assert_eq!(subs, vec!("cauchy", "plato456tyler789binx"));
19+
}
20+
21+
#[test]
22+
fn static_split() {
23+
let text = "cauchy123plato456tyler789binx";
24+
let subs: Vec<&str> = RE.split(text).collect();
25+
assert_eq!(subs, vec!("cauchy", "plato", "tyler", "binx"));
26+
}

0 commit comments

Comments
 (0)