Skip to content

Commit f2e0dfa

Browse files
committed
---
yaml --- r: 109309 b: refs/heads/dist-snap c: e6468a8 h: refs/heads/master i: 109307: 62eba61 v: v3
1 parent 1f05ec4 commit f2e0dfa

File tree

12 files changed

+128
-49
lines changed

12 files changed

+128
-49
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ refs/heads/try: f64fdf524a434f0e5cd0bc91d09c144723f3c90d
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: 147ecfdd8221e4a4d4e090486829a06da1e0ca3c
9-
refs/heads/dist-snap: 57ac379a630d9756c71f2747debe1756ccf62c5f
9+
refs/heads/dist-snap: e6468a82151c073130dc1c6517890bb41929ad11
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503
1212
refs/heads/try3: 9387340aab40a73e8424c48fd42f0c521a4875c0

branches/dist-snap/src/libsyntax/ext/base.rs

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,13 +119,31 @@ impl MacResult {
119119
pub fn raw_dummy_expr(sp: codemap::Span) -> @ast::Expr {
120120
@ast::Expr {
121121
id: ast::DUMMY_NODE_ID,
122-
node: ast::ExprTup(Vec::new()),
123-
span: sp
122+
node: ast::ExprLit(@codemap::respan(sp, ast::LitNil)),
123+
span: sp,
124124
}
125125
}
126126
pub fn dummy_expr(sp: codemap::Span) -> MacResult {
127127
MRExpr(MacResult::raw_dummy_expr(sp))
128128
}
129+
pub fn dummy_any(sp: codemap::Span) -> MacResult {
130+
MRAny(~DummyMacResult { sp: sp })
131+
}
132+
}
133+
struct DummyMacResult {
134+
sp: codemap::Span
135+
}
136+
impl AnyMacro for DummyMacResult {
137+
fn make_expr(&self) -> @ast::Expr {
138+
MacResult::raw_dummy_expr(self.sp)
139+
}
140+
fn make_items(&self) -> SmallVector<@ast::Item> {
141+
SmallVector::zero()
142+
}
143+
fn make_stmt(&self) -> @ast::Stmt {
144+
@codemap::respan(self.sp,
145+
ast::StmtExpr(MacResult::raw_dummy_expr(self.sp), ast::DUMMY_NODE_ID))
146+
}
129147
}
130148

131149
/// An enum representing the different kinds of syntax extensions.

branches/dist-snap/src/libsyntax/ext/log_syntax.rs

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,10 @@
1010

1111
use ast;
1212
use codemap;
13-
use ext::base::*;
1413
use ext::base;
1514
use print;
1615

