]> git.lizzy.rs Git - rust.git/commitdiff
syntax::parser::token -> syntax::token
authorMazdak Farrokhzad <twingoow@gmail.com>
Fri, 11 Oct 2019 10:46:32 +0000 (12:46 +0200)
committerMazdak Farrokhzad <twingoow@gmail.com>
Thu, 7 Nov 2019 12:50:12 +0000 (13:50 +0100)
58 files changed:
src/librustc/hir/lowering.rs
src/librustc/hir/map/def_collector.rs
src/librustc/ich/impls_syntax.rs
src/librustc_interface/interface.rs
src/librustc_resolve/build_reduced_graph.rs
src/librustc_save_analysis/dump_visitor.rs
src/librustc_save_analysis/span_utils.rs
src/librustdoc/html/highlight.rs
src/librustdoc/passes/check_code_block_syntax.rs
src/libsyntax/ast.rs
src/libsyntax/attr/mod.rs
src/libsyntax/feature_gate/check.rs
src/libsyntax/lib.rs
src/libsyntax/mut_visit.rs
src/libsyntax/parse/lexer/mod.rs
src/libsyntax/parse/lexer/tests.rs
src/libsyntax/parse/lexer/tokentrees.rs
src/libsyntax/parse/lexer/unicode_chars.rs
src/libsyntax/parse/literal.rs
src/libsyntax/parse/mod.rs
src/libsyntax/parse/parser/attr.rs
src/libsyntax/parse/parser/diagnostics.rs
src/libsyntax/parse/parser/expr.rs
src/libsyntax/parse/parser/generics.rs
src/libsyntax/parse/parser/mod.rs
src/libsyntax/parse/parser/module.rs
src/libsyntax/parse/parser/pat.rs
src/libsyntax/parse/parser/path.rs
src/libsyntax/parse/parser/stmt.rs
src/libsyntax/parse/parser/ty.rs
src/libsyntax/parse/tests.rs
src/libsyntax/parse/token.rs [deleted file]
src/libsyntax/print/pprust.rs
src/libsyntax/token.rs [new file with mode: 0644]
src/libsyntax/tokenstream.rs
src/libsyntax/util/parser.rs
src/libsyntax/visit.rs
src/libsyntax_expand/base.rs
src/libsyntax_expand/expand.rs
src/libsyntax_expand/mbe.rs
src/libsyntax_expand/mbe/macro_check.rs
src/libsyntax_expand/mbe/macro_parser.rs
src/libsyntax_expand/mbe/macro_rules.rs
src/libsyntax_expand/mbe/quoted.rs
src/libsyntax_expand/mbe/transcribe.rs
src/libsyntax_expand/proc_macro.rs
src/libsyntax_expand/proc_macro_server.rs
src/libsyntax_ext/asm.rs
src/libsyntax_ext/assert.rs
src/libsyntax_ext/cfg.rs
src/libsyntax_ext/cmdline_attrs.rs
src/libsyntax_ext/concat_idents.rs
src/libsyntax_ext/format.rs
src/libsyntax_ext/global_asm.rs
src/libsyntax_ext/plugin_macro_defs.rs
src/libsyntax_ext/source_util.rs
src/test/ui-fulldeps/ast_stmt_expr_attr.rs
src/test/ui-fulldeps/auxiliary/roman-numerals.rs

index 6344c7a233ca40440eca0fb802c78c60189ba30d..87ad4ace592386126c576547737e6f1ccbecc30b 100644 (file)
@@ -66,7 +66,7 @@
 use syntax::ast::*;
 use syntax::errors;
 use syntax::print::pprust;
-use syntax::parse::token::{self, Nonterminal, Token};
+use syntax::token::{self, Nonterminal, Token};
 use syntax::tokenstream::{TokenStream, TokenTree};
 use syntax::sess::ParseSess;
 use syntax::source_map::{respan, ExpnData, ExpnKind, DesugaringKind, Spanned};
index e9970e30bf9e5d716a33eff2839567be8dc61324..57c1421bde6cd23ccb7e5a1f9c1fcc3af69d4d55 100644 (file)
@@ -4,7 +4,7 @@
 use syntax::ast::*;
 use syntax::visit;
 use syntax::symbol::{kw, sym};
-use syntax::parse::token::{self, Token};
+use syntax::token::{self, Token};
 use syntax_pos::hygiene::ExpnId;
 use syntax_pos::Span;
 
index 2201c4b0980b3ba07c81f92771f17134ef311832..c401bd17dd4172b2fbb6057958f841891aafe21d 100644 (file)
@@ -8,9 +8,9 @@
 
 use syntax::ast;
 use syntax::feature_gate;
-use syntax::parse::token;
-use syntax::symbol::SymbolStr;
+use syntax::token;
 use syntax::tokenstream;
+use syntax_pos::symbol::SymbolStr;
 use syntax_pos::SourceFile;
 
 use crate::hir::def_id::{DefId, CrateNum, CRATE_DEF_INDEX};
index 4e4d6d982fbc59498dd89c2bd3d645bf707d495f..034e861b2123cd9b70c990e8d96c8c36e4d675e4 100644 (file)
@@ -16,7 +16,7 @@
 use std::sync::{Arc, Mutex};
 use syntax::{self, parse};
 use syntax::ast::{self, MetaItemKind};
-use syntax::parse::token;
+use syntax::token;
 use syntax::source_map::{FileName, FileLoader, SourceMap};
 use syntax::sess::ParseSess;
 use syntax_pos::edition;
index 55f054d0be323a2bf30d0dedd7cdd45a525583d2..4239518b879e3b5a247fcdd6e2381f598d472941 100644 (file)
@@ -33,7 +33,7 @@
 use syntax::ast::{self, Block, ForeignItem, ForeignItemKind, Item, ItemKind, NodeId};
 use syntax::ast::{MetaItemKind, StmtKind, TraitItem, TraitItemKind};
 use syntax::feature_gate::is_builtin_attr;
-use syntax::parse::token::{self, Token};
+use syntax::token::{self, Token};
 use syntax::print::pprust;
 use syntax::{span_err, struct_span_err};
 use syntax::source_map::{respan, Spanned};
index a372106d3795b57dc5c8a7615a4c9ca1828a20f4..5c5fbcc07de4c9db39ca1c0c651f4e55ee5d5292 100644 (file)
@@ -24,7 +24,7 @@
 use std::env;
 
 use syntax::ast::{self, Attribute, NodeId, PatKind};
