ParseQuery parses a query string. It can either be a predicate name, or an actual atom with constants, variables and wildcards.
(query string)
| 212 | // ParseQuery parses a query string. It can either be a predicate name, |
| 213 | // or an actual atom with constants, variables and wildcards. |
| 214 | func (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. |
| 238 | func (i *Interpreter) Query(query ast.Atom) ([]ast.Term, error) { |