Skip to content

Commit d94f09e

Browse files
committed
(parser) rev: display
1 parent 0c02460 commit d94f09e

File tree

3 files changed

+19
-10
lines changed

3 files changed

+19
-10
lines changed

src/parser/tree/binary.rs

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,22 @@ pub struct Binary {
1313
#[allow(clippy::min_ident_chars)]
1414
impl fmt::Display for Binary {
1515
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
16-
write!(
17-
f,
18-
"({} {} {})",
19-
self.arg_l,
20-
self.op,
21-
repr_option_node(self.arg_r.as_ref())
22-
)
16+
if self.op == BinaryOperator::ArraySubscript {
17+
write!(
18+
f,
19+
"({}[{}])",
20+
self.arg_l,
21+
repr_option_node(self.arg_r.as_ref())
22+
)
23+
} else {
24+
write!(
25+
f,
26+
"({} {} {})",
27+
self.arg_l,
28+
self.op,
29+
repr_option_node(self.arg_r.as_ref())
30+
)
31+
}
2332
}
2433
}
2534

src/parser/tree/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ impl fmt::Display for Literal {
135135
f,
136136
"{}",
137137
match self {
138-
Self::Empty => "\u{2205}".to_owned(),
138+
Self::Empty => "\u{2205} ".to_owned(),
139139
Self::String(val) | Self::Variable(val) | Self::Str(val) => val.to_string(),
140140
Self::Char(val) => val.to_string(),
141141
Self::Number(val) => format!("{val}"),
@@ -146,7 +146,7 @@ impl fmt::Display for Literal {
146146

147147
#[allow(clippy::borrowed_box)]
148148
fn repr_option_node(opt: Option<&Box<Node>>) -> String {
149-
opt.map_or_else(|| '\u{2205}'.to_string(), Box::<Node>::to_string)
149+
opt.map_or_else(|| "\u{2205} ".to_owned(), Box::<Node>::to_string)
150150
}
151151

152152
fn repr_vec_node(vec: &[Node]) -> String {

src/parser/tree/node.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ impl Node {
212212
impl fmt::Display for Node {
213213
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
214214
match self {
215-
Self::Empty => write!(f, "\u{2205}"),
215+
Self::Empty => write!(f, "\u{2205} "),
216216
Self::Binary(val) => val.fmt(f),
217217
Self::FunctionCall(val) => val.fmt(f),
218218
Self::Leaf(val) => val.fmt(f),

0 commit comments

Comments
 (0)