mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-08-01 05:27:45 +00:00
Merge pull request #5376 from cakebaker/expr_add_empty_lines
expr: add some empty lines
This commit is contained in:
commit
0997493038
2 changed files with 12 additions and 0 deletions
|
@ -31,10 +31,12 @@ pub enum AstNode {
|
||||||
operands: OperandsList,
|
operands: OperandsList,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
impl AstNode {
|
impl AstNode {
|
||||||
fn debug_dump(&self) {
|
fn debug_dump(&self) {
|
||||||
self.debug_dump_impl(1);
|
self.debug_dump_impl(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn debug_dump_impl(&self, depth: usize) {
|
fn debug_dump_impl(&self, depth: usize) {
|
||||||
for _ in 0..depth {
|
for _ in 0..depth {
|
||||||
print!("\t",);
|
print!("\t",);
|
||||||
|
@ -71,12 +73,14 @@ impl AstNode {
|
||||||
operands,
|
operands,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fn new_leaf(token_idx: usize, value: &str) -> Box<Self> {
|
fn new_leaf(token_idx: usize, value: &str) -> Box<Self> {
|
||||||
Box::new(Self::Leaf {
|
Box::new(Self::Leaf {
|
||||||
token_idx,
|
token_idx,
|
||||||
value: value.into(),
|
value: value.into(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn evaluate(&self) -> Result<String, String> {
|
pub fn evaluate(&self) -> Result<String, String> {
|
||||||
match self {
|
match self {
|
||||||
Self::Leaf { value, .. } => Ok(value.clone()),
|
Self::Leaf { value, .. } => Ok(value.clone()),
|
||||||
|
@ -154,6 +158,7 @@ impl AstNode {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn operand_values(&self) -> Result<Vec<String>, String> {
|
pub fn operand_values(&self) -> Result<Vec<String>, String> {
|
||||||
if let Self::Node {
|
if let Self::Node {
|
||||||
operands, op_type, ..
|
operands, op_type, ..
|
||||||
|
@ -257,6 +262,7 @@ fn ast_from_rpn(rpn: &mut TokenStack) -> Result<Box<AstNode>, String> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn maybe_ast_node(
|
fn maybe_ast_node(
|
||||||
token_idx: usize,
|
token_idx: usize,
|
||||||
op_type: &str,
|
op_type: &str,
|
||||||
|
@ -520,6 +526,7 @@ fn prefix_operator_substr(values: &[String]) -> String {
|
||||||
fn bool_as_int(b: bool) -> u8 {
|
fn bool_as_int(b: bool) -> u8 {
|
||||||
u8::from(b)
|
u8::from(b)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn bool_as_string(b: bool) -> String {
|
fn bool_as_string(b: bool) -> String {
|
||||||
if b {
|
if b {
|
||||||
"1".to_string()
|
"1".to_string()
|
||||||
|
@ -527,6 +534,7 @@ fn bool_as_string(b: bool) -> String {
|
||||||
"0".to_string()
|
"0".to_string()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn value_as_bool(s: &str) -> bool {
|
fn value_as_bool(s: &str) -> bool {
|
||||||
if s.is_empty() {
|
if s.is_empty() {
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -38,6 +38,7 @@ pub enum Token {
|
||||||
value: String,
|
value: String,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Token {
|
impl Token {
|
||||||
fn new_infix_op(v: &str, left_assoc: bool, precedence: u8) -> Self {
|
fn new_infix_op(v: &str, left_assoc: bool, precedence: u8) -> Self {
|
||||||
Self::InfixOp {
|
Self::InfixOp {
|
||||||
|
@ -46,6 +47,7 @@ impl Token {
|
||||||
value: v.into(),
|
value: v.into(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn new_value(v: &str) -> Self {
|
fn new_value(v: &str) -> Self {
|
||||||
Self::Value { value: v.into() }
|
Self::Value { value: v.into() }
|
||||||
}
|
}
|
||||||
|
@ -56,12 +58,14 @@ impl Token {
|
||||||
_ => false,
|
_ => false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn is_a_number(&self) -> bool {
|
fn is_a_number(&self) -> bool {
|
||||||
match self {
|
match self {
|
||||||
Self::Value { value, .. } => value.parse::<BigInt>().is_ok(),
|
Self::Value { value, .. } => value.parse::<BigInt>().is_ok(),
|
||||||
_ => false,
|
_ => false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn is_a_close_paren(&self) -> bool {
|
fn is_a_close_paren(&self) -> bool {
|
||||||
matches!(*self, Self::ParClose)
|
matches!(*self, Self::ParClose)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue