code: def get_field(ctx, field):
      
      # field can be a string or a node attribute
      if isinstance(field, str):
          field = getattr(ctx, field, None)
      # when not alias needs to be called
      if callable(field):
          field = field()
      # when alias set on token, need to go from CommonToken -> Terminal Node
      elif isinstance(field, CommonToken):
          # giving a name to lexer rules sets it to a token,
          # rather than the terminal node corresponding to that token
          # so we need to find it in children
          field = next(
              filter(lambda c: getattr(c, "symbol", None) is field, ctx.children)
          )
      return field
docs: Helper to get the value of a field