kodept_core/structure/rlt/
term.rs1use derive_more::From;
2
3use crate::code_point::CodePoint;
4use crate::structure::Located;
5use crate::structure::rlt::Context;
6use crate::structure::rlt::new_types::{Identifier, TypeName};
7
8#[derive(Debug, Clone, PartialEq, From)]
9pub enum Term {
10 Reference(Reference),
11 Contextual(ContextualReference)
12}
13
14#[derive(Debug, Clone, PartialEq)]
15pub enum Reference {
16 Type(TypeName),
17 Identifier(Identifier),
18}
19
20#[derive(Debug, Clone, PartialEq)]
21pub struct ContextualReference {
22 pub context: Context,
23 pub inner: Reference
24}
25
26impl Located for Term {
27 fn location(&self) -> CodePoint {
28 match self {
29 Term::Reference(x) => x.location(),
30 Term::Contextual(x) => x.location()
31 }
32 }
33}
34
35impl Located for ContextualReference {
36 fn location(&self) -> CodePoint {
37 let (_, unfolded) = self.context.clone().unfold();
38 let first = unfolded.first().unwrap_or(&self.inner);
39 let last = &self.inner;
40 let length = last.location().offset + last.location().length - first.location().offset;
41 CodePoint::new(length, first.location().offset)
42 }
43}
44
45impl Located for Reference {
46 fn location(&self) -> CodePoint {
47 match self {
48 Reference::Type(x) => x.location(),
49 Reference::Identifier(x) => x.location(),
50 }
51 }
52}