air_lambda_ast/ast.rs
1/*
2 * Copyright 2021 Fluence Labs Limited
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17mod impls;
18mod traits;
19
20use non_empty_vec::NonEmpty;
21use serde::Deserialize;
22use serde::Serialize;
23
24// TODO: rename lambda to smth more appropriate
25#[derive(Debug, PartialEq, Eq, Clone, Serialize, Deserialize)]
26pub enum LambdaAST<'input> {
27 /// Various functors that could applied to a value.
28 Functor(Functor),
29 /// Each value in AIR could be represented as a tree and
30 /// this variant acts as a path in such trees.
31 #[serde(borrow)]
32 ValuePath(NonEmpty<ValueAccessor<'input>>),
33}
34
35#[derive(Debug, PartialEq, Eq, Clone, Copy, Serialize, Deserialize)]
36pub enum ValueAccessor<'input> {
37 // (.)?[$idx]
38 ArrayAccess { idx: u32 },
39
40 // .field
41 FieldAccessByName { field_name: &'input str },
42
43 // (.)?[field]
44 FieldAccessByScalar { scalar_name: &'input str },
45
46 // needed to allow parser catch all errors from a lambda expression without stopping
47 // on the very first one. Although, this variant is guaranteed not to be present in a lambda.
48 Error,
49}
50
51#[derive(Debug, PartialEq, Eq, Clone, Copy, Serialize, Deserialize)]
52pub enum Functor {
53 /// Returns a length of a value if this value has array type (json array or canon stream)
54 /// or a error if not.
55 Length,
56}