nushell/crates/nu-protocol/src/ast/cell_path.rs

39 lines
907 B
Rust
Raw Normal View History

2021-09-07 00:02:24 +02:00
use super::Expression;
use crate::Span;
2021-10-02 04:59:11 +02:00
use serde::{Deserialize, Serialize};
2021-09-07 00:02:24 +02:00
2021-10-02 04:59:11 +02:00
#[derive(Debug, Clone, Serialize, Deserialize)]
2021-09-07 00:02:24 +02:00
pub enum PathMember {
String { val: String, span: Span },
Int { val: usize, span: Span },
}
2021-10-02 04:59:11 +02:00
#[derive(Debug, Clone, Serialize, Deserialize)]
2021-09-07 00:02:24 +02:00
pub struct CellPath {
pub members: Vec<PathMember>,
}
2021-10-02 06:55:05 +02:00
impl CellPath {
pub fn into_string(&self) -> String {
let mut output = String::new();
for (idx, elem) in self.members.iter().enumerate() {
if idx > 0 {
output.push('.');
}
match elem {
PathMember::Int { val, .. } => output.push_str(&format!("{}", val)),
PathMember::String { val, .. } => output.push_str(val),
}
}
output
}
}
2021-09-07 00:02:24 +02:00
#[derive(Debug, Clone)]
pub struct FullCellPath {
pub head: Expression,
pub tail: Vec<PathMember>,
}