17-
pub fn expand_syntax_ext(cx: &mut ExtCtxt,
16+
pub fn expand_syntax_ext(cx: &mut base::ExtCtxt,
1817
sp: codemap::Span,
1918
tt: &[ast::TokenTree])
2019
-> base::MacResult {
@@ -23,13 +22,6 @@ pub fn expand_syntax_ext(cx: &mut ExtCtxt,
2322
println!("{}", print::pprust::tt_to_str(&ast::TTDelim(
2423
@tt.iter().map(|x| (*x).clone()).collect())));
2524

26-
//trivial expression
27-
MRExpr(@ast::Expr {
28-
id: ast::DUMMY_NODE_ID,
29-
node: ast::ExprLit(@codemap::Spanned {
30-
node: ast::LitNil,
31-
span: sp
32-
}),
33-
span: sp,
34-
})
25+
// any so that `log_syntax` can be invoked as an expression and item.
26+
base::MacResult::dummy_any(sp)
3527
}

branches/dist-snap/src/libsyntax/ext/trace_macros.rs

Lines changed: 10 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -12,33 +12,21 @@ use ast;
1212
use codemap::Span;
1313
use ext::base::ExtCtxt;
1414
use ext::base;
15-
use parse::lexer::{new_tt_reader, Reader};
16-
use parse::parser::Parser;
17-
use parse::token::keywords;
15+
use parse::token::{keywords, is_keyword};
1816

1917
pub fn expand_trace_macros(cx: &mut ExtCtxt,
2018
sp: Span,
2119
tt: &[ast::TokenTree])
2220
-> base::MacResult {
23-
let sess = cx.parse_sess();
24-
let cfg = cx.cfg();
25-
let tt_rdr = new_tt_reader(&cx.parse_sess().span_diagnostic,
26-
None,
27-
tt.iter().map(|x| (*x).clone()).collect());
28-
let mut rust_parser = Parser(sess, cfg.clone(), tt_rdr.dup());
29-
30-
if rust_parser.is_keyword(keywords::True) {
31-
cx.set_trace_macros(true);
32-
} else if rust_parser.is_keyword(keywords::False) {
33-
cx.set_trace_macros(false);
34-
} else {
35-
cx.span_err(sp, "trace_macros! only accepts `true` or `false`");
36-
return base::MacResult::dummy_expr(sp);
21+
match tt {
22+
[ast::TTTok(_, ref tok)] if is_keyword(keywords::True, tok) => {
23+
cx.set_trace_macros(true);
24+
}
25+
[ast::TTTok(_, ref tok)] if is_keyword(keywords::False, tok) => {
26+
cx.set_trace_macros(false);
27+
}
28+
_ => cx.span_err(sp, "trace_macros! accepts only `true` or `false`"),
3729
}
3830

39-
rust_parser.bump();
40-
41-
let mut rust_parser = Parser(sess, cfg, tt_rdr.dup());
42-
let result = rust_parser.parse_expr();
43-
base::MRExpr(result)
31+
base::MacResult::dummy_any(sp)
4432
}

branches/dist-snap/src/libterm/lib.rs

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
html_root_url = "http://static.rust-lang.org/doc/master")];
2121

2222
#[feature(macro_rules)];
23+
#[deny(missing_doc)];
2324

2425
extern crate collections;
2526

@@ -34,7 +35,9 @@ pub mod terminfo;
3435

3536
// FIXME (#2807): Windows support.
3637

38+
/// Terminal color definitions
3739
pub mod color {
40+
/// Number for a terminal color
3841
pub type Color = u16;
3942

4043
pub static BLACK: Color = 0u16;
@@ -56,8 +59,10 @@ pub mod color {
5659
pub static BRIGHT_WHITE: Color = 15u16;
5760
}
5861

62+
/// Terminal attributes
5963
pub mod attr {
6064
/// Terminal attributes for use with term.attr().
65+
///
6166
/// Most attributes can only be turned on and must be turned off with term.reset().
6267
/// The ones that can be turned off explicitly take a boolean value.
6368
/// Color is also represented as an attribute for convenience.
@@ -103,13 +108,23 @@ fn cap_for_attr(attr: attr::Attr) -> &'static str {
103108
}
104109
}
105110

111+
/// A Terminal that knows how many colors it supports, with a reference to its
112+
/// parsed TermInfo database record.
106113
pub struct Terminal<T> {
107114
priv num_colors: u16,
108115
priv out: T,
109116
priv ti: ~TermInfo
110117
}
111118

112119
impl<T: Writer> Terminal<T> {
120+
/// Returns a wrapped output stream (`Terminal<T>`) as a `Result`.
121+
///
122+
/// Returns `Err()` if the TERM environment variable is undefined.
123+
/// TERM should be set to something like `xterm-color` or `screen-256color`.
124+
///
125+
/// Returns `Err()` on failure to open the terminfo database correctly.
126+
/// Also, in the event that the individual terminfo database entry can not
127+
/// be parsed.
113128
pub fn new(out: T) -> Result<Terminal<T>, ~str> {
114129
let term = match os::getenv("TERM") {
115130
Some(t) => t,
@@ -143,8 +158,8 @@ impl<T: Writer> Terminal<T> {
143158
/// If the color is a bright color, but the terminal only supports 8 colors,
144159
/// the corresponding normal color will be used instead.
145160
///
146-
/// Returns Ok(true) if the color was set, Ok(false) otherwise, and Err(e)
147-
/// if there was an I/O error
161+
/// Returns `Ok(true)` if the color was set, `Ok(false)` otherwise, and `Err(e)`
162+
/// if there was an I/O error.
148163
pub fn fg(&mut self, color: color::Color) -> io::IoResult<bool> {
149164
let color = self.dim_if_necessary(color);
150165
if self.num_colors > color {
@@ -166,8 +181,8 @@ impl<T: Writer> Terminal<T> {
166181
/// If the color is a bright color, but the terminal only supports 8 colors,
167182
/// the corresponding normal color will be used instead.
168183
///
169-
/// Returns Ok(true) if the color was set, Ok(false) otherwise, and Err(e)
170-
/// if there was an I/O error
184+
/// Returns `Ok(true)` if the color was set, `Ok(false)` otherwise, and `Err(e)`
185+
/// if there was an I/O error.
171186
pub fn bg(&mut self, color: color::Color) -> io::IoResult<bool> {
172187
let color = self.dim_if_necessary(color);
173188
if self.num_colors > color {
@@ -186,8 +201,8 @@ impl<T: Writer> Terminal<T> {
186201
}
187202

188203
/// Sets the given terminal attribute, if supported.
189-
/// Returns Ok(true) if the attribute was supported, Ok(false) otherwise,
190-
/// and Err(e) if there was an I/O error.
204+
/// Returns `Ok(true)` if the attribute was supported, `Ok(false)` otherwise,
205+
/// and `Err(e)` if there was an I/O error.
191206
pub fn attr(&mut self, attr: attr::Attr) -> io::IoResult<bool> {
192207
match attr {
193208
attr::ForegroundColor(c) => self.fg(c),
@@ -223,6 +238,7 @@ impl<T: Writer> Terminal<T> {
223238
}
224239

225240
/// Resets all terminal attributes and color to the default.
241+
/// Returns `Ok()`.
226242
pub fn reset(&mut self) -> io::IoResult<()> {
227243
let mut cap = self.ti.strings.find_equiv(&("sgr0"));
228244
if cap.is_none() {
@@ -248,10 +264,13 @@ impl<T: Writer> Terminal<T> {
248264
} else { color }
249265
}
250266

267+
/// Returns the contained stream
251268
pub fn unwrap(self) -> T { self.out }
252269

270+
/// Gets an immutable reference to the stream inside
253271
pub fn get_ref<'a>(&'a self) -> &'a T { &self.out }
254272

273+
/// Gets a mutable reference to the stream inside
255274
pub fn get_mut<'a>(&'a mut self) -> &'a mut T { &mut self.out }
256275
}
257276

branches/dist-snap/src/libterm/terminfo/mod.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
#[allow(missing_doc)];
11+
//! Terminfo database interface.
1212
1313
use collections::HashMap;
1414

15-
/// A parsed terminfo entry.
15+
/// A parsed terminfo database entry.
1616
pub struct TermInfo {
1717
/// Names for the terminal
1818
priv names: Vec<~str> ,
@@ -25,7 +25,10 @@ pub struct TermInfo {
2525
}
2626

2727
pub mod searcher;
28+
29+
/// TermInfo format parsing.
2830
pub mod parser {
31+
//! ncurses-compatible compiled terminfo format parsing (term(5))
2932
pub mod compiled;
3033
}
3134
pub mod parm;

branches/dist-snap/src/libterm/terminfo/parm.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ enum FormatState {
3838
}
3939

4040
/// Types of parameters a capability can use
41-
#[deriving(Clone)]
4241
#[allow(missing_doc)]
42+
#[deriving(Clone)]
4343
pub enum Param {
4444
String(~str),
4545
Number(int)

branches/dist-snap/src/libterm/terminfo/parser/compiled.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
#[allow(non_uppercase_statics)];
1212

13-
/// ncurses-compatible compiled terminfo format parsing (term(5))
13+
//! ncurses-compatible compiled terminfo format parsing (term(5))
1414
1515
use collections::HashMap;
1616
use std::io;

branches/dist-snap/src/libterm/terminfo/searcher.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
/// Implement ncurses-compatible database discovery
12-
/// Does not support hashed database, only filesystem!
11+
//! ncurses-compatible database discovery
12+
//!
13+
//! Does not support hashed database, only filesystem!
1314
1415
use std::io::File;
1516
use std::os::getenv;

branches/dist-snap/src/test/compile-fail/issue-11692.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,4 @@ fn main() {
1515

1616
concat!(test!());
1717
//~^ ERROR: macro undefined: 'test'
18-
//~^^ ERROR: expected a literal
1918
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
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+
// ignore-fast feature doesn't work
12+
#[feature(macro_rules, trace_macros)];
13+
14+
fn main() {
15+
trace_macros!(); //~ ERROR trace_macros! accepts only `true` or `false`
16+
trace_macros!(1); //~ ERROR trace_macros! accepts only `true` or `false`
17+
trace_macros!(ident); //~ ERROR trace_macros! accepts only `true` or `false`
18+
trace_macros!(for); //~ ERROR trace_macros! accepts only `true` or `false`
19+
trace_macros!(true,); //~ ERROR trace_macros! accepts only `true` or `false`
20+
trace_macros!(false 1); //~ ERROR trace_macros! accepts only `true` or `false`
21+
22+
23+
// should be fine:
24+
macro_rules! expando {
25+
($x: ident) => { trace_macros!($x) }
26+
}
27+
28+
expando!(true);
29+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
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+
// ignore-fast feature doesn't work
12+
#[feature(trace_macros, log_syntax)];
13+
14+
// make sure these macros can be used as in the various places that
15+
// macros can occur.
16+
17+
// items
18+
trace_macros!(false)
19+
log_syntax!()
20+
21+
fn main() {
22+
23+
// statements
24+
trace_macros!(false);
25+
log_syntax!();
26+
27+
// expressions
28+
(trace_macros!(false),
29+
log_syntax!());
30+
}

0 commit comments

Comments
 (0)