mirror of https://github.com/rm-dr/daisy
Merge branch 'master' of ssh://git.betalupi.com:33/Mark/daisy
commit
3007d7f875
|
@ -0,0 +1,21 @@
|
|||
on: [push]
|
||||
|
||||
name: CI
|
||||
|
||||
jobs:
|
||||
build_and_test:
|
||||
name: Daisy
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: actions-rs/toolchain@v1
|
||||
with:
|
||||
toolchain: stable
|
||||
- uses: actions-rs/cargo@v1
|
||||
with:
|
||||
command: build
|
||||
args: --release --all-features
|
||||
- uses: actions-rs/cargo@v1
|
||||
with:
|
||||
command: test
|
||||
args: --release
|
|
@ -81,7 +81,7 @@ pub fn main() -> Result<(), std::io::Error> {
|
|||
Ok(g) => {
|
||||
#[cfg(debug_assertions)]
|
||||
RawTerminal::suspend_raw_mode(&stdout)?;
|
||||
let out_str = g.print();
|
||||
let out_str = g.to_string();
|
||||
let g = evaluate::evaluate(g);
|
||||
#[cfg(debug_assertions)]
|
||||
RawTerminal::activate_raw_mode(&stdout)?;
|
||||
|
@ -100,7 +100,7 @@ pub fn main() -> Result<(), std::io::Error> {
|
|||
style::Bold,
|
||||
color::Fg(color::Green),
|
||||
style::Reset,
|
||||
q.print(),
|
||||
q.to_string_outer(),
|
||||
color::Fg(color::Reset)
|
||||
)?;
|
||||
},
|
||||
|
|
|
@ -36,6 +36,16 @@ impl ToString for Quantity {
|
|||
}
|
||||
|
||||
impl Quantity {
|
||||
pub fn to_string_outer(&self) -> String {
|
||||
let n = self.v.to_string();
|
||||
if self.unitless() { return n; }
|
||||
|
||||
let u = self.u.to_string();
|
||||
return format!("{n} {u}");
|
||||
}
|
||||
|
||||
|
||||
|
||||
pub fn new_float(f: f64) -> Option<Quantity> {
|
||||
let v = Scalar::new_float(f);
|
||||
if v.is_none() { return None; }
|
||||
|
|
|
@ -10,7 +10,7 @@ fn eval_to_str(s: &str) -> Result<String, ()> {
|
|||
//let out_str = g.print();
|
||||
|
||||
return match evaluate::evaluate(g) {
|
||||
Ok(x) => Ok(x.print()),
|
||||
Ok(x) => Ok(x.to_string()),
|
||||
Err(_) => Err(())
|
||||
};
|
||||
}
|
||||
|
|
|
@ -26,15 +26,28 @@ pub enum Token {
|
|||
),
|
||||
}
|
||||
|
||||
impl Token {
|
||||
|
||||
pub fn print(&self) -> String {
|
||||
impl ToString for Token {
|
||||
fn to_string(&self) -> String {
|
||||
match self {
|
||||
Token::Number(v) => v.to_string(),
|
||||
Token::Constant(_,s) => s.clone(),
|
||||
Token::Constant(_, s) => s.clone(),
|
||||
Token::Operator(o,a) => o.print(a)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Token {
|
||||
|
||||
// This is called only when this is the outermost token.
|
||||
// This sometimes leads to different--usually more verbose--behavior.
|
||||
pub fn to_string_outer(&self) -> String {
|
||||
match self {
|
||||
Token::Number(v) => v.to_string_outer(),
|
||||
Token::Constant(_, s) => s.clone(),
|
||||
Token::Operator(o,a) => o.print(a)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#[inline(always)]
|
||||
pub fn get_args(&self) -> Option<&VecDeque<Token>> {
|
||||
|
|
|
@ -54,7 +54,7 @@ impl Operator {
|
|||
|
||||
#[inline(always)]
|
||||
fn add_parens_to_arg(&self, arg: &Token) -> String {
|
||||
let mut astr: String = arg.print();
|
||||
let mut astr: String = arg.to_string();
|
||||
if let Token::Operator(o,_) = arg {
|
||||
if o < self {
|
||||
astr = format!("({})", astr);
|
||||
|
@ -65,7 +65,7 @@ impl Operator {
|
|||
|
||||
#[inline(always)]
|
||||
fn add_parens_to_arg_strict(&self, arg: &Token) -> String {
|
||||
let mut astr: String = arg.print();
|
||||
let mut astr: String = arg.to_string();
|
||||
if let Token::Operator(o,_) = arg {
|
||||
if o <= self {
|
||||
astr = format!("({})", astr);
|
||||
|
@ -193,7 +193,7 @@ impl Operator {
|
|||
},
|
||||
|
||||
Operator::Function(s) => {
|
||||
return format!("{}({})", s.to_string(), args[0].print());
|
||||
return format!("{}({})", s.to_string(), args[0].to_string());
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue