Skip to main content

Module tokenstream

Module tokenstream 

Source
Expand description

Β§Token Streams

TokenStreams represent syntactic objects before they are converted into ASTs. A TokenStream is, roughly speaking, a sequence of TokenTrees, which are themselves a single Token or a Delimited subsequence of tokens.

Re-exportsΒ§

use std::borrow::Cow; πŸ”’
use std::hash::Hash; πŸ”’
use std::hash::Hash; πŸ”’
use std::ops::Range; πŸ”’
use std::sync::Arc; πŸ”’
use std::sync::LazyLock; πŸ”’
use std::cmp; πŸ”’
use std::fmt; πŸ”’
use std::iter; πŸ”’
use std::mem; πŸ”’
use rustc_data_structures::stable_hash::StableHash; πŸ”’
use rustc_data_structures::stable_hash::StableHashCtxt; πŸ”’
use rustc_data_structures::stable_hash::StableHasher; πŸ”’
use rustc_data_structures::sync; πŸ”’
use rustc_macros::Decodable; πŸ”’
use rustc_macros::Encodable; πŸ”’
use rustc_macros::StableHash; πŸ”’
use rustc_macros::Walkable; πŸ”’
use rustc_serialize::Decodable; πŸ”’
use rustc_serialize::Encodable; πŸ”’
use rustc_span::DUMMY_SP; πŸ”’
use rustc_span::Span; πŸ”’
use rustc_span::SpanDecoder; πŸ”’
use rustc_span::SpanEncoder; πŸ”’
use rustc_span::Symbol; πŸ”’
use rustc_span::sym; πŸ”’
use thin_vec::ThinVec; πŸ”’
use crate::ast::AttrStyle; πŸ”’
use crate::ast_traits::HasTokens; πŸ”’
use crate::token; πŸ”’
use crate::token::Delimiter; πŸ”’
use crate::token::Token; πŸ”’
use crate::token::TokenKind; πŸ”’
use crate::AttrVec; πŸ”’
use crate::Attribute; πŸ”’

ModulesΒ§

size_asserts πŸ”’

StructsΒ§

AttrsTarget
Stores the tokens for an attribute target, along with its attributes.
DelimSpacing
DelimSpan
LazyTokenStream
A lazy version of TokenStream, which defers creation of an actual TokenStream until it is needed.
NodeRange
A token range within an individual AST node’s (lazy) token stream, i.e. relative to that node’s first token. Distinct from ParserRange so the two kinds of range can’t be mixed up.
ParserRange
A token range within a Parser’s full token stream.
TokenCursor
A TokenStream cursor that produces Tokens. It’s a bit odd that we (a) lex tokens into a nice tree structure (TokenStream), and then (b) use this type to emit them as a linear sequence. But a linear sequence is what the parser expects, for the most part.
TokenStream
A TokenStream is an abstract sequence of tokens, organized into TokenTrees.
TokenStreamIter
TokenTreeCursor πŸ”’
WithTokens

EnumsΒ§

FlatToken πŸ”’
A helper struct used when building a TokenStream from a LazyTokenStream. Both delimiter and non-delimited tokens are stored as FlatToken::Token. A vector of FlatTokens is then β€˜parsed’ to build up a TokenStream with nested TokenTree::Delimited tokens.
LazyTokenStreamInner πŸ”’
Spacing
Indicates whether a token can join with the following token to form a compound token. Used for conversions to proc_macro::Spacing. Also used to guide pretty-printing, which is where the JointHidden value (which isn’t part of proc_macro::Spacing) comes in useful.
TokenTree
Part of a TokenStream.

StaticsΒ§

EMPTY_TOKEN_STREAM πŸ”’
A shared empty token stream, used to avoid an unnecessary Arc allocation for every empty token stream.

FunctionsΒ§

_dummy πŸ”’
append_attrs_and_stream_as_token_trees_to πŸ”’
append_flat_tokens_as_token_trees_to πŸ”’
Converts a flattened iterator of tokens (including open and close delimiter tokens) into a sequence of TokenTree (appended to res), creating a TokenTree::Delimited for each matching pair of open and close delims. Any FlatToken::AttrsTarget element will only be appended if configure succeeds, and configure can also modify any such element.
keep_all πŸ”’
A ConfigureFn that keeps the target, i.e. the node and its tokens.

Type AliasesΒ§

ConfigureFn πŸ”’
Fn type used to do (or not do) cfg expansion. It can modify attributes. The return value indicates if the target should be retained. Any children of discarded targets are skipped.
NodeReplacement
See the comment on ParserReplacement.
ParserReplacement
Indicates a range of tokens that should be replaced by an AttrsTarget (replacement) or be replaced by nothing (deletion). This is used in two places during token collection.