/// <summary> /// Visits a grammar node. /// </summary> /// <param name="grammarNode"></param> /// <param name="argument">The argument data to be passed to the visitor methods.</param> /// <returns>The result of visiting this node.</returns> public virtual TReturn Visit(GrammarNode <Char> grammarNode, TArgument argument) { if (grammarNode is null) { throw new ArgumentNullException(nameof(grammarNode)); } return(grammarNode.Kind switch { GrammarNodeKind.Alternation => this.VisitAlternation((Alternation <Char>)grammarNode, argument), GrammarNodeKind.Repetition => this.VisitRepetition((Repetition <Char>)grammarNode, argument), GrammarNodeKind.Sequence => this.VisitSequence((Sequence <Char>)grammarNode, argument), GrammarNodeKind.CharacterRange => this.VisitCharacterRange((CharacterRange)grammarNode, argument), GrammarNodeKind.CharacterSet => this.VisitSet((Set)grammarNode, argument), GrammarNodeKind.CharacterTerminal => this.VisitCharacterTerminal((CharacterTerminal)grammarNode, argument), GrammarNodeKind.CharacterPositiveLookahead => this.VisitPositiveLookahead((PositiveLookahead)grammarNode, argument), GrammarNodeKind.CharacterNamedBackreference => this.VisitNamedBackreference((NamedBackreference)grammarNode, argument), GrammarNodeKind.CharacterNamedCapture => this.VisitNamedCapture((NamedCapture)grammarNode, argument), GrammarNodeKind.CharacterNegatedRange => this.VisitNegatedCharacterRange((NegatedCharacterRange)grammarNode, argument), GrammarNodeKind.CharacterNegatedSet => this.VisitNegatedSet((NegatedSet)grammarNode, argument), GrammarNodeKind.CharacterNegatedTerminal => this.VisitNegatedCharacterTerminal((NegatedCharacterTerminal)grammarNode, argument), GrammarNodeKind.CharacterNegatedUnicodeCategoryTerminal => this.VisitNegatedUnicodeCategoryTerminal((NegatedUnicodeCategoryTerminal)grammarNode, argument), GrammarNodeKind.CharacterNegativeLookahead => this.VisitNegativeLookahead((NegativeLookahead)grammarNode, argument), GrammarNodeKind.CharacterNumberedBackreference => this.VisitNumberedBackreference((NumberedBackreference)grammarNode, argument), GrammarNodeKind.CharacterNumberedCapture => this.VisitNumberedCapture((NumberedCapture)grammarNode, argument), GrammarNodeKind.CharacterStringTerminal => this.VisitStringTerminal((StringTerminal)grammarNode, argument), GrammarNodeKind.CharacterUnicodeCategoryTerminal => this.VisitUnicodeCategoryTerminal((UnicodeCategoryTerminal)grammarNode, argument), GrammarNodeKind.CharacterOptimizedSet => this.VisitOptimizedSet((OptimizedSet)grammarNode, argument), GrammarNodeKind.CharacterOptimizedNegatedSet => this.VisitOptimizedNegatedSet((OptimizedNegatedSet)grammarNode, argument), GrammarNodeKind.CharacterAny => this.VisitAny((Any)grammarNode, argument), _ => throw new NotSupportedException($"Node of type {grammarNode.GetType().Name} is not supported."), });
public static GrammarNode <Char>?Negate(this GrammarNode <Char> grammarNode) { return(grammarNode?.Kind switch { null => null, GrammarNodeKind.CharacterTerminal => !(CharacterTerminal)grammarNode, GrammarNodeKind.CharacterRange => !(CharacterRange)grammarNode, GrammarNodeKind.CharacterPositiveLookahead => !(PositiveLookahead)grammarNode, GrammarNodeKind.CharacterNegatedRange => !(NegatedCharacterRange)grammarNode, GrammarNodeKind.CharacterNegatedTerminal => !(NegatedCharacterTerminal)grammarNode, GrammarNodeKind.CharacterNegatedSet => !(NegatedSet)grammarNode, GrammarNodeKind.CharacterNegatedUnicodeCategoryTerminal => !(NegatedUnicodeCategoryTerminal)grammarNode, GrammarNodeKind.CharacterNegativeLookahead => !(NegativeLookahead)grammarNode, GrammarNodeKind.CharacterSet => !(Set)grammarNode, GrammarNodeKind.CharacterUnicodeCategoryTerminal => !(UnicodeCategoryTerminal)grammarNode, GrammarNodeKind.CharacterOptimizedSet => !(OptimizedSet)grammarNode, GrammarNodeKind.CharacterOptimizedNegatedSet => !(OptimizedNegatedSet)grammarNode, _ => throw new InvalidOperationException($"Cannot negate a node of the type {grammarNode.GetType().Name}."), });