71 lines
1.9 KiB
Rust
71 lines
1.9 KiB
Rust
#![feature(box_patterns, box_syntax, proc_macro_hygiene, decl_macro)]
|
|
#![feature(plugin)]
|
|
extern crate colored;
|
|
extern crate itertools;
|
|
extern crate linefeed;
|
|
|
|
#[macro_use]
|
|
extern crate serde_derive;
|
|
extern crate includedir;
|
|
extern crate phf;
|
|
extern crate serde_json;
|
|
|
|
use std::collections::HashSet;
|
|
use std::fs::File;
|
|
use std::io::Read;
|
|
use std::path::Path;
|
|
use std::process::exit;
|
|
|
|
mod language;
|
|
mod repl;
|
|
|
|
pub use language::{
|
|
ComputationRequest, ComputationResponse, DebugAsk, DebugResponse, GlobalOutputStats,
|
|
LangMetaRequest, LangMetaResponse, ProgrammingLanguageInterface,
|
|
};
|
|
|
|
include!(concat!(env!("OUT_DIR"), "/static.rs"));
|
|
const VERSION_STRING: &'static str = "0.1.0";
|
|
|
|
pub fn start_repl(langs: Vec<Box<dyn ProgrammingLanguageInterface>>) {
|
|
let mut repl = repl::Repl::new(langs);
|
|
repl.run_repl();
|
|
}
|
|
|
|
//TODO should really expect a list of paths
|
|
pub fn run_noninteractive(filename: &str, languages: Vec<Box<dyn ProgrammingLanguageInterface>>) {
|
|
let path = Path::new(filename);
|
|
let ext = path
|
|
.extension()
|
|
.and_then(|e| e.to_str())
|
|
.unwrap_or_else(|| {
|
|
println!("Source file lacks extension");
|
|
exit(1);
|
|
});
|
|
let mut language = Box::new(
|
|
languages
|
|
.into_iter()
|
|
.find(|lang| lang.get_source_file_suffix() == ext)
|
|
.unwrap_or_else(|| {
|
|
println!("Extension .{} not recognized", ext);
|
|
exit(1);
|
|
}),
|
|
);
|
|
|
|
let mut source_file = File::open(path).unwrap();
|
|
let mut buffer = String::new();
|
|
source_file.read_to_string(&mut buffer).unwrap();
|
|
|
|
let request = ComputationRequest {
|
|
source: &buffer,
|
|
debug_requests: HashSet::new(),
|
|
};
|
|
|
|
let response = language.run_computation(request);
|
|
match response.main_output {
|
|
Ok(s) => println!("{}", s),
|
|
Err(s) => println!("{}", s),
|
|
};
|
|
}
|
|
|