1
0
dust/src/abstract_tree/identifier.rs

36 lines
830 B
Rust
Raw Normal View History

2023-10-06 17:32:58 +00:00
use serde::{Deserialize, Serialize};
use tree_sitter::Node;
use crate::{AbstractTree, Result, Value, VariableMap};
#[derive(Debug, Clone, Serialize, Deserialize, Eq, PartialEq, PartialOrd, Ord)]
pub struct Identifier(String);
impl Identifier {
pub fn new(inner: String) -> Self {
Identifier(inner)
}
pub fn take_inner(self) -> String {
self.0
}
pub fn inner(&self) -> &String {
&self.0
}
}
impl AbstractTree for Identifier {
2023-10-10 17:29:11 +00:00
fn from_syntax_node(source: &str, node: Node) -> Result<Self> {
2023-10-06 17:32:58 +00:00
let identifier = &source[node.byte_range()];
Ok(Identifier(identifier.to_string()))
}
2023-10-10 18:12:07 +00:00
fn run(&self, _source: &str, context: &mut VariableMap) -> Result<Value> {
2023-10-06 17:32:58 +00:00
let value = context.get_value(&self.0)?.unwrap_or_default();
Ok(value)
}
}