15.2 Mod SDK
compiler-sdk package, Beskid.Syntax mirror, Collector contract hierarchy, query pipeline.
Mod SDK
The compiler-sdk package is the Beskid-side API for mods: contracts and Beskid.Syntax operations, not string templates.
Full normative article: Compiler Mod SDK.
Contract hierarchy
Section titled “Contract hierarchy”| Contract | Role |
|---|---|
Collector | Declarative target collection and scope narrowing |
Generator | Typed AST contributions (incremental by default) |
Analyzer | Diagnostics + rewrite fixes on merged program |
Rewriter<TSource, TTarget> | Result<TTarget, FixError> Rewrite(...) |
AttributeGenerator | Exported attributes (e.g. serialization mods) |
classDiagram
accTitle: Mod SDK contracts
accDescr: The compiler-sdk package declares the Collector, Generator, Analyzer, Rewriter and AttributeGenerator contracts, each with one entry method.
class Collector {
<<contract>>
Collect(CollectRequest) CollectTargetSet
}
class Generator {
<<contract>>
Generate(GenerationRequest) GeneratedSyntaxContribution
}
class Analyzer {
<<contract>>
Analyze(AnalysisRequest) AnalysisResult
}
class Rewriter~TSourceNode, TTargetNode~ {
<<contract>>
Rewrite(TSourceNode) Result
}
class AttributeGenerator {
<<contract>>
Attributes(AttributeGenerationRequest) AttributeDeclarationSet
}
Text equivalent: Each SDK contract has one entry method. Collector returns a target set, Generator a typed syntax contribution, Analyzer diagnostics with fixes, Rewriter a Result of the target node, and AttributeGenerator a set of attribute declarations.
Beskid.Syntax
Section titled “Beskid.Syntax”Nodeis a contract; traversal usesNodeRef{ syntaxGenerationId, nodeId }Beskid.Compiler.Query+ fluent DSL (Select,WhereKind,Replace, …)- No source text emission: hosts merge typed trees, then re-parse under bounds
Generated mirrors come from beskid_ast_reflect_gen. Rust AST is canonical; SDK sources are not hand-duplicated parallel syntax.
Rust host areas
Section titled “Rust host areas”Implementation specs under Compiler mods: