@@ -17,6 +17,7 @@ Item: Option<Item> = {
17
17
TraitDefn => Some(Item::TraitDefn(<>)),
18
18
Impl => Some(Item::Impl(<>)),
19
19
Clause => Some(Item::Clause(<>)),
20
+ Scalar => Some(Item::Scalar(<>)),
20
21
};
21
22
22
23
Comment: () = r"//.*";
@@ -217,6 +218,82 @@ Field: Field = {
217
218
}
218
219
};
219
220
221
+ Scalar: Scalar = {
222
+ <s:ScalarValue> => Scalar { name: None, value: s },
223
+ };
224
+
225
+ ScalarValue: ScalarValue = {
226
+ <Boolean> => ScalarValue::Bool(<>),
227
+ <Decimal> => <>,
228
+ };
229
+
230
+ Boolean: bool = <"(true|false)"> => <> == "true";
231
+
232
+ Decimal: ScalarValue = <s:r"-?[0-9][0-9_]*((u|i)(8|16|32|64|128|size))?"> => {
233
+ let mut negated = false;
234
+ let mut digits = String::new();
235
+ let mut end_type: Option<&str> = None;
236
+ if s.chars().next().unwrap() == '-' {
237
+ negated = true;
238
+ digits.push('-');
239
+ }
240
+ for (i, c) in s.chars().enumerate().skip(negated as usize) {
241
+ if c >= '0' && c <= '9' {
242
+ digits.push(c);
243
+ } else if c == 'i' || c == 'u' {
244
+ end_type = Some(&s[i..]);
245
+ break;
246
+ }
247
+ }
248
+ if let Some(et) = end_type {
249
+ // TODO: proper error handling here
250
+ match et {
251
+ "u8" => ScalarValue::Uint(UintValue::U8(
252
+ digits.parse::<u8>().expect("failed to parse u8"),
253
+ )),
254
+ "u16" => ScalarValue::Uint(UintValue::U16(
255
+ digits.parse::<u16>().expect("failed to parse u16"),
256
+ )),
257
+ "u32" => ScalarValue::Uint(UintValue::U32(
258
+ digits.parse::<u32>().expect("failed to parse u32"),
259
+ )),
260
+ "u64" => ScalarValue::Uint(UintValue::U64(
261
+ digits.parse::<u64>().expect("failed to parse u64"),
262
+ )),
263
+ "u128" => ScalarValue::Uint(UintValue::U128(
264
+ digits.parse::<u128>().expect("failed to parse u128"),
265
+ )),
266
+ "usize" => ScalarValue::Uint(UintValue::Usize(
267
+ digits.parse::<usize>().expect("failed to parse usize"),
268
+ )),
269
+ "i8" => ScalarValue::Int(IntValue::I8(
270
+ digits.parse::<i8>().expect("failed to parse i8"),
271
+ )),
272
+ "i16" => ScalarValue::Int(IntValue::I16(
273
+ digits.parse::<i16>().expect("failed to parse i16"),
274
+ )),
275
+ "i32" => ScalarValue::Int(IntValue::I32(
276
+ digits.parse::<i32>().expect("failed to parse i32"),
277
+ )),
278
+ "i64" => ScalarValue::Int(IntValue::I64(
279
+ digits.parse::<i64>().expect("failed to parse i64"),
280
+ )),
281
+ "i128" => ScalarValue::Int(IntValue::I128(
282
+ digits.parse::<i128>().expect("failed to parse i128"),
283
+ )),
284
+ "isize" => ScalarValue::Int(IntValue::Isize(
285
+ digits.parse::<isize>().expect("failed to parse isize"),
286
+ )),
287
+ otherwise => unreachable!("Unknown numeric type suffix found: `{}`", otherwise),
288
+ }
289
+ } else {
290
+ // TODO: try various parsers/do whatever rustc does here
291
+ ScalarValue::Uint(UintValue::U32(
292
+ digits.parse::<u32>().expect("failed to parse u32"),
293
+ ))
294
+ }
295
+ };
296
+
220
297
Clause: Clause = {
221
298
"forall" <pk:Angle<ParameterKind>> "{" <dg:DomainGoal> "if" <g:Comma<Goal1>> "}" => Clause {
222
299
parameter_kinds: pk,
0 commit comments