-
Notifications
You must be signed in to change notification settings - Fork 157
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
Differentiate documentation from triple slashes and doc attribute #3209
base: master
Are you sure you want to change the base?
Differentiate documentation from triple slashes and doc attribute #3209
Conversation
ef596d9
to
cad477c
Compare
gcc/rust/ChangeLog: * ast/rust-ast-collector.cc (TokenCollector::visit): Add behaviour. In Attribute visitor, recognize doc from comment and handle it. * ast/rust-ast.h: Changes Attribute constructor and add a boolean in the class for doc comments. * lex/rust-token.cc (Token::as_string): Return the correct string for the new DOC_STRING_LITERAL token. * lex/rust-token.h (enum PrimitiveCoreType): Add two tokens : DOC_STRING_LITERAL and DOC_END, for pretty-printing purposes. Also modify the string of two previous tokens. * parse/rust-parse-impl.h (Parser::parse_inner_attribute): Updates the Attribute constructor call. (Parser::parse_outer_attribute): Same as above. Signed-off-by: lucas.plantrose <[email protected]>
cad477c
to
91d4c03
Compare
@@ -636,6 +636,9 @@ struct Attribute | |||
|
|||
bool inner_attribute; | |||
|
|||
// Only relevant in case of a doc attribute | |||
bool from_comment; |
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.
bool from_comment; | |
bool from_doc_comment; |
location_t locus = UNDEF_LOCATION, bool inner_attribute = false, | ||
bool from_comment = 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.
I'm not a big fan of the two booleans here. I think it would be nice to improve it with two enums
RS_TOKEN (INNER_DOC_COMMENT, "/**!") \ | ||
RS_TOKEN (OUTER_DOC_COMMENT, "/**") \ |
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.
RS_TOKEN (INNER_DOC_COMMENT, "/**!") \ | |
RS_TOKEN (OUTER_DOC_COMMENT, "/**") \ | |
RS_TOKEN (INNER_DOC_COMMENT, "//!") \ | |
RS_TOKEN (OUTER_DOC_COMMENT, "///") \ |
RS_TOKEN (OUTER_DOC_COMMENT, "#[doc]") \ | ||
RS_TOKEN (INNER_DOC_COMMENT, "/**!") \ | ||
RS_TOKEN (OUTER_DOC_COMMENT, "/**") \ | ||
RS_TOKEN (DOC_COMMENT_END, "*/") \ |
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 think this isn't needed
RS_TOKEN (INNER_DOC_COMMENT, "/**!") \ | ||
RS_TOKEN (OUTER_DOC_COMMENT, "/**") \ | ||
RS_TOKEN (DOC_COMMENT_END, "*/") \ | ||
RS_TOKEN (DOC_STRING_LITERAL, "string") \ |
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.
What is this token for?
Fixes #3196
This PR changes some files in the ast directory as well as in the lex directory. It introduces two new tokens only used in pretty-printing, and changes the visitor of the Attribute class in the TokenCollector to properly detect doc attributes coming from comments. Also, a new boolean in the Attribute class has appeared to keep track of the origin of the attribute, and is only relevant in the case of a 'doc' attribute.