feat(ast): add type system declaration nodes
Added AST structures for new type system: - ConceptDecl: Base type definition - SubConceptDecl: Enum or record subtype with SubConceptKind - ConceptComparisonDecl: Compile-time enum mapping - ConceptMapping: Individual mapping entry Added Declaration enum variants and stubs throughout codebase for LSP, resolve, and semantic analysis modules.
This commit is contained in:
@@ -1704,6 +1704,9 @@ fn get_declaration_name(decl: &crate::syntax::ast::Declaration) -> String {
|
||||
| Declaration::Schedule(s) => s.name.clone(),
|
||||
| Declaration::Behavior(b) => b.name.clone(),
|
||||
| Declaration::Use(_) => "use".to_string(),
|
||||
| Declaration::Concept(c) => c.name.clone(),
|
||||
| Declaration::SubConcept(sc) => sc.name.clone(),
|
||||
| Declaration::ConceptComparison(cc) => cc.name.clone(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1722,6 +1725,9 @@ fn get_declaration_type_name(decl: &crate::syntax::ast::Declaration) -> &'static
|
||||
| Declaration::Schedule(_) => "Schedule",
|
||||
| Declaration::Behavior(_) => "Behavior",
|
||||
| Declaration::Use(_) => "Use",
|
||||
| Declaration::Concept(_) => "Concept",
|
||||
| Declaration::SubConcept(_) => "Sub Concept",
|
||||
| Declaration::ConceptComparison(_) => "Concept Comparison",
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1953,6 +1959,9 @@ fn get_declaration_span(decl: &crate::syntax::ast::Declaration) -> Span {
|
||||
| Declaration::Schedule(s) => s.span.clone(),
|
||||
| Declaration::Behavior(b) => b.span.clone(),
|
||||
| Declaration::Use(u) => u.span.clone(),
|
||||
| Declaration::Concept(c) => c.span.clone(),
|
||||
| Declaration::SubConcept(sc) => sc.span.clone(),
|
||||
| Declaration::ConceptComparison(cc) => cc.span.clone(),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -179,6 +179,9 @@ fn get_declaration_name(decl: &Declaration) -> Option<String> {
|
||||
| Declaration::Schedule(s) => Some(s.name.clone()),
|
||||
| Declaration::Behavior(b) => Some(b.name.clone()),
|
||||
| Declaration::Use(_) => None,
|
||||
| Declaration::Concept(_) |
|
||||
Declaration::SubConcept(_) |
|
||||
Declaration::ConceptComparison(_) => None, // TODO: Implement hover for type system
|
||||
}
|
||||
}
|
||||
|
||||
@@ -196,6 +199,9 @@ fn format_declaration_hover(decl: &Declaration, _kind: &DeclKind) -> Hover {
|
||||
| Declaration::Schedule(s) => format_schedule_hover(s),
|
||||
| Declaration::Behavior(b) => format_behavior_hover(b),
|
||||
| Declaration::Use(_) => "**use** declaration".to_string(),
|
||||
| Declaration::Concept(_) => "**concept** declaration".to_string(),
|
||||
| Declaration::SubConcept(_) => "**sub_concept** declaration".to_string(),
|
||||
| Declaration::ConceptComparison(_) => "**concept_comparison** declaration".to_string(),
|
||||
};
|
||||
|
||||
Hover {
|
||||
|
||||
@@ -407,6 +407,12 @@ pub fn get_semantic_tokens(doc: &Document) -> Option<SemanticTokensResult> {
|
||||
}
|
||||
}
|
||||
},
|
||||
| Declaration::Concept(_) |
|
||||
Declaration::SubConcept(_) |
|
||||
Declaration::ConceptComparison(_) => {
|
||||
// TODO: Implement semantic highlighting for type system
|
||||
// declarations
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -96,6 +96,9 @@ fn extract_declaration_symbol(
|
||||
extract_variant_symbols(&e.variants, positions),
|
||||
),
|
||||
| Declaration::Use(_) => return None, // Use statements don't create symbols
|
||||
| Declaration::Concept(_) |
|
||||
Declaration::SubConcept(_) |
|
||||
Declaration::ConceptComparison(_) => return None, // TODO: Implement symbols for type system
|
||||
};
|
||||
|
||||
let (start_line, start_col) = positions.offset_to_position(span.start);
|
||||
|
||||
@@ -98,6 +98,11 @@ pub fn convert_file_with_all_files(
|
||||
// Use declarations are handled during name resolution, not
|
||||
// conversion
|
||||
},
|
||||
| ast::Declaration::Concept(_) |
|
||||
ast::Declaration::SubConcept(_) |
|
||||
ast::Declaration::ConceptComparison(_) => {
|
||||
// TODO: Implement conversion for type system declarations
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -139,6 +139,10 @@ impl NameTable {
|
||||
| Declaration::Location(l) => (l.name.clone(), DeclKind::Location, l.span.clone()),
|
||||
| Declaration::Species(s) => (s.name.clone(), DeclKind::Species, s.span.clone()),
|
||||
| Declaration::Enum(e) => (e.name.clone(), DeclKind::Enum, e.span.clone()),
|
||||
| Declaration::Concept(_) |
|
||||
Declaration::SubConcept(_) |
|
||||
Declaration::ConceptComparison(_) => continue, /* TODO: Implement name resolution
|
||||
* for type system */
|
||||
};
|
||||
|
||||
// For now, qualified path is just the name
|
||||
|
||||
@@ -191,6 +191,11 @@ fn find_references_in_declaration(
|
||||
| Declaration::Use(_) => {
|
||||
// Use statements are handled separately
|
||||
},
|
||||
| Declaration::Concept(_) |
|
||||
Declaration::SubConcept(_) |
|
||||
Declaration::ConceptComparison(_) => {
|
||||
// TODO: Implement reference finding for type system
|
||||
},
|
||||
}
|
||||
|
||||
refs
|
||||
|
||||
@@ -70,6 +70,9 @@ pub enum Declaration {
|
||||
Location(Location),
|
||||
Species(Species),
|
||||
Enum(EnumDecl),
|
||||
Concept(ConceptDecl),
|
||||
SubConcept(SubConceptDecl),
|
||||
ConceptComparison(ConceptComparisonDecl),
|
||||
}
|
||||
|
||||
/// Use statement for importing definitions
|
||||
@@ -414,6 +417,46 @@ pub struct EnumDecl {
|
||||
pub span: Span,
|
||||
}
|
||||
|
||||
/// Concept declaration - base type definition
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub struct ConceptDecl {
|
||||
pub name: String,
|
||||
pub span: Span,
|
||||
}
|
||||
|
||||
/// Sub-concept declaration - enum or record subtype
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub struct SubConceptDecl {
|
||||
pub name: String,
|
||||
pub parent_concept: String,
|
||||
pub kind: SubConceptKind,
|
||||
pub span: Span,
|
||||
}
|
||||
|
||||
/// Sub-concept can be either enum-like or record-like
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub enum SubConceptKind {
|
||||
Enum { variants: Vec<String> },
|
||||
Record { fields: Vec<Field> },
|
||||
}
|
||||
|
||||
/// Concept comparison - compile-time enum mapping between two concepts
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub struct ConceptComparisonDecl {
|
||||
pub name: String,
|
||||
pub left_concept: String,
|
||||
pub right_concept: String,
|
||||
pub mappings: Vec<ConceptMapping>,
|
||||
pub span: Span,
|
||||
}
|
||||
|
||||
/// A single mapping entry in a concept comparison
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub struct ConceptMapping {
|
||||
pub left_variant: String,
|
||||
pub right_variant: String,
|
||||
}
|
||||
|
||||
/// Expression AST for conditions and queries
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub enum Expr {
|
||||
|
||||
Reference in New Issue
Block a user