cl-ast: Clean up "to", "extents", Module."kind"

This commit is contained in:
2025-03-14 00:52:43 -05:00
parent 11c8daaed0
commit 33e13425a9
13 changed files with 95 additions and 99 deletions

View File

@@ -63,13 +63,13 @@ impl ModuleInliner {
impl Fold for ModuleInliner {
/// Traverses down the module tree, entering ever nested directories
fn fold_module(&mut self, m: Module) -> Module {
let Module { name, kind } = m;
let Module { name, file } = m;
self.path.push(&*name); // cd ./name
let kind = self.fold_module_kind(kind);
let file = self.fold_module_kind(file);
self.path.pop(); // cd ..
Module { name, kind }
Module { name, file }
}
}

View File

@@ -320,7 +320,7 @@ impl Parse<'_> for Item {
attrs: Attrs::parse(p)?,
vis: Visibility::parse(p)?,
kind: ItemKind::parse(p)?,
extents: Span(start, p.loc()),
span: Span(start, p.loc()),
})
}
}
@@ -352,7 +352,7 @@ impl Parse<'_> for Alias {
p.consume_peeked();
let out = Ok(Alias {
to: Sym::parse(p)?,
name: Sym::parse(p)?,
from: if p.match_type(TokenKind::Eq, P).is_ok() {
Some(Ty::parse(p)?.into())
} else {
@@ -416,7 +416,7 @@ impl Parse<'_> for Module {
Ok(Module {
name: Sym::parse(p)?,
kind: {
file: {
const P: Parsing = Parsing::ModuleKind;
let inline = delim(Parse::parse, CURLIES, P);
@@ -636,7 +636,7 @@ impl Parse<'_> for ImplKind {
Err(Error {
reason: ExpectedParsing { want: Parsing::Path },
while_parsing: P,
loc: target.extents.head,
loc: target.span.head,
})?
}
}
@@ -696,7 +696,7 @@ impl Parse<'_> for Ty {
/// See also: [TyKind::parse]
fn parse(p: &mut Parser<'_>) -> PResult<Self> {
let start = p.loc();
Ok(Ty { kind: TyKind::parse(p)?, extents: Span(start, p.loc()) })
Ok(Ty { kind: TyKind::parse(p)?, span: Span(start, p.loc()) })
}
}
@@ -868,7 +868,7 @@ impl Parse<'_> for Stmt {
Ok(_) => Semi::Terminated,
_ => Semi::Unterminated,
},
extents: Span(start, p.loc()),
span: Span(start, p.loc()),
})
}
}
@@ -984,7 +984,7 @@ impl Parse<'_> for AddrOf {
mutable: Mutability::parse(p)?,
expr: Expr::parse(p)?.into(),
}),
extents: Span(start, p.loc()),
span: Span(start, p.loc()),
}
.into(),
})

View File

@@ -41,7 +41,7 @@ pub fn expr(p: &mut Parser, power: u8) -> PResult<Expr> {
Unary { kind, tail: expr(p, after)?.into() }.into()
}
},
extents: Span(start, p.loc()),
span: Span(start, p.loc()),
};
fn from_postfix(op: TokenKind) -> Option<Precedence> {
@@ -80,10 +80,7 @@ pub fn expr(p: &mut Parser, power: u8) -> PResult<Expr> {
kind: BinaryKind::Call,
parts: (
head,
Expr {
kind: Tuple { exprs }.into(),
extents: Span(start, p.loc()),
},
Expr { kind: Tuple { exprs }.into(), span: Span(start, p.loc()) },
)
.into(),
}
@@ -105,7 +102,7 @@ pub fn expr(p: &mut Parser, power: u8) -> PResult<Expr> {
}
_ => Err(p.error(Unexpected(op), parsing))?,
},
extents: Span(start, p.loc()),
span: Span(start, p.loc()),
};
continue;
}
@@ -120,7 +117,7 @@ pub fn expr(p: &mut Parser, power: u8) -> PResult<Expr> {
let tail = expr(p, after)?;
head = Expr {
kind: Binary { kind, parts: (head, tail).into() }.into(),
extents: Span(start, p.loc()),
span: Span(start, p.loc()),
};
continue;
}
@@ -135,7 +132,7 @@ pub fn expr(p: &mut Parser, power: u8) -> PResult<Expr> {
let tail = expr(p, after)?;
head = Expr {
kind: Modify { kind, parts: (head, tail).into() }.into(),
extents: Span(start, p.loc()),
span: Span(start, p.loc()),
};
continue;
}
@@ -152,7 +149,7 @@ pub fn expr(p: &mut Parser, power: u8) -> PResult<Expr> {
let tail = expr(p, after)?;
head = Expr {
kind: Assign { parts: (head, tail).into() }.into(),
extents: Span(start, p.loc()),
span: Span(start, p.loc()),
};
continue;
@@ -166,8 +163,7 @@ pub fn expr(p: &mut Parser, power: u8) -> PResult<Expr> {
p.consume_peeked();
let ty = Ty::parse(p)?;
head =
Expr { kind: Cast { head: head.into(), ty }.into(), extents: Span(start, p.loc()) };
head = Expr { kind: Cast { head: head.into(), ty }.into(), span: Span(start, p.loc()) };
continue;
}