rl_model/model/
mod.rs

1pub mod reference;
2pub use reference::*;
3
4// pub mod model;
5// pub use model::*;
6
7pub mod rl_type;
8pub use rl_type::*;
9
10pub mod skillset;
11pub use skillset::*;
12
13pub mod data;
14pub use data::*;
15
16pub mod resource;
17pub use resource::*;
18pub mod state;
19pub use state::*;
20pub mod transition;
21pub use transition::*;
22
23pub mod event;
24pub use event::*;
25
26pub mod skill;
27pub use skill::*;
28// pub mod input;
29// pub use input::*;
30// pub mod output;
31// pub use output::*;
32
33pub mod precondition;
34pub use precondition::*;
35
36pub mod postcondition;
37pub use postcondition::*;
38
39pub mod invariant;
40pub use invariant::*;
41
42pub mod progress;
43pub use progress::*;
44
45pub mod interrupt;
46pub use interrupt::*;
47
48pub mod terminate;
49pub use terminate::*;
50
51pub mod effect;
52pub use effect::*;
53
54pub mod variable;
55pub use variable::*;
56
57pub mod expr;
58pub use expr::*;
59
60use crate::parser::{Position, RlError};
61
62pub trait ToLang {
63    fn to_lang(&self, skillset: &Skillset) -> String;
64}
65
66//------------------------- Id -------------------------
67
68pub trait Id: Clone + Copy + PartialEq + Eq + core::hash::Hash + std::fmt::Debug + Default {
69    fn index(&self) -> usize;
70}
71
72pub trait GetFromId<I: Id, T> {
73    fn get(&self, i: I) -> Option<&T>;
74}
75
76//------------------------- Named -------------------------
77
78pub trait Named<I: Id> {
79    fn id(&self) -> I;
80    fn set_id(&mut self, id: I);
81    fn name(&self) -> &str;
82    fn position(&self) -> Option<Position>;
83    fn naming(&self) -> Naming {
84        (self.name().into(), self.position())
85    }
86}
87
88pub type Naming = (String, Option<Position>);
89
90pub fn check_duplicate(names: Vec<Naming>) -> Result<(), RlError> {
91    for (i, (n1, p1)) in names.iter().enumerate() {
92        for (n2, p2) in names.iter().skip(i + 1) {
93            if n1 == n2 {
94                return Err(RlError::Duplicate {
95                    name: n1.clone(),
96                    first: p1.clone(),
97                    second: p2.clone(),
98                });
99            }
100        }
101    }
102    Ok(())
103}