memefish icon indicating copy to clipboard operation
memefish copied to clipboard

Provide `Options`-like utilities for `Hint`

Open makenowjust opened this issue 9 months ago • 2 comments

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)
  • IntegerField and StringField

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.Hint may be paths. So, is it enough that name is string?
    • IMO, yes, it is enough. name can be dot-chained, and it is resolved in the Field method of each type.

makenowjust avatar Jan 01 '25 04:01 makenowjust