Skip to content

Provide Options-like utilities for Hint #251

@makenowjust

Description

@makenowjust

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 Support path hint keys #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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions