Description
Currently, as far as I am aware, there is no way to get spans for tokens parsed from a source other than the macro's callsite, and no good way to tell rustc & cargo a procedural macro depends on another file. It would be nice for macros which want to load other files to enable this.
It'd be nice to support some mechanism for loading a file as a TokenStream
. Ideally this would take the form of a method in the crate directly parsing a file / string to a TokenStream
. For example:
-
A function to load a file as a
TokenStream
with accurate span info etc, e.g.fn lex_file(path: &Path) -> io::Result<TokenStream>;
-
A function to parse a string with a given filename. This might need an additional mechanism to register the source file as a dependency, e.g.
fn lex_str(src: &str, filename: &Path) -> Result<TokenStream, LexErr>; fn add_path_dependency(path: &Path) -> ...;
To make it generally useful & able to implement something like include!()
we'd probably also want/need something like #54725 to get the file to load relative to.