-use syntax::parse::token;
+use syntax::token;
 use syntax::visit::{self, Visitor};
 use syntax::print::pprust::{
     bounds_to_string,
index fb9919d777db17da75d88f1f78eb2a3806291840..4d0780cf94df002ed4eeb2ddc8e0d6ca0005db7a 100644 (file)
@@ -3,7 +3,7 @@
 use crate::generated_code;
 
 use syntax::parse::lexer::{self, StringReader};
-use syntax::parse::token::{self, TokenKind};
+use syntax::token::{self, TokenKind};
 use syntax_pos::*;
 
 #[derive(Clone)]
index 88ba13f2796a003a29eabfd0e59dbc311450c3e2..4bd72f7e61ccc581c6739b7ed3ea3dbd0a403a42 100644 (file)
@@ -13,7 +13,7 @@
 
 use syntax::source_map::SourceMap;
 use syntax::parse::lexer;
-use syntax::parse::token::{self, Token};
+use syntax::token::{self, Token};
 use syntax::sess::ParseSess;
 use syntax::symbol::{kw, sym};
 use syntax_pos::{Span, FileName};
index 10e15ab8881afa29c7c5b55ffa54f3bf210e08ef..4603e77b0fda83647c18ca1b96b0d093b164b9e3 100644 (file)
@@ -1,6 +1,6 @@
 use errors::Applicability;
 use syntax::parse::lexer::{StringReader as Lexer};
-use syntax::parse::token;
+use syntax::token;
 use syntax::sess::ParseSess;
 use syntax::source_map::FilePathMapping;
 use syntax_pos::{InnerSpan, FileName};
index 67d1acbccfbe5beca1ca9dadde9cdf375899e67e..18151a1586c932eefd3ec57bdbf18f42b5733e2e 100644 (file)
@@ -24,9 +24,9 @@
 
 pub use syntax_pos::symbol::{Ident, Symbol as Name};
 
-use crate::parse::token::{self, DelimToken};
 use crate::ptr::P;
 use crate::source_map::{dummy_spanned, respan, Spanned};
+use crate::token::{self, DelimToken};
 use crate::tokenstream::TokenStream;
 
 use syntax_pos::symbol::{kw, sym, Symbol};
index c663995eb8fcbc218019dea09dd3efaf2d6984f0..1534d2723c87737e6ad9ebd6f124368b62570b6f 100644 (file)
@@ -17,7 +17,7 @@
 use crate::parse::lexer::comments::doc_comment_style;
 use crate::parse;
 use crate::parse::PResult;
-use crate::parse::token::{self, Token};
+use crate::token::{self, Token};
 use crate::ptr::P;
 use crate::sess::ParseSess;
 use crate::symbol::{sym, Symbol};
index 5b1493ebc9b01dd2b0f6aa06a2aa12a54177f80a..ecff89ad59bd94dbe22d08752ad2b4868ba93528 100644 (file)
@@ -11,7 +11,7 @@
 use crate::source_map::Spanned;
 use crate::edition::{ALL_EDITIONS, Edition};
 use crate::visit::{self, FnKind, Visitor};
-use crate::parse::token;
+use crate::token;
 use crate::sess::ParseSess;
 use crate::symbol::{Symbol, sym};
 use crate::tokenstream::TokenTree;
index 7be6e6c7e1876ecad9015494c3d6763b040e7831..4c134430f30e60f712062815eb7049525b403b31 100644 (file)
@@ -107,6 +107,7 @@ pub mod util {
 pub use syntax_pos::edition;
 pub use syntax_pos::symbol;
 pub mod sess;
+pub mod token;
 pub mod tokenstream;
 pub mod visit;
 
index 7261601e1449137639ec1f777ee5cd0ea025e14a..0c90652526d8078131aa3f3f06382b59cf234c52 100644 (file)
@@ -9,7 +9,7 @@
 
 use crate::ast::*;
 use crate::source_map::{Spanned, respan};
-use crate::parse::token::{self, Token};
+use crate::token::{self, Token};
 use crate::ptr::P;
 use crate::ThinVec;
 use crate::tokenstream::*;
index a6dfed542d6a6ddd25ecb1b936ccaef8fc857dce..5499a3cae5f737375a51a8476ba82e726e647bfe 100644 (file)
@@ -1,4 +1,4 @@
-use crate::parse::token::{self, Token, TokenKind};
+use crate::token::{self, Token, TokenKind};
 use crate::sess::ParseSess;
 use crate::symbol::{sym, Symbol};
 
index de301b1fc499d9aa43048174657fc88cbdacc67d..b9b82b2bcefa7c1af976d1826054d3c72e1ca4d4 100644 (file)
@@ -2,7 +2,7 @@
 
 use crate::symbol::Symbol;
 use crate::source_map::{SourceMap, FilePathMapping};
-use crate::parse::token;
+use crate::token;
 use crate::with_default_globals;
 
 use errors::{Handler, emitter::EmitterWriter};
index de8ac2c71e818a5f0af1579fc1d8ac1627913fa1..3c15a5e1daeda3555eee0dab8d3985f4200958ec 100644 (file)
@@ -4,8 +4,8 @@
 use super::{StringReader, UnmatchedBrace};
 
 use crate::print::pprust::token_to_string;
-use crate::parse::token::{self, Token};
 use crate::parse::PResult;
+use crate::token::{self, Token};
 use crate::tokenstream::{DelimSpan, IsJoint::{self, *}, TokenStream, TokenTree, TreeAndJoint};
 
 impl<'a> StringReader<'a> {
index 525b4215affb180c710009c4d2c8ac1383628c90..6eb995b61d3feeeb062f7388e61900d8e20f6f4c 100644 (file)
@@ -4,7 +4,7 @@
 use super::StringReader;
 use errors::{Applicability, DiagnosticBuilder};
 use syntax_pos::{BytePos, Pos, Span, symbol::kw};
-use crate::parse::token;
+use crate::token;
 
 #[rustfmt::skip] // for line breaks
 const UNICODE_ARRAY: &[(char, &str, char)] = &[
index a8eeac59954f14efcf6a3880e481561ab325605c..d4c9b7850c5c9256959769424b85c1e4d89078e0 100644 (file)
@@ -1,8 +1,8 @@
 //! Code related to parsing literals.
 
 use crate::ast::{self, Lit, LitKind};
-use crate::parse::token::{self, Token};
 use crate::symbol::{kw, sym, Symbol};
+use crate::token::{self, Token};
 use crate::tokenstream::TokenTree;
 
 use log::debug;
index 5b020d3d28853ba5f67b4946e5b4f87e34869bfa..7db0ca0b78d3d646ad458a6d3becfe7250c4f002 100644 (file)
@@ -2,7 +2,7 @@
 
 use crate::ast;
 use crate::parse::parser::{Parser, emit_unclosed_delims, make_unclosed_delims_error};
-use crate::parse::token::Nonterminal;
+use crate::token::{self, Nonterminal};
 use crate::tokenstream::{self, TokenStream, TokenTree};
 use crate::print::pprust;
 use crate::sess::ParseSess;
@@ -25,7 +25,6 @@
 #[macro_use]
 pub mod parser;
 pub mod lexer;
-pub mod token;
 
 crate mod classify;
 crate mod literal;
index 1c292661f24401faca9b21f7e2cc48242c27077c..aa0542a09a925e88d5e07d0bf8c9bcdc8558a6c0 100644 (file)
@@ -1,7 +1,7 @@
 use super::{SeqSep, PResult, Parser, TokenType, PathStyle};
 use crate::attr;
 use crate::ast;
-use crate::parse::token::{self, Nonterminal, DelimToken};
+use crate::token::{self, Nonterminal, DelimToken};
 use crate::tokenstream::{TokenStream, TokenTree};
 use crate::source_map::Span;
 
index 49a517a5c44daf4199ec57bdc0ff005eb6973ea6..09f0b9b74b2eb56c1e65b6f3603d914d359c74d4 100644 (file)
@@ -6,7 +6,7 @@
     self, Param, BinOpKind, BindingMode, BlockCheckMode, Expr, ExprKind, Ident, Item, ItemKind,
     Mutability, Pat, PatKind, PathSegment, QSelf, Ty, TyKind,
 };
-use crate::parse::token::{self, TokenKind, token_can_begin_expr};
+use crate::token::{self, TokenKind, token_can_begin_expr};
 use crate::print::pprust;
 use crate::ptr::P;
 use crate::symbol::{kw, sym};
index 509e6482dcc06d48d3610528d41547185c29280e..4b962201e85562d4d1de7f90cb237b41833dcc46 100644 (file)
@@ -12,7 +12,7 @@
 };
 use crate::maybe_recover_from_interpolated_ty_qpath;
 use crate::parse::classify;
-use crate::parse::token::{self, Token, TokenKind};
+use crate::token::{self, Token, TokenKind};
 use crate::print::pprust;
 use crate::ptr::P;
 use crate::source_map::{self, Span};
index 3c094750b4d98ee9901bb3d8638cb20543d88136..cfc3768cac543a2aac7393cf64ef709902e0ce80 100644 (file)
@@ -1,7 +1,7 @@
 use super::{Parser, PResult};
 
 use crate::ast::{self, WhereClause, GenericParam, GenericParamKind, GenericBounds, Attribute};
-use crate::parse::token;
+use crate::token;
 use crate::source_map::DUMMY_SP;
 
 use syntax_pos::symbol::{kw, sym};
index 1284e89f195c753a127b38ea53a8e519ca6e6ff6..6498b674a3b7d0ad621f2b210ed326ab47fac136 100644 (file)
@@ -18,7 +18,7 @@
 use crate::parse::{PResult, Directory, DirectoryOwnership};
 use crate::parse::lexer::UnmatchedBrace;
 use crate::parse::lexer::comments::{doc_comment_style, strip_doc_comment_decoration};
-use crate::parse::token::{self, Token, TokenKind, DelimToken};
+use crate::token::{self, Token, TokenKind, DelimToken};
 use crate::print::pprust;
 use crate::ptr::P;
 use crate::sess::ParseSess;
index 242a17659a06b461e94b24a8416f21059f62a18f..70e0dfc3e8808e66b9048b094c658db899888334 100644 (file)
@@ -5,7 +5,7 @@
 use crate::attr;
 use crate::ast::{self, Ident, Attribute, ItemKind, Mod, Crate};
 use crate::parse::{new_sub_parser_from_file, DirectoryOwnership};
-use crate::parse::token::{self, TokenKind};
+use crate::token::{self, TokenKind};
 use crate::source_map::{SourceMap, Span, DUMMY_SP, FileName};
 use crate::symbol::sym;
 
index fcb7c4d1323067970fbea4df852b720c57020b6b..c4a983188faff70ea8950c7d166bd4476fa5b418 100644 (file)
@@ -5,7 +5,7 @@
 use crate::ast::{self, Attribute, Pat, PatKind, FieldPat, RangeEnd, RangeSyntax, Mac};
 use crate::ast::{BindingMode, Ident, Mutability, Path, QSelf, Expr, ExprKind};
 use crate::mut_visit::{noop_visit_pat, noop_visit_mac, MutVisitor};
-use crate::parse::token;
+use crate::token;
 use crate::print::pprust;
 use crate::source_map::{respan, Span, Spanned};
 use crate::ThinVec;
index 4438d61d9eedde05f130fb7170f513e59cf5c09f..2659e0c680e3f3edf404b5d38e88e56683d3cea8 100644 (file)
@@ -3,7 +3,7 @@
 use crate::{maybe_whole, ThinVec};
 use crate::ast::{self, QSelf, Path, PathSegment, Ident, ParenthesizedArgs, AngleBracketedArgs};
 use crate::ast::{AnonConst, GenericArg, AssocTyConstraint, AssocTyConstraintKind, BlockCheckMode};
-use crate::parse::token::{self, Token};
+use crate::token::{self, Token};
 use crate::source_map::{Span, BytePos};
 use syntax_pos::symbol::{kw, sym};
 
index 12c530f3cbba09a08770acb32f4d60a20e3a59f4..010fd9c37fd7171bf5e7fb7cf14fec765165d23a 100644 (file)
@@ -9,7 +9,7 @@
 use crate::ast::{self, DUMMY_NODE_ID, Stmt, StmtKind, Local, Block, BlockCheckMode, Expr, ExprKind};
 use crate::ast::{Attribute, AttrStyle, VisibilityKind, MacStmtStyle, Mac, MacDelimiter};
 use crate::parse::{classify, DirectoryOwnership};
-use crate::parse::token;
+use crate::token;
 use crate::source_map::{respan, Span};
 use crate::symbol::{kw, sym};
 
index b770b90705cbe614559bbbd96af774d960320438..4183416e628cc5289ae64e83056021fcdb4f5dde 100644 (file)
@@ -6,7 +6,7 @@
 use crate::ast::{self, Ty, TyKind, MutTy, BareFnTy, FunctionRetTy, GenericParam, Lifetime, Ident};
 use crate::ast::{TraitBoundModifier, TraitObjectSyntax, GenericBound, GenericBounds, PolyTraitRef};
 use crate::ast::{Mutability, AnonConst, Mac};
-use crate::parse::token::{self, Token};
+use crate::token::{self, Token};
 use crate::source_map::Span;
 use crate::symbol::{kw};
 
index 201eaca947bc2784ec1cd1853d580ee4a150efb2..27ca2b6472f0c75240bf276893bcb23d68d357c5 100644 (file)
@@ -4,7 +4,7 @@
 use crate::attr::first_attr_value_str_by_name;
 use crate::sess::ParseSess;
 use crate::parse::{PResult, new_parser_from_source_str};
-use crate::parse::token::Token;
+use crate::token::Token;
 use crate::print::pprust::item_to_string;
 use crate::ptr::P;
 use crate::source_map::FilePathMapping;
diff --git a/src/libsyntax/parse/token.rs b/src/libsyntax/parse/token.rs
deleted file mode 100644 (file)
index 6f3da34..0000000
+++ /dev/null
@@ -1,728 +0,0 @@
-pub use BinOpToken::*;
-pub use Nonterminal::*;
-pub use DelimToken::*;
-pub use LitKind::*;
-pub use TokenKind::*;
-
-use crate::ast;
-use crate::ptr::P;
-use crate::symbol::kw;
-use crate::tokenstream::TokenTree;
-
-use syntax_pos::symbol::Symbol;
-use syntax_pos::{self, Span, DUMMY_SP};
-
-use std::fmt;
-use std::mem;
-#[cfg(target_arch = "x86_64")]
-use rustc_data_structures::static_assert_size;
-use rustc_data_structures::sync::Lrc;
-
-#[derive(Clone, PartialEq, RustcEncodable, RustcDecodable, Hash, Debug, Copy)]
-pub enum BinOpToken {
-    Plus,
-    Minus,
-    Star,
-    Slash,
-    Percent,
-    Caret,
-    And,
-    Or,
-    Shl,
-    Shr,
-}
-
-/// A delimiter token.
-#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug, Copy)]
-pub enum DelimToken {
-    /// A round parenthesis (i.e., `(` or `)`).
-    Paren,
-    /// A square bracket (i.e., `[` or `]`).
-    Bracket,
-    /// A curly brace (i.e., `{` or `}`).
-    Brace,
-    /// An empty delimiter.
-    NoDelim,
-}
-
-impl DelimToken {
-    pub fn len(self) -> usize {
-        if self == NoDelim { 0 } else { 1 }
-    }
-
-    pub fn is_empty(self) -> bool {
-        self == NoDelim
-    }
-}
-
-#[derive(Clone, Copy, PartialEq, RustcEncodable, RustcDecodable, Debug)]
-pub enum LitKind {
-    Bool, // AST only, must never appear in a `Token`
-    Byte,
-    Char,
-    Integer,
-    Float,
-    Str,
-    StrRaw(u16), // raw string delimited by `n` hash symbols
-    ByteStr,
-    ByteStrRaw(u16), // raw byte string delimited by `n` hash symbols
-    Err,
-}
-
-/// A literal token.
-#[derive(Clone, Copy, PartialEq, RustcEncodable, RustcDecodable, Debug)]
-pub struct Lit {
-    pub kind: LitKind,
-    pub symbol: Symbol,
-    pub suffix: Option<Symbol>,
-}
-
-impl fmt::Display for Lit {
-    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
-        let Lit { kind, symbol, suffix } = *self;
-        match kind {
-            Byte          => write!(f, "b'{}'", symbol)?,
-            Char          => write!(f, "'{}'", symbol)?,
-            Str           => write!(f, "\"{}\"", symbol)?,
-            StrRaw(n)     => write!(f, "r{delim}\"{string}\"{delim}",
-                                     delim="#".repeat(n as usize),
-                                     string=symbol)?,
-            ByteStr       => write!(f, "b\"{}\"", symbol)?,
-            ByteStrRaw(n) => write!(f, "br{delim}\"{string}\"{delim}",
-                                     delim="#".repeat(n as usize),
-                                     string=symbol)?,
-            Integer       |
-            Float         |
-            Bool          |
-            Err           => write!(f, "{}", symbol)?,
-        }
-
-        if let Some(suffix) = suffix {
-            write!(f, "{}", suffix)?;
-        }
-
-        Ok(())
-    }
-}
-
-impl LitKind {
-    /// An English article for the literal token kind.
-    crate fn article(self) -> &'static str {
-        match self {
-            Integer | Err => "an",
-            _ => "a",
-        }
-    }
-
-    crate fn descr(self) -> &'static str {
-        match self {
-            Bool => panic!("literal token contains `Lit::Bool`"),
-            Byte => "byte",
-            Char => "char",
-            Integer => "integer",
-            Float => "float",
-            Str | StrRaw(..) => "string",
-            ByteStr | ByteStrRaw(..) => "byte string",
-            Err => "error",
-        }
-    }
-
-    crate fn may_have_suffix(self) -> bool {
-        match self {
-            Integer | Float | Err => true,
-            _ => false,
-        }
-    }
-}
-
-impl Lit {
-    pub fn new(kind: LitKind, symbol: Symbol, suffix: Option<Symbol>) -> Lit {
-        Lit { kind, symbol, suffix }
-    }
-}
-
-pub(crate) fn ident_can_begin_expr(name: ast::Name, span: Span, is_raw: bool) -> bool {
-    let ident_token = Token::new(Ident(name, is_raw), span);
-    token_can_begin_expr(&ident_token)
-}
-
-pub(crate) fn token_can_begin_expr(ident_token: &Token) -> bool {
-    !ident_token.is_reserved_ident() ||
-    ident_token.is_path_segment_keyword() ||
-    match ident_token.kind {
-        TokenKind::Ident(ident, _) => [
-            kw::Async,
-            kw::Do,
-            kw::Box,
-            kw::Break,
-            kw::Continue,
-            kw::False,
-            kw::For,
-            kw::If,
-            kw::Let,
-            kw::Loop,
-            kw::Match,
-            kw::Move,
-            kw::Return,
-            kw::True,
-            kw::Unsafe,
-            kw::While,
-            kw::Yield,
-            kw::Static,
-        ].contains(&ident),
-        _=> false,
-    }
-}
-
-fn ident_can_begin_type(name: ast::Name, span: Span, is_raw: bool) -> bool {
-    let ident_token = Token::new(Ident(name, is_raw), span);
-
-    !ident_token.is_reserved_ident() ||
-    ident_token.is_path_segment_keyword() ||
-    [
-        kw::Underscore,
-        kw::For,
-        kw::Impl,
-        kw::Fn,
-        kw::Unsafe,
-        kw::Extern,
-        kw::Typeof,
-        kw::Dyn,
-    ].contains(&name)
-}
-
-#[derive(Clone, PartialEq, RustcEncodable, RustcDecodable, Debug)]
-pub enum TokenKind {
-    /* Expression-operator symbols. */
-    Eq,
-    Lt,
-    Le,
-    EqEq,
-    Ne,
-    Ge,
-    Gt,
-    AndAnd,
-    OrOr,
-    Not,
-    Tilde,
-    BinOp(BinOpToken),
-    BinOpEq(BinOpToken),
-
-    /* Structural symbols */
-    At,
-    Dot,
-    DotDot,
-    DotDotDot,
-    DotDotEq,
-    Comma,
-    Semi,
-    Colon,
-    ModSep,
-    RArrow,
-    LArrow,
-    FatArrow,
-    Pound,
-    Dollar,
-    Question,
-    /// Used by proc macros for representing lifetimes, not generated by lexer right now.
-    SingleQuote,
-    /// An opening delimiter (e.g., `{`).
-    OpenDelim(DelimToken),
-    /// A closing delimiter (e.g., `}`).
-    CloseDelim(DelimToken),
-
-    /* Literals */
-    Literal(Lit),
-
-    /* Name components */
-    Ident(ast::Name, /* is_raw */ bool),
-    Lifetime(ast::Name),
-
-    Interpolated(Lrc<Nonterminal>),
-
-    // Can be expanded into several tokens.
-    /// A doc comment.
-    DocComment(ast::Name),
-
-    // Junk. These carry no data because we don't really care about the data
-    // they *would* carry, and don't really want to allocate a new ident for
-    // them. Instead, users could extract that from the associated span.
-
-    /// Whitespace.
-    Whitespace,
-    /// A comment.
-    Comment,
-    Shebang(ast::Name),
-    /// A completely invalid token which should be skipped.
-    Unknown(ast::Name),
-
-    Eof,
-}
-
-// `TokenKind` is used a lot. Make sure it doesn't unintentionally get bigger.
-#[cfg(target_arch = "x86_64")]
-static_assert_size!(TokenKind, 16);
-
-#[derive(Clone, PartialEq, RustcEncodable, RustcDecodable, Debug)]
-pub struct Token {
-    pub kind: TokenKind,
-    pub span: Span,
-}
-
-impl TokenKind {
-    pub fn lit(kind: LitKind, symbol: Symbol, suffix: Option<Symbol>) -> TokenKind {
-        Literal(Lit::new(kind, symbol, suffix))
-    }
-
-    /// Returns tokens that are likely to be typed accidentally instead of the current token.
-    /// Enables better error recovery when the wrong token is found.
-    crate fn similar_tokens(&self) -> Option<Vec<TokenKind>> {
-        match *self {
-            Comma => Some(vec![Dot, Lt, Semi]),
-            Semi => Some(vec![Colon, Comma]),
-            _ => None
-        }
-    }
-}
-
-impl Token {
-    pub fn new(kind: TokenKind, span: Span) -> Self {
-        Token { kind, span }
-    }
-
-    /// Some token that will be thrown away later.
-    crate fn dummy() -> Self {
-        Token::new(TokenKind::Whitespace, DUMMY_SP)
-    }
-
-    /// Recovers a `Token` from an `ast::Ident`. This creates a raw identifier if necessary.
-    pub fn from_ast_ident(ident: ast::Ident) -> Self {
-        Token::new(Ident(ident.name, ident.is_raw_guess()), ident.span)
-    }
-
-    /// Return this token by value and leave a dummy token in its place.
-    pub fn take(&mut self) -> Self {
-        mem::replace(self, Token::dummy())
-    }
-
-    crate fn is_op(&self) -> bool {
-        match self.kind {
-            OpenDelim(..) | CloseDelim(..) | Literal(..) | DocComment(..) |
-            Ident(..) | Lifetime(..) | Interpolated(..) |
-            Whitespace | Comment | Shebang(..) | Eof => false,
-            _ => true,
-        }
-    }
-
-    crate fn is_like_plus(&self) -> bool {
-        match self.kind {
-            BinOp(Plus) | BinOpEq(Plus) => true,
-            _ => false,
-        }
-    }
-
-    /// Returns `true` if the token can appear at the start of an expression.
-    pub fn can_begin_expr(&self) -> bool {
-        match self.kind {
-            Ident(name, is_raw)              =>
-                ident_can_begin_expr(name, self.span, is_raw), // value name or keyword
-            OpenDelim(..)                     | // tuple, array or block
-            Literal(..)                       | // literal
-            Not                               | // operator not
-            BinOp(Minus)                      | // unary minus
-            BinOp(Star)                       | // dereference
-            BinOp(Or) | OrOr                  | // closure
-            BinOp(And)                        | // reference
-            AndAnd                            | // double reference
-            // DotDotDot is no longer supported, but we need some way to display the error
-            DotDot | DotDotDot | DotDotEq     | // range notation
-            Lt | BinOp(Shl)                   | // associated path
-            ModSep                            | // global path
-            Lifetime(..)                      | // labeled loop
-            Pound                             => true, // expression attributes
-            Interpolated(ref nt) => match **nt {
-                NtLiteral(..) |
-                NtIdent(..)   |
-                NtExpr(..)    |
-                NtBlock(..)   |
-                NtPath(..)    |
-                NtLifetime(..) => true,
-                _ => false,
-            },
-            _ => false,
-        }
-    }
-
-    /// Returns `true` if the token can appear at the start of a type.
-    pub fn can_begin_type(&self) -> bool {
-        match self.kind {
-            Ident(name, is_raw)        =>
-                ident_can_begin_type(name, self.span, is_raw), // type name or keyword
-            OpenDelim(Paren)            | // tuple
-            OpenDelim(Bracket)          | // array
-            Not                         | // never
-            BinOp(Star)                 | // raw pointer
-            BinOp(And)                  | // reference
-            AndAnd                      | // double reference
-            Question                    | // maybe bound in trait object
-            Lifetime(..)                | // lifetime bound in trait object
-            Lt | BinOp(Shl)             | // associated path
-            ModSep                      => true, // global path
-            Interpolated(ref nt) => match **nt {
-                NtIdent(..) | NtTy(..) | NtPath(..) | NtLifetime(..) => true,
-                _ => false,
-            },
-            _ => false,
-        }
-    }
-
-    /// Returns `true` if the token can appear at the start of a const param.
-    crate fn can_begin_const_arg(&self) -> bool {
-        match self.kind {
-            OpenDelim(Brace) => true,
-            Interpolated(ref nt) => match **nt {
-                NtExpr(..) | NtBlock(..) | NtLiteral(..) => true,
-                _ => false,
-            }
-            _ => self.can_begin_literal_or_bool(),
-        }
-    }
-
-    /// Returns `true` if the token can appear at the start of a generic bound.
-    crate fn can_begin_bound(&self) -> bool {
-        self.is_path_start() || self.is_lifetime() || self.is_keyword(kw::For) ||
-        self == &Question || self == &OpenDelim(Paren)
-    }
-
-    /// Returns `true` if the token is any literal
-    pub fn is_lit(&self) -> bool {
-        match self.kind {
-            Literal(..) => true,
-            _           => false,
-        }
-    }
-
-    /// Returns `true` if the token is any literal, a minus (which can prefix a literal,
-    /// for example a '-42', or one of the boolean idents).
-    pub fn can_begin_literal_or_bool(&self) -> bool {
-        match self.kind {
-            Literal(..) | BinOp(Minus) => true,
-            Ident(name, false) if name.is_bool_lit() => true,
-            Interpolated(ref nt) => match **nt {
-                NtLiteral(..) => true,
-                _             => false,
-            },
-            _            => false,
-        }
-    }
-
-    /// Returns an identifier if this token is an identifier.
-    pub fn ident(&self) -> Option<(ast::Ident, /* is_raw */ bool)> {
-        match self.kind {
-            Ident(name, is_raw) => Some((ast::Ident::new(name, self.span), is_raw)),
-            Interpolated(ref nt) => match **nt {
-                NtIdent(ident, is_raw) => Some((ident, is_raw)),
-                _ => None,
-            },
-            _ => None,
-        }
-    }
-
-    /// Returns a lifetime identifier if this token is a lifetime.
-    pub fn lifetime(&self) -> Option<ast::Ident> {
-        match self.kind {
-            Lifetime(name) => Some(ast::Ident::new(name, self.span)),
-            Interpolated(ref nt) => match **nt {
-                NtLifetime(ident) => Some(ident),
-                _ => None,
-            },
-            _ => None,
-        }
-    }
-
-    /// Returns `true` if the token is an identifier.
-    pub fn is_ident(&self) -> bool {
-        self.ident().is_some()
-    }
-
-    /// Returns `true` if the token is a lifetime.
-    crate fn is_lifetime(&self) -> bool {
-        self.lifetime().is_some()
-    }
-
-    /// Returns `true` if the token is a identifier whose name is the given
-    /// string slice.
-    crate fn is_ident_named(&self, name: Symbol) -> bool {
-        self.ident().map_or(false, |(ident, _)| ident.name == name)
-    }
-
-    /// Returns `true` if the token is an interpolated path.
-    fn is_path(&self) -> bool {
-        if let Interpolated(ref nt) = self.kind {
-            if let NtPath(..) = **nt {
-                return true;
-            }
-        }
-        false
-    }
-
-    /// Would `maybe_whole_expr` in `parser.rs` return `Ok(..)`?
-    /// That is, is this a pre-parsed expression dropped into the token stream
-    /// (which happens while parsing the result of macro expansion)?
-    crate fn is_whole_expr(&self) -> bool {
-        if let Interpolated(ref nt) = self.kind {
-            if let NtExpr(_) | NtLiteral(_) | NtPath(_) | NtIdent(..) | NtBlock(_) = **nt {
-                return true;
-            }
-        }
-
-        false
-    }
-
-    /// Returns `true` if the token is either the `mut` or `const` keyword.
-    crate fn is_mutability(&self) -> bool {
-        self.is_keyword(kw::Mut) ||
-        self.is_keyword(kw::Const)
-    }
-
-    crate fn is_qpath_start(&self) -> bool {
-        self == &Lt || self == &BinOp(Shl)
-    }
-
-    crate fn is_path_start(&self) -> bool {
-        self == &ModSep || self.is_qpath_start() || self.is_path() ||
-        self.is_path_segment_keyword() || self.is_ident() && !self.is_reserved_ident()
-    }
-
-    /// Returns `true` if the token is a given keyword, `kw`.
-    pub fn is_keyword(&self, kw: Symbol) -> bool {
-        self.is_non_raw_ident_where(|id| id.name == kw)
-    }
-
-    crate fn is_path_segment_keyword(&self) -> bool {
-        self.is_non_raw_ident_where(ast::Ident::is_path_segment_keyword)
-    }
-
-    // Returns true for reserved identifiers used internally for elided lifetimes,
-    // unnamed method parameters, crate root module, error recovery etc.
-    crate fn is_special_ident(&self) -> bool {
-        self.is_non_raw_ident_where(ast::Ident::is_special)
-    }
-
-    /// Returns `true` if the token is a keyword used in the language.
-    crate fn is_used_keyword(&self) -> bool {
-        self.is_non_raw_ident_where(ast::Ident::is_used_keyword)
-    }
-
-    /// Returns `true` if the token is a keyword reserved for possible future use.
-    crate fn is_unused_keyword(&self) -> bool {
-        self.is_non_raw_ident_where(ast::Ident::is_unused_keyword)
-    }
-
-    /// Returns `true` if the token is either a special identifier or a keyword.
-    pub fn is_reserved_ident(&self) -> bool {
-        self.is_non_raw_ident_where(ast::Ident::is_reserved)
-    }
-
-    /// Returns `true` if the token is the identifier `true` or `false`.
-    crate fn is_bool_lit(&self) -> bool {
-        self.is_non_raw_ident_where(|id| id.name.is_bool_lit())
-    }
-
-    /// Returns `true` if the token is a non-raw identifier for which `pred` holds.
-    fn is_non_raw_ident_where(&self, pred: impl FnOnce(ast::Ident) -> bool) -> bool {
-        match self.ident() {
-            Some((id, false)) => pred(id),
-            _ => false,
-        }
-    }
-
-    crate fn glue(&self, joint: &Token) -> Option<Token> {
-        let kind = match self.kind {
-            Eq => match joint.kind {
-                Eq => EqEq,
-                Gt => FatArrow,
-                _ => return None,
-            },
-            Lt => match joint.kind {
-                Eq => Le,
-                Lt => BinOp(Shl),
-                Le => BinOpEq(Shl),
-                BinOp(Minus) => LArrow,
-                _ => return None,
-            },
-            Gt => match joint.kind {
-                Eq => Ge,
-                Gt => BinOp(Shr),
-                Ge => BinOpEq(Shr),
-                _ => return None,
-            },
-            Not => match joint.kind {
-                Eq => Ne,
-                _ => return None,
-            },
-            BinOp(op) => match joint.kind {
-                Eq => BinOpEq(op),
-                BinOp(And) if op == And => AndAnd,
-                BinOp(Or) if op == Or => OrOr,
-                Gt if op == Minus => RArrow,
-                _ => return None,
-            },
-            Dot => match joint.kind {
-                Dot => DotDot,
-                DotDot => DotDotDot,
-                _ => return None,
-            },
-            DotDot => match joint.kind {
-                Dot => DotDotDot,
-                Eq => DotDotEq,
-                _ => return None,
-            },
-            Colon => match joint.kind {
-                Colon => ModSep,
-                _ => return None,
-            },
-            SingleQuote => match joint.kind {
-                Ident(name, false) => Lifetime(Symbol::intern(&format!("'{}", name))),
-                _ => return None,
-            },
-
-            Le | EqEq | Ne | Ge | AndAnd | OrOr | Tilde | BinOpEq(..) | At | DotDotDot |
-            DotDotEq | Comma | Semi | ModSep | RArrow | LArrow | FatArrow | Pound | Dollar |
-            Question | OpenDelim(..) | CloseDelim(..) |
-            Literal(..) | Ident(..) | Lifetime(..) | Interpolated(..) | DocComment(..) |
-            Whitespace | Comment | Shebang(..) | Unknown(..) | Eof => return None,
-        };
-
-        Some(Token::new(kind, self.span.to(joint.span)))
-    }
-
-    // See comments in `Nonterminal::to_tokenstream` for why we care about
-    // *probably* equal here rather than actual equality
-    crate fn probably_equal_for_proc_macro(&self, other: &Token) -> bool {
-        if mem::discriminant(&self.kind) != mem::discriminant(&other.kind) {
-            return false
-        }
-        match (&self.kind, &other.kind) {
-            (&Eq, &Eq) |
-            (&Lt, &Lt) |
-            (&Le, &Le) |
-            (&EqEq, &EqEq) |
-            (&Ne, &Ne) |
-            (&Ge, &Ge) |
-            (&Gt, &Gt) |
-            (&AndAnd, &AndAnd) |
-            (&OrOr, &OrOr) |
-            (&Not, &Not) |
-            (&Tilde, &Tilde) |
-            (&At, &At) |
-            (&Dot, &Dot) |
-            (&DotDot, &DotDot) |
-            (&DotDotDot, &DotDotDot) |
-            (&DotDotEq, &DotDotEq) |
-            (&Comma, &Comma) |
-            (&Semi, &Semi) |
-            (&Colon, &Colon) |
-            (&ModSep, &ModSep) |
-            (&RArrow, &RArrow) |
-            (&LArrow, &LArrow) |
-            (&FatArrow, &FatArrow) |
-            (&Pound, &Pound) |
-            (&Dollar, &Dollar) |
-            (&Question, &Question) |
-            (&Whitespace, &Whitespace) |
-            (&Comment, &Comment) |
-            (&Eof, &Eof) => true,
-
-            (&BinOp(a), &BinOp(b)) |
-            (&BinOpEq(a), &BinOpEq(b)) => a == b,
-
-            (&OpenDelim(a), &OpenDelim(b)) |
-            (&CloseDelim(a), &CloseDelim(b)) => a == b,
-
-            (&DocComment(a), &DocComment(b)) |
-            (&Shebang(a), &Shebang(b)) => a == b,
-
-            (&Literal(a), &Literal(b)) => a == b,
-
-            (&Lifetime(a), &Lifetime(b)) => a == b,
-            (&Ident(a, b), &Ident(c, d)) => b == d && (a == c ||
-                                                       a == kw::DollarCrate ||
-                                                       c == kw::DollarCrate),
-
-            (&Interpolated(_), &Interpolated(_)) => false,
-
-            _ => panic!("forgot to add a token?"),
-        }
-    }
-}
-
-impl PartialEq<TokenKind> for Token {
-    fn eq(&self, rhs: &TokenKind) -> bool {
-        self.kind == *rhs
-    }
-}
-
-#[derive(Clone, RustcEncodable, RustcDecodable)]
-/// For interpolation during macro expansion.
-pub enum Nonterminal {
-    NtItem(P<ast::Item>),
-    NtBlock(P<ast::Block>),
-    NtStmt(ast::Stmt),
-    NtPat(P<ast::Pat>),
-    NtExpr(P<ast::Expr>),
-    NtTy(P<ast::Ty>),
-    NtIdent(ast::Ident, /* is_raw */ bool),
-    NtLifetime(ast::Ident),
-    NtLiteral(P<ast::Expr>),
-    /// Stuff inside brackets for attributes
-    NtMeta(ast::AttrItem),
-    NtPath(ast::Path),
-    NtVis(ast::Visibility),
-    NtTT(TokenTree),
-    // Used only for passing items to proc macro attributes (they are not
-    // strictly necessary for that, `Annotatable` can be converted into
-    // tokens directly, but doing that naively regresses pretty-printing).
-    NtTraitItem(ast::TraitItem),
-    NtImplItem(ast::ImplItem),
-    NtForeignItem(ast::ForeignItem),
-}
-
-impl PartialEq for Nonterminal {
-    fn eq(&self, rhs: &Self) -> bool {
-        match (self, rhs) {
-            (NtIdent(ident_lhs, is_raw_lhs), NtIdent(ident_rhs, is_raw_rhs)) =>
-                ident_lhs == ident_rhs && is_raw_lhs == is_raw_rhs,
-            (NtLifetime(ident_lhs), NtLifetime(ident_rhs)) => ident_lhs == ident_rhs,
-            (NtTT(tt_lhs), NtTT(tt_rhs)) => tt_lhs == tt_rhs,
-            // FIXME: Assume that all "complex" nonterminal are not equal, we can't compare them
-            // correctly based on data from AST. This will prevent them from matching each other
-            // in macros. The comparison will become possible only when each nonterminal has an
-            // attached token stream from which it was parsed.
-            _ => false,
-        }
-    }
-}
-
-impl fmt::Debug for Nonterminal {
-    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
-        match *self {
-            NtItem(..) => f.pad("NtItem(..)"),
-            NtBlock(..) => f.pad("NtBlock(..)"),
-            NtStmt(..) => f.pad("NtStmt(..)"),
-            NtPat(..) => f.pad("NtPat(..)"),
-            NtExpr(..) => f.pad("NtExpr(..)"),
-            NtTy(..) => f.pad("NtTy(..)"),
-            NtIdent(..) => f.pad("NtIdent(..)"),
-            NtLiteral(..) => f.pad("NtLiteral(..)"),
-            NtMeta(..) => f.pad("NtMeta(..)"),
-            NtPath(..) => f.pad("NtPath(..)"),
-            NtTT(..) => f.pad("NtTT(..)"),
-            NtImplItem(..) => f.pad("NtImplItem(..)"),
-            NtTraitItem(..) => f.pad("NtTraitItem(..)"),
-            NtForeignItem(..) => f.pad("NtForeignItem(..)"),
-            NtVis(..) => f.pad("NtVis(..)"),
-            NtLifetime(..) => f.pad("NtLifetime(..)"),
-        }
-    }
-}
index 1d59c13a9d0818800aaaea91c1b36504ddcab8c5..049f34efc262c35dcfbc9e6e60535697fe985a5e 100644 (file)
@@ -4,7 +4,7 @@
 use crate::util::parser::{self, AssocOp, Fixity};
 use crate::attr;
 use crate::source_map::{self, SourceMap, Spanned};
