#![feature(box_patterns, box_syntax, proc_macro_hygiene, decl_macro)] #![feature(plugin)] #[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::PathBuf; 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>) { let mut repl = repl::Repl::new(langs); repl.run_repl(); } pub fn run_noninteractive(filenames: Vec, languages: Vec>) { // for now, ony do something with the first filename let filename = &filenames[0]; let ext = filename .extension() .and_then(|e| e.to_str()) .unwrap_or_else(|| { println!("Source file `{}` has no extension.", filename.display()); 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(filename).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), }; }