export type SearchGrammarType = Expression type Expression = OrQuery | AndQuery | Hierarchy | DeepHierarchy | Tag interface AndQuery { type: 'AND' parts: Expression[] // Parts is an array of Expressions due to the recursive nature of AndQuery in your grammar } interface Tag { type: 'TAG' symbol: string name: string } interface OrQuery { type: 'OR' parts: Expression[] // Changed to an array of exactly two expressions, since OR is binary } interface Hierarchy { type: 'HIERARCHY' parent: Expression // Parent can be any Expression (including another Hierarchy) child: Expression // Child can be any Expression (including another Hierarchy) } interface DeepHierarchy { type: 'DEEP_HIERARCHY' parent: Expression // Parent can be any Expression (including another Hierarchy) child: Expression // Child can be any Expression (including another Hierarchy) }