-use crate::parse::token::{self, BinOpToken, DelimToken, Nonterminal, Token, TokenKind};
+use crate::token::{self, BinOpToken, DelimToken, Nonterminal, Token, TokenKind};
 use crate::parse::lexer::comments;
 use crate::parse;
 use crate::print::pp::{self, Breaks};
diff --git a/src/libsyntax/token.rs b/src/libsyntax/token.rs
new file mode 100644 (file)
index 0000000..6f3da34
--- /dev/null
@@ -0,0 +1,728 @@
+pub use BinOpToken::*;
+pub use Nonterminal::*;
+pub use DelimToken::*;
+pub use LitKind::*;
+pub use TokenKind::*;
+
+use crate::ast;
+use crate::ptr::P;
+use crate::symbol::kw;
+use crate::tokenstream::TokenTree;
+
+use syntax_pos::symbol::Symbol;
+use syntax_pos::{self, Span, DUMMY_SP};
+
+use std::fmt;
+use std::mem;
+#[cfg(target_arch = "x86_64")]
+use rustc_data_structures::static_assert_size;
+use rustc_data_structures::sync::Lrc;
+
+#[derive(Clone, PartialEq, RustcEncodable, RustcDecodable, Hash, Debug, Copy)]
+pub enum BinOpToken {
+    Plus,
+    Minus,
+    Star,
+    Slash,
+    Percent,
+    Caret,
+    And,
+    Or,
+    Shl,
+    Shr,
+}
+
+/// A delimiter token.
+#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug, Copy)]
+pub enum DelimToken {
+    /// A round parenthesis (i.e., `(` or `)`).
+    Paren,
+    /// A square bracket (i.e., `[` or `]`).
+    Bracket,
+    /// A curly brace (i.e., `{` or `}`).
+    Brace,
+    /// An empty delimiter.
+    NoDelim,
+}
+
+impl DelimToken {
+    pub fn len(self) -> usize {
+        if self == NoDelim { 0 } else { 1 }
+    }
+
+    pub fn is_empty(self) -> bool {
+        self == NoDelim
+    }
+}
+
+#[derive(Clone, Copy, PartialEq, RustcEncodable, RustcDecodable, Debug)]
+pub enum LitKind {
+    Bool, // AST only, must never appear in a `Token`
+    Byte,
+    Char,
+    Integer,
+    Float,
+    Str,
+    StrRaw(u16), // raw string delimited by `n` hash symbols
+    ByteStr,
+    ByteStrRaw(u16), // raw byte string delimited by `n` hash symbols
+    Err,
+}
+
+/// A literal token.
+#[derive(Clone, Copy, PartialEq, RustcEncodable, RustcDecodable, Debug)]
+pub struct Lit {
+    pub kind: LitKind,
+    pub symbol: Symbol,
+    pub suffix: Option<Symbol>,
+}
+
+impl fmt::Display for Lit {
+    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
+        let Lit { kind, symbol, suffix } = *self;
+        match kind {
+            Byte          => write!(f, "b'{}'", symbol)?,
+            Char          => write!(f, "'{}'", symbol)?,
+            Str           => write!(f, "\"{}\"", symbol)?,
+            StrRaw(n)     => write!(f, "r{delim}\"{string}\"{delim}",
+                                     delim="#".repeat(n as usize),
+                                     string=symbol)?,
+            ByteStr       => write!(f, "b\"{}\"", symbol)?,
+            ByteStrRaw(n) => write!(f, "br{delim}\"{string}\"{delim}",
+                                     delim="#".repeat(n as usize),
+                                     string=symbol)?,
+            Integer       |
+            Float         |
+            Bool          |
+            Err           => write!(f, "{}", symbol)?,
+        }
+
+        if let Some(suffix) = suffix {
+            write!(f, "{}", suffix)?;
+        }
+
+        Ok(())
+    }
+}
+
+impl LitKind {
+    /// An English article for the literal token kind.
+    crate fn article(self) -> &'static str {
+        match self {
+            Integer | Err => "an",
+            _ => "a",
+        }
+    }
+
+    crate fn descr(self) -> &'static str {
+        match self {
+            Bool => panic!("literal token contains `Lit::Bool`"),
+            Byte => "byte",
+            Char => "char",
+            Integer => "integer",
+            Float => "float",
+            Str | StrRaw(..) => "string",
+            ByteStr | ByteStrRaw(..) => "byte string",
+            Err => "error",
+        }
+    }
+
+    crate fn may_have_suffix(self) -> bool {
+        match self {
+            Integer | Float | Err => true,
+            _ => false,
+        }
+    }
+}
+
+impl Lit {
+    pub fn new(kind: LitKind, symbol: Symbol, suffix: Option<Symbol>) -> Lit {
+        Lit { kind, symbol, suffix }
+    }
+}
+
+pub(crate) fn ident_can_begin_expr(name: ast::Name, span: Span, is_raw: bool) -> bool {
+    let ident_token = Token::new(Ident(name, is_raw), span);
+    token_can_begin_expr(&ident_token)
+}
+
+pub(crate) fn token_can_begin_expr(ident_token: &Token) -> bool {
+    !ident_token.is_reserved_ident() ||
+    ident_token.is_path_segment_keyword() ||
+    match ident_token.kind {
+        TokenKind::Ident(ident, _) => [
+            kw::Async,
+            kw::Do,
+            kw::Box,
+            kw::Break,
+            kw::Continue,
+            kw::False,
+            kw::For,
+            kw::If,
+            kw::Let,
+            kw::Loop,
+            kw::Match,
+            kw::Move,
+            kw::Return,
+            kw::True,
+            kw::Unsafe,
+            kw::While,
+            kw::Yield,
+            kw::Static,
+        ].contains(&ident),
+        _=> false,
+    }
+}
+
+fn ident_can_begin_type(name: ast::Name, span: Span, is_raw: bool) -> bool {
+    let ident_token = Token::new(Ident(name, is_raw), span);
+
+    !ident_token.is_reserved_ident() ||
+    ident_token.is_path_segment_keyword() ||
+    [
+        kw::Underscore,
+        kw::For,
+        kw::Impl,
+        kw::Fn,
+        kw::Unsafe,
+        kw::Extern,
+        kw::Typeof,
+        kw::Dyn,
+    ].contains(&name)
+}
+
+#[derive(Clone, PartialEq, RustcEncodable, RustcDecodable, Debug)]
+pub enum TokenKind {
+    /* Expression-operator symbols. */
+    Eq,
+    Lt,
+    Le,
+    EqEq,
+    Ne,
+    Ge,
+    Gt,
+    AndAnd,
+    OrOr,
+    Not,
+    Tilde,
+    BinOp(BinOpToken),
+    BinOpEq(BinOpToken),
+
+    /* Structural symbols */
+    At,
+    Dot,
+    DotDot,
+    DotDotDot,
+    DotDotEq,
+    Comma,
+    Semi,
+    Colon,
+    ModSep,
+    RArrow,
+    LArrow,
+    FatArrow,
+    Pound,
+    Dollar,
+    Question,
+    /// Used by proc macros for representing lifetimes, not generated by lexer right now.
+    SingleQuote,
+    /// An opening delimiter (e.g., `{`).
+    OpenDelim(DelimToken),
+    /// A closing delimiter (e.g., `}`).
+    CloseDelim(DelimToken),
+
+    /* Literals */
+    Literal(Lit),
+
+    /* Name components */
+    Ident(ast::Name, /* is_raw */ bool),
+    Lifetime(ast::Name),
+
+    Interpolated(Lrc<Nonterminal>),
+
+    // Can be expanded into several tokens.
+    /// A doc comment.
+    DocComment(ast::Name),
+
+    // Junk. These carry no data because we don't really care about the data
+    // they *would* carry, and don't really want to allocate a new ident for
+    // them. Instead, users could extract that from the associated span.
+
+    /// Whitespace.
+    Whitespace,
+    /// A comment.
+    Comment,
+    Shebang(ast::Name),
+    /// A completely invalid token which should be skipped.
+    Unknown(ast::Name),
+
+    Eof,
+}
+
+// `TokenKind` is used a lot. Make sure it doesn't unintentionally get bigger.
+#[cfg(target_arch = "x86_64")]
+static_assert_size!(TokenKind, 16);
+
+#[derive(Clone, PartialEq, RustcEncodable, RustcDecodable, Debug)]
+pub struct Token {
+    pub kind: TokenKind,
+    pub span: Span,
+}
+
+impl TokenKind {
+    pub fn lit(kind: LitKind, symbol: Symbol, suffix: Option<Symbol>) -> TokenKind {
+        Literal(Lit::new(kind, symbol, suffix))
+    }
+
+    /// Returns tokens that are likely to be typed accidentally instead of the current token.
+    /// Enables better error recovery when the wrong token is found.
+    crate fn similar_tokens(&self) -> Option<Vec<TokenKind>> {
+        match *self {
+            Comma => Some(vec![Dot, Lt, Semi]),
+            Semi => Some(vec![Colon, Comma]),
+            _ => None
+        }
+    }
+}
+
+impl Token {
+    pub fn new(kind: TokenKind, span: Span) -> Self {
+        Token { kind, span }
+    }
+
+    /// Some token that will be thrown away later.
+    crate fn dummy() -> Self {
+        Token::new(TokenKind::Whitespace, DUMMY_SP)
+    }
+
+    /// Recovers a `Token` from an `ast::Ident`. This creates a raw identifier if necessary.
+    pub fn from_ast_ident(ident: ast::Ident) -> Self {
+        Token::new(Ident(ident.name, ident.is_raw_guess()), ident.span)
+    }
+
+    /// Return this token by value and leave a dummy token in its place.
+    pub fn take(&mut self) -> Self {
+        mem::replace(self, Token::dummy())
+    }
+
+    crate fn is_op(&self) -> bool {
+        match self.kind {
+            OpenDelim(..) | CloseDelim(..) | Literal(..) | DocComment(..) |
+            Ident(..) | Lifetime(..) | Interpolated(..) |
+            Whitespace | Comment | Shebang(..) | Eof => false,
+            _ => true,
+        }
+    }
+
+    crate fn is_like_plus(&self) -> bool {
+        match self.kind {
+            BinOp(Plus) | BinOpEq(Plus) => true,
+            _ => false,
+        }
+    }
+
+    /// Returns `true` if the token can appear at the start of an expression.
+    pub fn can_begin_expr(&self) -> bool {
+        match self.kind {
+            Ident(name, is_raw)              =>
+                ident_can_begin_expr(name, self.span, is_raw), // value name or keyword
+            OpenDelim(..)                     | // tuple, array or block
+            Literal(..)                       | // literal
+            Not                               | // operator not
+            BinOp(Minus)                      | // unary minus
+            BinOp(Star)                       | // dereference
+            BinOp(Or) | OrOr                  | // closure
+            BinOp(And)                        | // reference
+            AndAnd                            | // double reference
+            // DotDotDot is no longer supported, but we need some way to display the error
+            DotDot | DotDotDot | DotDotEq     | // range notation
+            Lt | BinOp(Shl)                   | // associated path
+            ModSep                            | // global path
+            Lifetime(..)                      | // labeled loop
+            Pound                             => true, // expression attributes
+            Interpolated(ref nt) => match **nt {
+                NtLiteral(..) |
+                NtIdent(..)   |
+                NtExpr(..)    |
+                NtBlock(..)   |
+                NtPath(..)    |
+                NtLifetime(..) => true,
+                _ => false,
+            },
+            _ => false,
+        }
+    }
+
+    /// Returns `true` if the token can appear at the start of a type.
+    pub fn can_begin_type(&self) -> bool {
+        match self.kind {
+            Ident(name, is_raw)        =>
+                ident_can_begin_type(name, self.span, is_raw), // type name or keyword
+            OpenDelim(Paren)            | // tuple
+            OpenDelim(Bracket)          | // array
+            Not                         | // never
+            BinOp(Star)                 | // raw pointer
+            BinOp(And)                  | // reference
+            AndAnd                      | // double reference
+            Question                    | // maybe bound in trait object
+            Lifetime(..)                | // lifetime bound in trait object
+            Lt | BinOp(Shl)             | // associated path
+            ModSep                      => true, // global path
+            Interpolated(ref nt) => match **nt {
+                NtIdent(..) | NtTy(..) | NtPath(..) | NtLifetime(..) => true,
+                _ => false,
+            },
+            _ => false,
+        }
+    }
+
+    /// Returns `true` if the token can appear at the start of a const param.
+    crate fn can_begin_const_arg(&self) -> bool {
+        match self.kind {
+            OpenDelim(Brace) => true,
+            Interpolated(ref nt) => match **nt {
+                NtExpr(..) | NtBlock(..) | NtLiteral(..) => true,
+                _ => false,
+            }
+            _ => self.can_begin_literal_or_bool(),
+        }
+    }
+
+    /// Returns `true` if the token can appear at the start of a generic bound.
+    crate fn can_begin_bound(&self) -> bool {
+        self.is_path_start() || self.is_lifetime() || self.is_keyword(kw::For) ||
+        self == &Question || self == &OpenDelim(Paren)
+    }
+
+    /// Returns `true` if the token is any literal
+    pub fn is_lit(&self) -> bool {
+        match self.kind {
+            Literal(..) => true,
+            _           => false,
+        }
+    }
+
+    /// Returns `true` if the token is any literal, a minus (which can prefix a literal,
+    /// for example a '-42', or one of the boolean idents).
+    pub fn can_begin_literal_or_bool(&self) -> bool {
+        match self.kind {
+            Literal(..) | BinOp(Minus) => true,
+            Ident(name, false) if name.is_bool_lit() => true,
+            Interpolated(ref nt) => match **nt {
+                NtLiteral(..) => true,
+                _             => false,
+            },
+            _            => false,
+        }
+    }
+
+    /// Returns an identifier if this token is an identifier.
+    pub fn ident(&self) -> Option<(ast::Ident, /* is_raw */ bool)> {
+        match self.kind {
+            Ident(name, is_raw) => Some((ast::Ident::new(name, self.span), is_raw)),
+            Interpolated(ref nt) => match **nt {
+                NtIdent(ident, is_raw) => Some((ident, is_raw)),
+                _ => None,
+            },
+            _ => None,
+        }
+    }
+
+    /// Returns a lifetime identifier if this token is a lifetime.
+    pub fn lifetime(&self) -> Option<ast::Ident> {
+        match self.kind {
+            Lifetime(name) => Some(ast::Ident::new(name, self.span)),
+            Interpolated(ref nt) => match **nt {
+                NtLifetime(ident) => Some(ident),
+                _ => None,
+            },
+            _ => None,
+        }
+    }
+
+    /// Returns `true` if the token is an identifier.
+    pub fn is_ident(&self) -> bool {
+        self.ident().is_some()
+    }
+
+    /// Returns `true` if the token is a lifetime.
+    crate fn is_lifetime(&self) -> bool {
+        self.lifetime().is_some()
+    }
+
+    /// Returns `true` if the token is a identifier whose name is the given
+    /// string slice.
+    crate fn is_ident_named(&self, name: Symbol) -> bool {
+        self.ident().map_or(false, |(ident, _)| ident.name == name)
+    }
+
+    /// Returns `true` if the token is an interpolated path.
+    fn is_path(&self) -> bool {
+        if let Interpolated(ref nt) = self.kind {
+            if let NtPath(..) = **nt {
+                return true;
+            }
+        }
+        false
+    }
+
+    /// Would `maybe_whole_expr` in `parser.rs` return `Ok(..)`?
+    /// That is, is this a pre-parsed expression dropped into the token stream
+    /// (which happens while parsing the result of macro expansion)?
+    crate fn is_whole_expr(&self) -> bool {
+        if let Interpolated(ref nt) = self.kind {
+            if let NtExpr(_) | NtLiteral(_) | NtPath(_) | NtIdent(..) | NtBlock(_) = **nt {
+                return true;
+            }
+        }
+
+        false
+    }
+
+    /// Returns `true` if the token is either the `mut` or `const` keyword.
+    crate fn is_mutability(&self) -> bool {
+        self.is_keyword(kw::Mut) ||
+        self.is_keyword(kw::Const)
+    }
+
+    crate fn is_qpath_start(&self) -> bool {
+        self == &Lt || self == &BinOp(Shl)
+    }
+
+    crate fn is_path_start(&self) -> bool {
+        self == &ModSep || self.is_qpath_start() || self.is_path() ||
+        self.is_path_segment_keyword() || self.is_ident() && !self.is_reserved_ident()
+    }
+
+    /// Returns `true` if the token is a given keyword, `kw`.
+    pub fn is_keyword(&self, kw: Symbol) -> bool {
+        self.is_non_raw_ident_where(|id| id.name == kw)
+    }
+
+    crate fn is_path_segment_keyword(&self) -> bool {
+        self.is_non_raw_ident_where(ast::Ident::is_path_segment_keyword)
+    }
+
+    // Returns true for reserved identifiers used internally for elided lifetimes,
+    // unnamed method parameters, crate root module, error recovery etc.
+    crate fn is_special_ident(&self) -> bool {
+        self.is_non_raw_ident_where(ast::Ident::is_special)
+    }
+
+    /// Returns `true` if the token is a keyword used in the language.
+    crate fn is_used_keyword(&self) -> bool {
+        self.is_non_raw_ident_where(ast::Ident::is_used_keyword)
+    }
+
+    /// Returns `true` if the token is a keyword reserved for possible future use.
+    crate fn is_unused_keyword(&self) -> bool {
+        self.is_non_raw_ident_where(ast::Ident::is_unused_keyword)
+    }
+
+    /// Returns `true` if the token is either a special identifier or a keyword.
+    pub fn is_reserved_ident(&self) -> bool {
+        self.is_non_raw_ident_where(ast::Ident::is_reserved)
+    }
+
+    /// Returns `true` if the token is the identifier `true` or `false`.
+    crate fn is_bool_lit(&self) -> bool {
+        self.is_non_raw_ident_where(|id| id.name.is_bool_lit())
+    }
+
+    /// Returns `true` if the token is a non-raw identifier for which `pred` holds.
+    fn is_non_raw_ident_where(&self, pred: impl FnOnce(ast::Ident) -> bool) -> bool {
+        match self.ident() {
+            Some((id, false)) => pred(id),
+            _ => false,
+        }
+    }
+
+    crate fn glue(&self, joint: &Token) -> Option<Token> {
+        let kind = match self.kind {
+            Eq => match joint.kind {
+                Eq => EqEq,
+                Gt => FatArrow,
+                _ => return None,
+            },
+            Lt => match joint.kind {
+                Eq => Le,
+                Lt => BinOp(Shl),
+                Le => BinOpEq(Shl),
+                BinOp(Minus) => LArrow,
+                _ => return None,
+            },
+            Gt => match joint.kind {
+                Eq => Ge,
+                Gt => BinOp(Shr),
+                Ge => BinOpEq(Shr),
+                _ => return None,
+            },
+            Not => match joint.kind {
+                Eq => Ne,
+                _ => return None,
+            },
+            BinOp(op) => match joint.kind {
+                Eq => BinOpEq(op),
+                BinOp(And) if op == And => AndAnd,
+                BinOp(Or) if op == Or => OrOr,
+                Gt if op == Minus => RArrow,
+                _ => return None,
+            },
+            Dot => match joint.kind {
+                Dot => DotDot,
+                DotDot => DotDotDot,
+                _ => return None,
+            },
+            DotDot => match joint.kind {
+                Dot => DotDotDot,
+                Eq => DotDotEq,
+                _ => return None,
+            },
+            Colon => match joint.kind {
+                Colon => ModSep,
+                _ => return None,
+            },
+            SingleQuote => match joint.kind {
+                Ident(name, false) => Lifetime(Symbol::intern(&format!("'{}", name))),
+                _ => return None,
+            },
+
+            Le | EqEq | Ne | Ge | AndAnd | OrOr | Tilde | BinOpEq(..) | At | DotDotDot |
+            DotDotEq | Comma | Semi | ModSep | RArrow | LArrow | FatArrow | Pound | Dollar |
+            Question | OpenDelim(..) | CloseDelim(..) |
+            Literal(..) | Ident(..) | Lifetime(..) | Interpolated(..) | DocComment(..) |
+            Whitespace | Comment | Shebang(..) | Unknown(..) | Eof => return None,
+        };
+
+        Some(Token::new(kind, self.span.to(joint.span)))
+    }
+
+    // See comments in `Nonterminal::to_tokenstream` for why we care about
+    // *probably* equal here rather than actual equality
+    crate fn probably_equal_for_proc_macro(&self, other: &Token) -> bool {
+        if mem::discriminant(&self.kind) != mem::discriminant(&other.kind) {
+            return false
+        }
+        match (&self.kind, &other.kind) {
+            (&Eq, &Eq) |
+            (&Lt, &Lt) |
+            (&Le, &Le) |
+            (&EqEq, &EqEq) |
+            (&Ne, &Ne) |
+            (&Ge, &Ge) |
+            (&Gt, &Gt) |
+            (&AndAnd, &AndAnd) |
+            (&OrOr, &OrOr) |
+            (&Not, &Not) |
+            (&Tilde, &Tilde) |
+            (&At, &At) |
+            (&Dot, &Dot) |
+            (&DotDot, &DotDot) |
+            (&DotDotDot, &DotDotDot) |
+            (&DotDotEq, &DotDotEq) |
+            (&Comma, &Comma) |
+            (&Semi, &Semi) |
+            (&Colon, &Colon) |
+            (&ModSep, &ModSep) |
+            (&RArrow, &RArrow) |
+            (&LArrow, &LArrow) |
+            (&FatArrow, &FatArrow) |
+            (&Pound, &Pound) |
+            (&Dollar, &Dollar) |
+            (&Question, &Question) |
+            (&Whitespace, &Whitespace) |
+            (&Comment, &Comment) |
+            (&Eof, &Eof) => true,
+
+            (&BinOp(a), &BinOp(b)) |
+            (&BinOpEq(a), &BinOpEq(b)) => a == b,
+
+            (&OpenDelim(a), &OpenDelim(b)) |
+            (&CloseDelim(a), &CloseDelim(b)) => a == b,
+
+            (&DocComment(a), &DocComment(b)) |
+            (&Shebang(a), &Shebang(b)) => a == b,
+
+            (&Literal(a), &Literal(b)) => a == b,
+
+            (&Lifetime(a), &Lifetime(b)) => a == b,
+            (&Ident(a, b), &Ident(c, d)) => b == d && (a == c ||
+                                                       a == kw::DollarCrate ||
+                                                       c == kw::DollarCrate),
+
+            (&Interpolated(_), &Interpolated(_)) => false,
+
+            _ => panic!("forgot to add a token?"),
+        }
+    }
+}
+
+impl PartialEq<TokenKind> for Token {
+    fn eq(&self, rhs: &TokenKind) -> bool {
+        self.kind == *rhs
+    }
+}
+
+#[derive(Clone, RustcEncodable, RustcDecodable)]
+/// For interpolation during macro expansion.
+pub enum Nonterminal {
+    NtItem(P<ast::Item>),
+    NtBlock(P<ast::Block>),
+    NtStmt(ast::Stmt),
+    NtPat(P<ast::Pat>),
+    NtExpr(P<ast::Expr>),
+    NtTy(P<ast::Ty>),
+    NtIdent(ast::Ident, /* is_raw */ bool),
+    NtLifetime(ast::Ident),
+    NtLiteral(P<ast::Expr>),
+    /// Stuff inside brackets for attributes
+    NtMeta(ast::AttrItem),
+    NtPath(ast::Path),
+    NtVis(ast::Visibility),
+    NtTT(TokenTree),
+    // Used only for passing items to proc macro attributes (they are not
+    // strictly necessary for that, `Annotatable` can be converted into
+    // tokens directly, but doing that naively regresses pretty-printing).
+    NtTraitItem(ast::TraitItem),
+    NtImplItem(ast::ImplItem),
+    NtForeignItem(ast::ForeignItem),
+}
+
+impl PartialEq for Nonterminal {
+    fn eq(&self, rhs: &Self) -> bool {
+        match (self, rhs) {
+            (NtIdent(ident_lhs, is_raw_lhs), NtIdent(ident_rhs, is_raw_rhs)) =>
+                ident_lhs == ident_rhs && is_raw_lhs == is_raw_rhs,
+            (NtLifetime(ident_lhs), NtLifetime(ident_rhs)) => ident_lhs == ident_rhs,
+            (NtTT(tt_lhs), NtTT(tt_rhs)) => tt_lhs == tt_rhs,
+            // FIXME: Assume that all "complex" nonterminal are not equal, we can't compare them
+            // correctly based on data from AST. This will prevent them from matching each other
+            // in macros. The comparison will become possible only when each nonterminal has an
+            // attached token stream from which it was parsed.
+            _ => false,
+        }
+    }
+}
+
+impl fmt::Debug for Nonterminal {
+    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
+        match *self {
+            NtItem(..) => f.pad("NtItem(..)"),
+            NtBlock(..) => f.pad("NtBlock(..)"),
+            NtStmt(..) => f.pad("NtStmt(..)"),
+            NtPat(..) => f.pad("NtPat(..)"),
+            NtExpr(..) => f.pad("NtExpr(..)"),
+            NtTy(..) => f.pad("NtTy(..)"),
+            NtIdent(..) => f.pad("NtIdent(..)"),
+            NtLiteral(..) => f.pad("NtLiteral(..)"),
+            NtMeta(..) => f.pad("NtMeta(..)"),
+            NtPath(..) => f.pad("NtPath(..)"),
+            NtTT(..) => f.pad("NtTT(..)"),
+            NtImplItem(..) => f.pad("NtImplItem(..)"),
+            NtTraitItem(..) => f.pad("NtTraitItem(..)"),
+            NtForeignItem(..) => f.pad("NtForeignItem(..)"),
+            NtVis(..) => f.pad("NtVis(..)"),
+            NtLifetime(..) => f.pad("NtLifetime(..)"),
+        }
+    }
+}
index a51d208704ade04f4075caadbb97f378c21f96d6..6e1bb85ce1ac13cda27246e7fefe0c5b25e49366 100644 (file)
@@ -13,7 +13,7 @@
 //! and a borrowed `TokenStream` is sufficient to build an owned `TokenStream` without taking
 //! ownership of the original.
 
-use crate::parse::token::{self, DelimToken, Token, TokenKind};
+use crate::token::{self, DelimToken, Token, TokenKind};
 
 use syntax_pos::{Span, DUMMY_SP};
 #[cfg(target_arch = "x86_64")]
index 982755e868054ec159b06ba7cb7ffbffcf28f958..edb708d7e97b20012b54a58bacadfe862eac8605 100644 (file)
@@ -1,4 +1,4 @@
-use crate::parse::token::{self, Token, BinOpToken};
+use crate::token::{self, Token, BinOpToken};
 use crate::symbol::kw;
 use crate::ast::{self, BinOpKind};
 
index 117787d08c7503e3cef3de043345d727d0c10d14..cfd160fd57751d01b3a4080e88730bec14066b62 100644 (file)
@@ -14,7 +14,7 @@
 //! those that are created by the expansion of a macro.
 
 use crate::ast::*;
-use crate::parse::token::Token;
+use crate::token::Token;
 use crate::tokenstream::{TokenTree, TokenStream};
 
 use syntax_pos::Span;
index d02251eb746d0209c6dc613d31869cb2a9e5d025..47835c9265967268e339a050fc71bc996d7e066a 100644 (file)
@@ -6,11 +6,11 @@
 use syntax::edition::Edition;
 use syntax::mut_visit::{self, MutVisitor};
 use syntax::parse::{self, parser, DirectoryOwnership};
