impl Eq for Constant {}
impl Constant {
- pub fn to_atom(self) -> Option<ClauseName> {
+ pub fn to_atom(&self) -> Option<ClauseName> {
match self {
Constant::Atom(a, _) => Some(a.defrock_brackets()),
_ => None,
!self.as_str().is_empty() && self.as_str().chars().nth(1).is_none()
}
- pub fn defrock_brackets(self) -> Self {
+ pub fn defrock_brackets(&self) -> Self {
fn defrock_brackets(s: &str) -> &str {
if s.starts_with('(') && s.ends_with(')') {
&s[1..s.len() - 1]
}
}
- pub fn to_constant(self) -> Option<Constant> {
+ pub fn into_constant(self) -> Option<Constant> {
match self {
Term::Constant(_, c) => Some(c),
_ => None,
let name = *terms.pop().unwrap();
let arity = arity
- .to_constant()
+ .into_constant()
.and_then(|c| match c {
Constant::Integer(n) => n.to_usize(),
Constant::Fixnum(n) => usize::try_from(n).ok(),
.ok_or(CompilationError::InvalidModuleExport)?;
let name = name
- .to_constant()
+ .into_constant()
.and_then(|c| c.to_atom())
.ok_or(CompilationError::InvalidModuleExport)?;
export_list = *t2;
}
- if export_list.to_constant() != Some(Constant::EmptyList) {
+ if export_list.into_constant() != Some(Constant::EmptyList) {
Err(CompilationError::InvalidModuleDecl)
} else {
Ok(exports)
let name = terms
.pop()
.unwrap()
- .to_constant()
+ .into_constant()
.and_then(|c| c.to_atom())
.ok_or(CompilationError::InvalidModuleDecl)?;
terms
.pop()
.unwrap()
- .to_constant()
+ .into_constant()
.and_then(|c| c.to_atom())
.map(|c| ModuleSource::Library(c))
.ok_or(CompilationError::InvalidUseModuleDecl)
terms
.pop()
.unwrap()
- .to_constant()
+ .into_constant()
.and_then(|c| c.to_atom())
.map(|c| ModuleSource::Library(c))
.ok_or(CompilationError::InvalidUseModuleDecl)
export_list = *t2;
}
- if export_list.to_constant() != Some(Constant::EmptyList) {
+ if export_list.into_constant() != Some(Constant::EmptyList) {
Err(CompilationError::InvalidModuleDecl)
} else {
Ok((module_src, exports))