pub mod ast;
pub mod compiler;
pub mod error;
pub mod examples;
pub mod imports;
pub mod lexer;
pub mod macros;
pub mod optimizer;
pub mod parser;
pub mod stdlib;
pub mod types;
#[cfg(feature = "dwave")]
use crate::compile::{Compile, CompiledModel};
use scirs2_core::ndarray::Array2;
use std::collections::HashMap;
pub use ast::*;
pub use compiler::*;
pub use error::*;
pub use imports::*;
pub use lexer::*;
pub use macros::*;
pub use optimizer::*;
pub use parser::*;
pub use stdlib::*;
pub use types::*;
pub struct ProblemDSL {
parser: parser::Parser,
type_checker: types::TypeChecker,
stdlib: stdlib::StandardLibrary,
options: compiler::CompilerOptions,
macros: HashMap<String, macros::Macro>,
import_resolver: imports::ImportResolver,
optimization_hints: Vec<optimizer::OptimizationHint>,
}
impl ProblemDSL {
pub fn new() -> Self {
Self {
parser: parser::Parser::new(),
type_checker: types::TypeChecker::new(),
stdlib: stdlib::StandardLibrary::new(),
options: compiler::CompilerOptions::default(),
macros: HashMap::new(),
import_resolver: imports::ImportResolver::new(),
optimization_hints: Vec::new(),
}
}
pub const fn with_options(mut self, options: compiler::CompilerOptions) -> Self {
self.options = options;
self
}
pub fn with_hints(mut self, hints: Vec<optimizer::OptimizationHint>) -> Self {
self.optimization_hints = hints;
self
}
pub fn parse(&mut self, source: &str) -> Result<ast::AST, error::ParseError> {
let tokens = self.tokenize(source)?;
self.parser.set_tokens(tokens);
let ast = self.parser.parse()?;
self.type_checker.check(&ast)?;
Ok(ast)
}
pub fn tokenize(&self, source: &str) -> Result<Vec<lexer::Token>, error::ParseError> {
lexer::tokenize(source)
}
pub fn compile_to_qubo(&self, ast: &ast::AST) -> Result<Array2<f64>, error::CompileError> {
compiler::compile_to_qubo(ast, &self.options)
}
pub fn example<'a>(&self, name: &'a str) -> Option<&'a str> {
examples::get_example(name)
}
}
impl Default for ProblemDSL {
fn default() -> Self {
Self::new()
}
}