Skip to content

Commit

Permalink
Merge pull request conjure-cp#254 from niklasdewally/feat/solver-inte…
Browse files Browse the repository at this point in the history
…rface-minion-impl

[solver-interface 2/n]: Minion Implementation
  • Loading branch information
ozgurakgun authored Mar 11, 2024
2 parents 1390342 + f5f4b4c commit 130c16d
Show file tree
Hide file tree
Showing 21 changed files with 879 additions and 327 deletions.
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions conjure_oxide/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ strum = "0.26.2"
versions = "6.1.0"
linkme = "0.3.22"
walkdir = "2.5.0"
itertools = "0.12.1"
regex = "1.10.3"

[features]

Expand Down
26 changes: 12 additions & 14 deletions conjure_oxide/src/generate_custom.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,20 @@
use crate::parse::model_from_json;
use conjure_core::ast::Model;

use std::error::Error;

use std::path::PathBuf;
use walkdir::WalkDir;

/// Searches recursively in `../tests/integration` folder for an `.essence` file matching the given filename,
/// then uses conjure to process it into astjson, and returns the parsed model.
/// Searches recursively in `../tests/integration` folder for an `.essence` file matching the given
/// filename, then uses conjure to process it into astjson, and returns the parsed model.
///
/// # Arguments
///
/// * `filename` - A string slice that holds filename without extension
///
/// # Returns
///
/// Function returns a `Result<Value, Box<dyn Error>>`, where `Value` is the parsed model
pub fn get_example_model(filename: &str) -> Result<Model, Box<dyn Error>> {
/// Function returns a `Result<Value, anyhow::Error>`, where `Value` is the parsed model.
pub fn get_example_model(filename: &str) -> Result<Model, anyhow::Error> {
// define relative path -> integration tests dir
let base_dir = "tests/integration";
let mut essence_path = PathBuf::new();
Expand All @@ -36,11 +34,11 @@ pub fn get_example_model(filename: &str) -> Result<Model, Box<dyn Error>> {
}
}

println!("PATH TO FILE: {}", essence_path.display());
//println!("PATH TO FILE: {}", essence_path.display());

// return error if file not found
if essence_path.as_os_str().is_empty() {
return Err(Box::new(std::io::Error::new(
return Err(anyhow::Error::new(std::io::Error::new(
std::io::ErrorKind::NotFound,
"ERROR: File not found in any subdirectory",
)));
Expand All @@ -57,7 +55,7 @@ pub fn get_example_model(filename: &str) -> Result<Model, Box<dyn Error>> {
// convert Conjure's stdout from bytes to string
let astjson = String::from_utf8(output.stdout)?;

println!("ASTJSON: {}", astjson);
//println!("ASTJSON: {}", astjson);

// parse AST JSON from desired Model format
let generated_mdl = model_from_json(&astjson)?;
Expand All @@ -74,19 +72,19 @@ pub fn get_example_model(filename: &str) -> Result<Model, Box<dyn Error>> {
///
/// # Returns
///
/// Function returns a `Result<Value, Box<dyn Error>>`, where `Value` is the parsed model
pub fn get_example_model_by_path(filepath: &str) -> Result<Model, Box<dyn Error>> {
/// Function returns a `Result<Value, anyhow::Error>`, where `Value` is the parsed model
pub fn get_example_model_by_path(filepath: &str) -> Result<Model, anyhow::Error> {
let essence_path = PathBuf::from(filepath);

// return error if file not found
if essence_path.as_os_str().is_empty() {
return Err(Box::new(std::io::Error::new(
return Err(anyhow::Error::new(std::io::Error::new(
std::io::ErrorKind::NotFound,
"ERROR: File not found in any subdirectory",
)));
}

println!("PATH TO FILE: {}", essence_path.display());
// println!("PATH TO FILE: {}", essence_path.display());

// Command execution using 'conjure' CLI tool with provided path
let mut cmd = std::process::Command::new("conjure");
Expand All @@ -99,7 +97,7 @@ pub fn get_example_model_by_path(filepath: &str) -> Result<Model, Box<dyn Error>
// convert Conjure's stdout from bytes to string
let astjson = String::from_utf8(output.stdout)?;

println!("ASTJSON: {}", astjson);
// println!("ASTJSON: {}", astjson);

// parse AST JSON into the desired Model format
let generated_model = model_from_json(&astjson)?;
Expand Down
3 changes: 0 additions & 3 deletions conjure_oxide/src/unstable/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
//! Unstable and in-development features of Conjure-Oxide.
//!
//! Enabling these may introduce breaking changes that affect code compilation.

#![cfg(feature = "unstable-solver-interface")]
pub mod solver_interface;
Loading

0 comments on commit 130c16d

Please sign in to comment.