pub mod ast;
pub mod compilation_state;
pub mod diagnostic_emitter;
pub mod diagnostics;
pub mod grammar;
pub mod slice_file;
pub mod slice_options;
pub mod utils;
pub mod visitor;
mod parsers;
mod patchers;
mod validators;
use compilation_state::CompilationState;
use slice_file::SliceFile;
use slice_options::SliceOptions;
use std::collections::HashSet;
use utils::file_util;
pub fn compile_from_options(options: &SliceOptions) -> CompilationState {
let mut state = CompilationState::create();
if options.disable_color {
console::set_colors_enabled(false);
console::set_colors_enabled_stderr(false);
}
state.files = file_util::resolve_files_from(options, &mut state.diagnostics);
if !state.diagnostics.has_errors() {
compile_files(&mut state, options);
}
state
}
pub fn compile_from_strings(inputs: &[&str], options: Option<&SliceOptions>) -> CompilationState {
let mut state = CompilationState::create();
if options.map(|opts| opts.disable_color).unwrap_or_default() {
console::set_colors_enabled(false);
console::set_colors_enabled_stderr(false);
}
for (i, &input) in inputs.iter().enumerate() {
let slice_file = SliceFile::new(format!("string-{i}"), input.to_owned(), false);
state.files.push(slice_file);
}
match options {
Some(slice_options) => compile_files(&mut state, slice_options),
None => compile_files(&mut state, &SliceOptions::default()),
}
state
}
fn compile_files(state: &mut CompilationState, options: &SliceOptions) {
let defined_symbols = HashSet::from_iter(options.defined_symbols.clone());
parsers::parse_files(state, &defined_symbols);
unsafe { state.apply_unsafe(patchers::patch_ast) };
state.apply(validators::validate_ast);
}