-use syntax::parse::token;
 use syntax::ptr::P;
 use syntax::sess::ParseSess;
 use syntax::symbol::{kw, sym, Ident, Symbol};
 use syntax::{ThinVec, MACRO_ARGUMENTS};
+use syntax::token;
 use syntax::tokenstream::{self, TokenStream};
 use syntax::visit::Visitor;
 
index 7dbc7787010061592a7dc7ad344c4ce7306716e5..6d1f0abe49eaf98a0ae1e72146cf6b09f7842051 100644 (file)
 use syntax::feature_gate::{self, Features, GateIssue, is_builtin_attr, emit_feature_err};
 use syntax::mut_visit::*;
 use syntax::parse::{DirectoryOwnership, PResult};
-use syntax::parse::token;
 use syntax::parse::parser::Parser;
 use syntax::print::pprust;
 use syntax::ptr::P;
 use syntax::sess::ParseSess;
 use syntax::symbol::{sym, Symbol};
+use syntax::token;
 use syntax::tokenstream::{TokenStream, TokenTree};
 use syntax::visit::{self, Visitor};
 use syntax::util::map_in_place::MapInPlace;
index 06e0cde3ad88c345c5888627ee4abaa028e7d144..6964d01b719c945168e092c1f3ae54e64cdda139 100644 (file)
@@ -10,7 +10,7 @@
 crate mod quoted;
 
 use syntax::ast;
