1use std::convert::From;
2
3#[derive(PartialEq, Debug)]
4pub struct Token {
5 pub r#type: String,
6 pub raw: String,
7 pub start: usize,
8 pub end: usize,
9}
10
11#[derive(PartialEq, Debug)]
12pub struct Expression {
13 pub r#type: String,
14 pub body: Vec<Manipulation>,
15 pub start: usize,
16 pub end: usize,
17}
18
19#[derive(PartialEq, Debug)]
20pub enum Manipulation {
21 Offset {
22 r#type: String,
23 op: String,
24 number: usize,
25 unit: String,
26 start: usize,
27 end: usize,
28 },
29 Period {
30 r#type: String,
31 op: String,
32 unit: String,
33 start: usize,
34 end: usize,
35 },
36}
37
38#[derive(PartialEq, Debug)]
39pub struct InputExpression {
40 pub r#type: String,
41 pub body: Vec<InputManipulation>,
42}
43
44impl From<Expression> for InputExpression {
45 fn from(input: Expression) -> Self {
46 InputExpression {
47 r#type: input.r#type,
48 body: input.body.into_iter().map(|m| InputManipulation::from(m)).collect()
49 }
50 }
51}
52
53#[derive(PartialEq, Debug)]
54pub enum InputManipulation {
55 Offset {
56 r#type: String,
57 op: String,
58 number: usize,
59 unit: String,
60 },
61 Period {
62 r#type: String,
63 op: String,
64 unit: String,
65 },
66}
67
68impl From<Manipulation> for InputManipulation {
69 fn from(m: Manipulation) -> Self {
70 match m {
71 Manipulation::Offset { r#type, op, number, unit, .. } => InputManipulation::Offset {
72 r#type, op, number, unit,
73 },
74 Manipulation::Period { r#type, op, unit, .. } => InputManipulation::Period {
75 r#type, op, unit,
76 }
77 }
78 }
79}