memefish
memefish copied to clipboard
Provide `Options`-like utilities for `Hint`
Motivation
ast.Options has utility methods to access their fields, e.g.,
(*ast.Options).Field(name string) (expr Expr, found bool)(*ast.Options).BoolField(name string) (*bool, error)IntegerFieldandStringField
ast.Hint looks like ast.Options, but it does not have such utilities. Thus, we need to provide such utilities for ast.Hint.
Implementation Ideas
In my thoughts, most of APIs between ast.Options and ast.Hint are shared, so we first introduce a new interface such as:
type Fielder interface {
func Field(name string) (expr *ast.Expr, found bool)
}
Then, we will implement Fielder for ast.Options and ast.Hint and derive {Bool,Integer,String}Field as Fielder methods.
Questions
- According to #242, keys of
ast.Hintmay be paths. So, is it enough thatnameisstring?- IMO, yes, it is enough.
namecan be dot-chained, and it is resolved in theFieldmethod of each type.
- IMO, yes, it is enough.