Conversation
mcy
commented
Dec 18, 2024
internal/enum/enum.go
Outdated
Comment on lines
43
to
44
| // - //enum:stringfunc Name provides a function to use for stringifying | ||
| // based on the name of a constant (see below). |
Member
Author
There was a problem hiding this comment.
This functionality is used in only one place. I am so-so on whether it pulls its weight. Feel free to veto this.
jhump
reviewed
Dec 19, 2024
internal/enum/enum.go
Outdated
| return false | ||
| } | ||
|
|
||
| func ParseDirectives(fs *token.FileSet, comments []*ast.CommentGroup) ([]Directive, error) { |
Member
There was a problem hiding this comment.
These seems like serious overkill. How about just define the enums (name, doc, constants) in a yaml file and then parsing the YAML and generating Go code (including for the type definition and constants) is trivial. I don't think it needs to be very configurable -- you could make it always emit some sort of "Lookup" factory function or maybe just make it a simple bool flag in the yaml.
Member
Author
There was a problem hiding this comment.
Lol using a config file hadn't occurred to me.
jhump
approved these changes
Jan 7, 2025
Member
jhump
left a comment
There was a problem hiding this comment.
Cool. Just a couple of small things.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Go does not have enums, but they are quite useful, so we emulate them with int-kinded types and use switches and whatnot to convert them to and from strings.
There are enough of these in the new compiler stack at this point that maintaining all of these stringification functions is getting tedious and error-prone, so this PR contains a very simple, 200-line
//go:generatehelper for generating those functions.I surveyed other existing packages of this kind, but unfortunately they all want to put varying strong constraints on how we organize and name our "enums", so I felt that we should just write the simplest possible thing to fit our use-case.