pub enum TypeExpr {
Named {
name: String,
args: Vec<TypeExpr>,
span: ExprSpan,
},
Array {
element: Box<TypeExpr>,
span: ExprSpan,
},
Tuple {
elements: Vec<TypeExpr>,
span: ExprSpan,
},
}Expand description
type_expression = identifier [ "(" [ type_expression { "," type_expression } ] ")" ] | "[" type_expression "]" | "(" [ type_expression ["," [ type_expression { "," type_expression } ]] ] ")".
() is the empty tuple type (0 elements); (T) is grouping (same as bare T); (T,) is a
1-element tuple; (T, U, ...) is n-element, no trailing comma. [T] names a rank-one array
whose elements have type T; nested brackets compose recursively. Name(A, B) names a
parameterized (generic) type applying zero or more type arguments (RangeInclusive(f64),
RangeFull()); an identifier immediately followed by ( has no other meaning in type
position, so this is unambiguous with adjacent tuple-grouping syntax.
Fn((A, B), R) reserves structural callable syntax: the first argument must be a tuple
of parameter types and the second is the result. Fn((), R) has no parameters;
Fn((A,), R) has one. This syntax is resolved before host generic-leaf lookup.
§Examples
See Self::resolve for parsing and resolving syntax.
Variants§
Named
A single type name, optionally applying type arguments, resolved later through a
TypeResolver.
Fields
Array
A recursively nested array type expression ([T]).
Fields
Tuple
A recursively nested tuple type expression.
Implementations§
Source§impl TypeExpr
impl TypeExpr
Sourcepub fn span(&self) -> ExprSpan
pub fn span(&self) -> ExprSpan
Returns this type expression’s source span.
§Examples
use cel_parser::{CELParser, OpLookup};
let ty = CELParser::new(OpLookup::new()).parse_type_expr_str("i32").unwrap();
assert_eq!(ty.span().start.start().column, 0);Sourcepub fn resolve(&self, resolver: &dyn TypeResolver) -> Result<ResolvedType>
pub fn resolve(&self, resolver: &dyn TypeResolver) -> Result<ResolvedType>
Resolves every named leaf through resolver, preserving the recursive type shape.
§Errors
Returns Err if some named leaf is not recognized by resolver, or Fn lacks
exactly two arguments with a tuple of parameter types first.
- Complexity: O(n) traversal and output nodes, plus resolver and descriptor-copy costs.
§Examples
use cel_parser::{CELParser, OpLookup, builtin_type_resolver};
let ty = CELParser::new(OpLookup::new()).parse_type_expr_str("[i32]").unwrap();
assert_eq!(ty.resolve(builtin_type_resolver().as_ref()).unwrap().display_name(), "[i32]");