Add Span and separate open/close delims to TTDelim

This came up when working [on the gl-rs generator extension](990383de80/src/gl_generator/lib.rs (L135-L146)).

The new definition of  `TTDelim` adds an associated `Span` that covers the whole token tree and enforces the invariant that a delimited sequence of token trees must have an opening and closing delimiter.

A `get_span` method has also been added to `TokenTree` type to make it easier to implement better error messages for syntax extensions.
This commit is contained in:
Brendan Zabarauskas
2014-10-22 16:37:20 +11:00
parent 80e5fe1a56
commit 971d776aa5
9 changed files with 135 additions and 88 deletions

View File

@@ -571,7 +571,17 @@ pub fn noop_fold_tt<T: Folder>(tt: &TokenTree, fld: &mut T) -> TokenTree {
match *tt {
TTTok(span, ref tok) =>
TTTok(span, fld.fold_token(tok.clone())),
TTDelim(ref tts) => TTDelim(Rc::new(fld.fold_tts(tts.as_slice()))),
TTDelim(span, ref open, ref tts, ref close) =>
TTDelim(span,
Delimiter {
span: open.span,
token: fld.fold_token(open.token.clone())
},
Rc::new(fld.fold_tts(tts.as_slice())),
Delimiter {
span: close.span,
token: fld.fold_token(close.token.clone())
}),
TTSeq(span, ref pattern, ref sep, is_optional) =>
TTSeq(span,
Rc::new(fld.fold_tts(pattern.as_slice())),