mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-30 23:31:12 +00:00
Overhaul canonicalization to use global symbols.
This commit is contained in:
parent
1b5df3f1c3
commit
74ad51aae9
4 changed files with 608 additions and 582 deletions
36
src/expr.rs
36
src/expr.rs
|
@ -40,7 +40,7 @@ pub enum Expr {
|
|||
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
|
||||
pub enum VariantName {
|
||||
Unqualified(String),
|
||||
Qualified(Path, String),
|
||||
Qualified(String, String),
|
||||
}
|
||||
|
||||
/// An identifier, possibly fully-qualified with a module name
|
||||
|
@ -49,7 +49,7 @@ pub enum VariantName {
|
|||
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
|
||||
pub enum Ident {
|
||||
Unqualified(String),
|
||||
Qualified(Path, String),
|
||||
Qualified(String, String),
|
||||
}
|
||||
|
||||
impl Ident {
|
||||
|
@ -68,34 +68,6 @@ impl Ident {
|
|||
}
|
||||
}
|
||||
|
||||
/// A path to a module, which may include the package it came from.
|
||||
#[derive(Clone, Debug, Hash, PartialEq, Eq)]
|
||||
pub struct Path(String);
|
||||
|
||||
impl Path {
|
||||
pub fn new(string: String) -> Path {
|
||||
Path(string)
|
||||
}
|
||||
|
||||
pub fn into_string(self) -> String {
|
||||
let Path(str) = self;
|
||||
|
||||
str
|
||||
}
|
||||
}
|
||||
|
||||
impl Into<String> for Path {
|
||||
fn into(self) -> String {
|
||||
self.into_string()
|
||||
}
|
||||
}
|
||||
|
||||
impl From<String> for Path {
|
||||
fn from(str: String) -> Self {
|
||||
Path(str)
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Display for Ident {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
match self {
|
||||
|
@ -103,7 +75,7 @@ impl fmt::Display for Ident {
|
|||
write!(f, "{}", name)
|
||||
},
|
||||
Ident::Qualified(path, name) => {
|
||||
write!(f, "{}.{}", path.clone().into_string(), name)
|
||||
write!(f, "{}.{}", path, name)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -116,7 +88,7 @@ impl fmt::Display for VariantName {
|
|||
write!(f, "{}", name)
|
||||
},
|
||||
VariantName::Qualified(path, name) => {
|
||||
write!(f, "{}.{}", path.clone().into_string(), name)
|
||||
write!(f, "{}.{}", path, name)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue