feat(grammar): add type system nodes to tree-sitter
Added grammar rules for v0.3 type system declarations: - concept_declaration: semicolon-terminated base type - sub_concept: enum and record forms with dot notation - concept_comparison: nested pattern matching with variant_pattern - any_type: named node for the 'any' keyword - template species extension: optional ': Species' syntax Updated query files: - highlights.scm: new keywords and named field highlights - outline.scm: concept/sub_concept/concept_comparison in outline - indents.scm: indentation for new brace-delimited nodes Fixed pre-existing query issues: - Replaced invalid repeat_node reference with decorator_node - Removed invalid '?' punctuation reference Added comprehensive test corpus (type_system.txt) covering: - concept declaration (simple and multiple) - sub_concept enum and record forms - concept_comparison with any/is conditions - template with species extension - full combined example
This commit is contained in:
360
tree-sitter-storybook/test/corpus/type_system.txt
Normal file
360
tree-sitter-storybook/test/corpus/type_system.txt
Normal file
@@ -0,0 +1,360 @@
|
||||
==================
|
||||
Concept declaration
|
||||
==================
|
||||
|
||||
concept Cup;
|
||||
|
||||
---
|
||||
|
||||
(source_file
|
||||
(declaration
|
||||
(concept_declaration
|
||||
name: (identifier))))
|
||||
|
||||
==================
|
||||
Multiple concept declarations
|
||||
==================
|
||||
|
||||
concept Cup;
|
||||
concept Customer;
|
||||
concept Vendor;
|
||||
|
||||
---
|
||||
|
||||
(source_file
|
||||
(declaration
|
||||
(concept_declaration
|
||||
name: (identifier)))
|
||||
(declaration
|
||||
(concept_declaration
|
||||
name: (identifier)))
|
||||
(declaration
|
||||
(concept_declaration
|
||||
name: (identifier))))
|
||||
|
||||
==================
|
||||
Sub-concept - enum form
|
||||
==================
|
||||
|
||||
sub_concept Cup.Size {
|
||||
Small,
|
||||
Medium,
|
||||
Large
|
||||
}
|
||||
|
||||
---
|
||||
|
||||
(source_file
|
||||
(declaration
|
||||
(sub_concept
|
||||
parent: (identifier)
|
||||
name: (identifier)
|
||||
body: (sub_concept_enum_body
|
||||
(identifier)
|
||||
(identifier)
|
||||
(identifier)))))
|
||||
|
||||
==================
|
||||
Sub-concept - record form with any
|
||||
==================
|
||||
|
||||
sub_concept Vendor.Inventory {
|
||||
Bread: any,
|
||||
Pastries: any,
|
||||
Cakes: any,
|
||||
Cup: any
|
||||
}
|
||||
|
||||
---
|
||||
|
||||
(source_file
|
||||
(declaration
|
||||
(sub_concept
|
||||
parent: (identifier)
|
||||
name: (identifier)
|
||||
body: (sub_concept_record_body
|
||||
(sub_concept_field
|
||||
name: (identifier)
|
||||
type: (any_type))
|
||||
(sub_concept_field
|
||||
name: (identifier)
|
||||
type: (any_type))
|
||||
(sub_concept_field
|
||||
name: (identifier)
|
||||
type: (any_type))
|
||||
(sub_concept_field
|
||||
name: (identifier)
|
||||
type: (any_type))))))
|
||||
|
||||
==================
|
||||
Sub-concept - record form with typed fields
|
||||
==================
|
||||
|
||||
sub_concept Vendor.Inventory {
|
||||
Bread: any,
|
||||
Pastries: Number
|
||||
}
|
||||
|
||||
---
|
||||
|
||||
(source_file
|
||||
(declaration
|
||||
(sub_concept
|
||||
parent: (identifier)
|
||||
name: (identifier)
|
||||
body: (sub_concept_record_body
|
||||
(sub_concept_field
|
||||
name: (identifier)
|
||||
type: (any_type))
|
||||
(sub_concept_field
|
||||
name: (identifier)
|
||||
type: (identifier))))))
|
||||
|
||||
==================
|
||||
Concept comparison with any conditions
|
||||
==================
|
||||
|
||||
concept_comparison NotInterested {
|
||||
NotInterested: {
|
||||
Cup.Size: any,
|
||||
Cup.Type: any,
|
||||
Cup.Color: any
|
||||
}
|
||||
}
|
||||
|
||||
---
|
||||
|
||||
(source_file
|
||||
(declaration
|
||||
(concept_comparison
|
||||
name: (identifier)
|
||||
(variant_pattern
|
||||
name: (identifier)
|
||||
(field_condition
|
||||
sub_concept: (dotted_path
|
||||
(identifier)
|
||||
(identifier))
|
||||
condition: (condition_expr
|
||||
(any_type)))
|
||||
(field_condition
|
||||
sub_concept: (dotted_path
|
||||
(identifier)
|
||||
(identifier))
|
||||
condition: (condition_expr
|
||||
(any_type)))
|
||||
(field_condition
|
||||
sub_concept: (dotted_path
|
||||
(identifier)
|
||||
(identifier))
|
||||
condition: (condition_expr
|
||||
(any_type)))))))
|
||||
|
||||
==================
|
||||
Concept comparison with is conditions
|
||||
==================
|
||||
|
||||
concept_comparison Interest {
|
||||
Interested: {
|
||||
Cup.Type: Cup.Type is Glass or Cup.Type is Plastic,
|
||||
Cup.Color: Cup.Color is Red
|
||||
}
|
||||
}
|
||||
|
||||
---
|
||||
|
||||
(source_file
|
||||
(declaration
|
||||
(concept_comparison
|
||||
name: (identifier)
|
||||
(variant_pattern
|
||||
name: (identifier)
|
||||
(field_condition
|
||||
sub_concept: (dotted_path
|
||||
(identifier)
|
||||
(identifier))
|
||||
condition: (condition_expr
|
||||
(is_condition
|
||||
(dotted_path
|
||||
(identifier)
|
||||
(identifier))
|
||||
(identifier)
|
||||
(dotted_path
|
||||
(identifier)
|
||||
(identifier))
|
||||
(identifier))))
|
||||
(field_condition
|
||||
sub_concept: (dotted_path
|
||||
(identifier)
|
||||
(identifier))
|
||||
condition: (condition_expr
|
||||
(is_condition
|
||||
(dotted_path
|
||||
(identifier)
|
||||
(identifier))
|
||||
(identifier))))))))
|
||||
|
||||
==================
|
||||
Concept comparison with multiple variants
|
||||
==================
|
||||
|
||||
concept_comparison FoodQuality {
|
||||
Excellent: {
|
||||
Food.Freshness: Food.Freshness is Fresh
|
||||
},
|
||||
Poor: {
|
||||
Food.Freshness: Food.Freshness is Stale or Food.Freshness is Spoiled
|
||||
}
|
||||
}
|
||||
|
||||
---
|
||||
|
||||
(source_file
|
||||
(declaration
|
||||
(concept_comparison
|
||||
name: (identifier)
|
||||
(variant_pattern
|
||||
name: (identifier)
|
||||
(field_condition
|
||||
sub_concept: (dotted_path
|
||||
(identifier)
|
||||
(identifier))
|
||||
condition: (condition_expr
|
||||
(is_condition
|
||||
(dotted_path
|
||||
(identifier)
|
||||
(identifier))
|
||||
(identifier)))))
|
||||
(variant_pattern
|
||||
name: (identifier)
|
||||
(field_condition
|
||||
sub_concept: (dotted_path
|
||||
(identifier)
|
||||
(identifier))
|
||||
condition: (condition_expr
|
||||
(is_condition
|
||||
(dotted_path
|
||||
(identifier)
|
||||
(identifier))
|
||||
(identifier)
|
||||
(dotted_path
|
||||
(identifier)
|
||||
(identifier))
|
||||
(identifier))))))))
|
||||
|
||||
==================
|
||||
Template with species extension
|
||||
==================
|
||||
|
||||
template Person: Human {
|
||||
age: 0..100
|
||||
name: ""
|
||||
}
|
||||
|
||||
---
|
||||
|
||||
(source_file
|
||||
(declaration
|
||||
(template
|
||||
name: (identifier)
|
||||
species: (identifier)
|
||||
(field
|
||||
name: (dotted_path (identifier))
|
||||
value: (value (range (integer) (integer))))
|
||||
(field
|
||||
name: (dotted_path (identifier))
|
||||
value: (value (string))))))
|
||||
|
||||
==================
|
||||
Full type system example
|
||||
==================
|
||||
|
||||
concept Cup;
|
||||
|
||||
sub_concept Cup.Size {
|
||||
Small,
|
||||
Medium,
|
||||
Large
|
||||
}
|
||||
|
||||
sub_concept Cup.Type {
|
||||
Ceramic,
|
||||
Glass,
|
||||
Plastic
|
||||
}
|
||||
|
||||
concept_comparison CupPreference {
|
||||
Preferred: {
|
||||
Cup.Size: any,
|
||||
Cup.Type: Cup.Type is Glass or Cup.Type is Ceramic
|
||||
},
|
||||
Avoided: {
|
||||
Cup.Size: any,
|
||||
Cup.Type: Cup.Type is Plastic
|
||||
}
|
||||
}
|
||||
|
||||
---
|
||||
|
||||
(source_file
|
||||
(declaration
|
||||
(concept_declaration
|
||||
name: (identifier)))
|
||||
(declaration
|
||||
(sub_concept
|
||||
parent: (identifier)
|
||||
name: (identifier)
|
||||
body: (sub_concept_enum_body
|
||||
(identifier)
|
||||
(identifier)
|
||||
(identifier))))
|
||||
(declaration
|
||||
(sub_concept
|
||||
parent: (identifier)
|
||||
name: (identifier)
|
||||
body: (sub_concept_enum_body
|
||||
(identifier)
|
||||
(identifier)
|
||||
(identifier))))
|
||||
(declaration
|
||||
(concept_comparison
|
||||
name: (identifier)
|
||||
(variant_pattern
|
||||
name: (identifier)
|
||||
(field_condition
|
||||
sub_concept: (dotted_path
|
||||
(identifier)
|
||||
(identifier))
|
||||
condition: (condition_expr
|
||||
(any_type)))
|
||||
(field_condition
|
||||
sub_concept: (dotted_path
|
||||
(identifier)
|
||||
(identifier))
|
||||
condition: (condition_expr
|
||||
(is_condition
|
||||
(dotted_path
|
||||
(identifier)
|
||||
(identifier))
|
||||
(identifier)
|
||||
(dotted_path
|
||||
(identifier)
|
||||
(identifier))
|
||||
(identifier)))))
|
||||
(variant_pattern
|
||||
name: (identifier)
|
||||
(field_condition
|
||||
sub_concept: (dotted_path
|
||||
(identifier)
|
||||
(identifier))
|
||||
condition: (condition_expr
|
||||
(any_type)))
|
||||
(field_condition
|
||||
sub_concept: (dotted_path
|
||||
(identifier)
|
||||
(identifier))
|
||||
condition: (condition_expr
|
||||
(is_condition
|
||||
(dotted_path
|
||||
(identifier)
|
||||
(identifier))
|
||||
(identifier))))))))
|
||||
Reference in New Issue
Block a user