mirror of
https://github.com/rm-dr/daisy
synced 2025-10-11 21:02:58 -07:00
Cleanup, added to_string_outer
This commit is contained in:
@ -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());
|
||||
}
|
||||
};
|
||||
}
|
||||
|
Reference in New Issue
Block a user