- Renamed "intrinsic" -> "primitive" - I thought it was funny, but it's just annoying. - Rename "Uninferred" -> "Inferred" - It's a concrete type, but an inferred one. - Add lifetimes to the Entry API - Categorize does not care about recursive types. You can't have a recursive AST. - Added helpful constructors to the inference engine - Added some overloadable operators to the inference engine - These are a MAJOR work in progress - Reorganized the Inference implementation file by functionality. stdlib: - Updated standard library.
61 lines
1.6 KiB
Rust
61 lines
1.6 KiB
Rust
//! Utils for [Path]
|
|
use crate::{PathPart, Sym, ast::Path};
|
|
|
|
impl Path {
|
|
/// Appends a [PathPart] to this [Path]
|
|
pub fn push(&mut self, part: PathPart) {
|
|
self.parts.push(part);
|
|
}
|
|
/// Removes a [PathPart] from this [Path]
|
|
pub fn pop(&mut self) -> Option<PathPart> {
|
|
self.parts.pop()
|
|
}
|
|
/// Concatenates `self::other`. If `other` is an absolute [Path],
|
|
/// this replaces `self` with `other`
|
|
pub fn concat(mut self, other: &Self) -> Self {
|
|
if other.absolute {
|
|
other.clone()
|
|
} else {
|
|
self.parts.extend(other.parts.iter().cloned());
|
|
self
|
|
}
|
|
}
|
|
|
|
/// Gets the defining [Sym] of this path
|
|
pub fn as_sym(&self) -> Option<Sym> {
|
|
match self.parts.as_slice() {
|
|
[.., PathPart::Ident(name)] => Some(*name),
|
|
_ => None,
|
|
}
|
|
}
|
|
|
|
/// Checks whether this path ends in the given [Sym]
|
|
pub fn ends_with(&self, name: &str) -> bool {
|
|
match self.parts.as_slice() {
|
|
[.., PathPart::Ident(last)] => name == &**last,
|
|
_ => false,
|
|
}
|
|
}
|
|
|
|
/// Checks whether this path refers to the sinkhole identifier, `_`
|
|
pub fn is_sinkhole(&self) -> bool {
|
|
if let [PathPart::Ident(id)] = self.parts.as_slice() {
|
|
if let "_" = id.to_ref() {
|
|
return true;
|
|
}
|
|
}
|
|
false
|
|
}
|
|
}
|
|
impl PathPart {
|
|
pub fn from_sym(ident: Sym) -> Self {
|
|
Self::Ident(ident)
|
|
}
|
|
}
|
|
|
|
impl From<Sym> for Path {
|
|
fn from(value: Sym) -> Self {
|
|
Self { parts: vec![PathPart::Ident(value)], absolute: false }
|
|
}
|
|
}
|