-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
92 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
mod syntest; | ||
mod var; | ||
|
||
pub use syntest::LocalVariable; | ||
pub use syntest::Syntest; | ||
pub use var::LocalVariable; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
use std::fmt::Display; | ||
|
||
#[derive(Debug, PartialEq)] | ||
pub struct VarDetails { | ||
pub name: String, | ||
pub used: bool, | ||
} | ||
|
||
#[derive(Debug, PartialEq)] | ||
pub enum LocalVariable { | ||
Str { | ||
name: String, | ||
value: String, | ||
used: bool, | ||
}, | ||
Int { | ||
name: String, | ||
value: usize, | ||
used: bool, | ||
}, | ||
Float { | ||
name: String, | ||
value: f64, | ||
used: bool, | ||
}, | ||
Char { | ||
name: String, | ||
value: char, | ||
used: bool, | ||
}, | ||
Bool { | ||
name: String, | ||
value: bool, | ||
used: bool, | ||
}, | ||
Closure { | ||
name: String, | ||
used: bool, | ||
}, | ||
Other { | ||
name: String, | ||
used: bool, | ||
}, | ||
} | ||
|
||
impl LocalVariable { | ||
pub fn is_used(&self) -> bool { | ||
match self { | ||
LocalVariable::Str { used, .. } => *used, | ||
LocalVariable::Int { used, .. } => *used, | ||
LocalVariable::Float { used, .. } => *used, | ||
LocalVariable::Char { used, .. } => *used, | ||
LocalVariable::Bool { used, .. } => *used, | ||
LocalVariable::Closure { used, .. } => *used, | ||
LocalVariable::Other { used, .. } => *used, | ||
} | ||
} | ||
|
||
pub fn name(&self) -> &str { | ||
match self { | ||
LocalVariable::Str { name, .. } => name, | ||
LocalVariable::Int { name, .. } => name, | ||
LocalVariable::Float { name, .. } => name, | ||
LocalVariable::Char { name, .. } => name, | ||
LocalVariable::Bool { name, .. } => name, | ||
LocalVariable::Closure { name, .. } => name, | ||
LocalVariable::Other { name, .. } => name, | ||
} | ||
} | ||
|
||
pub fn value(&self) -> String { | ||
match self { | ||
LocalVariable::Str { value, .. } => value.clone(), | ||
LocalVariable::Int { value, .. } => value.to_string(), | ||
LocalVariable::Float { value, .. } => value.to_string(), | ||
LocalVariable::Char { value, .. } => value.to_string(), | ||
LocalVariable::Bool { value, .. } => value.to_string(), | ||
LocalVariable::Closure { .. } => "closure".to_string(), | ||
LocalVariable::Other { .. } => "other".to_string(), | ||
} | ||
} | ||
} | ||
|
||
impl Display for LocalVariable { | ||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | ||
write!(f, "{}", self.name()) | ||
} | ||
} |