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};
|
2022-06-04 08:47:36 +02:00
|
|
|
use std::fmt::Write;
|
2021-09-07 00:02:24 +02:00
|
|
|
|
2022-02-16 20:30:37 +01:00
|
|
|
#[derive(Debug, Clone, PartialOrd, Serialize, Deserialize)]
|
2021-09-07 00:02:24 +02:00
|
|
|
pub enum PathMember {
|
2023-03-16 04:50:58 +01:00
|
|
|
String {
|
|
|
|
val: String,
|
|
|
|
span: Span,
|
|
|
|
optional: bool,
|
|
|
|
},
|
|
|
|
Int {
|
|
|
|
val: usize,
|
|
|
|
span: Span,
|
|
|
|
optional: bool,
|
|
|
|
},
|
2021-09-07 00:02:24 +02:00
|
|
|
}
|
|
|
|
|
2022-01-23 23:32:02 +01:00
|
|
|
impl PartialEq for PathMember {
|
|
|
|
fn eq(&self, other: &Self) -> bool {
|
|
|
|
match (self, other) {
|
2023-03-16 04:50:58 +01:00
|
|
|
(
|
|
|
|
Self::String {
|
|
|
|
val: l_val,
|
|
|
|
optional: l_opt,
|
|
|
|
..
|
|
|
|
},
|
|
|
|
Self::String {
|
|
|
|
val: r_val,
|
|
|
|
optional: r_opt,
|
|
|
|
..
|
|
|
|
},
|
|
|
|
) => l_val == r_val && l_opt == r_opt,
|
|
|
|
(
|
|
|
|
Self::Int {
|
|
|
|
val: l_val,
|
|
|
|
optional: l_opt,
|
|
|
|
..
|
|
|
|
},
|
|
|
|
Self::Int {
|
|
|
|
val: r_val,
|
|
|
|
optional: r_opt,
|
|
|
|
..
|
|
|
|
},
|
|
|
|
) => l_val == r_val && l_opt == r_opt,
|
2022-01-23 23:32:02 +01:00
|
|
|
_ => false,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-02-16 20:30:37 +01:00
|
|
|
#[derive(Debug, Clone, PartialEq, PartialOrd, 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 {
|
2022-06-04 08:47:36 +02:00
|
|
|
PathMember::Int { val, .. } => {
|
2023-01-30 02:37:54 +01:00
|
|
|
let _ = write!(output, "{val}");
|
2022-06-04 08:47:36 +02:00
|
|
|
}
|
2021-10-02 06:55:05 +02:00
|
|
|
PathMember::String { val, .. } => output.push_str(val),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
output
|
|
|
|
}
|
2023-03-16 04:50:58 +01:00
|
|
|
|
|
|
|
pub fn make_optional(&mut self) {
|
|
|
|
for member in &mut self.members {
|
|
|
|
match member {
|
|
|
|
PathMember::String {
|
|
|
|
ref mut optional, ..
|
|
|
|
} => *optional = true,
|
|
|
|
PathMember::Int {
|
|
|
|
ref mut optional, ..
|
|
|
|
} => *optional = true,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-10-02 06:55:05 +02:00
|
|
|
}
|
|
|
|
|
2022-03-07 21:08:56 +01:00
|
|
|
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
2021-09-07 00:02:24 +02:00
|
|
|
pub struct FullCellPath {
|
|
|
|
pub head: Expression,
|
|
|
|
pub tail: Vec<PathMember>,
|
|
|
|
}
|