Skip to content

Commit 82c596a

Browse files
committed
(main) ref: remove unnecessary options
1 parent bfc9697 commit 82c596a

File tree

6 files changed

+95
-145
lines changed

6 files changed

+95
-145
lines changed

src/parser/keyword/types/attributes.rs

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,6 @@ macro_rules! define_attribute_keywords {
2626
}
2727
}
2828

29-
// impl PushInNode for AttributeKeyword {
30-
// fn push_in_node(self, node: &mut Ast) -> Result<(), String> {
31-
// match self {
32-
// $(Self::$name(val) => val.push_in_node(node),)*
33-
// }
34-
// }
35-
// }
36-
3729
pub enum UnsortedAttributeKeyword {
3830
$($($variant,)*)*
3931
}
@@ -78,8 +70,7 @@ impl PushInNode for AttributeKeyword {
7870
Ast::Empty => *node = self.into_node(),
7971
Ast::Leaf(Literal::Variable(var)) => var.push_attr(self),
8072
Ast::ParensBlock(_) | Ast::Leaf(_) => return Err(format!("invalid attribute. Attribute keywords can only be applied to variables, but found {node}")),
81-
Ast::Unary(Unary{arg: Some(arg), ..}) | Ast::Binary(Binary {arg_r: Some(arg), ..}) | Ast::Ternary(Ternary { failure: Some(arg), ..} | Ternary { success: arg, .. }) => return self.push_in_node(arg),
82-
Ast::Unary(Unary{arg: None, ..}) | Ast::Binary(Binary {arg_r: None, ..}) => return node.push_block_as_leaf(self.into_node()),
73+
Ast::Unary(Unary{arg, ..}) | Ast::Binary(Binary {arg_r: arg, ..}) | Ast::Ternary(Ternary { failure: Some(arg), ..} | Ternary { success: arg, .. }) => return self.push_in_node(arg),
8374
Ast::ListInitialiser(ListInitialiser{ full: true, ..}) | Ast::FunctionCall(FunctionCall{full: true, .. }) => return Err("Attributes can only be placed before variables.".to_owned())
8475
,Ast::ListInitialiser(ListInitialiser{elts , ..}) | Ast::FunctionCall(FunctionCall{args: elts, ..}) | Ast::Block(Block{elts, ..}) => match elts.last_mut() {
8576
Some(last) => return self.push_in_node(last),

src/parser/tree/binary.rs

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
use core::fmt;
44

5-
use super::{repr_option_node, Associativity, Ast, Operator};
5+
use super::{Associativity, Ast, Operator};
66

77
macro_rules! define_binary_operator {
88
($($name_left:ident $precedence_left:expr, $repr_left:expr)*; $($name_right:ident $precedence_right:expr, $repr_right:expr)*) => {
@@ -45,27 +45,16 @@ macro_rules! define_binary_operator {
4545
pub struct Binary {
4646
pub op: BinaryOperator,
4747
pub arg_l: Box<Ast>,
48-
pub arg_r: Option<Box<Ast>>,
48+
pub arg_r: Box<Ast>,
4949
}
5050

5151
#[expect(clippy::min_ident_chars)]
5252
impl fmt::Display for Binary {
5353
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
5454
if self.op == BinaryOperator::ArraySubscript {
55-
write!(
56-
f,
57-
"({}[{}])",
58-
self.arg_l,
59-
repr_option_node(self.arg_r.as_ref())
60-
)
55+
write!(f, "({}[{}])", self.arg_l, self.arg_r)
6156
} else {
62-
write!(
63-
f,
64-
"({} {} {})",
65-
self.arg_l,
66-
self.op,
67-
repr_option_node(self.arg_r.as_ref())
68-
)
57+
write!(f, "({} {} {})", self.arg_l, self.op, self.arg_r)
6958
}
7059
}
7160
}

src/parser/tree/conversions.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ impl OperatorConversions for BinaryOperator {
1616
Ok(Ast::Binary(Binary {
1717
op: self,
1818
arg_l: Box::new(arg),
19-
arg_r: None,
19+
arg_r: Box::new(Ast::Empty),
2020
}))
2121
}
2222
}
@@ -60,14 +60,14 @@ impl OperatorConversions for UnaryOperator {
6060
fn try_to_node(self) -> Result<Ast, String> {
6161
Ok(Ast::Unary(Unary {
6262
op: self,
63-
arg: None,
63+
arg: Box::new(Ast::Empty),
6464
}))
6565
}
6666

6767
fn try_to_node_with_arg(self, arg: Ast) -> Result<Ast, String> {
6868
Ok(Ast::Unary(Unary {
6969
op: self,
70-
arg: Some(Box::from(arg)),
70+
arg: Box::from(arg),
7171
}))
7272
}
7373
}

0 commit comments

Comments
 (0)