conlang: Remove "self" keyword

This commit is contained in:
John 2025-05-05 02:20:47 -04:00
parent 7c2dd1468b
commit fc80be5fcc
12 changed files with 12 additions and 22 deletions

View File

@ -285,7 +285,6 @@ pub struct Path {
#[derive(Clone, Debug, PartialEq, Eq, Hash)] #[derive(Clone, Debug, PartialEq, Eq, Hash)]
pub enum PathPart { pub enum PathPart {
SuperKw, SuperKw,
SelfKw,
SelfTy, SelfTy,
Ident(Sym), Ident(Sym),
} }

View File

@ -4,7 +4,6 @@ use super::*;
impl<T: AsRef<str>> From<T> for PathPart { impl<T: AsRef<str>> From<T> for PathPart {
fn from(value: T) -> Self { fn from(value: T) -> Self {
match value.as_ref() { match value.as_ref() {
"self" => PathPart::SelfKw,
"super" => PathPart::SuperKw, "super" => PathPart::SuperKw,
ident => PathPart::Ident(ident.into()), ident => PathPart::Ident(ident.into()),
} }

View File

@ -370,7 +370,6 @@ impl Display for PathPart {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self { match self {
PathPart::SuperKw => "super".fmt(f), PathPart::SuperKw => "super".fmt(f),
PathPart::SelfKw => "self".fmt(f),
PathPart::SelfTy => "Self".fmt(f), PathPart::SelfTy => "Self".fmt(f),
PathPart::Ident(id) => id.fmt(f), PathPart::Ident(id) => id.fmt(f),
} }

View File

@ -264,7 +264,6 @@ impl WeightOf for PathPart {
fn weight_of(&self) -> usize { fn weight_of(&self) -> usize {
match self { match self {
PathPart::SuperKw => size_of_val(self), PathPart::SuperKw => size_of_val(self),
PathPart::SelfKw => size_of_val(self),
PathPart::SelfTy => size_of_val(self), PathPart::SelfTy => size_of_val(self),
PathPart::Ident(interned) => interned.weight_of(), PathPart::Ident(interned) => interned.weight_of(),
} }

View File

@ -210,7 +210,6 @@ pub trait Fold {
fn fold_path_part(&mut self, p: PathPart) -> PathPart { fn fold_path_part(&mut self, p: PathPart) -> PathPart {
match p { match p {
PathPart::SuperKw => PathPart::SuperKw, PathPart::SuperKw => PathPart::SuperKw,
PathPart::SelfKw => PathPart::SelfKw,
PathPart::SelfTy => PathPart::SelfTy, PathPart::SelfTy => PathPart::SelfTy,
PathPart::Ident(i) => PathPart::Ident(self.fold_sym(i)), PathPart::Ident(i) => PathPart::Ident(self.fold_sym(i)),
} }

View File

@ -464,7 +464,6 @@ impl Walk for PathPart {
fn children<'a, V: Visit<'a>>(&'a self, v: &mut V) { fn children<'a, V: Visit<'a>>(&'a self, v: &mut V) {
match self { match self {
PathPart::SuperKw => {} PathPart::SuperKw => {}
PathPart::SelfKw => {}
PathPart::SelfTy => {} PathPart::SelfTy => {}
PathPart::Ident(sym) => sym.visit_in(v), PathPart::Ident(sym) => sym.visit_in(v),
} }

View File

@ -512,7 +512,6 @@ mod assignment {
_ => Err(Error::NotIndexable()), _ => Err(Error::NotIndexable()),
} }
} }
[PathPart::SelfKw, rest @ ..] => project_path_in_namespace(env, rest),
[PathPart::SelfTy, ..] => todo!("calc_address for `Self`"), [PathPart::SelfTy, ..] => todo!("calc_address for `Self`"),
[PathPart::SuperKw, ..] => todo!("calc_address for `super`"), [PathPart::SuperKw, ..] => todo!("calc_address for `super`"),
} }
@ -764,7 +763,6 @@ impl Interpret for Structor {
let name = match parts.last() { let name = match parts.last() {
Some(PathPart::Ident(name)) => *name, Some(PathPart::Ident(name)) => *name,
Some(PathPart::SelfKw) => "self".into(),
Some(PathPart::SelfTy) => "Self".into(), Some(PathPart::SelfTy) => "Self".into(),
Some(PathPart::SuperKw) => "super".into(), Some(PathPart::SuperKw) => "super".into(),
None => "".into(), None => "".into(),

View File

@ -188,11 +188,7 @@ macro literal_like() {
/// Expands to a pattern which matches path-like [TokenKinds](TokenKind) /// Expands to a pattern which matches path-like [TokenKinds](TokenKind)
macro path_like() { macro path_like() {
TokenKind::Super TokenKind::Super | TokenKind::SelfTy | TokenKind::Identifier | TokenKind::ColonColon
| TokenKind::SelfKw
| TokenKind::SelfTy
| TokenKind::Identifier
| TokenKind::ColonColon
} }
pub trait Parse<'t>: Sized { pub trait Parse<'t>: Sized {
@ -689,7 +685,7 @@ impl Parse<'_> for UseTree {
CURLIES, CURLIES,
P, P,
)(p)?), )(p)?),
TokenKind::SelfKw | TokenKind::Super | TokenKind::Identifier => { TokenKind::Super | TokenKind::Identifier => {
let name = PathPart::parse(p)?; let name = PathPart::parse(p)?;
if p.match_type(TokenKind::ColonColon, P).is_ok() { if p.match_type(TokenKind::ColonColon, P).is_ok() {
UseTree::Path(name, Box::new(UseTree::parse(p)?)) UseTree::Path(name, Box::new(UseTree::parse(p)?))
@ -864,7 +860,6 @@ impl Parse<'_> for PathPart {
const P: Parsing = Parsing::PathPart; const P: Parsing = Parsing::PathPart;
let out = match p.peek_kind(P)? { let out = match p.peek_kind(P)? {
TokenKind::Super => PathPart::SuperKw, TokenKind::Super => PathPart::SuperKw,
TokenKind::SelfKw => PathPart::SelfKw,
TokenKind::SelfTy => PathPart::SelfTy, TokenKind::SelfTy => PathPart::SelfTy,
TokenKind::Identifier => PathPart::Ident(Sym::parse(p)?), TokenKind::Identifier => PathPart::Ident(Sym::parse(p)?),
t => return Err(p.error(Unexpected(t), P)), t => return Err(p.error(Unexpected(t), P)),

View File

@ -664,7 +664,6 @@ pub mod yamlify {
fn yaml(&self, y: &mut Yamler) { fn yaml(&self, y: &mut Yamler) {
match self { match self {
PathPart::SuperKw => y.value("super"), PathPart::SuperKw => y.value("super"),
PathPart::SelfKw => y.value("self"),
PathPart::SelfTy => y.value("Self"), PathPart::SelfTy => y.value("Self"),
PathPart::Ident(i) => y.yaml(i), PathPart::Ident(i) => y.yaml(i),
}; };

View File

@ -33,7 +33,6 @@ pub enum TokenKind {
Mut, // "mut" Mut, // "mut"
Pub, // "pub" Pub, // "pub"
Return, // "return" Return, // "return"
SelfKw, // "self"
SelfTy, // "Self" SelfTy, // "Self"
Static, // "static" Static, // "static"
Struct, // "struct" Struct, // "struct"
@ -127,7 +126,6 @@ impl Display for TokenKind {
TokenKind::Mut => "mut".fmt(f), TokenKind::Mut => "mut".fmt(f),
TokenKind::Pub => "pub".fmt(f), TokenKind::Pub => "pub".fmt(f),
TokenKind::Return => "return".fmt(f), TokenKind::Return => "return".fmt(f),
TokenKind::SelfKw => "self".fmt(f),
TokenKind::SelfTy => "Self".fmt(f), TokenKind::SelfTy => "Self".fmt(f),
TokenKind::Static => "static".fmt(f), TokenKind::Static => "static".fmt(f),
TokenKind::Struct => "struct".fmt(f), TokenKind::Struct => "struct".fmt(f),
@ -220,7 +218,6 @@ impl FromStr for TokenKind {
"mut" => Self::Mut, "mut" => Self::Mut,
"pub" => Self::Pub, "pub" => Self::Pub,
"return" => Self::Return, "return" => Self::Return,
"self" => Self::SelfKw,
"Self" => Self::SelfTy, "Self" => Self::SelfTy,
"static" => Self::Static, "static" => Self::Static,
"struct" => Self::Struct, "struct" => Self::Struct,

View File

@ -245,6 +245,14 @@ impl<'a> Table<'a> {
} }
} }
pub fn super_of(&self, node: Handle) -> Option<Handle> {
match self.kinds.get(node)? {
NodeKind::Root => None,
NodeKind::Module => self.parent(node).copied(),
_ => self.super_of(*self.parent(node)?),
}
}
pub fn name(&self, node: Handle) -> Option<Sym> { pub fn name(&self, node: Handle) -> Option<Sym> {
self.source(node).and_then(|s| s.name()) self.source(node).and_then(|s| s.name())
} }
@ -280,8 +288,7 @@ impl<'a> Table<'a> {
/// Does path traversal relative to the provided `node`. /// Does path traversal relative to the provided `node`.
pub fn nav(&self, node: Handle, path: &[PathPart]) -> Option<Handle> { pub fn nav(&self, node: Handle, path: &[PathPart]) -> Option<Handle> {
match path { match path {
[PathPart::SuperKw, rest @ ..] => self.nav(*self.parent(node)?, rest), [PathPart::SuperKw, rest @ ..] => self.nav(self.super_of(node)?, rest),
[PathPart::SelfKw, rest @ ..] => self.nav(node, rest),
[PathPart::SelfTy, rest @ ..] => self.nav(self.selfty(node)?, rest), [PathPart::SelfTy, rest @ ..] => self.nav(self.selfty(node)?, rest),
[PathPart::Ident(name), rest @ ..] => self.nav(self.get_by_sym(node, name)?, rest), [PathPart::Ident(name), rest @ ..] => self.nav(self.get_by_sym(node, name)?, rest),
[] => Some(node), [] => Some(node),

View File

@ -4,7 +4,7 @@ use super::preamble::*;
struct UnitLike; struct UnitLike;
struct TupleLike(super::num::i32, super::self::test::char) struct TupleLike(super::num::i32, super::test::char)
struct StructLike { struct StructLike {
pub member1: UnitLike, pub member1: UnitLike,