about summary refs log tree commit diff
path: root/crates/mbe/src
AgeCommit message (Collapse)AuthorLines
2021-12-25internal: replace TreeSink with a data structureAleksey Kladov-32/+34
The general theme of this is to make parser a better independent library. The specific thing we do here is replacing callback based TreeSink with a data structure. That is, rather than calling user-provided tree construction methods, the parser now spits out a very bare-bones tree, effectively a log of a DFS traversal. This makes the parser usable without any *specifc* tree sink, and allows us to, eg, move tests into this crate. Now, it's also true that this is a distinction without a difference, as the old and the new interface are equivalent in expressiveness. Still, this new thing seems somewhat simpler. But yeah, I admit I don't have a suuper strong motivation here, just a hunch that this is better.
2021-12-18internal: move all the lexing to the parser crateAleksey Kladov-52/+52
2021-12-12tighten up invariantsAleksey Kladov-1/+3
2021-12-12port mbe to soa tokensAleksey Kladov-181/+104
2021-11-22Fix mbe::Shift::new not accounting for non-ident token idsLukas Wirth-5/+8
2021-11-22Add to macro testing infra to emit token map idsLukas Wirth-0/+4
2021-10-23internal: replace L_DOLLAR/R_DOLLAR with parenthesis hackAleksey Kladov-63/+80
The general problem we are dealing with here is this: ``` macro_rules! thrice { ($e:expr) => { $e * 3} } fn main() { let x = thrice!(1 + 2); } ``` we really want this to print 9 rather than 7. The way rustc solves this is rather ad-hoc. In rustc, token trees are allowed to include whole AST fragments, so 1+2 is passed through macro expansion as a single unit. This is a significant violation of token tree model. In rust-analyzer, we intended to handle this in a more elegant way, using token trees with "invisible" delimiters. The idea was is that we introduce a new kind of parenthesis, "left $"/"right $", and let the parser intelligently handle this. The idea was inspired by the relevant comment in the proc_macro crate: https://doc.rust-lang.org/stable/proc_macro/enum.Delimiter.html#variant.None > An implicit delimiter, that may, for example, appear around tokens > coming from a “macro variable” $var. It is important to preserve > operator priorities in cases like $var * 3 where $var is 1 + 2. > Implicit delimiters might not survive roundtrip of a token stream > through a string. Now that we are older and wiser, we conclude that the idea doesn't work. _First_, the comment in the proc-macro crate is wishful thinking. Rustc currently completely ignores none delimiters. It solves the (1 + 2) * 3 problem by having magical token trees which can't be duplicated: * https://rust-lang.zulipchat.com/#narrow/stream/185405-t-compiler.2Frust-analyzer/topic/TIL.20that.20token.20streams.20are.20magic * https://rust-lang.zulipchat.com/#narrow/stream/131828-t-compiler/topic/Handling.20of.20Delimiter.3A.3ANone.20by.20the.20parser _Second_, it's not like our implementation in rust-analyzer works. We special-case expressions (as opposed to treating all kinds of $var captures the same) and we don't know how parser error recovery should work with these dollar-parenthesis. So, in this PR we simplify the whole thing away by not pretending that we are doing something proper and instead just explicitly special-casing expressions by wrapping them into real `()`. In the future, to maintain bug-parity with `rustc` what we are going to do is probably adding an explicit `CAPTURED_EXPR` *token* which we can explicitly account for in the parser. If/when rustc starts handling delimiter=none properly, we'll port that logic as well, in addition to special handling.
2021-10-10internal: clean up code duplicationAleksey Kladov-39/+13
2021-10-10internal: add integrated test for token censoringAleksey Kladov-58/+0
2021-10-10drop obsolete testsAleksey Kladov-301/+2
2021-10-10move testAleksey Kladov-23/+0
2021-10-10move testsAleksey Kladov-88/+0
2021-10-10move testsAleksey Kladov-80/+0
2021-10-10move testAleksey Kladov-48/+0
2021-10-10move testsAleksey Kladov-66/+0
2021-10-10move testAleksey Kladov-28/+0
2021-10-10move testsAleksey Kladov-63/+0
2021-10-10move testsAleksey Kladov-102/+0
2021-10-10move testAleksey Kladov-20/+0
2021-10-10move testAleksey Kladov-36/+0
2021-10-10move testAleksey Kladov-96/+0
2021-10-10internal: move testAleksey Kladov-57/+1
2021-10-10move testAleksey Kladov-14/+0
2021-10-10move testAleksey Kladov-30/+0
2021-10-10move testsAleksey Kladov-21/+0
2021-10-10internal: move testsAleksey Kladov-37/+0
2021-10-10internal: move testsAleksey Kladov-54/+0
2021-10-10move some testsAleksey Kladov-83/+0
2021-10-10move testsAleksey Kladov-84/+1
2021-10-10move testAleksey Kladov-19/+0
2021-10-10move testAleksey Kladov-45/+0
2021-10-10move testsAleksey Kladov-41/+0
2021-10-10internal: move testsAleksey Kladov-37/+0
2021-10-10dead codeAleksey Kladov-22/+1
2021-10-10internal: move some mbe testsAleksey Kladov-52/+0
2021-10-10move testsAleksey Kladov-46/+0
2021-10-10fix testsAleksey Kladov-15/+0
2021-10-09move testAleksey Kladov-22/+0
2021-10-09internal: move testsAleksey Kladov-28/+0
2021-10-09internal: move testAleksey Kladov-50/+0
2021-10-09internal: move testAleksey Kladov-14/+0
2021-10-09internal: drop duplicated testAleksey Kladov-29/+0
2021-10-09internal: move testAleksey Kladov-52/+0
2021-10-09internal: move testsAleksey Kladov-22/+0
2021-10-09internal: move some testsAleksey Kladov-22/+0
2021-10-09internal: move some macro testsAleksey Kladov-96/+0
2021-10-09internal: allow macro tests to inspect parse treeAleksey Kladov-42/+0
2021-10-09move testsAleksey Kladov-27/+0
2021-10-09move some testsAleksey Kladov-42/+0
2021-10-09internal: move testAleksey Kladov-23/+0