Parent
Part of the MagicAST restructure milestone. Phase 3 of 5. Reuses the attribute-discovery + reflection-based registry pattern established in Phase 2, applied to parser dispatch instead of JSON serialization.
What to build
Today, OracleParser.ParseClause (in libs/magic-ast/Parsing/OracleParser.cs, around line 112) contains a switch over classification.Kind that routes each clause to the appropriate parser:
return classification.Kind switch
{
AbilityKind.Triggered => triggeredParser.Parse(...),
AbilityKind.Activated => activatedParser.Parse(...),
AbilityKind.Static => staticParser.Parse(...),
// ... etc
};
Adding a new AbilityKind requires editing this switch — another shared-file merge hotspot.
Replace with a parser registry:
// New interface (or similar shape — implementer's choice on exact signature):
public interface IAbilityParser
{
Ability Parse(OracleClause clause, ClauseClassification classification);
}
// New attribute that pins a parser to an AbilityKind:
[OracleAbilityParser(AbilityKind.Triggered)]
public sealed class TriggeredAbilityParser : IAbilityParser { ... }
// New registry — scans for IAbilityParser implementations at startup,
// builds AbilityKind -> parser map, caches.
public sealed class AbilityParserRegistry { ... }
// OracleParser becomes a thin coordinator:
return _registry.GetParser(classification.Kind).Parse(clause, classification);
The FallbackParser should also be registered (likely via a special-cased attribute like [OracleAbilityParser(AbilityKind.Unparsed)] or via a [OracleAbilityFallback] attribute) so that no special-casing leaks back into OracleParser.
Acceptance criteria
Blocked by
Parent
Part of the MagicAST restructure milestone. Phase 3 of 5. Reuses the attribute-discovery + reflection-based registry pattern established in Phase 2, applied to parser dispatch instead of JSON serialization.
What to build
Today,
OracleParser.ParseClause(inlibs/magic-ast/Parsing/OracleParser.cs, around line 112) contains aswitchoverclassification.Kindthat routes each clause to the appropriate parser:Adding a new
AbilityKindrequires editing this switch — another shared-file merge hotspot.Replace with a parser registry:
The
FallbackParsershould also be registered (likely via a special-cased attribute like[OracleAbilityParser(AbilityKind.Unparsed)]or via a[OracleAbilityFallback]attribute) so that no special-casing leaks back intoOracleParser.Acceptance criteria
OracleParser.ParseClausecontains noswitchoverAbilityKindfor parser dispatch.ActivatedAbilityParser,StaticAbilityParser,TriggeredAbilityParser, andFallbackParserall implement the new parser interface and are decorated with the new attribute (or its fallback variant).IAbilityParserimplementations once at startup and caches the result for the process lifetime.OracleParser.csor any other existing file.[OracleAbilityParser]attribute produces a clear startup error (don't silently let one win).AbilityKindwith no registered parser produces a clear error (either at startup, if discoverable, or when first encountered).test-baseline.json.Blocked by