Skip to content

Commit

Permalink
feat(logic-bindings): make Answer match logic module format
Browse files Browse the repository at this point in the history
  • Loading branch information
amimart committed Feb 22, 2024
1 parent 8495cd4 commit f1a809c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 16 deletions.
2 changes: 1 addition & 1 deletion packages/okp4-logic-bindings/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ mod query;
mod term_parser;
pub mod uri;

pub use query::{Answer, AskResponse, LogicCustomQuery, Result, Substitution, Term};
pub use query::{Answer, AskResponse, LogicCustomQuery, Result, Substitution};
pub use term_parser::TermValue;

// Exposed for testing only
Expand Down
24 changes: 9 additions & 15 deletions packages/okp4-logic-bindings/src/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ pub struct AskResponse {
#[serde(rename_all = "snake_case")]
pub struct Answer {
pub success: bool,
pub error: Option<String>,
pub has_more: bool,
pub variables: Vec<String>,
pub results: Vec<Result>,
Expand All @@ -39,19 +40,12 @@ pub struct Result {
#[serde(rename_all = "snake_case")]
pub struct Substitution {
pub variable: String,
pub term: Term,
pub expression: String,
}

#[derive(Serialize, Deserialize, Default, Clone, PartialEq, Eq, JsonSchema, Debug)]
#[serde(rename_all = "snake_case")]
pub struct Term {
pub name: String,
pub arguments: Vec<Term>,
}

impl Term {
pub fn parse(self) -> std::result::Result<TermValue, TermParseError> {
from_str(self.name.as_str())
impl Substitution {
pub fn parse_expression(self) -> std::result::Result<TermValue, TermParseError> {
from_str(self.expression.as_str())
}
}

Expand All @@ -62,11 +56,11 @@ mod tests {
#[test]
fn term_parse() {
assert_eq!(
Term {
name: "'hello'".to_string(),
arguments: vec![],
Substitution {
variable: "X".to_string(),
expression: "'hello'".to_string(),
}
.parse(),
.parse_expression(),
Ok(TermValue::Value("hello".to_string()))
);
}
Expand Down

0 comments on commit f1a809c

Please sign in to comment.