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

go/ast, go/parser: parse doc/comment for stmt #62646

Closed
dugenkui03 opened this issue Sep 14, 2023 · 4 comments
Closed

go/ast, go/parser: parse doc/comment for stmt #62646

dugenkui03 opened this issue Sep 14, 2023 · 4 comments
Labels
WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.

Comments

@dugenkui03
Copy link

background

I'd like to analysis the go source code by go parse and get important info represented by File.

But I find that the info of doc/comment will not assign to Stmt.

proposal

I propose change Stmt from

type Stmt interface {
	Node
	stmtNode()
}

to

type Stmt interface {
	Node
	stmtNode()
	SetDoc(*CommentGroup)
	SetComment(*CommentGroup)
}

demo

Code like below:

...

func testFunc() {
	// first lead doc
	sprintf := fmt.Sprintf("%s", 222) // first line comment
	// second lead doc
	print(sprintf) // second line comment
}
...

will parse and get FuncDecl like that
image

@qiulaidongfeng
Copy link
Contributor

Changing the export API violates the go1 compatibility commitment.

@mvdan
Copy link
Member

mvdan commented Sep 15, 2023

This problem has been known for a long time; for example, see #20744.

@adonovan has a work in progress solution at https://go-review.googlesource.com/c/go/+/429639, although I don't think it has a tracking issue.

Personally, I don't think this proposal is the right approach, and it's not nearly detailed enough to really tell how it would work beyond adding a bit of API.

@mvdan mvdan added the WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. label Sep 15, 2023
@adonovan
Copy link
Member

The previous two comments are correct: we can't change the interface, and we have a different solution for comments (that has been moving slowly but is not forgotten). So I think we must reject this proposal.

@dugenkui03
Copy link
Author

@qiulaidongfeng Thanks for you remind "go1 compatibility commitment"

@mvdan @adonovan thanks, I will close this issue, and this proposal should be continue in t https://go-review.googlesource.com/c/go/+/429639

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Projects
None yet
Development

No branches or pull requests

5 participants