Description
Currently, there are two different approaches for dealing with composite tokens like >>
in rustc.
- Keep tokens in composed form, and split into pieces,
>
and>
, when necessary. - Keep tokens decomposed, with jointness information, and join tokens when necessary.
At the moment, the first approach is used by the parser, and the second approach is used by the proc_macro API. It would be good to move the parser to the decomposed approach as well, as it is somewhat more natural, more future-compatible (one can introduce new tokens) and having two of a thing is bad in itself!
Here are some relevant bits of the code that handle composed model:
- Composed tokens as produced by rustc_lexer
- Composed tokens preserved by the token cooking
- Here's the bit when we produce a TokenTree, consumed by the parser. Note that, although we are tracking jointness here, the tokens are composed.
- Here's the bit of the parser which decomposes tokens on the fly.
Here are the bits relevant to decomposed model:
- Gluing tokens in TokenStreamBuilder
- Token::glue
Note that the tt
matcher in macro_rules
eats one composed token, and this is affects language specification.
That is, when we transition to decomposed model, we'll need to fix this code to eat one composed token to maintain backwards compatibility.