about summary refs log tree commit diff
path: root/src/libsyntax/parse/token.rs
AgeCommit message (Collapse)AuthorLines
2018-11-12Change `Lit::short_name` to `Lit::literal_name`.Nicholas Nethercote-7/+7
This avoids a moderately hot allocation in `parse_lit_token`.
2018-09-16Treat `dyn` as a keyword in the 2018 editionvarkor-0/+1
2018-09-08Track distinct spans for open and close delimiterDavid Tolnay-3/+3
2018-08-05Enable macros to pass $:literal to another macroMatthew Tran-0/+4
2018-08-01async can begin expressionsTaylor Cramer-0/+1
2018-07-19proc_macro: Preserve spans of attributes on functionsAlex Crichton-5/+44
This commit updates the tokenization of items which are subsequently passed to `proc_macro` to ensure that span information is preserved on attributes as much as possible. Previously this area of the code suffered from #43081 where we haven't actually implemented converting an attribute to to a token tree yet, but a local fix was possible here. Closes #47941
2018-07-14Remove most of `Hash` impls from AST and HIR structuresVadim Petrochenkov-2/+2
2018-07-14Remove most of `PartialEq` impls from AST and HIR structuresVadim Petrochenkov-5/+5
2018-06-09Crate-ify and delete unused code in syntax::parseMark Simulacrum-45/+21
2018-06-04Tidy fixes.Crazycolorz5-1/+1
2018-06-04Added is_like_plus to token, and used that in place of equality comparison ↵Crazycolorz5-0/+7
to Plus token.
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