Skip to content

Commit af5fc79

Browse files
committed
---
yaml --- r: 272822 b: refs/heads/beta c: 5daf13c h: refs/heads/master
1 parent e405ba8 commit af5fc79

File tree

8 files changed

+82
-51
lines changed

8 files changed

+82
-51
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ refs/tags/0.9: 36870b185fc5f5486636d4515f0e22677493f225
2323
refs/tags/0.10: ac33f2b15782272ae348dbd7b14b8257b2148b5a
2424
refs/tags/0.11.0: e1247cb1d0d681be034adb4b558b5a0c0d5720f9
2525
refs/tags/0.12.0: f0c419429ef30723ceaf6b42f9b5a2aeb5d2e2d1
26-
refs/heads/beta: c5d58de665819f7330b3d64bdd084d25a412830a
26+
refs/heads/beta: 5daf13cae371ce4ee90450a1d3006b53395a40d7
2727
refs/tags/1.0.0-alpha: e42bd6d93a1d3433c486200587f8f9e12590a4d7
2828
refs/heads/tmp: e06d2ad9fcd5027bcaac5b08fc9aa39a49d0ecd3
2929
refs/tags/1.0.0-alpha.2: 4c705f6bc559886632d3871b04f58aab093bfa2f

branches/beta/src/libsyntax/ast.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -886,6 +886,15 @@ impl fmt::Debug for Expr {
886886
}
887887
}
888888

889+
/// Limit types of a range (inclusive or exclusive)
890+
#[derive(Copy, Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
891+
pub enum RangeLimits {
892+
/// Inclusive at the beginning, exclusive at the end
893+
HalfOpen,
894+
/// Inclusive at the beginning and end
895+
Closed,
896+
}
897+
889898
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
890899
pub enum ExprKind {
891900
/// A `box x` expression.
@@ -974,8 +983,8 @@ pub enum ExprKind {
974983
TupField(P<Expr>, Spanned<usize>),
975984
/// An indexing operation (`foo[2]`)
976985
Index(P<Expr>, P<Expr>),
977-
/// A range (`1..2`, `1..`, or `..2`)
978-
Range(Option<P<Expr>>, Option<P<Expr>>),
986+
/// A range (`1..2`, `1..`, `..2`, `1...2`, `1...`, `...2`)
987+
Range(Option<P<Expr>>, Option<P<Expr>>, RangeLimits),
979988

980989
/// Variable reference, possibly containing `::` and/or type
981990
/// parameters, e.g. foo::bar::<baz>.

branches/beta/src/libsyntax/fold.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1273,9 +1273,10 @@ pub fn noop_fold_expr<T: Folder>(Expr {id, node, span, attrs}: Expr, folder: &mu
12731273
ExprKind::Index(el, er) => {
12741274
ExprKind::Index(folder.fold_expr(el), folder.fold_expr(er))
12751275
}
1276-
ExprKind::Range(e1, e2) => {
1276+
ExprKind::Range(e1, e2, lim) => {
12771277
ExprKind::Range(e1.map(|x| folder.fold_expr(x)),
1278-
e2.map(|x| folder.fold_expr(x)))
1278+
e2.map(|x| folder.fold_expr(x)),
1279+
lim)
12791280
}
12801281
ExprKind::Path(qself, path) => {
12811282
let qself = qself.map(|QSelf { ty, position }| {

branches/beta/src/libsyntax/parse/parser.rs

Lines changed: 50 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use ast::{BlockCheckMode, CaptureBy};
2020
use ast::{Constness, Crate, CrateConfig};
2121
use ast::{Decl, DeclKind};
2222
use ast::{EMPTY_CTXT, EnumDef, ExplicitSelf};
23-
use ast::{Expr, ExprKind};
23+
use ast::{Expr, ExprKind, RangeLimits};
2424
use ast::{Field, FnDecl};
2525
use ast::{ForeignItem, ForeignItemKind, FunctionRetTy};
2626
use ast::{Ident, ImplItem, Item, ItemKind};
@@ -2054,9 +2054,10 @@ impl<'a> Parser<'a> {
20542054

20552055
pub fn mk_range(&mut self,
20562056
start: Option<P<Expr>>,
2057-
end: Option<P<Expr>>)
2058-
-> ast::ExprKind {
2059-
ExprKind::Range(start, end)
2057+
end: Option<P<Expr>>,
2058+
limits: RangeLimits)
2059+
-> ast::Expr_ {
2060+
ExprKind::Range(start, end, limits)
20602061
}
20612062

20622063
pub fn mk_field(&mut self, expr: P<Expr>, ident: ast::SpannedIdent) -> ast::ExprKind {
@@ -2894,7 +2895,7 @@ impl<'a> Parser<'a> {
28942895
LhsExpr::AttributesParsed(attrs) => Some(attrs),
28952896
_ => None,
28962897
};
2897-
if self.token == token::DotDot {
2898+
if self.token == token::DotDot || self.token == token::DotDotDot {
28982899
return self.parse_prefix_range_expr(attrs);
28992900
} else {
29002901
try!(self.parse_prefix_expr(attrs))
@@ -2940,32 +2941,32 @@ impl<'a> Parser<'a> {
29402941
ExprKind::Type(lhs, rhs), None);
29412942
continue
29422943
} else if op == AssocOp::DotDot {
2943-
// If we didn’t have to handle `x..`, it would be pretty easy to generalise
2944-
// it to the Fixity::None code.
2945-
//
2946-
// We have 2 alternatives here: `x..y` and `x..` The other two variants are
2947-
// handled with `parse_prefix_range_expr` call above.
2948-
let rhs = if self.is_at_start_of_range_notation_rhs() {
2949-
let rhs = self.parse_assoc_expr_with(op.precedence() + 1,
2950-
LhsExpr::NotYetParsed);
2951-
match rhs {
2952-
Ok(e) => Some(e),
2953-
Err(mut e) => {
2954-
e.cancel();
2955-
None
2956-
}
2944+
// If we didn’t have to handle `x..`, it would be pretty easy to generalise
2945+
// it to the Fixity::None code.
2946+
//
2947+
// We have 2 alternatives here: `x..y` and `x..` The other two variants are
2948+
// handled with `parse_prefix_range_expr` call above.
2949+
let rhs = if self.is_at_start_of_range_notation_rhs() {
2950+
let rhs = self.parse_assoc_expr_with(op.precedence() + 1,
2951+
LhsExpr::NotYetParsed);
2952+
match rhs {
2953+
Ok(e) => Some(e),
2954+
Err(mut e) => {
2955+
e.cancel();
2956+
None
29572957
}
2958-
} else {
2959-
None
2960-
};
2961-
let (lhs_span, rhs_span) = (lhs_span, if let Some(ref x) = rhs {
2962-
x.span
2963-
} else {
2964-
cur_op_span
2965-
});
2966-
let r = self.mk_range(Some(lhs), rhs);
2967-
lhs = self.mk_expr(lhs_span.lo, rhs_span.hi, r, None);
2968-
break
2958+
}
2959+
} else {
2960+
None
2961+
};
2962+
let (lhs_span, rhs_span) = (lhs.span, if let Some(ref x) = rhs {
2963+
x.span
2964+
} else {
2965+
cur_op_span
2966+
});
2967+
let r = self.mk_range(Some(lhs), rhs, RangeLimits::HalfOpen);
2968+
lhs = self.mk_expr(lhs_span.lo, rhs_span.hi, r, None);
2969+
break
29692970
}
29702971

29712972
let rhs = try!(match op.fixity() {
@@ -2981,8 +2982,8 @@ impl<'a> Parser<'a> {
29812982
this.parse_assoc_expr_with(op.precedence() + 1,
29822983
LhsExpr::NotYetParsed)
29832984
}),
2984-
// We currently have no non-associative operators that are not handled above by
2985-
// the special cases. The code is here only for future convenience.
2985+
// the only operator handled here is `...` (the other non-associative operators are
2986+
// special-cased above)
29862987
Fixity::None => self.with_res(
29872988
restrictions - Restrictions::RESTRICTION_STMT_EXPR,
29882989
|this| {
@@ -3023,6 +3024,11 @@ impl<'a> Parser<'a> {
30233024
let aopexpr = self.mk_assign_op(codemap::respan(cur_op_span, aop), lhs, rhs);
30243025
self.mk_expr(lhs_span.lo, rhs_span.hi, aopexpr, None)
30253026
}
3027+
AssocOp::DotDotDot => {
3028+
let (lhs_span, rhs_span) = (lhs.span, rhs.span);
3029+
let r = self.mk_range(Some(lhs), Some(rhs), RangeLimits::Closed);
3030+
self.mk_expr(lhs_span.lo, rhs_span.hi, r, None)
3031+
}
30263032
AssocOp::As | AssocOp::Colon | AssocOp::DotDot => {
30273033
self.bug("As, Colon or DotDot branch reached")
30283034
}
@@ -3054,18 +3060,19 @@ impl<'a> Parser<'a> {
30543060
}
30553061
}
30563062

3057-
/// Parse prefix-forms of range notation: `..expr` and `..`
3063+
/// Parse prefix-forms of range notation: `..expr`, `..`, `...expr`
30583064
fn parse_prefix_range_expr(&mut self,
30593065
already_parsed_attrs: Option<ThinAttributes>)
30603066
-> PResult<'a, P<Expr>> {
3061-
debug_assert!(self.token == token::DotDot);
3067+
debug_assert!(self.token == token::DotDot || self.token == token::DotDotDot);
3068+
let tok = self.token.clone();
30623069
let attrs = try!(self.parse_or_use_outer_attributes(already_parsed_attrs));
30633070
let lo = self.span.lo;
30643071
let mut hi = self.span.hi;
30653072
self.bump();
30663073
let opt_end = if self.is_at_start_of_range_notation_rhs() {
3067-
// RHS must be parsed with more associativity than DotDot.
3068-
let next_prec = AssocOp::from_token(&token::DotDot).unwrap().precedence() + 1;
3074+
// RHS must be parsed with more associativity than the dots.
3075+
let next_prec = AssocOp::from_token(&tok).unwrap().precedence() + 1;
30693076
Some(try!(self.parse_assoc_expr_with(next_prec,
30703077
LhsExpr::NotYetParsed)
30713078
.map(|x|{
@@ -3075,7 +3082,13 @@ impl<'a> Parser<'a> {
30753082
} else {
30763083
None
30773084
};
3078-
let r = self.mk_range(None, opt_end);
3085+
let r = self.mk_range(None,
3086+
opt_end,
3087+
if tok == token::DotDot {
3088+
RangeLimits::HalfOpen
3089+
} else {
3090+
RangeLimits::Closed
3091+
});
30793092
Ok(self.mk_expr(lo, hi, r, attrs))
30803093
}
30813094

branches/beta/src/libsyntax/parse/token.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ impl Token {
196196
BinOp(Or) => true, // in lambda syntax
197197
OrOr => true, // in lambda syntax
198198
AndAnd => true, // double borrow
199-
DotDot => true, // range notation
199+
DotDot | DotDotDot => true, // range notation
200200
ModSep => true,
201201
Interpolated(NtExpr(..)) => true,
202202
Interpolated(NtIdent(..)) => true,

branches/beta/src/libsyntax/print/pprust.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2163,11 +2163,15 @@ impl<'a> State<'a> {
21632163
try!(self.print_expr(&index));
21642164
try!(word(&mut self.s, "]"));
21652165
}
2166-
ast::ExprKind::Range(ref start, ref end) => {
2166+
ast::ExprKing::Range(ref start, ref end, limits) => {
21672167
if let &Some(ref e) = start {
21682168
try!(self.print_expr(&e));
21692169
}
2170-
try!(word(&mut self.s, ".."));
2170+
if limits == ast::RangeLimits::HalfOpen {
2171+
try!(word(&mut self.s, ".."));
2172+
} else {
2173+
try!(word(&mut self.s, "..."));
2174+
}
21712175
if let &Some(ref e) = end {
21722176
try!(self.print_expr(&e));
21732177
}

branches/beta/src/libsyntax/util/parser.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ pub enum AssocOp {
6161
As,
6262
/// `..` range
6363
DotDot,
64+
/// `...` range
65+
DotDotDot,
6466
/// `:`
6567
Colon,
6668
}
@@ -102,6 +104,7 @@ impl AssocOp {
102104
Token::AndAnd => Some(LAnd),
103105
Token::OrOr => Some(LOr),
104106
Token::DotDot => Some(DotDot),
107+
Token::DotDotDot => Some(DotDotDot),
105108
Token::Colon => Some(Colon),
106109
_ if t.is_keyword(keywords::As) => Some(As),
107110
_ => None
@@ -147,7 +150,7 @@ impl AssocOp {
147150
Less | Greater | LessEqual | GreaterEqual | Equal | NotEqual => 7,
148151
LAnd => 6,
149152
LOr => 5,
150-
DotDot => 4,
153+
DotDot | DotDotDot => 4,
151154
Inplace => 3,
152155
Assign | AssignOp(_) => 2,
153156
}
@@ -162,7 +165,7 @@ impl AssocOp {
162165
As | Multiply | Divide | Modulus | Add | Subtract | ShiftLeft | ShiftRight | BitAnd |
163166
BitXor | BitOr | Less | Greater | LessEqual | GreaterEqual | Equal | NotEqual |
164167
LAnd | LOr | Colon => Fixity::Left,
165-
DotDot => Fixity::None
168+
DotDot | DotDotDot => Fixity::None
166169
}
167170
}
168171

@@ -171,7 +174,8 @@ impl AssocOp {
171174
match *self {
172175
Less | Greater | LessEqual | GreaterEqual | Equal | NotEqual => true,
173176
Inplace | Assign | AssignOp(_) | As | Multiply | Divide | Modulus | Add | Subtract |
174-
ShiftLeft | ShiftRight | BitAnd | BitXor | BitOr | LAnd | LOr | DotDot | Colon => false
177+
ShiftLeft | ShiftRight | BitAnd | BitXor | BitOr | LAnd | LOr |
178+
DotDot | DotDotDot | Colon => false
175179
}
176180
}
177181

@@ -181,7 +185,7 @@ impl AssocOp {
181185
Assign | AssignOp(_) | Inplace => true,
182186
Less | Greater | LessEqual | GreaterEqual | Equal | NotEqual | As | Multiply | Divide |
183187
Modulus | Add | Subtract | ShiftLeft | ShiftRight | BitAnd | BitXor | BitOr | LAnd |
184-
LOr | DotDot | Colon => false
188+
LOr | DotDot | DotDotDot | Colon => false
185189
}
186190
}
187191

@@ -206,7 +210,7 @@ impl AssocOp {
206210
BitOr => Some(BinOpKind::BitOr),
207211
LAnd => Some(BinOpKind::And),
208212
LOr => Some(BinOpKind::Or),
209-
Inplace | Assign | AssignOp(_) | As | DotDot | Colon => None
213+
Inplace | Assign | AssignOp(_) | As | DotDot | DotDotDot | Colon => None
210214
}
211215
}
212216
}

branches/beta/src/libsyntax/visit.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -763,7 +763,7 @@ pub fn walk_expr<'v, V: Visitor<'v>>(visitor: &mut V, expression: &'v Expr) {
763763
visitor.visit_expr(main_expression);
764764
visitor.visit_expr(index_expression)
765765
}
766-
ExprKind::Range(ref start, ref end) => {
766+
ExprKind::Range(ref start, ref end, _) => {
767767
walk_list!(visitor, visit_expr, start);
768768
walk_list!(visitor, visit_expr, end);
769769
}

0 commit comments

Comments
 (0)