Skip to content
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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

MajoraSans
Copy link

Fixes #3196

* ast/rust-ast-collector.cc (TokenCollector::visit):
* ast/rust-ast.h:
* lex/rust-token.cc (Token::as_string):
* lex/rust-token.h (enum PrimitiveCoreType):
* parse/rust-parse-impl.h (Parser::parse_inner_attribute): (Parser::parse_outer_attribute):

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.

@MajoraSans MajoraSans changed the title gcc/rust/ChangeLog: Differentiate documentation from triple slashes and doc attribute Oct 17, 2024
@MajoraSans MajoraSans force-pushed the diff-between-slash-and-attr branch 3 times, most recently from ef596d9 to cad477c Compare October 17, 2024 12:32
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]>
@@ -636,6 +636,9 @@ struct Attribute

bool inner_attribute;

// Only relevant in case of a doc attribute
bool from_comment;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
bool from_comment;
bool from_doc_comment;

Comment on lines +650 to +651
location_t locus = UNDEF_LOCATION, bool inner_attribute = false,
bool from_comment = false)
Copy link
Member

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

Comment on lines +147 to +148
RS_TOKEN (INNER_DOC_COMMENT, "/**!") \
RS_TOKEN (OUTER_DOC_COMMENT, "/**") \
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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, "*/") \
Copy link
Member

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") \
Copy link
Member

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Differentiate documentation from triple slashes and doc attribute
2 participants