1ast_enum! {
10 #[cfg_attr(feature = "clone-impls", derive(Copy))]
15 pub enum BinOp {
16 Add(Token![+]),
18 Sub(Token![-]),
20 Mul(Token![*]),
22 Div(Token![/]),
24 Rem(Token![%]),
26 And(Token![&&]),
28 Or(Token![||]),
30 BitXor(Token![^]),
32 BitAnd(Token![&]),
34 BitOr(Token![|]),
36 Shl(Token![<<]),
38 Shr(Token![>>]),
40 Eq(Token![==]),
42 Lt(Token![<]),
44 Le(Token![<=]),
46 Ne(Token![!=]),
48 Ge(Token![>=]),
50 Gt(Token![>]),
52 AddEq(Token![+=]),
54 SubEq(Token![-=]),
56 MulEq(Token![*=]),
58 DivEq(Token![/=]),
60 RemEq(Token![%=]),
62 BitXorEq(Token![^=]),
64 BitAndEq(Token![&=]),
66 BitOrEq(Token![|=]),
68 ShlEq(Token![<<=]),
70 ShrEq(Token![>>=]),
72 }
73}
74
75ast_enum! {
76 #[cfg_attr(feature = "clone-impls", derive(Copy))]
81 pub enum UnOp {
82 Deref(Token![*]),
84 Not(Token![!]),
86 Neg(Token![-]),
88 }
89}
90
91#[cfg(feature = "parsing")]
92pub mod parsing {
93 use super::*;
94 use synom::Synom;
95
96 impl BinOp {
97 named!(pub parse_binop -> Self, alt!(
98 punct!(&&) => { BinOp::And }
99 |
100 punct!(||) => { BinOp::Or }
101 |
102 punct!(<<) => { BinOp::Shl }
103 |
104 punct!(>>) => { BinOp::Shr }
105 |
106 punct!(==) => { BinOp::Eq }
107 |
108 punct!(<=) => { BinOp::Le }
109 |
110 punct!(!=) => { BinOp::Ne }
111 |
112 punct!(>=) => { BinOp::Ge }
113 |
114 punct!(+) => { BinOp::Add }
115 |
116 punct!(-) => { BinOp::Sub }
117 |
118 punct!(*) => { BinOp::Mul }
119 |
120 punct!(/) => { BinOp::Div }
121 |
122 punct!(%) => { BinOp::Rem }
123 |
124 punct!(^) => { BinOp::BitXor }
125 |
126 punct!(&) => { BinOp::BitAnd }
127 |
128 punct!(|) => { BinOp::BitOr }
129 |
130 punct!(<) => { BinOp::Lt }
131 |
132 punct!(>) => { BinOp::Gt }
133 ));
134
135 #[cfg(feature = "full")]
136 named!(pub parse_assign_op -> Self, alt!(
137 punct!(+=) => { BinOp::AddEq }
138 |
139 punct!(-=) => { BinOp::SubEq }
140 |
141 punct!(*=) => { BinOp::MulEq }
142 |
143 punct!(/=) => { BinOp::DivEq }
144 |
145 punct!(%=) => { BinOp::RemEq }
146 |
147 punct!(^=) => { BinOp::BitXorEq }
148 |
149 punct!(&=) => { BinOp::BitAndEq }
150 |
151 punct!(|=) => { BinOp::BitOrEq }
152 |
153 punct!(<<=) => { BinOp::ShlEq }
154 |
155 punct!(>>=) => { BinOp::ShrEq }
156 ));
157 }
158
159 impl Synom for UnOp {
160 named!(parse -> Self, alt!(
161 punct!(*) => { UnOp::Deref }
162 |
163 punct!(!) => { UnOp::Not }
164 |
165 punct!(-) => { UnOp::Neg }
166 ));
167
168 fn description() -> Option<&'static str> {
169 Some("unary operator: `*`, `!`, or `-`")
170 }
171 }
172}
173
174#[cfg(feature = "printing")]
175mod printing {
176 use super::*;
177 use quote::{ToTokens, Tokens};
178
179 impl ToTokens for BinOp {
180 fn to_tokens(&self, tokens: &mut Tokens) {
181 match *self {
182 BinOp::Add(ref t) => t.to_tokens(tokens),
183 BinOp::Sub(ref t) => t.to_tokens(tokens),
184 BinOp::Mul(ref t) => t.to_tokens(tokens),
185 BinOp::Div(ref t) => t.to_tokens(tokens),
186 BinOp::Rem(ref t) => t.to_tokens(tokens),
187 BinOp::And(ref t) => t.to_tokens(tokens),
188 BinOp::Or(ref t) => t.to_tokens(tokens),
189 BinOp::BitXor(ref t) => t.to_tokens(tokens),
190 BinOp::BitAnd(ref t) => t.to_tokens(tokens),
191 BinOp::BitOr(ref t) => t.to_tokens(tokens),
192 BinOp::Shl(ref t) => t.to_tokens(tokens),
193 BinOp::Shr(ref t) => t.to_tokens(tokens),
194 BinOp::Eq(ref t) => t.to_tokens(tokens),
195 BinOp::Lt(ref t) => t.to_tokens(tokens),
196 BinOp::Le(ref t) => t.to_tokens(tokens),
197 BinOp::Ne(ref t) => t.to_tokens(tokens),
198 BinOp::Ge(ref t) => t.to_tokens(tokens),
199 BinOp::Gt(ref t) => t.to_tokens(tokens),
200 BinOp::AddEq(ref t) => t.to_tokens(tokens),
201 BinOp::SubEq(ref t) => t.to_tokens(tokens),
202 BinOp::MulEq(ref t) => t.to_tokens(tokens),
203 BinOp::DivEq(ref t) => t.to_tokens(tokens),
204 BinOp::RemEq(ref t) => t.to_tokens(tokens),
205 BinOp::BitXorEq(ref t) => t.to_tokens(tokens),
206 BinOp::BitAndEq(ref t) => t.to_tokens(tokens),
207 BinOp::BitOrEq(ref t) => t.to_tokens(tokens),
208 BinOp::ShlEq(ref t) => t.to_tokens(tokens),
209 BinOp::ShrEq(ref t) => t.to_tokens(tokens),
210 }
211 }
212 }
213
214 impl ToTokens for UnOp {
215 fn to_tokens(&self, tokens: &mut Tokens) {
216 match *self {
217 UnOp::Deref(ref t) => t.to_tokens(tokens),
218 UnOp::Not(ref t) => t.to_tokens(tokens),
219 UnOp::Neg(ref t) => t.to_tokens(tokens),
220 }
221 }
222 }
223}