-
Notifications
You must be signed in to change notification settings - Fork 12.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add an option to the parser to avoid parsing out of line modules #42071
Conversation
(rust_highfive has picked a reviewer for you, use r? to override) |
This is useful if parsing from stdin or a String and don't want to try and read in a module from another file. Instead we just leave a stub in the AST.
ping @nikomatsakis, pinging you on IRC too! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good. r=me with or without changing the order of the arguments to Parser::new
@@ -320,7 +320,7 @@ impl Attribute { | |||
pub fn parse<'a, T, F>(&self, sess: &'a ParseSess, mut f: F) -> PResult<'a, T> | |||
where F: FnMut(&mut Parser<'a>) -> PResult<'a, T>, | |||
{ | |||
let mut parser = Parser::new(sess, self.tokens.clone(), None, false); | |||
let mut parser = Parser::new(sess, self.tokens.clone(), None, false, false); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you just using false
here because we don't expect inline modules in attributes? In other words, we don't expect this option to matter here one way or the other, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Correct
@@ -439,6 +442,7 @@ impl<'a> Parser<'a> { | |||
pub fn new(sess: &'a ParseSess, | |||
tokens: TokenStream, | |||
directory: Option<Directory>, | |||
recurse_into_file_modules: bool, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't really care, but adding the new argument "next-to-last" seems a bit error-prone, as I imagine people may be inclined add the new argument at the end of the list. More generally, having a lot of booleans is a crappy API, it'd be sort of nice to make this a builder-style thing... but I guess that's for another PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I put it here to be next to the directory
option since they are related. My first attempt tried to combine the two into an enum, but it was really grotty. Builder would be best I guess, but yeah, later.
@bors: r=nikomatsakis |
📌 Commit a256630 has been approved by |
Add an option to the parser to avoid parsing out of line modules This is useful if parsing from stdin or a String and don't want to try and read in a module from another file. Instead we just leave a stub in the AST.
Add an option to the parser to avoid parsing out of line modules This is useful if parsing from stdin or a String and don't want to try and read in a module from another file. Instead we just leave a stub in the AST.
Add an option to the parser to avoid parsing out of line modules This is useful if parsing from stdin or a String and don't want to try and read in a module from another file. Instead we just leave a stub in the AST.
Add an option to the parser to avoid parsing out of line modules This is useful if parsing from stdin or a String and don't want to try and read in a module from another file. Instead we just leave a stub in the AST.
Add an option to the parser to avoid parsing out of line modules This is useful if parsing from stdin or a String and don't want to try and read in a module from another file. Instead we just leave a stub in the AST.
This is useful if parsing from stdin or a String and don't want to try and read in a module from another file. Instead we just leave a stub in the AST.