about summary refs log tree commit diff
path: root/src/libsyntax/parse/token.rs
AgeCommit message (Collapse)AuthorLines
2018-05-26Add `Ident::as_str` helperVadim Petrochenkov-1/+1
2018-05-23Rollup merge of #50946 - alexcrichton:fix-parse-lifetime, r=petrochenkovkennytm-1/+8
rustc: Fix procedural macros generating lifetime tokens This commit fixes an accidental regression from #50473 where lifetime tokens produced by procedural macros ended up getting lost in translation in the compiler and not actually producing parseable code. The issue lies in the fact that a lifetime's `Ident` is prefixed with `'`. The `glue` implementation for gluing joint tokens together forgot to take this into account so the lifetime inside of `Ident` was missing the leading tick! The `glue` implementation here is updated to create a new `Symbol` in these situations to manufacture a new `Ident` with a leading tick to ensure it parses correctly. Closes #50942
2018-05-21rustc: Fix procedural macros generating lifetime tokensAlex Crichton-1/+8
This commit fixes an accidental regression from #50473 where lifetime tokens produced by procedural macros ended up getting lost in translation in the compiler and not actually producing parseable code. The issue lies in the fact that a lifetime's `Ident` is prefixed with `'`. The `glue` implementation for gluing joint tokens together forgot to take this into account so the lifetime inside of `Ident` was missing the leading tick! The `glue` implementation here is updated to create a new `Symbol` in these situations to manufacture a new `Ident` with a leading tick to ensure it parses correctly. Closes #50942
2018-05-18rustc: Fix joint-ness of stringified token-streamsAlex Crichton-0/+2
This commit fixes `StringReader`'s parsing of tokens which have been stringified through procedural macros. Whether or not a token tree is joint is defined by span information, but when working with procedural macros these spans are often dummy and/or overridden which means that they end up considering all operators joint if they can! The fix here is to track the raw source span as opposed to the overridden span. With this information we can more accurately classify `Punct` structs as either joint or not. Closes #50700
2018-05-17Turn some functions from `token.rs` into methods on `Ident`Vadim Petrochenkov-50/+7
2018-05-17Add two keywords specific to editions 2015 and 2018 respectivelyVadim Petrochenkov-2/+7
2018-05-15Represent lifetimes as two joint tokens in proc macrosVadim Petrochenkov-0/+6
2018-05-13Macros: Add a 'literal' fragment specifierDan Aloni-1/+20
Implements RFC 1576. See: https://github.com/rust-lang/rfcs/blob/master/text/1576-macros-literal-matcher.md Changes are mostly in libsyntax, docs, and tests. Feature gate is enabled for 1.27.0. Many thanks to Vadim Petrochenkov for following through code reviews and suggestions. Example: ````rust macro_rules! test_literal { ($l:literal) => { println!("literal: {}", $l); }; ($e:expr) => { println!("expr: {}", $e); }; } fn main() { let a = 1; test_literal!(a); test_literal!(2); test_literal!(-3); } ``` Output: ``` expr: 1 literal: 2 literal: -3 ```
2018-04-23'label can start expressionsest31-1/+2
let foo = 'label: loop { break 'label 42; }; is valid Rust code.
2018-04-18proc_macro: Stay on the "use the cache" path moreAlex Crichton-9/+91
Discovered in #50061 we're falling off the "happy path" of using a stringified token stream more often than we should. This was due to the fact that a user-written token like `0xf` is equality-different from the stringified token of `15` (despite being semantically equivalent). This patch updates the call to `eq_unspanned` with an even more awful solution, `probably_equal_for_proc_macro`, which ignores the value of each token and basically only compares the structure of the token stream, assuming that the AST doesn't change just one token at a time. While this is a step towards fixing #50061 there is still one regression from #49154 which needs to be fixed.
2018-04-18Auto merge of #49993 - nnethercote:shrink-Token, r=alexcrichtonbors-2/+2
Change the hashcounts in raw `Lit` variants from usize to u16. This reduces the size of `Token` from 32 bytes to 24 bytes on 64-bit platforms.
2018-04-14Rollup merge of #49852 - alexcrichton:fix-more-proc-macros, r=nrckennytm-9/+22
proc_macro: Avoid cached TokenStream more often This commit adds even more pessimization to use the cached `TokenStream` inside of an AST node. As a reminder the `proc_macro` API requires taking an arbitrary AST node and transforming it back into a `TokenStream` to hand off to a procedural macro. Such functionality isn't actually implemented in rustc today, so the way `proc_macro` works today is that it stringifies an AST node and then reparses for a list of tokens. This strategy unfortunately loses all span information, so we try to avoid it whenever possible. Implemented in #43230 some AST nodes have a `TokenStream` cache representing the tokens they were originally parsed from. This `TokenStream` cache, however, has turned out to not always reflect the current state of the item when it's being tokenized. For example `#[cfg]` processing or macro expansion could modify the state of an item. Consequently we've seen a number of bugs (#48644 and #49846) related to using this stale cache. This commit tweaks the usage of the cached `TokenStream` to compare it to our lossy stringification of the token stream. If the tokens that make up the cache and the stringified token stream are the same then we return the cached version (which has correct span information). If they differ, however, then we will return the stringified version as the cache has been invalidated and we just haven't figured that out. Closes #48644 Closes #49846
2018-04-14macros: Do not match on "complex" nonterminals requiring AST comparisonsVadim Petrochenkov-1/+17
2018-04-12Change the hashcounts in raw `Lit` variants from usize to u16.Nicholas Nethercote-2/+2
This reduces the size of `Token` from 32 bytes to 24 bytes on 64-bit platforms.
2018-04-10proc_macro: Avoid cached TokenStream more oftenAlex Crichton-9/+22
This commit adds even more pessimization to use the cached `TokenStream` inside of an AST node. As a reminder the `proc_macro` API requires taking an arbitrary AST node and transforming it back into a `TokenStream` to hand off to a procedural macro. Such functionality isn't actually implemented in rustc today, so the way `proc_macro` works today is that it stringifies an AST node and then reparses for a list of tokens. This strategy unfortunately loses all span information, so we try to avoid it whenever possible. Implemented in #43230 some AST nodes have a `TokenStream` cache representing the tokens they were originally parsed from. This `TokenStream` cache, however, has turned out to not always reflect the current state of the item when it's being tokenized. For example `#[cfg]` processing or macro expansion could modify the state of an item. Consequently we've seen a number of bugs (#48644 and #49846) related to using this stale cache. This commit tweaks the usage of the cached `TokenStream` to compare it to our lossy stringification of the token stream. If the tokens that make up the cache and the stringified token stream are the same then we return the cached version (which has correct span information). If they differ, however, then we will return the stringified version as the cache has been invalidated and we just haven't figured that out. Closes #48644 Closes #49846
2018-04-10Auto merge of #49390 - Zoxc:sync-syntax, r=michaelwoeristerbors-15/+6
More thread-safety changes r? @michaelwoerister
2018-04-09in which `!` is suggested for erroneous identifier `not`Zack M. Davis-1/+10
Impressing confused Python users with magical diagnostics is perhaps worth this not-grossly-unreasonable (only 40ish lines) extra complexity in the parser? Thanks to Vadim Petrochenkov for guidance. This resolves #46836.
2018-04-06Make lifetime nonterminals closer to identifier nonterminalsVadim Petrochenkov-34/+29
2018-04-06Remove more duplicated spansVadim Petrochenkov-5/+5
2018-04-06Get rid of `SpannedIdent`Vadim Petrochenkov-3/+3
2018-04-03expand macro invocations in `extern {}` blocksAustin Bonander-0/+2
2018-03-28Make LazyTokenStream thread-safeJohn Kåre Alsaker-15/+6
2018-03-27Fix pretty-printing for raw identifiersVadim Petrochenkov-1/+8
2018-03-22Clean up raw identifier handling when recovering tokens from AST.Lymia Aluysia-1/+1
2018-03-18Return a is_raw parameter from Token::ident rather than having separate methods.Lymia Aluysia-30/+15
2018-03-18Initial implementation of RFC 2151, Raw IdentifiersLymia Aluysia-29/+79
2018-03-18Auto merge of #48917 - petrochenkov:import, r=oli-obkbors-0/+1
syntax: Make imports in AST closer to the source and cleanup their parsing This is a continuation of https://github.com/rust-lang/rust/pull/45846 in some sense.
2018-03-17AST: Keep distinction between `path` and `::path` in imports and visibilitiesVadim Petrochenkov-0/+1
Add the root segment for name resolution purposes only
2018-03-17syntax: Make `_` an identifierVadim Petrochenkov-5/+4
2018-03-02Replace Rc with Lrc for shared dataJohn Kåre Alsaker-3/+3
2018-01-30The `static` keyword can now begin expressionsJohn Kåre Alsaker-0/+1
2018-01-03Support `extern` in pathsVadim Petrochenkov-0/+1
2017-12-30refactor lifetime out of is_lifetimeMatt Peterson-6/+14
2017-12-28Fix testsMatt Peterson-2/+10
2017-12-28Resurrecting #33135Michael Hewson-0/+2
Started rebasing @sgrif's PR #33135 off of current master. (Well, actually merging it into a new branch based off current master.) The following files still need to be fixed or at least reviewed: - `src/libsyntax/ext/tt/macro_parser.rs`: calls `Parser::parse_lifetime`, which doesn't exist anymore - `src/libsyntax/parse/parser.rs`: @sgrif added an error message to `Parser::parse_lifetime`. Code has since been refactored, so I just took it out for now. - `src/libsyntax/ext/tt/transcribe.rs`: This code has been refactored bigtime. Not sure whether @sgrif's changes here are still necessary. Took it out for this commit.
2017-12-14Use PathBuf instead of String where applicableOliver Schneider-4/+3
2017-12-09Use Try syntax for Option in place of macros or matchMatt Brubeck-4/+1
2017-11-21Support `::crate` in pathsVadim Petrochenkov-0/+1
2017-11-06Using `...` in expressions is now an errorBadel2-1/+1
2017-10-25Improve recovery after unexpected tokens parsing sequenceThomas Karpiniec-0/+10
2017-10-14Implement `dyn Trait` syntaxVadim Petrochenkov-0/+6
2017-09-22Add support for `..=` syntaxAlex Burka-15/+20
Add ..= to the parser Add ..= to libproc_macro Add ..= to ICH Highlight ..= in rustdoc Update impl Debug for RangeInclusive to ..= Replace `...` to `..=` in range docs Make the dotdoteq warning point to the ... Add warning for ... in expressions Updated more tests to the ..= syntax Updated even more tests to the ..= syntax Updated the inclusive_range entry in unstable book
2017-09-18rustc: Forbid interpolated tokens in the HIRAlex Crichton-0/+85
Right now the HIR contains raw `syntax::ast::Attribute` structure but nowadays these can contain arbitrary tokens. One variant of the `Token` enum is an "interpolated" token which basically means to shove all the tokens for a nonterminal in this position. A "nonterminal" in this case is roughly analagous to a macro argument: macro_rules! foo { ($a:expr) => { // $a is a nonterminal as an expression } } Currently nonterminals contain namely items and expressions, and this poses a problem for incremental compilation! With incremental we want a stable hash of all HIR items, but this means we may transitively need a stable hash *of the entire AST*, which is certainly not stable w/ node ids and whatnot. Hence today there's a "bug" where the "stable hash" of an AST is just the raw hash value of the AST, and this only arises with interpolated nonterminals. The downside of this approach, however, is that a bunch of errors get spewed out during compilation about how this isn't a great idea. This PR is focused at fixing these warnings, basically deleting them from the compiler. The implementation here is to alter attributes as they're lowered from the AST to HIR, expanding all nonterminals in-place as we see them. This code for expanding a nonterminal to a token stream already exists for the `proc_macro` crate, so we basically just reuse the same implementation there. After this PR it's considered a bug to have an `Interpolated` token and hence the stable hash implementation simply uses `bug!` in this location. Closes #40946
2017-07-28Generator literal supportJohn Kåre Alsaker-0/+1
2017-07-05Merge remote-tracking branch 'origin/master' into proc_macro_apiAlex Crichton-10/+20
2017-06-29Change some terminology around keywords and reserved identifierspetrochenkov-9/+18
2017-06-29Make `$crate` a keywordVadim Petrochenkov-1/+2
2017-06-26Address review comments.Jeffrey Seyfried-12/+32
2017-06-26Add `LazyTokenStream`.Jeffrey Seyfried-6/+47
2017-06-26Implement `quote!` and other `proc_macro` API.Jeffrey Seyfried-0/+63