// ParseQueryPos parses the source query position pos. // If needExact, it must identify a single AST subtree. // func ParseQueryPos(imp *importer.Importer, pos string, needExact bool) (*QueryPos, error) { start, end, err := parseQueryPos(imp.Fset, pos) if err != nil { return nil, err } info, path, exact := imp.PathEnclosingInterval(start, end) if path == nil { return nil, fmt.Errorf("no syntax here") } if needExact && !exact { return nil, fmt.Errorf("ambiguous selection within %s", importer.NodeDescription(path[0])) } return &QueryPos{start, end, info, path}, nil }
// ParseQueryPos parses the source query position pos. // If needExact, it must identify a single AST subtree; // this is appropriate for queries that allow fairly arbitrary syntax, // e.g. "describe". // func ParseQueryPos(imp *importer.Importer, posFlag string, needExact bool) (*QueryPos, error) { filename, startOffset, endOffset, err := parsePosFlag(posFlag) if err != nil { return nil, err } start, end, err := findQueryPos(imp.Fset, filename, startOffset, endOffset) if err != nil { return nil, err } info, path, exact := imp.PathEnclosingInterval(start, end) if path == nil { return nil, fmt.Errorf("no syntax here") } if needExact && !exact { return nil, fmt.Errorf("ambiguous selection within %s", astutil.NodeDescription(path[0])) } return &QueryPos{imp.Fset, start, end, path, exact, info}, nil }