feat(type-system): implement concept_comparison with pattern matching
Added complete support for the new type system syntax including: - concept: Base type declarations - sub_concept: Enum and record sub-type definitions - concept_comparison: Compile-time pattern matching with conditional guards Parser changes: - Added VariantPattern, FieldCondition, and Condition AST nodes - Implemented "is" keyword for pattern matching (e.g., "CupType is Glass or CupType is Plastic") - Added Value::Any variant to support universal type matching - Disambiguated enum-like vs record-like sub_concept syntax LSP updates: - Added Value::Any match arms across code_actions, completion, hover, inlay_hints, and semantic_tokens - Type inference and formatting support for Any values Example fixes: - Fixed syntax error in baker-family behaviors (missing closing brace in nested if) - Removed deprecated core_enums.sb file
This commit is contained in:
@@ -69,7 +69,6 @@ pub enum Declaration {
|
||||
Relationship(Relationship),
|
||||
Location(Location),
|
||||
Species(Species),
|
||||
Enum(EnumDecl),
|
||||
Concept(ConceptDecl),
|
||||
SubConcept(SubConceptDecl),
|
||||
ConceptComparison(ConceptComparisonDecl),
|
||||
@@ -171,6 +170,7 @@ pub enum Value {
|
||||
Object(Vec<Field>),
|
||||
ProseBlock(ProseBlock),
|
||||
Override(Override),
|
||||
Any, // Special marker for type system - matches any value
|
||||
}
|
||||
|
||||
/// Time literal (HH:MM or HH:MM:SS)
|
||||
@@ -409,14 +409,6 @@ pub struct Species {
|
||||
pub span: Span,
|
||||
}
|
||||
|
||||
/// Enum definition
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub struct EnumDecl {
|
||||
pub name: String,
|
||||
pub variants: Vec<String>,
|
||||
pub span: Span,
|
||||
}
|
||||
|
||||
/// Concept declaration - base type definition
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub struct ConceptDecl {
|
||||
@@ -440,21 +432,35 @@ pub enum SubConceptKind {
|
||||
Record { fields: Vec<Field> },
|
||||
}
|
||||
|
||||
/// Concept comparison - compile-time enum mapping between two concepts
|
||||
/// Concept comparison - compile-time pattern matching for concept variants
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub struct ConceptComparisonDecl {
|
||||
pub name: String,
|
||||
pub left_concept: String,
|
||||
pub right_concept: String,
|
||||
pub mappings: Vec<ConceptMapping>,
|
||||
pub variants: Vec<VariantPattern>,
|
||||
pub span: Span,
|
||||
}
|
||||
|
||||
/// A single mapping entry in a concept comparison
|
||||
/// A variant pattern with field conditions
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub struct ConceptMapping {
|
||||
pub left_variant: String,
|
||||
pub right_variant: String,
|
||||
pub struct VariantPattern {
|
||||
pub name: String,
|
||||
pub conditions: Vec<FieldCondition>,
|
||||
pub span: Span,
|
||||
}
|
||||
|
||||
/// A condition on a field within a variant pattern
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub struct FieldCondition {
|
||||
pub field_name: String,
|
||||
pub condition: Condition,
|
||||
pub span: Span,
|
||||
}
|
||||
|
||||
/// The type of condition for field matching
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub enum Condition {
|
||||
Any, // matches any value
|
||||
Is(Vec<String>), // matches specific values (e.g., "is Glass or is Plastic")
|
||||
}
|
||||
|
||||
/// Expression AST for conditions and queries
|
||||
|
||||
Reference in New Issue
Block a user