Skip to main content

microcad_lang/parse/
identifier.rs

1// Copyright © 2025-2026 The µcad authors <info@ucad.xyz>
2// SPDX-License-Identifier: AGPL-3.0-or-later
3
4use crate::{parse::*, parser::*, src_ref::*, syntax::*};
5use microcad_syntax::ast;
6
7impl FromAst for Identifier {
8    type AstNode = ast::Identifier;
9
10    fn from_ast(node: &Self::AstNode, context: &ParseContext) -> Result<Self, ParseError> {
11        Ok(Self(Refer::new(node.name.clone(), context.src_ref(&node.span))))
12    }
13}
14
15impl FromAst for QualifiedName {
16    type AstNode = ast::QualifiedName;
17
18    fn from_ast(node: &Self::AstNode, context: &ParseContext) -> Result<Self, ParseError> {
19        let parts = node.parts.iter()
20            .map(|ident| Identifier::from_ast(ident, context))
21            .collect::<Result<Vec<_>, _>>()?;
22        Ok(Self::new(parts, context.src_ref(&node.span)))
23    }
24}