-
Notifications
You must be signed in to change notification settings - Fork 19
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 helper functions for SQL(), Pos(), End() #120
Add helper functions for SQL(), Pos(), End() #120
Conversation
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 have a comment to lastElem
. Other functions are acceptable.
ast/util.go
Outdated
|
||
// Helper functions for Pos(), End() | ||
|
||
// lastElem returns last element of slice s. |
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 understand your intention, but this function seems too generic. I would not want to add this as it could be used in places it is not supposed to be.
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.
OK, lastElem
can be written as inline, so I will remove it.
(It may be possible to be accepted if T
is restricted to Node
)
-func lastElem[T any](s []T) T {
+func lastElem[T Node](s []T) T {
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.
Fixed e1a3e81
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.
func last
is acceptable.ElemNode[T Node](s []T) T {
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.
Introduce func lastNode[T Node](s []T) T
in 47ea709
@apstndb If these PRs are merged, do you rewrite existing implementations with them as well? |
If you want to unify style of existing implementation immediately, I can rewrite them. |
I may be better to place functions into |
This sounds good 👍 |
This reverts commit e1a3e81.
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.
LGTM. Thank you!
Contributors need to maintain comments in
ast/ast.go
and implementations ofSQL()
,Pos()
, andEnd()
methods inast/sql.go
andast/pos.go
.I believe productability is improved if comments and implementations can be written as similar structure.
I propose to add helper functions to implement the methods.
I believe these functions are useful as long as memefish have
ast.Node
interface .Note
These helper functions are already used in PRs(#99, #101, #111).
sqlOpt
needscomparable
after Go 1.20, so this PR bump Go version to 1.20.I have refacotored
ast.Select
,ast.Path
andast.CallExpr
to demonstrate the usage and effect of helper functions.