Commit 258ba1a7 authored by Dan Sheppard's avatar Dan Sheppard
Browse files

Start of tánaiste for styled data.

parent 75902027
......@@ -36,5 +36,5 @@ fn main() {
let cmd_re = Regex::new(r"@(.*?)@").unwrap();
let out = cmd_re.replace_all(&tmpl,command_output);
write(&Path::new(&dest).join("thisbuild.rs"),out.as_bytes()).ok();
to_console(&out);
to_console(&out);
}
#![feature(non_ascii_idents)]
// (help put the E into EMBL)
#[macro_use]
extern crate stdweb;
#[macro_use]
......@@ -24,6 +27,7 @@ mod drawing;
mod print;
mod program;
mod shape;
mod tánaiste;
mod types;
use controller::global;
......
mod value;
pub use self::value::Value;
use std::cell::RefCell;
use std::rc::Rc;
pub enum ValueImpl {
Float(Vec<f64>),
String(String)
}
impl ValueImpl {
}
fn float_to_string(data: &Vec<f64>) -> String {
let bytes : Vec<u8> = data.iter().map(|s| *s as u8).collect();
String::from_utf8(bytes).unwrap_or_else(|_| "".to_string())
}
fn string_to_float(data: String) -> Vec<f64> {
data.into_bytes().iter().map(|s| *s as f64).collect()
}
#[derive(Clone)]
pub struct Value(Rc<RefCell<ValueImpl>>);
impl Value {
pub fn new_from_float(data: Vec<f64>) -> Value {
Value(Rc::new(RefCell::new(ValueImpl::Float(data))))
}
pub fn new_from_string(data: String) -> Value {
Value(Rc::new(RefCell::new(ValueImpl::String(data))))
}
pub fn to_string(&self) -> Value {
let imp = self.0.borrow();
match *imp {
ValueImpl::Float(ref f) => Value::new_from_string(float_to_string(&f.clone())),
ValueImpl::String(_) => self.clone()
}
}
pub fn to_float(&self) -> Value {
let imp = self.0.borrow();
match *imp {
ValueImpl::String(ref s) => Value::new_from_float(string_to_float(s.clone())),
ValueImpl::Float(_) => self.clone()
}
}
pub fn coerce_to_string(&mut self) {
let mut v = {
match *self.0.borrow() {
ValueImpl::Float(ref f) =>
Some(ValueImpl::String(float_to_string(&f))),
ValueImpl::String(_) => None
}
};
if let Some(v) = v {
*self.0.borrow_mut() = v;
}
}
pub fn coerce_to_float(&mut self) {
let mut v = {
match *self.0.borrow() {
ValueImpl::String(ref s) =>
Some(ValueImpl::Float(string_to_float(s.clone()))),
ValueImpl::Float(_) => None
}
};
if let Some(v) = v {
*self.0.borrow_mut() = v;
}
}
}
mod core;
pub use self::core::Value;
......@@ -3,5 +3,5 @@ const VERSION_DATE : &str = "@date@";
const VERSION_HOSTNAME : &str= "@hostname@";
const VERSION_DIR : &str= "@pwd@";
const VERSION_USER : &str= "@whoami@";
const VERSION_CHANGES : &str = "@git status --porcelain@";
const VERSION_CHANGES : &str = "@git status --porcelain | perl -pe 's/"//g; s/\\(...)/chr(oct($1))/ge;'@";
const VERSION_POM : &str = "@pom@";
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment