namespace ParadoxSaveParser.Lib; /// /// One step of a compiled query. Each step points at the step its matched nodes /// are searched with, so the query runs in a single pass down the tree. /// public interface ISearchExpression { /// Tests one node against this step of the query. /// The node being tested, identified by its key or its position. /// /// On a match, the step for the node's children, or null if the node is kept whole. /// Undefined when the method returns false. /// /// true if the node is selected by this step bool DoesMatch(MatchCandidate candidate, out ISearchExpression? nextSearchExpression); /// /// Encodes the literal keys of this step and of every step below it. /// Called by , never during matching. /// void ReEncode(Encoding encoding); } /// /// A node the query is tested against: its raw key and its position in the parent. /// The key stays undecoded, so a rejected key never becomes a string. /// public readonly ref struct MatchCandidate { /// Undecoded key of the node. Empty for list items. public readonly ReadOnlySpan Key; /// Position of the node among its siblings, counted from 0. public readonly int Index; /// A list item, which has a position but no key. public MatchCandidate(int index) { Key = default; Index = index; } /// A dictionary entry, which has both a key and a position. public MatchCandidate(int index, ReadOnlySpan key) { Key = key; Index = index; } }