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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
/// Implement `TokenDeserialize` for a token with `[REF:ty]`
/// There `ty` is the type given in the argument
/// So it adds: `impl TokenDeserialize for ty {...}`
#[macro_export]
macro_rules! token_deserialize_unary_token {
( $x:ty ) => {
/// Deserialize a token with following pattern: `[REF:ty]`
impl TokenDeserialize for $x {
fn deserialize_tokens(
mut cursor: &mut $crate::TreeCursor,
source: &str,
mut diagnostics: &mut DiagnosticsInfo,
) -> Result<Box<Self>, ()> {
// Get arguments from token
let mut token =
match $crate::Token::deserialize_tokens(&mut cursor, &source, &mut diagnostics)
{
Ok(token) => token,
Err(err) => {
// Token could not be parsed, so we can consume it.
// Because this will always fail.
$crate::Token::consume_token(&mut cursor)?;
return Err(err);
}
};
$crate::Token::consume_token(&mut cursor)?;
// Token Name
token.check_token_name(source, &mut diagnostics, true)?;
// Arg 0
let result =
Self::try_from_argument_group(&mut token, source, &mut diagnostics, true);
// Just check if all tokens are consumed if no other errors are present
if result.is_ok() {
token.check_all_arg_consumed(source, &mut diagnostics, true)?;
} else {
// In case of an error, mark other arguments as unchecked.
$crate::mark_rest_of_token_as_unchecked(diagnostics, &token);
}
Ok(Box::new(result?))
}
fn deserialize_general_token(
_cursor: &mut $crate::TreeCursor,
_source: &str,
_diagnostics: &mut DiagnosticsInfo,
new_self: Box<Self>,
) -> ($crate::LoopControl, Box<Self>) {
($crate::LoopControl::DoNothing, new_self)
}
fn get_vec_loopcontrol() -> $crate::LoopControl {
$crate::LoopControl::DoNothing
}
fn get_allowed_tokens() -> Option<Vec<String>> {
None
}
}
};
( $x:ty, $t:tt ) => {
/// Deserialize a token with following pattern: `[REF:ty]`
impl<$t> TokenDeserialize for $x
where
$t: Default + $crate::TryFromArgumentGroup,
$x: Default + $crate::TryFromArgumentGroup,
{
fn deserialize_tokens(
mut cursor: &mut $crate::TreeCursor,
source: &str,
mut diagnostics: &mut DiagnosticsInfo,
) -> Result<Box<Self>, ()> {
// Get arguments from token
let mut token =
match $crate::Token::deserialize_tokens(&mut cursor, &source, &mut diagnostics)
{
Ok(token) => token,
Err(err) => {
// Token could not be parsed, so we can consume it.
// Because this will always fail.
$crate::Token::consume_token(&mut cursor)?;
return Err(err);
}
};
$crate::Token::consume_token(&mut cursor)?;
// Token Name
token.check_token_name(source, &mut diagnostics, true)?;
// Arg 0
let result =
Self::try_from_argument_group(&mut token, source, &mut diagnostics, true);
// Just check if all tokens are consumed if no other errors are present
if result.is_ok() {
token.check_all_arg_consumed(source, &mut diagnostics, true)?;
} else {
// In case of an error, mark other arguments as unchecked.
$crate::mark_rest_of_token_as_unchecked(diagnostics, &token);
}
Ok(Box::new(result?))
}
fn deserialize_general_token(
_cursor: &mut $crate::TreeCursor,
_source: &str,
_diagnostics: &mut DiagnosticsInfo,
new_self: Box<Self>,
) -> ($crate::LoopControl, Box<Self>) {
($crate::LoopControl::DoNothing, new_self)
}
fn get_vec_loopcontrol() -> $crate::LoopControl {
$crate::LoopControl::DoNothing
}
fn get_allowed_tokens() -> Option<Vec<String>> {
None
}
}
};
}