]>
git.proxmox.com Git - rustc.git/blob - src/libsyntax/parse/obsolete.rs
00d9b7f4ea6875daba352124b7daa601d6e8a62c
1 // Copyright 2012-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.
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.
11 //! Support for parsing unsupported, old syntaxes, for the purpose of reporting errors. Parsing of
12 //! these syntaxes is tested by compile-test/obsolete-syntax.rs.
14 //! Obsolete syntax that becomes too hard to parse can be removed.
16 use ast
::{Expr, ExprTup}
;
22 /// The specific types of unsupported syntax
23 #[derive(Copy, Clone, PartialEq, Eq, Hash)]
24 pub enum ObsoleteSyntax
{
29 pub trait ParserObsoleteMethods
{
30 /// Reports an obsolete syntax non-fatal error.
31 fn obsolete(&mut self, sp
: Span
, kind
: ObsoleteSyntax
);
32 /// Reports an obsolete syntax non-fatal error, and returns
33 /// a placeholder expression
34 fn obsolete_expr(&mut self, sp
: Span
, kind
: ObsoleteSyntax
) -> P
<Expr
>;
41 fn is_obsolete_ident(&mut self, ident
: &str) -> bool
;
42 fn eat_obsolete_ident(&mut self, ident
: &str) -> bool
;
45 impl<'a
> ParserObsoleteMethods
for parser
::Parser
<'a
> {
46 /// Reports an obsolete syntax non-fatal error.
47 fn obsolete(&mut self, sp
: Span
, kind
: ObsoleteSyntax
) {
48 let (kind_str
, desc
, error
) = match kind
{
49 ObsoleteSyntax
::ClosureKind
=> (
50 "`:`, `&mut:`, or `&:`",
51 "rely on inference instead",
54 ObsoleteSyntax
::ExternCrateString
=> (
56 "use an identifier not in quotes instead",
57 false, // warning for now
61 self.report(sp
, kind
, kind_str
, desc
, error
);
64 /// Reports an obsolete syntax non-fatal error, and returns
65 /// a placeholder expression
66 fn obsolete_expr(&mut self, sp
: Span
, kind
: ObsoleteSyntax
) -> P
<Expr
> {
67 self.obsolete(sp
, kind
);
68 self.mk_expr(sp
.lo
, sp
.hi
, ExprTup(vec
![]))
78 self.span_err(sp
, &format
!("obsolete syntax: {}", kind_str
));
80 self.span_warn(sp
, &format
!("obsolete syntax: {}", kind_str
));
83 if !self.obsolete_set
.contains(&kind
) &&
84 (error
|| self.sess
.span_diagnostic
.handler().can_emit_warnings
) {
88 .note(&format
!("{}", desc
));
89 self.obsolete_set
.insert(kind
);
93 fn is_obsolete_ident(&mut self, ident
: &str) -> bool
{
95 token
::Ident(sid
, _
) => {
96 token
::get_ident(sid
) == ident
102 fn eat_obsolete_ident(&mut self, ident
: &str) -> bool
{
103 if self.is_obsolete_ident(ident
) {
104 panictry
!(self.bump());