Add information about the syntax used in ranges
... or ..=
This commit is contained in:
parent
4737c5a068
commit
7aabf57278
4 changed files with 19 additions and 9 deletions
|
@ -1869,7 +1869,7 @@ impl<'a> LoweringContext<'a> {
|
||||||
|
|
||||||
fn lower_range_end(&mut self, e: &RangeEnd) -> hir::RangeEnd {
|
fn lower_range_end(&mut self, e: &RangeEnd) -> hir::RangeEnd {
|
||||||
match *e {
|
match *e {
|
||||||
RangeEnd::Included => hir::RangeEnd::Included,
|
RangeEnd::Included(_) => hir::RangeEnd::Included,
|
||||||
RangeEnd::Excluded => hir::RangeEnd::Excluded,
|
RangeEnd::Excluded => hir::RangeEnd::Excluded,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -538,10 +538,16 @@ pub enum BindingMode {
|
||||||
|
|
||||||
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
|
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
|
||||||
pub enum RangeEnd {
|
pub enum RangeEnd {
|
||||||
Included,
|
Included(RangeSyntax),
|
||||||
Excluded,
|
Excluded,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
|
||||||
|
pub enum RangeSyntax {
|
||||||
|
DotDotDot,
|
||||||
|
DotDotEq,
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
|
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
|
||||||
pub enum PatKind {
|
pub enum PatKind {
|
||||||
/// Represents a wildcard pattern (`_`)
|
/// Represents a wildcard pattern (`_`)
|
||||||
|
@ -578,7 +584,7 @@ pub enum PatKind {
|
||||||
Ref(P<Pat>, Mutability),
|
Ref(P<Pat>, Mutability),
|
||||||
/// A literal
|
/// A literal
|
||||||
Lit(P<Expr>),
|
Lit(P<Expr>),
|
||||||
/// A range pattern, e.g. `1...2` or `1..2`
|
/// A range pattern, e.g. `1...2`, `1..=2` or `1..2`
|
||||||
Range(P<Expr>, P<Expr>, RangeEnd),
|
Range(P<Expr>, P<Expr>, RangeEnd),
|
||||||
/// `[a, b, ..i, y, z]` is represented as:
|
/// `[a, b, ..i, y, z]` is represented as:
|
||||||
/// `PatKind::Slice(box [a, b], Some(i), box [y, z])`
|
/// `PatKind::Slice(box [a, b], Some(i), box [y, z])`
|
||||||
|
|
|
@ -38,7 +38,7 @@ use ast::{Ty, TyKind, TypeBinding, TyParam, TyParamBounds};
|
||||||
use ast::{ViewPath, ViewPathGlob, ViewPathList, ViewPathSimple};
|
use ast::{ViewPath, ViewPathGlob, ViewPathList, ViewPathSimple};
|
||||||
use ast::{Visibility, WhereClause};
|
use ast::{Visibility, WhereClause};
|
||||||
use ast::{BinOpKind, UnOp};
|
use ast::{BinOpKind, UnOp};
|
||||||
use ast::RangeEnd;
|
use ast::{RangeEnd, RangeSyntax};
|
||||||
use {ast, attr};
|
use {ast, attr};
|
||||||
use codemap::{self, CodeMap, Spanned, respan};
|
use codemap::{self, CodeMap, Spanned, respan};
|
||||||
use syntax_pos::{self, Span, BytePos};
|
use syntax_pos::{self, Span, BytePos};
|
||||||
|
@ -3557,7 +3557,8 @@ impl<'a> Parser<'a> {
|
||||||
token::DotDotDot | token::DotDotEq | token::DotDot => {
|
token::DotDotDot | token::DotDotEq | token::DotDot => {
|
||||||
let end_kind = match self.token {
|
let end_kind = match self.token {
|
||||||
token::DotDot => RangeEnd::Excluded,
|
token::DotDot => RangeEnd::Excluded,
|
||||||
token::DotDotDot | token::DotDotEq => RangeEnd::Included,
|
token::DotDotDot => RangeEnd::Included(RangeSyntax::DotDotDot),
|
||||||
|
token::DotDotEq => RangeEnd::Included(RangeSyntax::DotDotEq),
|
||||||
_ => panic!("can only parse `..`/`...`/`..=` for ranges \
|
_ => panic!("can only parse `..`/`...`/`..=` for ranges \
|
||||||
(checked above)"),
|
(checked above)"),
|
||||||
};
|
};
|
||||||
|
@ -3600,10 +3601,12 @@ impl<'a> Parser<'a> {
|
||||||
Ok(begin) => {
|
Ok(begin) => {
|
||||||
if self.eat(&token::DotDotDot) {
|
if self.eat(&token::DotDotDot) {
|
||||||
let end = self.parse_pat_range_end()?;
|
let end = self.parse_pat_range_end()?;
|
||||||
pat = PatKind::Range(begin, end, RangeEnd::Included);
|
pat = PatKind::Range(begin, end,
|
||||||
|
RangeEnd::Included(RangeSyntax::DotDotDot));
|
||||||
} else if self.eat(&token::DotDotEq) {
|
} else if self.eat(&token::DotDotEq) {
|
||||||
let end = self.parse_pat_range_end()?;
|
let end = self.parse_pat_range_end()?;
|
||||||
pat = PatKind::Range(begin, end, RangeEnd::Included);
|
pat = PatKind::Range(begin, end,
|
||||||
|
RangeEnd::Included(RangeSyntax::DotDotEq));
|
||||||
} else if self.eat(&token::DotDot) {
|
} else if self.eat(&token::DotDot) {
|
||||||
let end = self.parse_pat_range_end()?;
|
let end = self.parse_pat_range_end()?;
|
||||||
pat = PatKind::Range(begin, end, RangeEnd::Excluded);
|
pat = PatKind::Range(begin, end, RangeEnd::Excluded);
|
||||||
|
|
|
@ -11,7 +11,7 @@
|
||||||
pub use self::AnnNode::*;
|
pub use self::AnnNode::*;
|
||||||
|
|
||||||
use abi::{self, Abi};
|
use abi::{self, Abi};
|
||||||
use ast::{self, BlockCheckMode, PatKind, RangeEnd};
|
use ast::{self, BlockCheckMode, PatKind, RangeEnd, RangeSyntax};
|
||||||
use ast::{SelfKind, RegionTyParamBound, TraitTyParamBound, TraitBoundModifier};
|
use ast::{SelfKind, RegionTyParamBound, TraitTyParamBound, TraitBoundModifier};
|
||||||
use ast::Attribute;
|
use ast::Attribute;
|
||||||
use util::parser::{self, AssocOp, Fixity};
|
use util::parser::{self, AssocOp, Fixity};
|
||||||
|
@ -2590,7 +2590,8 @@ impl<'a> State<'a> {
|
||||||
self.print_expr(begin)?;
|
self.print_expr(begin)?;
|
||||||
self.s.space()?;
|
self.s.space()?;
|
||||||
match *end_kind {
|
match *end_kind {
|
||||||
RangeEnd::Included => self.s.word("...")?,
|
RangeEnd::Included(RangeSyntax::DotDotDot) => self.s.word("...")?,
|
||||||
|
RangeEnd::Included(RangeSyntax::DotDotEq) => self.s.word("..=")?,
|
||||||
RangeEnd::Excluded => self.s.word("..")?,
|
RangeEnd::Excluded => self.s.word("..")?,
|
||||||
}
|
}
|
||||||
self.print_expr(end)?;
|
self.print_expr(end)?;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue