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
#[macro_use]
use corollary_support::*;
use std::hash::{Hash, Hasher};
use data::position::*;
use data::node::*;
use data::name::Name;
#[derive(Clone, Debug, PartialEq, PartialOrd, Eq)]
pub enum SUERef {
AnonymousRef(Name),
NamedRef(Ident),
}
pub use self::SUERef::*;
impl SUERef {
pub fn is_anonymous(&self) -> bool {
match *self {
AnonymousRef(_) => true,
_ => false,
}
}
pub fn to_string(self) -> String {
match self {
AnonymousRef(_) => "".into(),
NamedRef(ident) => ident.to_string(),
}
}
}
#[derive(Clone, Debug, PartialOrd, Eq)]
pub struct Ident(pub String, pub NodeInfo);
impl Hash for Ident {
fn hash<H: Hasher>(&self, h: &mut H) {
(self.0).hash(h);
}
}
impl PartialEq for Ident {
fn eq(&self, other: &Self) -> bool {
self.0 == other.0
}
}
impl CNode for Ident {
fn node_info(&self) -> &NodeInfo {
&self.1
}
fn into_node_info(self) -> NodeInfo {
self.1
}
}
impl Ident {
pub fn new(pos: Position, s: String, name: Name) -> Ident {
let len = s.len() as isize;
Ident(s, NodeInfo::new(pos.clone(), (pos, len), name))
}
pub fn internal(s: String) -> Ident {
Ident(s, NodeInfo::with_only_pos(Position::internal()))
}
pub fn internal_at(pos: Position, s: String) -> Ident {
let len = s.len() as isize;
Ident(s, NodeInfo::with_pos_len(pos.clone(), (pos, len)))
}
pub fn builtin(s: String) -> Ident {
Ident(s, NodeInfo::with_only_pos(Position::builtin()))
}
pub fn is_internal(&self) -> bool {
self.1.pos().isInternal()
}
pub fn to_string(self) -> String {
self.0
}
pub fn dump(&self) -> String {
format!("{:?} at {:?}", self.0, self.1)
}
}