Skip to content

Commit 005c4a1

Browse files
committed
(parser) feat: impl MakeFunction for Variables
1 parent d8314ea commit 005c4a1

File tree

3 files changed

+49
-2
lines changed

3 files changed

+49
-2
lines changed

src/parser/variable/declaration.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use super::{Variable, traits};
99
use crate::parser::display::repr_option_vec;
1010
use crate::parser::keyword::attributes::{AttributeKeyword, UserDefinedTypes};
1111
use crate::parser::literal::{Attribute, repr_vec_attr};
12+
use crate::parser::modifiers::functions::{CanMakeFnRes, MakeFunction};
1213
use crate::parser::modifiers::push::Push;
1314
use crate::parser::operators::api::OperatorConversions;
1415
use crate::parser::tree::api::{Ast, CanPush};
@@ -93,6 +94,30 @@ impl AttributeVariable {
9394
}
9495
}
9596

97+
impl MakeFunction for AttributeVariable {
98+
fn can_make_function(&self) -> CanMakeFnRes {
99+
match self.declarations.last()? {
100+
Some(declaration) => declaration.value.as_ref()?.can_make_function(),
101+
None => CanMakeFnRes::None,
102+
}
103+
}
104+
105+
fn make_function(&mut self, depth: u32, arguments: Vec<Ast>) {
106+
match self
107+
.declarations
108+
.last_mut()
109+
.expect("checked with can_make_function")
110+
{
111+
Some(declaration) => declaration
112+
.value
113+
.as_mut()
114+
.expect("checked with can_make_function")
115+
.make_function(depth, arguments),
116+
None => unreachable!(),
117+
}
118+
}
119+
}
120+
96121
impl CanPush for AttributeVariable {
97122
fn can_push_leaf(&self) -> bool {
98123
self.declarations.last().is_some_and(|opt| {

src/parser/variable/mod.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,11 +109,15 @@ impl Variable {
109109

110110
impl MakeFunction for Variable {
111111
fn can_make_function(&self) -> CanMakeFnRes {
112-
todo!()
112+
if self.full {
113+
CanMakeFnRes::None
114+
} else {
115+
self.value.can_make_function()
116+
}
113117
}
114118

115119
fn make_function(&mut self, depth: u32, arguments: Vec<Ast>) {
116-
todo!()
120+
self.value.make_function(depth, arguments);
117121
}
118122
}
119123

src/parser/variable/value.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ use super::name::VariableName;
88
use super::traits::{PureType, VariableConversion};
99
use crate::parser::keyword::attributes::UserDefinedTypes;
1010
use crate::parser::literal::Attribute;
11+
use crate::parser::modifiers::functions::{CanMakeFnRes, MakeFunction};
12+
use crate::parser::tree::Ast;
1113
use crate::parser::tree::api::{CanPush, PushAttribute};
1214
use crate::utils::display;
1315

@@ -108,6 +110,22 @@ impl VariableValue {
108110
}
109111
}
110112

113+
impl MakeFunction for VariableValue {
114+
fn can_make_function(&self) -> CanMakeFnRes {
115+
match self {
116+
Self::AttributeVariable(var) => var.can_make_function(),
117+
Self::VariableName(_) => CanMakeFnRes::None,
118+
}
119+
}
120+
121+
fn make_function(&mut self, depth: u32, arguments: Vec<Ast>) {
122+
match self {
123+
Self::AttributeVariable(var) => var.make_function(depth, arguments),
124+
Self::VariableName(_) => unreachable!(),
125+
}
126+
}
127+
}
128+
111129
impl CanPush for VariableValue {
112130
fn can_push_leaf(&self) -> bool {
113131
match self {

0 commit comments

Comments
 (0)