-use syntax::parse::token::{self, Token, TokenKind};
+use syntax::token::{self, Token, TokenKind};
 use syntax::tokenstream::{DelimSpan};
 
 use syntax_pos::Span;
index 50abda8d45e979fbd68914e04e4b0552a56f3560..25754ed42177fd5ed18c94d1f8ae3d88059284cb 100644 (file)
 
 use syntax::ast::NodeId;
 use syntax::early_buffered_lints::BufferedEarlyLintId;
-use syntax::parse::token::{DelimToken, Token, TokenKind};
+use syntax::token::{DelimToken, Token, TokenKind};
 use syntax::sess::ParseSess;
 use syntax::symbol::{kw, sym};
 
index 3efe22626a9fa9b0cecea9c435cfc94b84170b9f..950e7c0f286fa410e7bdab2054b07471f1efbe4c 100644 (file)
 use syntax::ast::{Ident, Name};
 use syntax::parse::{Directory, PResult};
 use syntax::parse::parser::{Parser, PathStyle};
-use syntax::parse::token::{self, DocComment, Nonterminal, Token};
 use syntax::print::pprust;
 use syntax::sess::ParseSess;
 use syntax::symbol::{kw, sym, Symbol};
+use syntax::token::{self, DocComment, Nonterminal, Token};
 use syntax::tokenstream::{DelimSpan, TokenStream};
 
 use errors::FatalError;
index 5571990740317f2dfbc50fd13bc53602d14e7e00..a5fc301fbf67b59b3c951ae9c79dc07e4168340c 100644 (file)
 use syntax::edition::Edition;
 use syntax::feature_gate::Features;
 use syntax::parse::parser::Parser;
-use syntax::parse::token::TokenKind::*;
-use syntax::parse::token::{self, NtTT, Token};
 use syntax::parse::Directory;
 use syntax::print::pprust;
 use syntax::sess::ParseSess;
 use syntax::symbol::{kw, sym, Symbol};
+use syntax::token::{self, NtTT, Token, TokenKind::*};
 use syntax::tokenstream::{DelimSpan, TokenStream};
 
 use errors::{DiagnosticBuilder, FatalError};
index cedd59233adf5da0988350f3e67d9338e1b72697..dec504c0d97452830d8e3d320c13e0752a294ea0 100644 (file)
@@ -2,10 +2,10 @@
 use crate::mbe::{TokenTree, KleeneOp, KleeneToken, SequenceRepetition, Delimited};
 
 use syntax::ast;
-use syntax::parse::token::{self, Token};
 use syntax::print::pprust;
 use syntax::sess::ParseSess;
 use syntax::symbol::kw;
+use syntax::token::{self, Token};
 use syntax::tokenstream;
 
 use syntax_pos::Span;
index 6f060103ef48ecacb6c01a9078aa04662057f48c..4092d4b97de04965a40821a9a01c4a353681e6fa 100644 (file)
@@ -4,7 +4,7 @@
 
 use syntax::ast::{Ident, Mac};
 use syntax::mut_visit::{self, MutVisitor};
-use syntax::parse::token::{self, NtTT, Token};
+use syntax::token::{self, NtTT, Token};
 use syntax::tokenstream::{DelimSpan, TokenStream, TokenTree, TreeAndJoint};
 
 use smallvec::{smallvec, SmallVec};
index 1f4c481e3ea04d9157c144cbf1833c2f197b8239..51c368bbaa6067693a13bdff17fa4e30da4a6111 100644 (file)
@@ -4,8 +4,9 @@
 use syntax::ast::{self, ItemKind, Attribute, Mac};
 use syntax::attr::{mark_used, mark_known};
 use syntax::errors::{Applicability, FatalError};
-use syntax::parse::{self, token};
+use syntax::parse;
 use syntax::symbol::sym;
+use syntax::token;
 use syntax::tokenstream::{self, TokenStream};
 use syntax::visit::Visitor;
 
index 4ce99cfe73b5c2f0e74bb21c725921ab6a70e8d1..67a15e48205b990b8bda7bd2e7e9f9038f553037 100644 (file)
@@ -1,10 +1,11 @@
 use crate::base::ExtCtxt;
 
 use syntax::ast;
-use syntax::parse::{self, token};
+use syntax::parse::{self};
 use syntax::parse::lexer::comments;
 use syntax::print::pprust;
 use syntax::sess::ParseSess;
+use syntax::token;
 use syntax::tokenstream::{self, DelimSpan, IsJoint::*, TokenStream, TreeAndJoint};
 
 use errors::Diagnostic;
@@ -52,7 +53,7 @@ impl FromInternal<(TreeAndJoint, &'_ ParseSess, &'_ mut Vec<Self>)>
 {
     fn from_internal(((tree, is_joint), sess, stack): (TreeAndJoint, &ParseSess, &mut Vec<Self>))
                     -> Self {
-        use syntax::parse::token::*;
+        use syntax::token::*;
 
         let joint = is_joint == Joint;
         let Token { kind, span } = match tree {
@@ -193,7 +194,7 @@ macro_rules! op {
 
 impl ToInternal<TokenStream> for TokenTree<Group, Punct, Ident, Literal> {
     fn to_internal(self) -> TokenStream {
-        use syntax::parse::token::*;
+        use syntax::token::*;
 
         let (ch, joint, span) = match self {
             TokenTree::Punct(Punct { ch, joint, span }) => (ch, joint, span),
index 8c9a34713ea604f5d2146520c1b50530eae7fbc6..539d777105d7466d0215a4ed8a7c2f4e2dfa0727 100644 (file)
@@ -8,7 +8,7 @@
 
 use syntax::ast;
 use syntax_expand::base::{self, *};
-use syntax::parse::token::{self, Token};
+use syntax::token::{self, Token};
 use syntax::ptr::P;
 use syntax::symbol::{kw, sym, Symbol};
 use syntax::ast::AsmDialect;
index f4d1f7fb09cdf1d1cef8430668c3f10c16cce528..a15423b7ad85a5e91e74bb5b0b0b737c9c80cc37 100644 (file)
@@ -2,7 +2,7 @@
 
 use syntax::ast::{self, *};
 use syntax_expand::base::*;
-use syntax::parse::token::{self, TokenKind};
+use syntax::token::{self, TokenKind};
 use syntax::parse::parser::Parser;
 use syntax::print::pprust;
 use syntax::ptr::P;
index 9e693f29c5a3c80b9183364847a0e2c7e85ba90c..583236d97546df82024e372afde80d91a8543832 100644 (file)
@@ -8,7 +8,7 @@
 use syntax_expand::base::{self, *};
 use syntax::attr;
 use syntax::tokenstream::TokenStream;
-use syntax::parse::token;
+use syntax::token;
 use syntax_pos::Span;
 
 pub fn expand_cfg(
index 2d981526a39837374c4a9b917574f64ee3b93a0c..171f2405573c016064f90a6f3479728a7e30ac62 100644 (file)
@@ -2,7 +2,8 @@
 
 use syntax::ast::{self, AttrItem, AttrStyle};
 use syntax::attr::mk_attr;
-use syntax::parse::{self, token};
+use syntax::parse;
+use syntax::token;
 use syntax::sess::ParseSess;
 use syntax_expand::panictry;
 use syntax_pos::FileName;
index a132a4136ea01b090b83743c637ad12f82d1945f..8a1bc56cf1ced956340405f4440afcadd8d1ddba 100644 (file)
@@ -2,7 +2,7 @@
 
 use syntax::ast;
 use syntax_expand::base::{self, *};
-use syntax::parse::token::{self, Token};
+use syntax::token::{self, Token};
 use syntax::ptr::P;
 use syntax_pos::Span;
 use syntax_pos::symbol::Symbol;
index 314c2eefd4c74cf31579a31efb8ebf75ccf3c1cc..e25ba7b17837190a3469d943fb8290a3862fca97 100644 (file)
@@ -9,7 +9,7 @@
 
 use syntax::ast;
 use syntax_expand::base::{self, *};
-use syntax::parse::token;
+use syntax::token;
 use syntax::ptr::P;
 use syntax::symbol::{Symbol, sym};
 use syntax::tokenstream::TokenStream;
index 879ae1e42153da497bd250c099ca2b8b1bfc642d..8a8ce9a7f14b5e268e9208cdfca5226acd08aca9 100644 (file)
@@ -13,7 +13,7 @@
 use syntax::ast;
 use syntax::source_map::respan;
 use syntax_expand::base::{self, *};
-use syntax::parse::token;
+use syntax::token;
 use syntax::ptr::P;
 use syntax_pos::Span;
 use syntax::tokenstream::TokenStream;
index 1ca9422eb9dcc364f47d5cd605be55b5ca8787a1..cee1b97af55b21489a5966a63111c03c1caa2368 100644 (file)
@@ -4,12 +4,12 @@
 use syntax::ast::*;
 use syntax::attr;
 use syntax::edition::Edition;
-use syntax_expand::base::{Resolver, NamedSyntaxExtension};
-use syntax::parse::token;
 use syntax::ptr::P;
 use syntax::source_map::respan;
 use syntax::symbol::sym;
+use syntax::token;
 use syntax::tokenstream::*;
+use syntax_expand::base::{Resolver, NamedSyntaxExtension};
 use syntax_pos::{Span, DUMMY_SP};
 use syntax_pos::hygiene::{ExpnData, ExpnKind, AstPass};
 
index f6c58fcdfa1cbf009ab10d56a0007f91773fada4..7e47b40714da0505e1451580db57b25e9d4f2ce1 100644 (file)
@@ -1,10 +1,11 @@
 use syntax_expand::panictry;
 use syntax_expand::base::{self, *};
 use syntax::ast;
-use syntax::parse::{self, token, DirectoryOwnership};
+use syntax::parse::{self, DirectoryOwnership};
 use syntax::print::pprust;
 use syntax::ptr::P;
 use syntax::symbol::Symbol;
+use syntax::token;
 use syntax::tokenstream::TokenStream;
 use syntax::early_buffered_lints::BufferedEarlyLintId;
 
index 927e2c0820eb2bf35118ae5b2a1c2ad62b5eb2b1..6277e2e7ea9b9a5b41eed992620c9d30f20715b3 100644 (file)
@@ -16,7 +16,7 @@
 use syntax::parse::PResult;
 use syntax::parse::new_parser_from_source_str;
 use syntax::parse::parser::Parser;
-use syntax::parse::token;
+use syntax::token;
 use syntax::ptr::P;
 use syntax::parse::parser::attr::*;
 use syntax::print::pprust;
index 3524f449c745221636ddd10bd58c740f9a72b3e9..520347faa15aa8e13e8a6357e593954b0351dca7 100644 (file)
@@ -15,7 +15,7 @@
 extern crate rustc;
 extern crate rustc_driver;
 
-use syntax::parse::token::{self, Token};
+use syntax::token::{self, Token};
 use syntax::tokenstream::{TokenTree, TokenStream};
 use syntax_expand::base::{ExtCtxt, MacResult, DummyResult, MacEager};
 use syntax_pos::Span;