MCPcopy
hub / github.com/google/mangle / ParseQuery

Method ParseQuery

interpreter/interpreter.go:214–235  ·  view source on GitHub ↗

ParseQuery parses a query string. It can either be a predicate name, or an actual atom with constants, variables and wildcards.

(query string)

Source from the content-addressed store, hash-verified

212// ParseQuery parses a query string. It can either be a predicate name,
213// or an actual atom with constants, variables and wildcards.
214func (i *Interpreter) ParseQuery(query string) (ast.Atom, error) {
215 var (
216 atom ast.Atom
217 err error
218 )
219 if strings.Contains(query, "(") {
220 atom, err = parse.Atom(query)
221 } else {
222 err = fmt.Errorf("predicate %s not found", query)
223 for sym := range i.knownPredicates {
224 if sym.Symbol == query {
225 atom = ast.NewQuery(sym)
226 err = nil
227 break
228 }
229 }
230 }
231 if err != nil {
232 return ast.Atom{}, err
233 }
234 return atom, nil
235}
236
237// Query queries the interpreter's state.
238func (i *Interpreter) Query(query ast.Atom) ([]ast.Term, error) {

Callers 3

QueryInteractiveMethod · 0.95
mainFunction · 0.80

Calls 3

AtomFunction · 0.92
NewQueryFunction · 0.92
ContainsMethod · 0.65

Tested by 1