Skip to content

Commit 34b7db3

Browse files
committed
Merge pull request #4001 from jesse99/features/docs
Features/docs
2 parents 318e534 + ca332a6 commit 34b7db3

File tree

3 files changed

+104
-24
lines changed

3 files changed

+104
-24
lines changed

doc/README

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
The markdown docs are only generated by make when node is installed (use
2+
`make doc`). If you don't have node installed you can generate them yourself.
3+
Unfortunately there's no real standard for markdown and all the tools work
4+
differently. pandoc is one that seems to work well.
5+
6+
To generate an html version of a doc do something like:
7+
pandoc --from=markdown --to=html --number-sections -o build/doc/rust.html doc/rust.md && git web--browse build/doc/rust.html
8+
9+
The syntax for pandoc flavored markdown can be found at:
10+
http://johnmacfarlane.net/pandoc/README.html#pandocs-markdown
11+
12+
A nice quick reference (for non-pandoc markdown) is at:
13+
http://kramdown.rubyforge.org/quickref.html

doc/rust.md

Lines changed: 45 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -510,9 +510,8 @@ For parsing reasons, delimiters must be balanced, but they are otherwise not spe
510510

511511
In the matcher, `$` _name_ `:` _designator_ matches the nonterminal in the
512512
Rust syntax named by _designator_. Valid designators are `item`, `block`,
513-
`stmt`, `pat`, `expr`, `ty`, `ident`, `path`, `tt`, `matchers`. The last two
514-
are the right-hand side and the left-hand side respectively of the `=>` in
515-
macro rules. In the transcriber, the designator is already known, and so only
513+
`stmt`, `pat`, `expr`, `ty` (type), `ident`, `path`, `matchers` (lhs of the `=>` in macro rules),
514+
`tt` (rhs of the `=>` in macro rules). In the transcriber, the designator is already known, and so only
516515
the name of a matched nonterminal comes after the dollar sign.
517516

518517
In both the matcher and transcriber, the Kleene star-like operator indicates repetition.
@@ -799,7 +798,7 @@ extern mod ruststd (name = "std"); // linking to 'std' under another name
799798
##### Use declarations
800799

801800
~~~~~~~~ {.ebnf .gram}
802-
use_decl : "use" ident [ '=' path
801+
use_decl : "pub"? "use" ident [ '=' path
803802
| "::" path_glob ] ;
804803
805804
path_glob : ident [ "::" path_glob ] ?
@@ -1104,6 +1103,17 @@ Constants are declared with the `const` keyword.
11041103
A constant item must have an expression giving its definition.
11051104
The definition expression of a constant is limited to expression forms that can be evaluated at compile time.
11061105

1106+
Constants must be explicitly typed. The type may be ```bool```, ```char```, a number, or a type derived from
1107+
those primitive types. The derived types are borrowed pointers, static arrays, tuples, and structs.
1108+
1109+
~~~~
1110+
const bit1: uint = 1 << 0;
1111+
const bit2: uint = 1 << 1;
1112+
1113+
const bits: [uint * 2] = [bit1, bit2];
1114+
const bits_r: &[uint] = &bits;
1115+
~~~~
1116+
11071117
### Traits
11081118

11091119
A _trait_ describes a set of method types.
@@ -1175,6 +1185,9 @@ Values with a trait type can have [methods called](#method-call-expressions) on
11751185
for any method in the trait,
11761186
and can be used to instantiate type parameters that are bounded by the trait.
11771187

1188+
Trait methods may be static. Currently implementations of static methods behave like
1189+
functions declared in the implentation's module.
1190+
11781191
### Implementations
11791192

11801193
An _implementation_ is an item that implements a [trait](#traits) for a specific type.
@@ -1304,9 +1317,8 @@ Attributes may appear as any of
13041317
* An identifier followed by the equals sign '=' and a literal, providing a key/value pair
13051318
* An identifier followed by a parenthesized list of sub-attribute arguments
13061319

1307-
Attributes are applied to an entity by placing them within a hash-list
1308-
(`#[...]`) as either a prefix to the entity or as a semicolon-delimited
1309-
declaration within the entity body.
1320+
Attributes terminated by a semi-colon apply to the entity that the attribute is declared
1321+
within. Attributes that are not terminated by a semi-colon apply to the next entity.
13101322

13111323
An example of attributes:
13121324

@@ -1326,9 +1338,9 @@ mod bar {
13261338
...
13271339
}
13281340
1329-
// A documentation attribute
1330-
#[doc = "Add two numbers together."]
1331-
fn add(x: int, y: int) { x + y }
1341+
// A lint attribute used to suppress a warning/error
1342+
#[allow(non_camel_case_types)]
1343+
pub type int8_t = i8;
13321344
~~~~~~~~
13331345

13341346
> **Note:** In future versions of Rust, user-provided extensions to the compiler will be able to interpret attributes.
@@ -1341,6 +1353,8 @@ names are effectively reserved. Some significant attributes include:
13411353
* The `cfg` attribute, for conditional-compilation by build-configuration.
13421354
* The `link` attribute, for describing linkage metadata for a crate.
13431355
* The `test` attribute, for marking functions as unit tests.
1356+
* The `allow`, `warn`, `forbid`, and `deny` attributes, for controling lint checks. Lint checks supported
1357+
by the compiler can be found via `rustc -W help`.
13441358

13451359
Other attributes may be added or removed during development of the language.
13461360

@@ -1546,7 +1560,9 @@ it is automatically derferenced to make the field access possible.
15461560
### Vector expressions
15471561

15481562
~~~~~~~~{.ebnf .gram}
1549-
vec_expr : '[' "mut" ? [ expr [ ',' expr ] * ] ? ']'
1563+
vec_expr : '[' "mut"? vec_elems? ']'
1564+
1565+
vec_elems : [expr [',' expr]*] | [expr ',' ".." expr]
15501566
~~~~~~~~
15511567

15521568
A [_vector_](#vector-types) _expression_ is written by enclosing zero or
@@ -1558,6 +1574,7 @@ When no mutability is specified, the vector is immutable.
15581574
~~~~
15591575
[1, 2, 3, 4];
15601576
["a", "b", "c", "d"];
1577+
[0, ..128]; // vector with 128 zeros
15611578
[mut 0u8, 0u8, 0u8, 0u8];
15621579
~~~~
15631580

@@ -1889,7 +1906,7 @@ let x: int = add(1, 2);
18891906

18901907
~~~~~~~~ {.abnf .gram}
18911908
ident_list : [ ident [ ',' ident ]* ] ? ;
1892-
lambda_expr : '|' ident_list '| expr ;
1909+
lambda_expr : '|' ident_list '|' expr ;
18931910
~~~~~~~~
18941911

18951912
A _lambda expression_ (a.k.a. "anonymous function expression") defines a function and denotes it as a value,
@@ -2169,17 +2186,6 @@ Records and structures can also be pattern-matched and their fields bound to var
21692186
When matching fields of a record,
21702187
the fields being matched are specified first,
21712188
then a placeholder (`_`) represents the remaining fields.
2172-
2173-
A pattern that's just a variable binding,
2174-
like `Nil` in the previous answer,
2175-
could either refer to an enum variant that's in scope,
2176-
or bind a new variable.
2177-
The compiler resolves this ambiguity by forbidding variable bindings that occur in ```match``` patterns from shadowing names of variants that are in scope.
2178-
For example, wherever ```List``` is in scope,
2179-
a ```match``` pattern would not be able to bind ```Nil``` as a new name.
2180-
The compiler interprets a variable pattern `x` as a binding _only_ if there is no variant named `x` in scope.
2181-
A convention you can use to avoid conflicts is simply to name variants with upper-case letters,
2182-
and local variables with lower-case letters.
21832189

21842190
~~~~
21852191
# type options = {choose: bool, size: ~str};
@@ -2212,6 +2218,22 @@ fn main() {
22122218
}
22132219
~~~~
22142220

2221+
Patterns that bind variables default to binding to a copy of the matched value. This can be made
2222+
explicit using the ```copy``` keyword, changed to bind to a borrowed pointer by using the ```ref```
2223+
keyword, or to a mutable borrowed pointer using ```ref mut```, or the value can be moved into
2224+
the new binding using ```move```.
2225+
2226+
A pattern that's just an identifier,
2227+
like `Nil` in the previous answer,
2228+
could either refer to an enum variant that's in scope,
2229+
or bind a new variable.
2230+
The compiler resolves this ambiguity by forbidding variable bindings that occur in ```match``` patterns from shadowing names of variants that are in scope.
2231+
For example, wherever ```List``` is in scope,
2232+
a ```match``` pattern would not be able to bind ```Nil``` as a new name.
2233+
The compiler interprets a variable pattern `x` as a binding _only_ if there is no variant named `x` in scope.
2234+
A convention you can use to avoid conflicts is simply to name variants with upper-case letters,
2235+
and local variables with lower-case letters.
2236+
22152237
Multiple match patterns may be joined with the `|` operator. A
22162238
range of values may be specified with `..`. For example:
22172239

src/libcore/extfmt.rs

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,46 @@
1-
#[doc(hidden)];
1+
//! Support for fmt! expressions.
2+
//!
3+
//! The syntax is close to that of Posix format strings:
4+
//!
5+
//! ~~~~~~
6+
//! Format := '%' Parameter? Flag* Width? Precision? Type
7+
//! Parameter := [0-9]+ '$'
8+
//! Flag := [ 0#+-]
9+
//! Width := Parameter | [0-9]+
10+
//! Precision := '.' [0-9]+
11+
//! Type := [bcdfiostuxX?]
12+
//! ~~~~~~
13+
//!
14+
//! * Parameter is the 1-based argument to apply the format to. Currently not
15+
//! implemented.
16+
//! * Flag 0 causes leading zeros to be used for padding when converting
17+
//! numbers.
18+
//! * Flag # causes the conversion to be done in an *alternative* manner.
19+
//! Currently not implemented.
20+
//! * Flag + causes signed numbers to always be prepended with a sign
21+
//! character.
22+
//! * Flag - left justifies the result
23+
//! * Width specifies the minimum field width of the result. By default
24+
//! leading spaces are added.
25+
//! * Precision specifies the minimum number of digits for integral types
26+
//! and the minimum number
27+
//! of decimal places for float.
28+
//!
29+
//! The types currently supported are:
30+
//!
31+
//! * b - bool
32+
//! * c - char
33+
//! * d - int
34+
//! * f - float
35+
//! * i - int (same as d)
36+
//! * o - uint as octal
37+
//! * t - uint as binary
38+
//! * u - uint
39+
//! * x - uint as lower-case hexadecimal
40+
//! * X - uint as upper-case hexadecimal
41+
//! * s - str (any flavor)
42+
//! * ? - arbitrary type (does not use the to_str trait)
43+
244
// NB: transitionary, de-mode-ing.
345
#[forbid(deprecated_mode)];
446
#[forbid(deprecated_pattern)];
@@ -44,6 +86,7 @@ use option::{Some, None};
4486
*/
4587

4688
// Functions used by the fmt extension at compile time
89+
#[doc(hidden)]
4790
pub mod ct {
4891
pub enum Signedness { Signed, Unsigned, }
4992
pub enum Caseness { CaseUpper, CaseLower, }
@@ -277,6 +320,7 @@ pub mod ct {
277320
// decisions made a runtime. If it proves worthwhile then some of these
278321
// conditions can be evaluated at compile-time. For now though it's cleaner to
279322
// implement it 0this way, I think.
323+
#[doc(hidden)]
280324
pub mod rt {
281325
pub const flag_none : u32 = 0u32;
282326
pub const flag_left_justify : u32 = 0b00000000000001u32;
@@ -483,6 +527,7 @@ pub mod rt {
483527
}
484528
}
485529

530+
// Bulk of the tests are in src/test/run-pass/syntax-extension-fmt.rs
486531
#[cfg(test)]
487532
mod test {
488533
#[test]

0 commit comments

Comments
 (0)