Function parse_query

Source
pub fn parse_query(to_parse: &str) -> Result<Goal, String>
Expand description

Parses a string to produce a query.

Queries are complex terms entered after the query prompt, ?-. For example:

?- symptom(flu, $Sym).

A query is the same as a complex term, but before it can be submitted to a solver, its logic variables must be given unique IDs.

This function simply calls parse_complex(), then recreates the logic variables.

§Arguments

  • to_parse - string to parse

§Return

  • Result - Ok(Goal) or Err(message)

§Usage

use suiron::*;

match parse_query("loves($X, $Y)") {
    Ok(q) => { println!("{}", q); },
    Err(err) => { println!("{}", err); },
}
// Prints: loves($X_1, $Y_2)

§Note

Backslash is used to escape characters, such as the comma. For example:

use suiron::*;

let cmplx = parse_complex("punctuation(comma, \\,)");
match cmplx {
    Ok(c) => { println!("{}", c); },
    Err(err) => { println!("{}", err); },
}
// Prints: punctuation(comma, ,)

The backslash is doubled because the Rust compiler also interprets the backslash.