Introduce TypelessStructLiteralArg and NewConstructorArg interfaces#183
Introduce TypelessStructLiteralArg and NewConstructorArg interfaces#183makenowjust merged 22 commits intomainfrom
TypelessStructLiteralArg and NewConstructorArg interfaces#183Conversation
I have concerned about there are undocumented differences in I believe it is a syntax for proto extensions and it is not yet available in Cloud Spanner, but I think these semantics are not same. It may be a reason to distinguish between |
|
This difference is natural because:
|
|
IMHO, when |
|
Personally I think it is acceptable to generalize them temporarily, even if their semantics are not same,
I think it can't be a general name because it is |
|
I understood. We can add another interface when it is needed. |
IMHO,
(There are many variants.) |
ast/ast.go
Outdated
| Values []*ExprAsName | ||
| } | ||
|
|
||
| // ExprAsName is value with optional name in typeless struct literal or new constructor. |
There was a problem hiding this comment.
I think it is not only for typeless struct literal and new constructor.
We can encourage to use this struct for any expr [AS ident] syntax, without semantic implications.
There was a problem hiding this comment.
We can update the document anytime.
There was a problem hiding this comment.
It means that this struct is added only for NewConstructorArg and TypelessStructValue in this PR context and we need to discuss to change this struct semantics in another PR.
There was a problem hiding this comment.
From this conversation, it sounds like you don't intend to widely recommend the use of this struct.
There was a problem hiding this comment.
My thought:
TypelessStructValueandNewConstructorArgis not same abstraction, but have common concrete structure.- Concrete structure will able to be reused without modification.
- IMO, currently
ExprAsNameis no strong reason to be introduced.
|
Finally, I conclude there is no better name for the struct Therefore, we introduce new interfaces |
AsExpr instead of TypelessStructValue and NewConstructorValueTypelessStructLiteralArg and NewConstructorArg interfaces
apstndb
left a comment
There was a problem hiding this comment.
I feel it is natural to introduce these interfaces and use ExprArg and Alias.
I have not noticed their SelectItem implementation can be used to implement them.
I agree their implementations are better than my original PRs.
parser.go
Outdated
| } | ||
|
|
||
| func (p *Parser) tryParseAsAlias() *ast.AsAlias { | ||
| func (p *Parser) tryParseAsAlias(requiredAs bool) *ast.AsAlias { |
There was a problem hiding this comment.
I feel like p.tryParseAsAlias( /* requiredAs */ false) is a little difficult to write.
Can't we introduce two method for requiredAs=true and requiredAs=False? (like (tryParseAsAliasAsRequired and tryParseAsAliasAsOptional)
There was a problem hiding this comment.
tryParseAsAliasAsRequired seems like a strange name to someone unfamiliar with this project (e.g. twice As looks like typo, and try and required seem contradictory), and it is hard to guess what the method does. By making the explicit argument, it is clear that the method parses AS name as possible, and the comment makes it clear that the argument gives the required AS.
There was a problem hiding this comment.
My thought:
twice
Aslooks like typo
I think that the current AsAlias([AS] alias) may be better to be called as Alias, and the current Alias(expr [AS] alias, alias required) can be called as ExprWithAlias or AliasedExpr.
tryParseAliasAsRequired and tryParseAliasAsOptional are felt better.
the comment makes it clear that the argument gives the required AS.
I think maintaining /* requiredAs */ comment is harder because it can't be assisted by go-lsp gopls or IDEs, and it is also strange to someone(me) unfamiliar with this project. At least, it must be noted in doc comment of tryParseAsAlias().
There was a problem hiding this comment.
tryParseAliasAsRequired also seems strange to me because As looks like a usual preposition, and try and required have conflicting meanings.
I think that Alias is the identifier after AS, not the AS name itself. In that sense, I think that the current Alias should be changed to AliasedExpr, but I do not agree with naming AsAlias as Alias.
There was a problem hiding this comment.
tryParseAliasAsRequiredalso seems strange to me becauseAslooks like a usual preposition, andtryandrequiredhave conflicting meanings.
It means they can be better if the subject of "required" or "optional" is unambiguous.
The subject is AS keyword, so they can be called as like tryParseAsAliasRequireKeyword, tryParseAsAliasOptionalKeyword.
There was a problem hiding this comment.
It's ambiguous enough that there are multiple methods to parse a particular struct, and I don't think it's a good idea to distinguish them by method names. If it really should be parsed by multiple methods, we should introduce multiple structs, but I don't think in this case.
There was a problem hiding this comment.
It's ambiguous enough that there are multiple methods to parse a particular struct
I agree structs and methods should be one by one.
In other languages, it may be a usecase of named parameter which is missing in Go.
In Go, it may be better to introduce typed constant with enum semantics.
There was a problem hiding this comment.
Okay, because of code jumps and editor popups, I decided to remove the /* requiredAs */ comment.
There was a problem hiding this comment.
We have agreed about tryParseAsAlias(), so it is just my thought.
I think that
Aliasis the identifier afterAS, not theAS nameitself. In that sense, I think that the currentAliasshould be changed toAliasedExpr, but I do not agree with namingAsAliasasAlias.
SQL has common structure "alias, which is optionally prefixed by AS", and they are safe to unparse always with AS in GoogleSQL.
I prefer to call it Alias than AsAlias because someones have coding guideline which prefer to omit AS.
As far as I know, AS of table alias is often omitted. (Probably due to Oracle's past not allowing AS.)
There was a problem hiding this comment.
The name Alias has less information than the name AsAlias, so I don't think it should be changed proactively.
…TypedStructLiteral
Also, this fixes a `AsAlias.As` position bug.
Co-authored-by: apstndb <803393+apstndb@users.noreply.github.com>
a2a7a36 to
8ea0e53
Compare
Close #119
Close #177
TypelessStructValue(#177) andNewConstructorValue(#119) share their struct shapes. Then, this PR introduces a new struct namedAsExprforexpression AS name-kind values and replaces them with it.I believe this is not a hasty generalization because these struct shapes are exactly the same, and they are used for common semantics. However, I'm not sureAsExpris the best name. If you have a better name, please tell me it!Thank you.See #183 (comment).