26 lines
614 B
Rust
26 lines
614 B
Rust
use super::*;
|
|
|
|
pub struct Ident {
|
|
pub name: String,
|
|
pub span: Span,
|
|
}
|
|
|
|
impl Node for Ident {
|
|
fn parse(ctx: &mut super::ParseCtx) -> Result<Self, crate::io::CompilerMsg> {
|
|
match ctx.expect_next()? {
|
|
Token::Ident(ident) => Ok(ctx.ident(ident)),
|
|
t => ctx.unexpected(t, "an identifier"),
|
|
}
|
|
}
|
|
|
|
fn fmt(&self, f: &mut std::fmt::Formatter, _: DisplayCtx) -> std::fmt::Result {
|
|
write!(f, "{}", self.name)
|
|
}
|
|
}
|
|
|
|
impl std::fmt::Display for Ident {
|
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
|
self.name.fmt(f)
|
|
}
|
|
}
|