1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#[macro_use]
use corollary_support::*;
use data::name::Name;
use data::position::*;
use std::fmt;
#[derive(Clone, Eq, Ord, PartialEq, PartialOrd, Hash)]
pub enum NodeInfo {
OnlyPos(Position, PosLength),
NodeInfo(Position, PosLength, Name),
}
pub use self::NodeInfo::*;
impl fmt::Debug for NodeInfo {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "..")
}
}
impl Pos for NodeInfo {
fn posOf(self) -> Position {
match self {
NodeInfo::OnlyPos(pos, _) => pos,
NodeInfo::NodeInfo(pos, _, _) => pos
}
}
}
pub fn lengthOfNode(ni: NodeInfo) -> Option<isize> {
let computeLength = |pos, (lastPos, lastTokLen)| {
if lastTokLen < 0 {
None
} else {
Some(posOffset(lastPos) + lastTokLen - posOffset(pos))
}
};
let len = match ni {
NodeInfo(firstPos, lastTok, _) => computeLength(firstPos, lastTok),
OnlyPos(firstPos, lastTok) => computeLength(firstPos, lastTok),
};
len
}
pub fn getLastTokenPos(_0: NodeInfo) -> PosLength {
match (_0) {
NodeInfo(_, lastTok, _) => lastTok,
OnlyPos(_, lastTok) => lastTok,
}
}
pub trait CNode {
fn nodeInfo(self) -> NodeInfo;
}
impl CNode for NodeInfo {
fn nodeInfo(self) -> NodeInfo { self }
}
pub fn nodeInfo<T: CNode>(n: T) -> NodeInfo {
n.nodeInfo()
}
pub fn nameOfNode(_0: NodeInfo) -> Option<Name> {
match (_0) {
OnlyPos(_, _) => None,
NodeInfo(_, _, name) => Some(name),
}
}
pub fn posOfNode(ni: NodeInfo) -> Position {
match ni {
OnlyPos(pos, _) => pos,
NodeInfo(pos, _, _) => pos,
}
}
pub fn fileOfNode<A: CNode>(obj: A) -> Option<FilePath> {
fn justIf<T>(predicate: bool, x: T) -> Option<T> {
if predicate { Some(x) } else { None }
}
unreachable!()
}
pub fn eqByName<A: CNode>(obj1: A, obj2: A) -> bool {
obj1.nodeInfo() == obj2.nodeInfo()
}
pub fn internalNode() -> NodeInfo {
undefNode()
}
pub fn undefNode() -> NodeInfo {
OnlyPos(nopos(), (nopos(), -(1)))
}
pub fn mkNodeInfoOnlyPos(pos: Position) -> NodeInfo {
OnlyPos(pos, (nopos(), -(1)))
}
pub fn mkNodeInfoPosLen(a: Position, b: PosLength) -> NodeInfo {
OnlyPos(a, b)
}
pub fn mkNodeInfo(pos: Position, name: Name) -> NodeInfo {
NodeInfo(pos, (nopos(), -(1)), name)
}
pub fn mkNodeInfo_q(pos: Position, lasttok: PosLength, name: Name) -> NodeInfo {
NodeInfo(pos, lasttok, name)
}