use super::{CompileTimeConstant, Statement};
#[derive(Debug,PartialEq)]
pub struct Simulation {
pub name: String,
pub default_particle: Option<String>,
pub blocks: Vec<SimulationBlock>
}
#[derive(Debug,PartialEq)]
pub enum SimulationBlock {
Once(OnceBlock),
Step(StepBlock)
}
#[derive(Debug,PartialEq)]
pub struct OnceBlock {
pub step: CompileTimeConstant<usize>,
pub subblocks: Vec<SimulationSubBlock>
}
#[derive(Debug,PartialEq)]
pub struct StepBlock {
pub step_range: StepRange,
pub subblocks: Vec<SimulationSubBlock>
}
#[derive(Debug,PartialEq)]
pub struct StepRange {
pub start: CompileTimeConstant<usize>,
pub end: CompileTimeConstant<usize>,
pub step: CompileTimeConstant<usize>
}
impl Default for StepRange {
fn default() -> Self {
Self {
start: CompileTimeConstant::Literal(0),
end: CompileTimeConstant::Literal(usize::MAX),
step: CompileTimeConstant::Literal(1)
}
}
}
#[derive(Debug,PartialEq)]
pub struct SimulationSubBlock {
pub particle: Option<String>,
pub statements: Vec<Statement>
}
mod tests {
#[allow(unused_imports)] use super::super::*;
#[test]
fn step_range() {
assert!(fips_parser::step_range("1..2..3").is_err(),
"1..2..3 not caught as invalid");
let test_cases = std::collections::HashMap::from([
("..", (0,usize::MAX,1)),
("1..", (1,usize::MAX,1)),
("..2", (0,2,1)),
("1..2", (1,2,1)),
("..,3", (0,usize::MAX,3)),
("1..,3", (1,usize::MAX,3)),
("..2,3", (0,2,3)),
("1..2,3",(1,2,3)),
]);
for (s,(start,end,step)) in test_cases {
assert_eq!(fips_parser::step_range(s).expect(&format!("Cannot parse {} as step range", s)),
StepRange {
start: start.into(),
end: end.into(),
step: step.into(),
});
}
}
}