-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtask.rs
71 lines (61 loc) · 2.19 KB
/
task.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
use crate::{
model::{Command, ModelError, Runtime, RuntimeAttribute, Task, TaskElement},
parsers::pest::{expressions, node::PestNode, Rule},
};
use error_stack::{bail, Report, Result};
use std::convert::TryFrom;
impl<'a> TryFrom<PestNode<'a>> for Command {
type Error = Report<ModelError>;
fn try_from(node: PestNode<'a>) -> Result<Self, ModelError> {
Ok(Self {
parts: node.one_inner()?.into_inner().collect_anchors()?,
})
}
}
impl<'a> TryFrom<PestNode<'a>> for RuntimeAttribute {
type Error = Report<ModelError>;
fn try_from(node: PestNode<'a>) -> Result<Self, ModelError> {
let mut inner = node.into_inner();
Ok(Self {
name: inner.next_node().try_into()?,
expression: expressions::try_into_expression_anchor(inner.next_node()?)?,
})
}
}
impl<'a> TryFrom<PestNode<'a>> for Runtime {
type Error = Report<ModelError>;
fn try_from(node: PestNode<'a>) -> Result<Self, ModelError> {
Ok(Self {
attributes: node.into_inner().collect_anchors_with_inner_spans()?,
})
}
}
impl<'a> TryFrom<PestNode<'a>> for TaskElement {
type Error = Report<ModelError>;
fn try_from(node: PestNode<'a>) -> Result<Self, ModelError> {
let e = match node.as_rule() {
Rule::input => Self::Input(node.try_into()?),
Rule::output => Self::Output(node.try_into()?),
Rule::bound_declaration => Self::Declaration(node.try_into()?),
Rule::meta => Self::Meta(node.try_into()?),
Rule::parameter_meta => Self::ParameterMeta(node.try_into()?),
Rule::command => Self::Command(node.try_into()?),
Rule::runtime => Self::Runtime(node.try_into()?),
_ => bail!(ModelError::parser(format!(
"Invalid task element {:?}",
node
))),
};
Ok(e)
}
}
impl<'a> TryFrom<PestNode<'a>> for Task {
type Error = Report<ModelError>;
fn try_from(node: PestNode<'a>) -> Result<Self, ModelError> {
let mut inner = node.into_inner();
Ok(Self {
name: inner.next_node().try_into()?,
body: inner.collect_anchors()?,
})
}
}